applied codestyle

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@656928 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Maria Odea B. Ching 2008-05-16 03:02:11 +00:00
parent db59374ab7
commit 9bf8c6b96b
6 changed files with 428 additions and 351 deletions

View File

@ -50,7 +50,7 @@ public class RepositoryServlet
extends AbstractWebdavServlet
implements ConfigurationListener
{
private Logger log = LoggerFactory.getLogger(RepositoryServlet.class);
private Logger log = LoggerFactory.getLogger( RepositoryServlet.class );
private ArchivaConfiguration configuration;
@ -64,17 +64,16 @@ public class RepositoryServlet
private final Object reloadLock = new Object();
public void init(javax.servlet.ServletConfig servletConfig)
public void init( javax.servlet.ServletConfig servletConfig )
throws ServletException
{
super.init(servletConfig);
initServers(servletConfig);
super.init( servletConfig );
initServers( servletConfig );
}
/**
* Service the given request.
* This method has been overridden and copy/pasted to allow better exception handling
* and to support different realms
* Service the given request. This method has been overridden and copy/pasted to allow better exception handling and
* to support different realms
*
* @param request
* @param response
@ -82,62 +81,79 @@ public class RepositoryServlet
* @throws java.io.IOException
*/
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
protected void service( HttpServletRequest request, HttpServletResponse response )
throws ServletException, IOException
{
WebdavRequest webdavRequest = new WebdavRequestImpl(request, getLocatorFactory());
WebdavRequest webdavRequest = new WebdavRequestImpl( request, getLocatorFactory() );
// DeltaV requires 'Cache-Control' header for all methods except 'VERSION-CONTROL' and 'REPORT'.
int methodCode = DavMethods.getMethodCode(request.getMethod());
boolean noCache = DavMethods.isDeltaVMethod(webdavRequest) && !(DavMethods.DAV_VERSION_CONTROL == methodCode || DavMethods.DAV_REPORT == methodCode);
WebdavResponse webdavResponse = new WebdavResponseImpl(response, noCache);
try {
int methodCode = DavMethods.getMethodCode( request.getMethod() );
boolean noCache =
DavMethods.isDeltaVMethod( webdavRequest ) &&
!( DavMethods.DAV_VERSION_CONTROL == methodCode || DavMethods.DAV_REPORT == methodCode );
WebdavResponse webdavResponse = new WebdavResponseImpl( response, noCache );
try
{
// make sure there is a authenticated user
if (!getDavSessionProvider().attachSession(webdavRequest)) {
if ( !getDavSessionProvider().attachSession( webdavRequest ) )
{
return;
}
// check matching if=header for lock-token relevant operations
DavResource resource = getResourceFactory().createResource(webdavRequest.getRequestLocator(), webdavRequest, webdavResponse);
if (!isPreconditionValid(webdavRequest, resource)) {
webdavResponse.sendError(DavServletResponse.SC_PRECONDITION_FAILED);
DavResource resource =
getResourceFactory().createResource( webdavRequest.getRequestLocator(), webdavRequest, webdavResponse );
if ( !isPreconditionValid( webdavRequest, resource ) )
{
webdavResponse.sendError( DavServletResponse.SC_PRECONDITION_FAILED );
return;
}
if (!execute(webdavRequest, webdavResponse, methodCode, resource)) {
super.service(request, response);
if ( !execute( webdavRequest, webdavResponse, methodCode, resource ) )
{
super.service( request, response );
}
}
catch (UnauthorizedDavException e)
catch ( UnauthorizedDavException e )
{
webdavResponse.setHeader("WWW-Authenticate", getAuthenticateHeaderValue(e.getRepositoryName()));
webdavResponse.sendError(e.getErrorCode(), e.getStatusPhrase());
webdavResponse.setHeader( "WWW-Authenticate", getAuthenticateHeaderValue( e.getRepositoryName() ) );
webdavResponse.sendError( e.getErrorCode(), e.getStatusPhrase() );
}
catch (BrowserRedirectException e)
catch ( BrowserRedirectException e )
{
response.sendRedirect(e.getLocation());
response.sendRedirect( e.getLocation() );
}
catch (DavException e)
catch ( DavException e )
{
if ( e.getErrorCode() == HttpServletResponse.SC_UNAUTHORIZED )
{
if (e.getErrorCode() == HttpServletResponse.SC_UNAUTHORIZED) {
final String msg = "Should throw " + UnauthorizedDavException.class.getName();
log.error(msg);
webdavResponse.sendError(e.getErrorCode(), msg);
} else if ( e.getCause() != null ) {
webdavResponse.sendError(e.getErrorCode(), e.getCause().getMessage());
} else {
webdavResponse.sendError(e.getErrorCode(), e.getMessage());
log.error( msg );
webdavResponse.sendError( e.getErrorCode(), msg );
}
} finally {
getDavSessionProvider().releaseSession(webdavRequest);
else if ( e.getCause() != null )
{
webdavResponse.sendError( e.getErrorCode(), e.getCause().getMessage() );
}
else
{
webdavResponse.sendError( e.getErrorCode(), e.getMessage() );
}
}
finally
{
getDavSessionProvider().releaseSession( webdavRequest );
}
}
public synchronized void initServers( ServletConfig servletConfig )
{
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext( servletConfig.getServletContext() );
WebApplicationContext wac =
WebApplicationContextUtils.getRequiredWebApplicationContext( servletConfig.getServletContext() );
configuration = (ArchivaConfiguration) wac.getBean(
PlexusToSpringUtils.buildSpringId( ArchivaConfiguration.class.getName() ) );
configuration =
(ArchivaConfiguration) wac.getBean( PlexusToSpringUtils.buildSpringId( ArchivaConfiguration.class.getName() ) );
configuration.addListener( this );
repositoryMap = configuration.getConfiguration().getManagedRepositoriesAsMap();
@ -157,14 +173,15 @@ public class RepositoryServlet
}
}
resourceFactory = (DavResourceFactory)wac.getBean(PlexusToSpringUtils.buildSpringId(ArchivaDavResourceFactory.class));
resourceFactory =
(DavResourceFactory) wac.getBean( PlexusToSpringUtils.buildSpringId( ArchivaDavResourceFactory.class ) );
locatorFactory = new ArchivaDavLocatorFactory();
sessionProvider = new ArchivaDavSessionProvider(wac);
sessionProvider = new ArchivaDavSessionProvider( wac );
}
public void configurationEvent( ConfigurationEvent event )
{
if( event.getType() == ConfigurationEvent.SAVED )
if ( event.getType() == ConfigurationEvent.SAVED )
{
initRepositories();
}
@ -198,7 +215,7 @@ public class RepositoryServlet
return configuration;
}
protected boolean isPreconditionValid(final WebdavRequest request, final DavResource davResource)
protected boolean isPreconditionValid( final WebdavRequest request, final DavResource davResource )
{
return true;
}
@ -208,7 +225,7 @@ public class RepositoryServlet
return sessionProvider;
}
public void setDavSessionProvider(final DavSessionProvider davSessionProvider)
public void setDavSessionProvider( final DavSessionProvider davSessionProvider )
{
this.sessionProvider = davSessionProvider;
}
@ -218,7 +235,7 @@ public class RepositoryServlet
return locatorFactory;
}
public void setLocatorFactory(final DavLocatorFactory davLocatorFactory)
public void setLocatorFactory( final DavLocatorFactory davLocatorFactory )
{
locatorFactory = davLocatorFactory;
}
@ -228,7 +245,7 @@ public class RepositoryServlet
return resourceFactory;
}
public void setResourceFactory(final DavResourceFactory davResourceFactory)
public void setResourceFactory( final DavResourceFactory davResourceFactory )
{
resourceFactory = davResourceFactory;
}
@ -238,7 +255,7 @@ public class RepositoryServlet
throw new UnsupportedOperationException();
}
public String getAuthenticateHeaderValue(String repository)
public String getAuthenticateHeaderValue( String repository )
{
return "Basic realm=\"Repository Archiva Managed " + repository + " Repository\"";
}

View File

@ -29,41 +29,45 @@ import org.apache.maven.archiva.webdav.util.RepositoryPathUtil;
/**
* @author <a href="mailto:james@atlassian.com">James William Dumay</a>
*/
public class ArchivaDavLocatorFactory implements DavLocatorFactory
public class ArchivaDavLocatorFactory
implements DavLocatorFactory
{
public DavResourceLocator createResourceLocator(String prefix, String href)
public DavResourceLocator createResourceLocator( String prefix, String href )
{
// build prefix string and remove all prefixes from the given href.
StringBuilder b = new StringBuilder();
if (prefix != null && prefix.length() > 0) {
b.append(prefix);
if (!prefix.endsWith("/"))
if ( prefix != null && prefix.length() > 0 )
{
b.append('/');
b.append( prefix );
if ( !prefix.endsWith( "/" ) )
{
b.append( '/' );
}
if (href.startsWith(prefix)) {
href = href.substring(prefix.length());
if ( href.startsWith( prefix ) )
{
href = href.substring( prefix.length() );
}
}
// special treatment for root item, that has no name but '/' path.
if (href == null || "".equals(href)) {
if ( href == null || "".equals( href ) )
{
href = "/";
}
final String repository = RepositoryPathUtil.getRepositoryName(href);
return new ArchivaDavResourceLocator(b.toString(), Text.unescape(href), repository, this);
final String repository = RepositoryPathUtil.getRepositoryName( href );
return new ArchivaDavResourceLocator( b.toString(), Text.unescape( href ), repository, this );
}
public DavResourceLocator createResourceLocator(String prefix, String workspacePath, String resourcePath)
public DavResourceLocator createResourceLocator( String prefix, String workspacePath, String resourcePath )
{
return createResourceLocator(prefix, workspacePath, resourcePath, true);
return createResourceLocator( prefix, workspacePath, resourcePath, true );
}
public DavResourceLocator createResourceLocator(String prefix, String workspacePath,
String path, boolean isResourcePath)
public DavResourceLocator createResourceLocator( String prefix, String workspacePath, String path,
boolean isResourcePath )
{
final String repository = RepositoryPathUtil.getRepositoryName(path);
return new ArchivaDavResourceLocator(prefix, path, repository, this);
final String repository = RepositoryPathUtil.getRepositoryName( path );
return new ArchivaDavResourceLocator( prefix, path, repository, this );
}
}

View File

@ -39,10 +39,10 @@ import java.util.ArrayList;
import java.io.*;
/**
* @author <a href="mailto:james@atlassian.com">James William Dumay</a>
* Portions from the Apache Jackrabbit Project
* @author <a href="mailto:james@atlassian.com">James William Dumay</a> Portions from the Apache Jackrabbit Project
*/
public class ArchivaDavResource implements DavResource
public class ArchivaDavResource
implements DavResource
{
public static final String HIDDEN_PATH_PREFIX = ".";
@ -56,7 +56,8 @@ public class ArchivaDavResource implements DavResource
private final String logicalResource;
private static final String METHODS = "OPTIONS, GET, HEAD, POST, TRACE, PROPFIND, PROPPATCH, MKCOL, COPY, PUT, DELETE, MOVE";
private static final String METHODS =
"OPTIONS, GET, HEAD, POST, TRACE, PROPFIND, PROPPATCH, MKCOL, COPY, PUT, DELETE, MOVE";
private static final String COMPLIANCE_CLASS = "1";
@ -64,10 +65,11 @@ public class ArchivaDavResource implements DavResource
private boolean propsInitialized = false;
public ArchivaDavResource(String localResource, String logicalResource, MimeTypes mimeTypes, ArchivaDavResourceLocator locator, DavResourceFactory factory)
public ArchivaDavResource( String localResource, String logicalResource, MimeTypes mimeTypes,
ArchivaDavResourceLocator locator, DavResourceFactory factory )
{
this.mimeTypes = mimeTypes;
this.localResource = new File(localResource);
this.localResource = new File( localResource );
this.logicalResource = logicalResource;
this.locator = locator;
this.factory = factory;
@ -76,7 +78,7 @@ public class ArchivaDavResource implements DavResource
public String getContentType()
{
return mimeTypes.getMimeType(localResource.getName());
return mimeTypes.getMimeType( localResource.getName() );
}
public String getComplianceClass()
@ -102,7 +104,7 @@ public class ArchivaDavResource implements DavResource
public String getDisplayName()
{
String resPath = getResourcePath();
return (resPath != null) ? Text.getName(resPath) : resPath;
return ( resPath != null ) ? Text.getName( resPath ) : resPath;
}
public DavResourceLocator getLocator()
@ -122,7 +124,7 @@ public class ArchivaDavResource implements DavResource
public String getHref()
{
return locator.getHref(isCollection());
return locator.getHref( isCollection() );
}
public long getModificationTime()
@ -137,29 +139,30 @@ public class ArchivaDavResource implements DavResource
return localResource.length();
}
public void spool(OutputContext outputContext) throws IOException
public void spool( OutputContext outputContext )
throws IOException
{
if (!isCollection())
if ( !isCollection() )
{
FileInputStream is = null;
try
{
outputContext.setContentLength(getContentLength());
outputContext.setContentType(getContentType());
outputContext.setContentLength( getContentLength() );
outputContext.setContentType( getContentType() );
//Write content to stream
is = new FileInputStream(localResource);
IOUtils.copy(is, outputContext.getOutputStream());
// Write content to stream
is = new FileInputStream( localResource );
IOUtils.copy( is, outputContext.getOutputStream() );
}
finally
{
IOUtils.closeQuietly(is);
IOUtils.closeQuietly( is );
}
}
else
{
IndexWriter writer = new IndexWriter(this, localResource, logicalResource);
writer.write(outputContext);
IndexWriter writer = new IndexWriter( this, localResource, logicalResource );
writer.write( outputContext );
}
}
@ -168,10 +171,10 @@ public class ArchivaDavResource implements DavResource
return getProperties().getPropertyNames();
}
public DavProperty getProperty(DavPropertyName name)
public DavProperty getProperty( DavPropertyName name )
{
initProperties();
return properties.get(name);
return properties.get( name );
}
public DavPropertySet getProperties()
@ -180,20 +183,24 @@ public class ArchivaDavResource implements DavResource
return properties;
}
public void setProperty(DavProperty property) throws DavException
public void setProperty( DavProperty property )
throws DavException
{
}
public void removeProperty(DavPropertyName propertyName) throws DavException
public void removeProperty( DavPropertyName propertyName )
throws DavException
{
}
public MultiStatusResponse alterProperties(DavPropertySet setProperties, DavPropertyNameSet removePropertyNames) throws DavException
public MultiStatusResponse alterProperties( DavPropertySet setProperties, DavPropertyNameSet removePropertyNames )
throws DavException
{
return null;
}
public MultiStatusResponse alterProperties(List changeList) throws DavException
public MultiStatusResponse alterProperties( List changeList )
throws DavException
{
return null;
}
@ -201,190 +208,202 @@ public class ArchivaDavResource implements DavResource
public DavResource getCollection()
{
DavResource parent = null;
if (getResourcePath() != null && !getResourcePath().equals("/")) {
String parentPath = Text.getRelativeParent(getResourcePath(), 1);
if (parentPath.equals("")) {
if ( getResourcePath() != null && !getResourcePath().equals( "/" ) )
{
String parentPath = Text.getRelativeParent( getResourcePath(), 1 );
if ( parentPath.equals( "" ) )
{
parentPath = "/";
}
DavResourceLocator parentloc = locator.getFactory().createResourceLocator(locator.getPrefix(), parentPath);
try {
parent = factory.createResource(parentloc, null);
} catch (DavException e) {
DavResourceLocator parentloc = locator.getFactory().createResourceLocator( locator.getPrefix(), parentPath );
try
{
parent = factory.createResource( parentloc, null );
}
catch ( DavException e )
{
// should not occur
}
}
return parent;
}
public void addMember(DavResource resource, InputContext inputContext) throws DavException
public void addMember( DavResource resource, InputContext inputContext )
throws DavException
{
File localFile = new File(localResource, resource.getDisplayName());
if (isCollection() && inputContext.hasStream()) //New File
File localFile = new File( localResource, resource.getDisplayName() );
if ( isCollection() && inputContext.hasStream() ) // New File
{
boolean deleteFile = false;
FileOutputStream stream = null;
try
{
stream = new FileOutputStream(localFile);
IOUtils.copy(inputContext.getInputStream(), stream);
if (inputContext.getContentLength() != localFile.length())
stream = new FileOutputStream( localFile );
IOUtils.copy( inputContext.getInputStream(), stream );
if ( inputContext.getContentLength() != localFile.length() )
{
deleteFile = true;
throw new DavException(HttpServletResponse.SC_BAD_REQUEST, "Content Header length was "
+ inputContext.getContentLength() + " but was " + localFile.length());
throw new DavException( HttpServletResponse.SC_BAD_REQUEST, "Content Header length was " +
inputContext.getContentLength() + " but was " + localFile.length() );
}
}
catch (IOException e)
catch ( IOException e )
{
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e );
}
finally
{
IOUtils.closeQuietly(stream);
if (deleteFile)
IOUtils.closeQuietly( stream );
if ( deleteFile )
{
FileUtils.deleteQuietly(localFile);
FileUtils.deleteQuietly( localFile );
}
}
}
else if (!inputContext.hasStream() && isCollection()) //New directory
else if ( !inputContext.hasStream() && isCollection() ) // New directory
{
localFile.mkdir();
}
else
{
throw new DavException(HttpServletResponse.SC_BAD_REQUEST, "Could not write member "
+ resource.getResourcePath() + " at " + getResourcePath());
throw new DavException( HttpServletResponse.SC_BAD_REQUEST, "Could not write member " +
resource.getResourcePath() + " at " + getResourcePath() );
}
}
public DavResourceIterator getMembers()
{
ArrayList list = new ArrayList();
if (exists() && isCollection())
if ( exists() && isCollection() )
{
for (String item : localResource.list())
for ( String item : localResource.list() )
{
try
{
if (!item.startsWith(HIDDEN_PATH_PREFIX))
if ( !item.startsWith( HIDDEN_PATH_PREFIX ) )
{
String path = locator.getResourcePath() + '/' + item;
DavResourceLocator resourceLocator = locator.getFactory().createResourceLocator(locator.getPrefix(), path);
DavResource resource = factory.createResource(resourceLocator, null);
if (resource != null) list.add(resource);
DavResourceLocator resourceLocator =
locator.getFactory().createResourceLocator( locator.getPrefix(), path );
DavResource resource = factory.createResource( resourceLocator, null );
if ( resource != null )
list.add( resource );
}
}
catch (DavException e)
catch ( DavException e )
{
//Should not occur
// Should not occur
}
}
}
return new DavResourceIteratorImpl(list);
return new DavResourceIteratorImpl( list );
}
public void removeMember(DavResource member) throws DavException
public void removeMember( DavResource member )
throws DavException
{
File localResource = checkDavResourceIsArchivaDavResource(member).getLocalResource();
File localResource = checkDavResourceIsArchivaDavResource( member ).getLocalResource();
if (!localResource.exists())
if ( !localResource.exists() )
{
throw new DavException(HttpServletResponse.SC_NOT_FOUND, member.getResourcePath());
throw new DavException( HttpServletResponse.SC_NOT_FOUND, member.getResourcePath() );
}
boolean suceeded = false;
if (localResource.isDirectory())
if ( localResource.isDirectory() )
{
try
{
FileUtils.deleteDirectory(localResource);
FileUtils.deleteDirectory( localResource );
suceeded = true;
}
catch (IOException e)
catch ( IOException e )
{
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e );
}
}
if (!suceeded && localResource.isFile())
if ( !suceeded && localResource.isFile() )
{
suceeded = localResource.delete();
}
if (!suceeded)
if ( !suceeded )
{
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not delete resource " + member.getResourcePath());
throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not delete resource " +
member.getResourcePath() );
}
}
public void move(DavResource destination) throws DavException
public void move( DavResource destination )
throws DavException
{
if (!exists())
if ( !exists() )
{
throw new DavException(HttpServletResponse.SC_NOT_FOUND, "Resource to copy does not exist.");
throw new DavException( HttpServletResponse.SC_NOT_FOUND, "Resource to copy does not exist." );
}
try
{
ArchivaDavResource localResource = checkDavResourceIsArchivaDavResource(destination);
if (isCollection())
ArchivaDavResource localResource = checkDavResourceIsArchivaDavResource( destination );
if ( isCollection() )
{
FileUtils.moveDirectory(getLocalResource(), localResource.getLocalResource());
FileUtils.moveDirectory( getLocalResource(), localResource.getLocalResource() );
}
else
{
FileUtils.moveFile(getLocalResource(), localResource.getLocalResource());
FileUtils.moveFile( getLocalResource(), localResource.getLocalResource() );
}
}
catch ( IOException e )
{
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e );
}
}
public void copy(DavResource destination, boolean shallow) throws DavException
public void copy( DavResource destination, boolean shallow )
throws DavException
{
if (!exists())
if ( !exists() )
{
throw new DavException(HttpServletResponse.SC_NOT_FOUND, "Resource to copy does not exist.");
throw new DavException( HttpServletResponse.SC_NOT_FOUND, "Resource to copy does not exist." );
}
if (shallow && isCollection())
if ( shallow && isCollection() )
{
throw new DavException(DavServletResponse.SC_FORBIDDEN, "Unable to perform shallow copy for collection");
throw new DavException( DavServletResponse.SC_FORBIDDEN, "Unable to perform shallow copy for collection" );
}
try
{
ArchivaDavResource localResource = checkDavResourceIsArchivaDavResource(destination);
if (isCollection())
ArchivaDavResource localResource = checkDavResourceIsArchivaDavResource( destination );
if ( isCollection() )
{
FileUtils.copyDirectory(getLocalResource(), localResource.getLocalResource());
FileUtils.copyDirectory( getLocalResource(), localResource.getLocalResource() );
}
else
{
FileUtils.copyFile(getLocalResource(), localResource.getLocalResource());
FileUtils.copyFile( getLocalResource(), localResource.getLocalResource() );
}
}
catch ( IOException e)
catch ( IOException e )
{
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e );
}
}
public boolean isLockable(Type type, Scope scope)
public boolean isLockable( Type type, Scope scope )
{
return false;
}
public boolean hasLock(Type type, Scope scope)
public boolean hasLock( Type type, Scope scope )
{
return false;
}
public ActiveLock getLock(Type type, Scope scope)
public ActiveLock getLock( Type type, Scope scope )
{
return null;
}
@ -394,21 +413,24 @@ public class ArchivaDavResource implements DavResource
return new ActiveLock[0];
}
public ActiveLock lock(LockInfo reqLockInfo) throws DavException
public ActiveLock lock( LockInfo reqLockInfo )
throws DavException
{
return null;
}
public ActiveLock refreshLock(LockInfo reqLockInfo, String lockToken) throws DavException
public ActiveLock refreshLock( LockInfo reqLockInfo, String lockToken )
throws DavException
{
return null;
}
public void unlock(String lockToken) throws DavException
public void unlock( String lockToken )
throws DavException
{
}
public void addLockManager(LockManager lockmgr)
public void addLockManager( LockManager lockmgr )
{
}
@ -425,46 +447,54 @@ public class ArchivaDavResource implements DavResource
/**
* Fill the set of properties
*/
protected void initProperties() {
if (!exists() || propsInitialized) {
protected void initProperties()
{
if ( !exists() || propsInitialized )
{
return;
}
// set (or reset) fundamental properties
if (getDisplayName() != null) {
properties.add(new DefaultDavProperty(DavPropertyName.DISPLAYNAME, getDisplayName()));
if ( getDisplayName() != null )
{
properties.add( new DefaultDavProperty( DavPropertyName.DISPLAYNAME, getDisplayName() ) );
}
if (isCollection()) {
properties.add(new ResourceType(ResourceType.COLLECTION));
if ( isCollection() )
{
properties.add( new ResourceType( ResourceType.COLLECTION ) );
// Windows XP support
properties.add(new DefaultDavProperty(DavPropertyName.ISCOLLECTION, "1"));
} else {
properties.add(new ResourceType(ResourceType.DEFAULT_RESOURCE));
properties.add( new DefaultDavProperty( DavPropertyName.ISCOLLECTION, "1" ) );
}
else
{
properties.add( new ResourceType( ResourceType.DEFAULT_RESOURCE ) );
// Windows XP support
properties.add(new DefaultDavProperty(DavPropertyName.ISCOLLECTION, "0"));
properties.add( new DefaultDavProperty( DavPropertyName.ISCOLLECTION, "0" ) );
}
//Need to get the ISO8601 date for properties
DateTime dt = new DateTime(localResource.lastModified());
// Need to get the ISO8601 date for properties
DateTime dt = new DateTime( localResource.lastModified() );
DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
String modifiedDate = fmt.print(dt);
String modifiedDate = fmt.print( dt );
properties.add(new DefaultDavProperty(DavPropertyName.GETLASTMODIFIED, modifiedDate));
properties.add( new DefaultDavProperty( DavPropertyName.GETLASTMODIFIED, modifiedDate ) );
properties.add(new DefaultDavProperty(DavPropertyName.CREATIONDATE, modifiedDate));
properties.add( new DefaultDavProperty( DavPropertyName.CREATIONDATE, modifiedDate ) );
properties.add(new DefaultDavProperty(DavPropertyName.GETCONTENTLENGTH, localResource.length()));
properties.add( new DefaultDavProperty( DavPropertyName.GETCONTENTLENGTH, localResource.length() ) );
propsInitialized = true;
}
private ArchivaDavResource checkDavResourceIsArchivaDavResource(DavResource resource) throws DavException
private ArchivaDavResource checkDavResourceIsArchivaDavResource( DavResource resource )
throws DavException
{
if (!(resource instanceof ArchivaDavResource))
if ( !( resource instanceof ArchivaDavResource ) )
{
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "DavResource is not instance of ArchivaDavResource");
throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"DavResource is not instance of ArchivaDavResource" );
}
return (ArchivaDavResource)resource;
return (ArchivaDavResource) resource;
}
}

View File

@ -61,9 +61,10 @@ import java.io.*;
* @author <a href="mailto:james@atlassian.com">James William Dumay</a>
* @plexus.component role="org.apache.maven.archiva.webdav.ArchivaDavResourceFactory"
*/
public class ArchivaDavResourceFactory implements DavResourceFactory, Auditable
public class ArchivaDavResourceFactory
implements DavResourceFactory, Auditable
{
private Logger log = LoggerFactory.getLogger(ArchivaDavResourceFactory.class);
private Logger log = LoggerFactory.getLogger( ArchivaDavResourceFactory.class );
/**
* @plexus.requirement role="org.apache.maven.archiva.repository.audit.AuditListener"
@ -95,35 +96,37 @@ public class ArchivaDavResourceFactory implements DavResourceFactory, Auditable
*/
private MimeTypes mimeTypes;
/**
* @plexus.requirement
*/
private ArchivaConfiguration archivaConfiguration;
public DavResource createResource(final DavResourceLocator locator, final DavServletRequest request, final DavServletResponse response) throws DavException
public DavResource createResource( final DavResourceLocator locator, final DavServletRequest request,
final DavServletResponse response )
throws DavException
{
checkLocatorIsInstanceOfRepositoryLocator(locator);
ArchivaDavResourceLocator archivaLocator = (ArchivaDavResourceLocator)locator;
checkLocatorIsInstanceOfRepositoryLocator( locator );
ArchivaDavResourceLocator archivaLocator = (ArchivaDavResourceLocator) locator;
RepositoryGroupConfiguration repoGroupConfig = archivaConfiguration.getConfiguration()
.getRepositoryGroupsAsMap().get( ( (RepositoryLocator) locator).getRepositoryId() );
RepositoryGroupConfiguration repoGroupConfig =
archivaConfiguration.getConfiguration().getRepositoryGroupsAsMap().get(
( (RepositoryLocator) locator ).getRepositoryId() );
List<String> repositories = new ArrayList<String>();
if ( repoGroupConfig != null )
{
if ( RepositoryPathUtil.getLogicalResource( locator.getResourcePath() ).equals( "/" )
|| WebdavMethodUtil.isWriteMethod( request.getMethod() ) )
if ( RepositoryPathUtil.getLogicalResource( locator.getResourcePath() ).equals( "/" ) ||
WebdavMethodUtil.isWriteMethod( request.getMethod() ) )
{
throw new DavException( HttpServletResponse.SC_BAD_REQUEST, "Bad request to repository group <"
+ repoGroupConfig.getId() + ">" );
throw new DavException( HttpServletResponse.SC_BAD_REQUEST, "Bad request to repository group <" +
repoGroupConfig.getId() + ">" );
}
repositories.addAll( repoGroupConfig.getRepositories() );
}
else
{
repositories.add( ( (RepositoryLocator) locator).getRepositoryId() );
repositories.add( ( (RepositoryLocator) locator ).getRepositoryId() );
}
DavResource resource = null;
@ -139,46 +142,47 @@ public class ArchivaDavResourceFactory implements DavResourceFactory, Auditable
}
catch ( DavException de )
{
throw new DavException( HttpServletResponse.SC_NOT_FOUND, "Invalid managed repository <" + repositoryId
+ ">" );
throw new DavException( HttpServletResponse.SC_NOT_FOUND, "Invalid managed repository <" +
repositoryId + ">" );
}
if (!locator.getResourcePath().startsWith(ArchivaDavResource.HIDDEN_PATH_PREFIX))
if ( !locator.getResourcePath().startsWith( ArchivaDavResource.HIDDEN_PATH_PREFIX ) )
{
if (managedRepository != null)
if ( managedRepository != null )
{
LogicalResource logicalResource = new LogicalResource(RepositoryPathUtil.getLogicalResource(locator.getResourcePath()));
LogicalResource logicalResource =
new LogicalResource( RepositoryPathUtil.getLogicalResource( locator.getResourcePath() ) );
boolean isGet = WebdavMethodUtil.isReadMethod( request.getMethod() );
boolean isPut = WebdavMethodUtil.isWriteMethod( request.getMethod() );
if (isGet)
if ( isGet )
{
resource = doGet(managedRepository, request, archivaLocator, logicalResource);
resource = doGet( managedRepository, request, archivaLocator, logicalResource );
}
if (isPut)
if ( isPut )
{
resource = doPut(managedRepository, request, archivaLocator, logicalResource);
resource = doPut( managedRepository, request, archivaLocator, logicalResource );
}
}
else
{
e = new DavException(HttpServletResponse.SC_NOT_FOUND, "Repository does not exist");
e = new DavException( HttpServletResponse.SC_NOT_FOUND, "Repository does not exist" );
}
if (resource == null)
if ( resource == null )
{
e = new DavException(HttpServletResponse.SC_NOT_FOUND, "Repository does not exist");
e = new DavException( HttpServletResponse.SC_NOT_FOUND, "Repository does not exist" );
}
else
{
setHeaders(locator, response);
setHeaders( locator, response );
//compatibility with MRM-440 to ensure browsing the repository works ok
if (resource.isCollection() && !resource.getLocator().getResourcePath().endsWith("/"))
// compatibility with MRM-440 to ensure browsing the repository works ok
if ( resource.isCollection() && !resource.getLocator().getResourcePath().endsWith( "/" ) )
{
throw new BrowserRedirectException(resource.getHref());
throw new BrowserRedirectException( resource.getHref() );
}
return resource;
@ -189,32 +193,38 @@ public class ArchivaDavResourceFactory implements DavResourceFactory, Auditable
throw e;
}
public DavResource createResource(final DavResourceLocator locator, final DavSession davSession) throws DavException
public DavResource createResource( final DavResourceLocator locator, final DavSession davSession )
throws DavException
{
checkLocatorIsInstanceOfRepositoryLocator(locator);
ArchivaDavResourceLocator archivaLocator = (ArchivaDavResourceLocator)locator;
checkLocatorIsInstanceOfRepositoryLocator( locator );
ArchivaDavResourceLocator archivaLocator = (ArchivaDavResourceLocator) locator;
DavResource resource = null;
if (!locator.getResourcePath().startsWith(ArchivaDavResource.HIDDEN_PATH_PREFIX))
if ( !locator.getResourcePath().startsWith( ArchivaDavResource.HIDDEN_PATH_PREFIX ) )
{
ManagedRepositoryContent managedRepository = getManagedRepository(archivaLocator.getRepositoryId());
String logicalResource = RepositoryPathUtil.getLogicalResource(locator.getResourcePath());
File resourceFile = new File ( managedRepository.getRepoRoot(), logicalResource);
resource = new ArchivaDavResource(resourceFile.getAbsolutePath(), logicalResource, mimeTypes, archivaLocator, this);
ManagedRepositoryContent managedRepository = getManagedRepository( archivaLocator.getRepositoryId() );
String logicalResource = RepositoryPathUtil.getLogicalResource( locator.getResourcePath() );
File resourceFile = new File( managedRepository.getRepoRoot(), logicalResource );
resource =
new ArchivaDavResource( resourceFile.getAbsolutePath(), logicalResource, mimeTypes, archivaLocator,
this );
}
return resource;
}
private DavResource doGet(ManagedRepositoryContent managedRepository, DavServletRequest request, ArchivaDavResourceLocator locator, LogicalResource logicalResource) throws DavException
private DavResource doGet( ManagedRepositoryContent managedRepository, DavServletRequest request,
ArchivaDavResourceLocator locator, LogicalResource logicalResource )
throws DavException
{
File resourceFile = new File ( managedRepository.getRepoRoot(), logicalResource.getPath());
ArchivaDavResource resource = new ArchivaDavResource(resourceFile.getAbsolutePath(), logicalResource.getPath(), mimeTypes, locator, this);
File resourceFile = new File( managedRepository.getRepoRoot(), logicalResource.getPath() );
ArchivaDavResource resource =
new ArchivaDavResource( resourceFile.getAbsolutePath(), logicalResource.getPath(), mimeTypes, locator, this );
if ( !resource.isCollection() )
{
// At this point the incoming request can either be in default or
// legacy layout format.
boolean fromProxy = fetchContentFromProxies(managedRepository, request, logicalResource );
boolean fromProxy = fetchContentFromProxies( managedRepository, request, logicalResource );
boolean previouslyExisted = resourceFile.exists();
@ -222,7 +232,8 @@ public class ArchivaDavResourceFactory implements DavResourceFactory, Auditable
{
// Perform an adjustment of the resource to the managed
// repository expected path.
String localResourcePath = repositoryRequest.toNativePath( logicalResource.getPath(), managedRepository );
String localResourcePath =
repositoryRequest.toNativePath( logicalResource.getPath(), managedRepository );
resourceFile = new File( managedRepository.getRepoRoot(), localResourcePath );
}
catch ( LayoutException e )
@ -231,15 +242,18 @@ public class ArchivaDavResourceFactory implements DavResourceFactory, Auditable
{
return resource;
}
throw new DavException(HttpServletResponse.SC_NOT_FOUND, e);
throw new DavException( HttpServletResponse.SC_NOT_FOUND, e );
}
// Attempt to fetch the resource from any defined proxy.
if ( fromProxy )
{
processAuditEvents(request, locator.getWorkspaceName(), logicalResource.getPath(), previouslyExisted, resourceFile, " (proxied)");
processAuditEvents( request, locator.getWorkspaceName(), logicalResource.getPath(), previouslyExisted,
resourceFile, " (proxied)" );
}
resource = new ArchivaDavResource(resourceFile.getAbsolutePath(), logicalResource.getPath(), mimeTypes, locator, this);
resource =
new ArchivaDavResource( resourceFile.getAbsolutePath(), logicalResource.getPath(), mimeTypes, locator,
this );
if ( !resourceFile.exists() )
{
@ -249,36 +263,38 @@ public class ArchivaDavResourceFactory implements DavResourceFactory, Auditable
return resource;
}
private DavResource doPut(ManagedRepositoryContent managedRepository, DavServletRequest request, ArchivaDavResourceLocator locator, LogicalResource logicalResource) throws DavException
private DavResource doPut( ManagedRepositoryContent managedRepository, DavServletRequest request,
ArchivaDavResourceLocator locator, LogicalResource logicalResource )
throws DavException
{
/*
* Create parent directories that don't exist when writing a file
* This actually makes this implementation not compliant to the
* WebDAV RFC - but we have enough knowledge about how the
* collection is being used to do this reasonably and some versions
* of Maven's WebDAV don't correctly create the collections
* themselves.
* Create parent directories that don't exist when writing a file This actually makes this implementation not
* compliant to the WebDAV RFC - but we have enough knowledge about how the collection is being used to do this
* reasonably and some versions of Maven's WebDAV don't correctly create the collections themselves.
*/
File rootDirectory = new File(managedRepository.getRepoRoot());
File rootDirectory = new File( managedRepository.getRepoRoot() );
File destDir = new File( rootDirectory, logicalResource.getPath() ).getParentFile();
if ( !destDir.exists() )
{
destDir.mkdirs();
String relPath = PathUtil.getRelative( rootDirectory.getAbsolutePath(), destDir );
triggerAuditEvent(request, logicalResource.getPath(), relPath, AuditEvent.CREATE_DIR );
triggerAuditEvent( request, logicalResource.getPath(), relPath, AuditEvent.CREATE_DIR );
}
File resourceFile = new File( managedRepository.getRepoRoot(), logicalResource.getPath() );
boolean previouslyExisted = resourceFile.exists();
processAuditEvents(request, locator.getRepositoryId(), logicalResource.getPath(), previouslyExisted, resourceFile, null );
processAuditEvents( request, locator.getRepositoryId(), logicalResource.getPath(), previouslyExisted,
resourceFile, null );
return new ArchivaDavResource(resourceFile.getAbsolutePath(), logicalResource.getPath(), mimeTypes, locator, this);
return new ArchivaDavResource( resourceFile.getAbsolutePath(), logicalResource.getPath(), mimeTypes, locator,
this );
}
private boolean fetchContentFromProxies( ManagedRepositoryContent managedRepository, DavServletRequest request, LogicalResource resource )
private boolean fetchContentFromProxies( ManagedRepositoryContent managedRepository, DavServletRequest request,
LogicalResource resource )
throws DavException
{
if ( repositoryRequest.isSupportFile( resource.getPath() ) )
@ -292,7 +308,7 @@ public class ArchivaDavResourceFactory implements DavResourceFactory, Auditable
// Is it a Metadata resource?
if ( repositoryRequest.isDefault( resource.getPath() ) && repositoryRequest.isMetadata( resource.getPath() ) )
{
return fetchMetadataFromProxies(managedRepository, request, resource );
return fetchMetadataFromProxies( managedRepository, request, resource );
}
// Not any of the above? Then it's gotta be an artifact reference.
@ -303,7 +319,7 @@ public class ArchivaDavResourceFactory implements DavResourceFactory, Auditable
if ( artifact != null )
{
applyServerSideRelocation(managedRepository, artifact );
applyServerSideRelocation( managedRepository, artifact );
File proxiedFile = connectors.fetchFromProxies( managedRepository, artifact );
@ -318,13 +334,14 @@ public class ArchivaDavResourceFactory implements DavResourceFactory, Auditable
}
catch ( ProxyDownloadException e )
{
log.error(e.getMessage(), e);
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to fetch artifact resource.");
log.error( e.getMessage(), e );
throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to fetch artifact resource." );
}
return false;
}
private boolean fetchMetadataFromProxies(ManagedRepositoryContent managedRepository, DavServletRequest request, LogicalResource resource )
private boolean fetchMetadataFromProxies( ManagedRepositoryContent managedRepository, DavServletRequest request,
LogicalResource resource )
throws DavException
{
ProjectReference project;
@ -363,14 +380,12 @@ public class ArchivaDavResourceFactory implements DavResourceFactory, Auditable
}
/**
* A relocation capable client will request the POM prior to the artifact,
* and will then read meta-data and do client side relocation. A simplier
* client (like maven 1) will only request the artifact and not use the
* A relocation capable client will request the POM prior to the artifact, and will then read meta-data and do
* client side relocation. A simplier client (like maven 1) will only request the artifact and not use the
* metadatas.
* <p>
* For such clients, archiva does server-side relocation by reading itself
* the &lt;relocation&gt; element in metadatas and serving the expected
* artifact.
* For such clients, archiva does server-side relocation by reading itself the &lt;relocation&gt; element in
* metadatas and serving the expected artifact.
*/
protected void applyServerSideRelocation( ManagedRepositoryContent managedRepository, ArtifactReference artifact )
throws ProxyDownloadException
@ -492,7 +507,8 @@ public class ArchivaDavResourceFactory implements DavResourceFactory, Auditable
private void triggerAuditEvent( DavServletRequest request, String repositoryId, String resource, String action )
{
triggerAuditEvent( ArchivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() ), getRemoteIP( request ), repositoryId, resource, action );
triggerAuditEvent( ArchivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() ),
getRemoteIP( request ), repositoryId, resource, action );
}
private String getRemoteIP( DavServletRequest request )
@ -515,7 +531,7 @@ public class ArchivaDavResourceFactory implements DavResourceFactory, Auditable
this.auditListeners.remove( listener );
}
private void setHeaders(DavResourceLocator locator, DavServletResponse response)
private void setHeaders( DavResourceLocator locator, DavServletResponse response )
{
// [MRM-503] - Metadata file need Pragma:no-cache response
// header.
@ -528,31 +544,34 @@ public class ArchivaDavResourceFactory implements DavResourceFactory, Auditable
// TODO: [MRM-524] determine http caching options for other types of files (artifacts, sha1, md5, snapshots)
}
private ManagedRepositoryContent getManagedRepository(String respositoryId) throws DavException
private ManagedRepositoryContent getManagedRepository( String respositoryId )
throws DavException
{
if (respositoryId != null)
if ( respositoryId != null )
{
try
{
return repositoryFactory.getManagedRepositoryContent(respositoryId);
return repositoryFactory.getManagedRepositoryContent( respositoryId );
}
catch (RepositoryNotFoundException e)
catch ( RepositoryNotFoundException e )
{
throw new DavException(HttpServletResponse.SC_NOT_FOUND, e);
throw new DavException( HttpServletResponse.SC_NOT_FOUND, e );
}
catch (RepositoryException e)
catch ( RepositoryException e )
{
throw new DavException(HttpServletResponse.SC_NOT_FOUND, e);
throw new DavException( HttpServletResponse.SC_NOT_FOUND, e );
}
}
return null;
}
private void checkLocatorIsInstanceOfRepositoryLocator(DavResourceLocator locator) throws DavException
private void checkLocatorIsInstanceOfRepositoryLocator( DavResourceLocator locator )
throws DavException
{
if (!(locator instanceof RepositoryLocator))
if ( !( locator instanceof RepositoryLocator ) )
{
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Locator does not implement RepositoryLocator");
throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"Locator does not implement RepositoryLocator" );
}
}
@ -560,7 +579,7 @@ public class ArchivaDavResourceFactory implements DavResourceFactory, Auditable
{
private String path;
public LogicalResource(String path)
public LogicalResource( String path )
{
this.path = path;
}
@ -570,7 +589,7 @@ public class ArchivaDavResourceFactory implements DavResourceFactory, Auditable
return path;
}
public void setPath(String path)
public void setPath( String path )
{
this.path = path;
}

View File

@ -26,7 +26,8 @@ import org.apache.jackrabbit.util.Text;
/**
* @author <a href="mailto:james@atlassian.com">James William Dumay</a>
*/
public class ArchivaDavResourceLocator implements DavResourceLocator, RepositoryLocator
public class ArchivaDavResourceLocator
implements DavResourceLocator, RepositoryLocator
{
private String prefix;
@ -38,20 +39,21 @@ public class ArchivaDavResourceLocator implements DavResourceLocator, Repository
private DavLocatorFactory davLocatorFactory;
public ArchivaDavResourceLocator(String prefix, String resourcePath, String repositoryId, DavLocatorFactory davLocatorFactory)
public ArchivaDavResourceLocator( String prefix, String resourcePath, String repositoryId,
DavLocatorFactory davLocatorFactory )
{
this.prefix = prefix;
this.repositoryId = repositoryId;
this.davLocatorFactory = davLocatorFactory;
this.resourcePath = resourcePath;
String escapedPath = Text.escapePath(resourcePath);
String escapedPath = Text.escapePath( resourcePath );
String hrefPrefix = prefix;
//Ensure no extra slashes when href is joined
if (hrefPrefix.endsWith("/") && escapedPath.startsWith("/"))
// Ensure no extra slashes when href is joined
if ( hrefPrefix.endsWith( "/" ) && escapedPath.startsWith( "/" ) )
{
hrefPrefix = hrefPrefix.substring(0, hrefPrefix.length()-1);
hrefPrefix = hrefPrefix.substring( 0, hrefPrefix.length() - 1 );
}
href = hrefPrefix + escapedPath;
@ -82,26 +84,26 @@ public class ArchivaDavResourceLocator implements DavResourceLocator, Repository
return "";
}
public boolean isSameWorkspace(DavResourceLocator locator)
public boolean isSameWorkspace( DavResourceLocator locator )
{
return isSameWorkspace(locator.getWorkspaceName());
return isSameWorkspace( locator.getWorkspaceName() );
}
public boolean isSameWorkspace(String workspaceName)
public boolean isSameWorkspace( String workspaceName )
{
return getWorkspaceName().equals(workspaceName);
return getWorkspaceName().equals( workspaceName );
}
public String getHref(boolean isCollection)
public String getHref( boolean isCollection )
{
// avoid doubled trailing '/' for the root item
String suffix = (isCollection && !isRootLocation()) ? "/" : "";
String suffix = ( isCollection && !isRootLocation() ) ? "/" : "";
return href + suffix;
}
public boolean isRootLocation()
{
return "/".equals(resourcePath);
return "/".equals( resourcePath );
}
public DavLocatorFactory getFactory()
@ -115,8 +117,7 @@ public class ArchivaDavResourceLocator implements DavResourceLocator, Repository
}
/**
* Computes the hash code from the href, which is built using the final
* fields prefix and resourcePath.
* Computes the hash code from the href, which is built using the final fields prefix and resourcePath.
*
* @return the hash code
*/
@ -126,16 +127,15 @@ public class ArchivaDavResourceLocator implements DavResourceLocator, Repository
}
/**
* Equality of path is achieved if the specified object is a <code>DavResourceLocator</code>
* object with the same hash code.
* Equality of path is achieved if the specified object is a <code>DavResourceLocator</code> object with the same
* hash code.
*
* @param obj the object to compare to
* @return <code>true</code> if the 2 objects are equal;
* <code>false</code> otherwise
* @return <code>true</code> if the 2 objects are equal; <code>false</code> otherwise
*/
public boolean equals(Object obj)
public boolean equals( Object obj )
{
if (obj instanceof DavResourceLocator)
if ( obj instanceof DavResourceLocator )
{
DavResourceLocator other = (DavResourceLocator) obj;
return hashCode() == other.hashCode();

View File

@ -44,71 +44,78 @@ import javax.servlet.http.HttpServletResponse;
/**
* @author <a href="mailto:james@atlassian.com">James William Dumay</a>
*/
public class ArchivaDavSessionProvider implements DavSessionProvider
public class ArchivaDavSessionProvider
implements DavSessionProvider
{
private Logger log = LoggerFactory.getLogger(ArchivaDavSessionProvider.class);
private Logger log = LoggerFactory.getLogger( ArchivaDavSessionProvider.class );
private ServletAuthenticator servletAuth;
private HttpAuthenticator httpAuth;
public ArchivaDavSessionProvider(WebApplicationContext applicationContext)
public ArchivaDavSessionProvider( WebApplicationContext applicationContext )
{
servletAuth = (ServletAuthenticator) applicationContext.getBean( PlexusToSpringUtils.buildSpringId( ServletAuthenticator.class.getName() ) );
servletAuth =
(ServletAuthenticator) applicationContext.getBean( PlexusToSpringUtils.buildSpringId( ServletAuthenticator.class.getName() ) );
httpAuth =
(HttpAuthenticator) applicationContext.getBean( PlexusToSpringUtils.buildSpringId( HttpAuthenticator.ROLE, "basic" ) );
(HttpAuthenticator) applicationContext.getBean( PlexusToSpringUtils.buildSpringId( HttpAuthenticator.ROLE,
"basic" ) );
}
public boolean attachSession(WebdavRequest request) throws DavException
public boolean attachSession( WebdavRequest request )
throws DavException
{
final String repositoryId = RepositoryPathUtil.getRepositoryName(removeContextPath(request));
final String repositoryId = RepositoryPathUtil.getRepositoryName( removeContextPath( request ) );
try
{
AuthenticationResult result = httpAuth.getAuthenticationResult( request, null );
SecuritySession securitySession = httpAuth.getSecuritySession();
return servletAuth.isAuthenticated(request, result, repositoryId) &&
servletAuth.isAuthorized(request, securitySession, repositoryId, WebdavMethodUtil.isWriteMethod( request.getMethod() ) );
return servletAuth.isAuthenticated( request, result, repositoryId ) &&
servletAuth.isAuthorized( request, securitySession, repositoryId,
WebdavMethodUtil.isWriteMethod( request.getMethod() ) );
}
catch ( AuthenticationException e )
{
log.error( "Cannot authenticate user.", e );
throw new UnauthorizedDavException(repositoryId, "You are not authenticated");
throw new UnauthorizedDavException( repositoryId, "You are not authenticated" );
}
catch ( MustChangePasswordException e )
{
log.error( "User must change password." );
throw new UnauthorizedDavException(repositoryId, "You must change your password.");
throw new UnauthorizedDavException( repositoryId, "You must change your password." );
}
catch ( AccountLockedException e )
{
log.error( "User account is locked." );
throw new UnauthorizedDavException(repositoryId, "User account is locked.");
throw new UnauthorizedDavException( repositoryId, "User account is locked." );
}
catch ( AuthorizationException e )
{
log.error( "Fatal Authorization Subsystem Error." );
throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Fatal Authorization Subsystem Error." );
throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"Fatal Authorization Subsystem Error." );
}
catch ( UnauthorizedException e )
{
log.error( e.getMessage() );
throw new UnauthorizedDavException(repositoryId, e.getMessage() );
throw new UnauthorizedDavException( repositoryId, e.getMessage() );
}
}
public void releaseSession(WebdavRequest webdavRequest)
public void releaseSession( WebdavRequest webdavRequest )
{
}
private String removeContextPath(final DavServletRequest request)
private String removeContextPath( final DavServletRequest request )
{
String path = request.getRequestURI();
String ctx = request.getContextPath();
if (path.startsWith(ctx)) {
path = path.substring(ctx.length());
if ( path.startsWith( ctx ) )
{
path = path.substring( ctx.length() );
}
return path;
}