import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*/
-@Service("davResourceFactory#archiva")
+@Service( "davResourceFactory#archiva" )
public class ArchivaDavResourceFactory
implements DavResourceFactory, Auditable
{
private RepositoryRequest repositoryRequest;
@Inject
- @Named(value = "repositoryProxyConnectors#default")
+ @Named( value = "repositoryProxyConnectors#default" )
private RepositoryProxyConnectors connectors;
@Inject
private ServletAuthenticator servletAuth;
@Inject
- @Named(value = "httpAuthenticator#basic")
+ @Named( value = "httpAuthenticator#basic" )
private HttpAuthenticator httpAuth;
@Inject
private Digester digestMd5;
@Inject
- @Named(value = "archivaTaskScheduler#repository")
+ @Named( value = "archivaTaskScheduler#repository" )
private RepositoryArchivaTaskScheduler scheduler;
@Inject
- @Named(value = "fileLockManager#default")
+ @Named( value = "fileLockManager#default" )
private FileLockManager fileLockManager;
private ApplicationContext applicationContext;
{
try
{
- return getResourceFromGroup( request, repoGroupConfig.getRepositories(), archivaLocator,
- repoGroupConfig );
+ DavResource davResource =
+ getResourceFromGroup( request, repoGroupConfig.getRepositories(), archivaLocator,
+ repoGroupConfig );
+
+ setHeaders( response, locator, davResource );
+
+ return davResource;
+
}
catch ( RepositoryAdminException e )
{
{
resource = processRepository( request, archivaLocator, activePrincipal, managedRepositoryContent,
managedRepositoryAdmin.getManagedRepository(
- archivaLocator.getRepositoryId() ) );
+ archivaLocator.getRepositoryId() )
+ );
String logicalResource = getLogicalResource( archivaLocator, null, false );
resourcesInAbsolutePath.add(
catch ( DigesterException de )
{
throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
- "Error occurred while generating checksum files."
- + de.getMessage() );
+ "Error occurred while generating checksum files." + de.getMessage()
+ );
}
}
}
{
// [MRM-503] - Metadata file need Pragma:no-cache response
// header.
- if ( locator.getResourcePath().endsWith( "/maven-metadata.xml" )
- || ( (ArchivaDavResource) resource ).getLocalResource().isDirectory() )
+ if ( locator.getResourcePath().endsWith( "/maven-metadata.xml" ) || ( resource instanceof ArchivaDavResource
+ && ( ArchivaDavResource.class.cast( resource ).getLocalResource().isDirectory() ) ) )
{
response.setHeader( "Pragma", "no-cache" );
response.setHeader( "Cache-Control", "no-cache" );
}
// if the resource is a directory don't cache it as new groupId deployed will be available
// without need of refreshing browser
- else
+ else if ( locator.getResourcePath().endsWith( "/maven-metadata.xml" ) || (
+ resource instanceof ArchivaVirtualDavResource && ( new File(
+ ArchivaVirtualDavResource.class.cast( resource ).getLogicalResource() ).isDirectory() ) ) )
{
- // We need to specify this so connecting wagons can work correctly
- response.setDateHeader( "Last-Modified", resource.getModificationTime() );
+ response.setHeader( "Pragma", "no-cache" );
+ response.setHeader( "Cache-Control", "no-cache" );
+ response.setDateHeader( "Last-Modified", new Date().getTime() );
}
// TODO: [MRM-524] determine http caching options for other types of files (artifacts, sha1, md5, snapshots)
}
return servletAuth.isAuthenticated( request, result ) && servletAuth.isAuthorized( request, securitySession,
repositoryId,
WebdavMethodUtil.getMethodPermission(
- request.getMethod() ) );
+ request.getMethod() )
+ );
}
catch ( AuthenticationException e )
{
RepositoryGroupConfiguration repositoryGroupConfiguration )
throws DavException, RepositoryAdminException
{
+ if ( repositoryGroupConfiguration.getRepositories() == null
+ || repositoryGroupConfiguration.getRepositories().isEmpty() )
+ {
+ File file =
+ new File( System.getProperty( "appserver.base"), "groups/" + repositoryGroupConfiguration.getId() );
+
+ return new ArchivaDavResource( file.getPath(), "groups/" + repositoryGroupConfiguration.getId(),
+ null,request.getDavSession(), locator, this,
+ mimeTypes, auditListeners,
+ scheduler, fileLockManager );
+ }
List<File> mergedRepositoryContents = new ArrayList<File>();
// multiple repo types so we guess they are all the same type
// so use the first one
// FIXME add a method with group in the repository storage
- String firstRepoId = repositoryGroupConfiguration.getRepositories().get( 1 );
+ String firstRepoId = repositoryGroupConfiguration.getRepositories().get( 0 );
String path = getLogicalResource( locator, managedRepositoryAdmin.getManagedRepository( firstRepoId ), false );
if ( path.startsWith( "/" ) )
{
File tmpDirectory = new File( SystemUtils.getJavaIoTmpDir(),
repositoryGroupConfiguration.getId() + "/"
- + repositoryGroupConfiguration.getMergedIndexPath() );
+ + repositoryGroupConfiguration.getMergedIndexPath()
+ );
if ( !tmpDirectory.exists() )
{
synchronized ( tmpDirectory.getAbsolutePath() )
repoIndexDirectory = new File( managedRepository.getRepository().getLocation(),
StringUtils.isEmpty( repoIndexDirectory )
? ".indexer"
- : repoIndexDirectory ).getAbsolutePath();
+ : repoIndexDirectory
+ ).getAbsolutePath();
}
}
if ( StringUtils.isEmpty( repoIndexDirectory ) )
{
if ( servletAuth.isAuthorized( activePrincipal, repository,
WebdavMethodUtil.getMethodPermission(
- request.getMethod() ) ) )
+ request.getMethod() )
+ ) )
{
mergedRepositoryContents.add( resourceFile );
log.debug( "Repository '{}' accessed by '{}'", repository, activePrincipal );
File tempRepoFile = Files.createTempDir();
tempRepoFile.deleteOnExit();
- IndexMergerRequest indexMergerRequest = new IndexMergerRequest( authzRepos, true, repositoryGroupConfiguration.getId(),
- repositoryGroupConfiguration.getMergedIndexPath(),
- repositoryGroupConfiguration.getMergedIndexTtl() ).mergedIndexDirectory( tempRepoFile )
- .temporary( true );
+ IndexMergerRequest indexMergerRequest =
+ new IndexMergerRequest( authzRepos, true, repositoryGroupConfiguration.getId(),
+ repositoryGroupConfiguration.getMergedIndexPath(),
+ repositoryGroupConfiguration.getMergedIndexTtl() ).mergedIndexDirectory(
+ tempRepoFile ).temporary( true );
MergedRemoteIndexesTaskRequest taskRequest =
- new MergedRemoteIndexesTaskRequest(indexMergerRequest, indexMerger);
+ new MergedRemoteIndexesTaskRequest( indexMergerRequest, indexMerger );
MergedRemoteIndexesTask job = new MergedRemoteIndexesTask( taskRequest );