public static final String GUEST_ROLE = "Guest";
- // principals
-
- public static final String PRINCIPAL_GUEST = "guest";
-
// dynamic role prefixes
public static final String REPOSITORY_MANAGER_ROLE_PREFIX = "Repository Manager";
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.redback.users.UserManager;
import org.codehaus.plexus.registry.Registry;
/**
- * ArchivaXworkUser
+ * ArchivaXworkUser
*
* @version $Id$
- *
* @plexus.component role="org.apache.maven.archiva.security.ArchivaXworkUser"
*/
public class ArchivaXworkUser
{
- /**
- * @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 getGuest();
}
- SecuritySession securitySession =
+ SecuritySession securitySession =
(SecuritySession) sessionMap.get( SecuritySystemConstants.SECURITY_SESSION_KEY );
if ( securitySession == null )
return getGuest();
}
- User user = securitySession.getUser();
+ User user = securitySession.getUser();
if ( user == null )
{
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;
}
-
- public void setGuest( String guesT )
+
+ public String getGuest()
{
- guest = guesT;
+ return UserManager.GUEST_USERNAME;
}
}
import org.slf4j.LoggerFactory;
/**
- * SecurityStartup
+ * SecurityStartup
*
* @version $Id$
- *
* @plexus.component role="org.apache.maven.archiva.security.SecurityStartup"
*/
public class SecurityStartup
implements RegistryListener
{
private Logger log = LoggerFactory.getLogger( SecurityStartup.class );
-
+
/**
* @plexus.requirement
*/
*/
private ArchivaConfiguration archivaConfiguration;
+ /**
+ * @plexus.requirement
+ */
+ private ArchivaXworkUser archivaXworkUser;
+
public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
{
if ( ConfigurationNames.isManagedRepositories( propertyName ) )
{
String repoId = repoConfig.getId();
- // TODO: Use the Redback / UserConfiguration..getString( "redback.default.guest" ) to get the right name.
- String principal = "guest";
+ String principal = archivaXworkUser.getGuest();
try
{
catch ( RbacManagerException e )
{
log.warn(
- "Unable to add role [" + ArchivaRoleConstants.toRepositoryObserverRoleName( repoId )
- + "] to " + principal + " user.", e );
+ "Unable to add role [" + ArchivaRoleConstants.toRepositoryObserverRoleName( repoId ) + "] to " +
+ principal + " user.", e );
}
}
}
{
if ( ( checkers == null ) || CollectionUtils.isEmpty( checkers.values() ) )
{
- throw new ArchivaException( "Unable to initialize the Redback Security Environment, "
- + "no Environment Check components found." );
+ throw new ArchivaException(
+ "Unable to initialize the Redback Security Environment, " + "no Environment Check components found." );
}
List<String> violations = new ArrayList<String>();
msg.append( "======================================================================" );
log.error( msg.toString() );
- throw new ArchivaException( "Unable to initialize Redback Security Environment, [" + violations.size()
- + "] violation(s) encountered, See log for details." );
+ throw new ArchivaException( "Unable to initialize Redback Security Environment, [" + violations.size() +
+ "] violation(s) encountered, See log for details." );
}
}
import org.apache.maven.archiva.configuration.ConfigurationNames;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.security.ArchivaRoleConstants;
+import org.apache.maven.archiva.security.ArchivaXworkUser;
import org.codehaus.plexus.redback.rbac.RBACManager;
import org.codehaus.plexus.redback.rbac.RbacManagerException;
import org.codehaus.plexus.redback.rbac.UserAssignment;
* ConfigurationSynchronization
*
* @version $Id$
- *
* @plexus.component role="org.apache.maven.archiva.web.startup.SecuritySynchronization"
* role-hint="default"
*/
implements RegistryListener
{
private Logger log = LoggerFactory.getLogger( SecuritySynchronization.class );
-
+
/**
* @plexus.requirement role-hint="default"
*/
*/
private ArchivaConfiguration archivaConfiguration;
+ /**
+ * @plexus.requirement
+ */
+ private ArchivaXworkUser archivaXworkUser;
+
public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
{
if ( ConfigurationNames.isManagedRepositories( propertyName ) )
// manage roles for repositories
try
{
- if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoConfig
- .getId() ) )
+ if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER,
+ repoConfig.getId() ) )
{
- roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoConfig
- .getId() );
+ roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER,
+ repoConfig.getId() );
}
- if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoConfig
- .getId() ) )
+ if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER,
+ repoConfig.getId() ) )
{
- roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoConfig
- .getId() );
+ roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER,
+ repoConfig.getId() );
}
}
catch ( RoleManagerException e )
{
if ( ( checkers == null ) || CollectionUtils.isEmpty( checkers.values() ) )
{
- throw new ArchivaException( "Unable to initialize the Redback Security Environment, "
- + "no Environment Check components found." );
+ throw new ArchivaException(
+ "Unable to initialize the Redback Security Environment, " + "no Environment Check components found." );
}
List<String> violations = new ArrayList<String>();
msg.append( "======================================================================" );
log.error( msg.toString() );
- throw new ArchivaException( "Unable to initialize Redback Security Environment, [" + violations.size()
- + "] violation(s) encountered, See log for details." );
+ throw new ArchivaException( "Unable to initialize Redback Security Environment, [" + violations.size() +
+ "] violation(s) encountered, See log for details." );
}
}
for ( ManagedRepositoryConfiguration repoConfig : repos )
{
String repoId = repoConfig.getId();
-
- // TODO: Use the Redback / UserConfiguration..getString( "redback.default.guest" ) to get the right name.
- String principal = "guest";
-
+
+ String principal = archivaXworkUser.getGuest();
+
try
{
UserAssignment ua;
}
catch ( RbacManagerException e )
{
- log.warn( "Unable to add role [" + ArchivaRoleConstants.toRepositoryObserverRoleName( repoId )
- + "] to " + principal + " user.", e );
+ log.warn(
+ "Unable to add role [" + ArchivaRoleConstants.toRepositoryObserverRoleName( repoId ) + "] to " +
+ principal + " user.", e );
}
}
}
private HttpAuthenticator httpAuth;
- private ArchivaXworkUser archivaXworkUser;
-
private RepositoryServlet servlet;
public void setUp()
httpAuthControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
httpAuth = (HttpAuthenticator) httpAuthControl.getMock();
- archivaXworkUser = new ArchivaXworkUser();
- archivaXworkUser.setGuest( "guest" );
+ ArchivaXworkUser archivaXworkUser = (ArchivaXworkUser) lookup( ArchivaXworkUser.class );
davSessionProvider = new ArchivaDavSessionProvider( servletAuth, httpAuth, archivaXworkUser );
}