* under the License.
*/
-import java.util.HashMap;
import java.util.Map;
import org.apache.maven.archiva.security.ArchivaRoleConstants;
import org.codehaus.plexus.redback.system.SecuritySession;
import org.codehaus.plexus.redback.system.SecuritySystemConstants;
import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.registry.Registry;
/**
* ArchivaXworkUser
*
* @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
* @version $Id$
+ *
+ * @plexus.component role="org.apache.maven.archiva.security.ArchivaXworkUser"
*/
public class ArchivaXworkUser
{
- public static String getActivePrincipal( Map<String, Object> sessionMap )
- {
+ /**
+ * @plexus.requirement role-hint="commons-configuration"
+ */
+ private Registry registry;
+
+ private static final String KEY = "org.codehaus.plexus.redback";
+
+ private static String guest;
+
+ public String getActivePrincipal( Map<String, Object> sessionMap )
+ {
if ( sessionMap == null )
{
- return ArchivaRoleConstants.PRINCIPAL_GUEST;
+ return getGuest();
}
SecuritySession securitySession =
if ( securitySession == null )
{
- return ArchivaRoleConstants.PRINCIPAL_GUEST;
+ return getGuest();
}
User user = securitySession.getUser();
if ( user == null )
{
- return ArchivaRoleConstants.PRINCIPAL_GUEST;
+ return getGuest();
}
return (String) user.getPrincipal();
+ }
+
+ public String getGuest()
+ {
+ if( guest == null || "".equals( guest ) )
+ {
+ Registry subset = registry.getSubset( KEY );
+ guest = subset.getString( "redback.default.guest", ArchivaRoleConstants.PRINCIPAL_GUEST );
+ }
+
+ return guest;
}
}
*/
private UserRepositories userRepositories;
+ /**
+ * @plexus.requirement
+ */
+ private ArchivaXworkUser archivaXworkUser;
+
private BrowsingResults results;
private String groupId;
private String getPrincipal()
{
- return ArchivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
+ return archivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
}
private List<String> getObservableRepos()
*/
private UserRepositories userRepositories;
+ /**
+ * @plexus.requirement
+ */
+ private ArchivaXworkUser archivaXworkUser;
+
private static final String RESULTS = "results";
private static final String ARTIFACT = "artifact";
private String getPrincipal()
{
- return ArchivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
+ return archivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
}
private List<String> getObservableRepos()
* @plexus.requirement
*/
private UserRepositories userRepositories;
+
+ /**
+ * @plexus.requirement
+ */
+ private ArchivaXworkUser archivaXworkUser;
/* .\ Input Parameters \.________________________________________ */
private String getPrincipal()
{
- return ArchivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
+ return archivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
}
private List<String> getObservableRepos()
* @plexus.requirement
*/
private RepositoryContentConsumers consumers;
+
+ /**
+ * @plexus.requirement
+ */
+ private ArchivaXworkUser archivaXworkUser;
/**
* The groupId of the artifact to be deployed.
private String getPrincipal()
{
- return ArchivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
+ return archivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
}
private void copyFile( File sourceFile, File targetPath, String targetFilename )
import org.apache.maven.archiva.security.AccessDeniedException;
import org.apache.maven.archiva.security.ArchivaRoleConstants;
import org.apache.maven.archiva.security.ArchivaSecurityException;
+import org.apache.maven.archiva.security.ArchivaXworkUser;
import org.apache.maven.archiva.security.PrincipalNotFoundException;
import org.apache.maven.archiva.security.ServletAuthenticator;
import org.apache.maven.archiva.security.UserRepositories;
private ServletAuthenticator servletAuth;
private HttpAuthenticator httpAuth;
+
+ private ArchivaXworkUser archivaXworkUser;
public void init( javax.servlet.ServletConfig servletConfig )
throws ServletException
(ServletAuthenticator) wac.getBean( PlexusToSpringUtils.buildSpringId( ServletAuthenticator.class.getName() ) );
httpAuth =
(HttpAuthenticator) wac.getBean( PlexusToSpringUtils.buildSpringId( HttpAuthenticator.ROLE, "basic" ) );
+ archivaXworkUser = (ArchivaXworkUser) wac.getBean( PlexusToSpringUtils.buildSpringId( ArchivaXworkUser.class ) );
}
public void doGet( HttpServletRequest req, HttpServletResponse res )
if ( usernamePassword == null || usernamePassword.trim().equals( "" ) )
{
- repoIds = getObservableRepos( ArchivaRoleConstants.PRINCIPAL_GUEST );
+ repoIds = getObservableRepos( archivaXworkUser.getGuest() );
}
else
{
}
else
{
- repoIds = getObservableRepos( ArchivaRoleConstants.PRINCIPAL_GUEST );
+ repoIds = getObservableRepos( archivaXworkUser.getGuest() );
}
}
else
private final MimeTypes mimeTypes;
private List<AuditListener> auditListeners;
+
+ private ArchivaXworkUser archivaXworkUser;
public ArchivaDavResource( String localResource, String logicalResource, ManagedRepositoryConfiguration repository,
DavSession session, ArchivaDavResourceLocator locator, DavResourceFactory factory,
MimeTypes mimeTypes, List<AuditListener> auditListeners,
- RepositoryContentConsumers consumers )
+ RepositoryContentConsumers consumers, ArchivaXworkUser archivaXworkUser )
{
this.localResource = new File( localResource );
this.logicalResource = logicalResource;
this.locator = locator;
this.factory = factory;
this.session = session;
+ this.archivaXworkUser = archivaXworkUser;
// TODO: push into locator as well as moving any references out of the resource factory
this.repository = repository;
public ArchivaDavResource( String localResource, String logicalResource, ManagedRepositoryConfiguration repository,
String remoteAddr, DavSession session, ArchivaDavResourceLocator locator,
DavResourceFactory factory, MimeTypes mimeTypes, List<AuditListener> auditListeners,
- RepositoryContentConsumers consumers )
+ RepositoryContentConsumers consumers, ArchivaXworkUser archivaXworkUser )
{
this( localResource, logicalResource, repository, session, locator, factory, mimeTypes, auditListeners,
- consumers );
+ consumers, archivaXworkUser );
this.remoteAddr = remoteAddr;
}
private void triggerAuditEvent( String remoteIP, String repositoryId, String resource, String action )
{
- String activePrincipal = ArchivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
+ String activePrincipal = archivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
AuditEvent event = new AuditEvent( repositoryId, activePrincipal, resource, action );
event.setRemoteIP( remoteIP );
* @plexus.requirement role-hint="md5";
*/
private Digester digestMd5;
+
+ /**
+ * @plexus.requirement
+ */
+ private ArchivaXworkUser archivaXworkUser;
public DavResource createResource( final DavResourceLocator locator, final DavServletRequest request,
final DavServletResponse response )
ArchivaDavResource metadataChecksumResource =
new ArchivaDavResource( metadataChecksum.getAbsolutePath(), logicalResource.getPath(), null,
request.getRemoteAddr(), request.getDavSession(), archivaLocator, this,
- mimeTypes, auditListeners, consumers );
+ mimeTypes, auditListeners, consumers, archivaXworkUser );
availableResources.add( 0, metadataChecksumResource );
}
}
ArchivaDavResource metadataResource =
new ArchivaDavResource( resourceFile.getAbsolutePath(), logicalResource.getPath(), null,
request.getRemoteAddr(), request.getDavSession(), archivaLocator, this,
- mimeTypes, auditListeners, consumers );
+ mimeTypes, auditListeners, consumers, archivaXworkUser );
availableResources.add( 0, metadataResource );
}
catch ( RepositoryMetadataException r )
resource =
new ArchivaDavResource( resourceFile.getAbsolutePath(), logicalResource,
managedRepository.getRepository(), davSession, archivaLocator, this, mimeTypes,
- auditListeners, consumers );
+ auditListeners, consumers, archivaXworkUser );
}
resource.addLockManager(lockManager);
return resource;
ArchivaDavResource resource =
new ArchivaDavResource( resourceFile.getAbsolutePath(), logicalResource.getPath(),
managedRepository.getRepository(), request.getRemoteAddr(),
- request.getDavSession(), locator, this, mimeTypes, auditListeners, consumers );
+ request.getDavSession(), locator, this, mimeTypes, auditListeners, consumers, archivaXworkUser );
if ( !resource.isCollection() )
{
new ArchivaDavResource( resourceFile.getAbsolutePath(), logicalResource.getPath(),
managedRepository.getRepository(), request.getRemoteAddr(),
request.getDavSession(), locator, this, mimeTypes, auditListeners,
- consumers );
+ consumers, archivaXworkUser );
}
}
return resource;
return new ArchivaDavResource( resourceFile.getAbsolutePath(), logicalResource.getPath(),
managedRepository.getRepository(), request.getRemoteAddr(),
- request.getDavSession(), locator, this, mimeTypes, auditListeners, consumers );
+ request.getDavSession(), locator, this, mimeTypes, auditListeners, consumers, archivaXworkUser );
}
private boolean fetchContentFromProxies( ManagedRepositoryContent managedRepository, DavServletRequest request,
// TODO: remove?
private void triggerAuditEvent( String remoteIP, String repositoryId, String resource, String action )
{
- String activePrincipal = ArchivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
+ String activePrincipal = archivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
AuditEvent event = new AuditEvent( repositoryId, activePrincipal, resource, action );
event.setRemoteIP( remoteIP );
request.getSession().getAttribute( SecuritySystemConstants.SECURITY_SESSION_KEY ) );
}
- String activePrincipal = ArchivaXworkUser.getActivePrincipal( sessionMap );
+ String activePrincipal = archivaXworkUser.getActivePrincipal( sessionMap );
boolean allow = isAllowedToContinue( request, repositories, activePrincipal );
if( allow )
*/
import java.io.File;
-import java.util.List;
import org.apache.commons.io.FileUtils;
import org.apache.jackrabbit.webdav.DavException;
import org.apache.jackrabbit.webdav.lock.SimpleLockManager;
import org.apache.jackrabbit.webdav.lock.Type;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
-import org.apache.maven.archiva.repository.audit.AuditListener;
import org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers;
+import org.apache.maven.archiva.security.ArchivaXworkUser;
import org.apache.maven.archiva.webdav.util.MimeTypes;
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
import org.codehaus.plexus.spring.PlexusToSpringUtils;
-import org.easymock.MockControl;
import edu.emory.mathcs.backport.java.util.Collections;
private RepositoryContentConsumers consumers;
private ManagedRepositoryConfiguration repository = new ManagedRepositoryConfiguration();
+
+ private ArchivaXworkUser archivaXworkUser;
@Override
protected void setUp()
lockManager = new SimpleLockManager();
resource.addLockManager(lockManager);
consumers = new RepositoryContentConsumers();
+ archivaXworkUser = (ArchivaXworkUser) getApplicationContext().getBean( PlexusToSpringUtils.buildSpringId( ArchivaXworkUser.class ) );
}
@Override
private DavResource getDavResource(String logicalPath, File file)
{
return new ArchivaDavResource( file.getAbsolutePath(), logicalPath, repository, session, resourceLocator,
- resourceFactory, mimeTypes, Collections.emptyList(), consumers );
+ resourceFactory, mimeTypes, Collections.emptyList(), consumers, archivaXworkUser );
}
public void testDeleteNonExistantResourceShould404()
public DavResource createResource(DavResourceLocator locator, DavSession session) throws DavException {
return new ArchivaDavResource( baseDir.getAbsolutePath(), "/", repository, session, resourceLocator,
- resourceFactory, mimeTypes, Collections.emptyList(), consumers );
+ resourceFactory, mimeTypes, Collections.emptyList(), consumers, archivaXworkUser );
}
}
}
<role>org.codehaus.plexus.digest.Digester</role>
<role-hint>md5</role-hint>
<field-name>digestMd5</field-name>
+ </requirement>
+ <requirement>
+ <role>org.apache.maven.archiva.security.ArchivaXworkUser</role>
+ <field-name>archivaXworkUser</field-name>
</requirement>
</requirements>
</component>