]> source.dussan.org Git - archiva.git/commitdiff
get RID of org.apache.maven.archiva packages : security package
authorOlivier Lamy <olamy@apache.org>
Sat, 3 Sep 2011 08:15:36 +0000 (08:15 +0000)
committerOlivier Lamy <olamy@apache.org>
Sat, 3 Sep 2011 08:15:36 +0000 (08:15 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1164822 13f79535-47bb-0310-9956-ffa450edef68

74 files changed:
archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ManagedRepositoriesService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java
archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/AccessDeniedException.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/ArchivaRoleConstants.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/ArchivaSecurityException.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/ArchivaServletAuthenticator.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/ArchivaStandardRolesCheck.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/ArchivaXworkUser.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/DefaultUserRepositories.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/PrincipalNotFoundException.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/ServletAuthenticator.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/UserRepositories.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/AccessDeniedException.java [deleted file]
archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaRoleConstants.java [deleted file]
archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaSecurityException.java [deleted file]
archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaServletAuthenticator.java [deleted file]
archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaStandardRolesCheck.java [deleted file]
archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaXworkUser.java [deleted file]
archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/DefaultUserRepositories.java [deleted file]
archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/PrincipalNotFoundException.java [deleted file]
archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ServletAuthenticator.java [deleted file]
archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/UserRepositories.java [deleted file]
archiva-modules/archiva-web/archiva-security/src/main/resources/META-INF/spring-context.xml
archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/archiva/security/AbstractSecurityTest.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/archiva/security/ArchivaServletAuthenticatorTest.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/archiva/security/DefaultUserRepositoriesTest.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/archiva/security/RoleManagerTest.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/maven/archiva/security/AbstractSecurityTest.java [deleted file]
archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/maven/archiva/security/ArchivaServletAuthenticatorTest.java [deleted file]
archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/maven/archiva/security/DefaultUserRepositoriesTest.java [deleted file]
archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/maven/archiva/security/RoleManagerTest.java [deleted file]
archiva-modules/archiva-web/archiva-security/src/test/resources/spring-context.xml
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/rss/RssFeedServlet.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/startup/SecuritySynchronization.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/tags/DependencyTree.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/AbstractActionSupport.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/AbstractRepositoryBasedAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/SchedulerAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/SystemStatusAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/appearance/EditOrganisationInfoAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/legacy/LegacyArtifactPathAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/networkproxies/ConfigureNetworkProxyAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/networkproxies/NetworkProxiesAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/scanning/RepositoryScanningAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/GenerateReportAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/ViewAuditLogReportAction.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/security/UserRepositoriesStub.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/security/UserRepositoriesStub.java [deleted file]
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AbstractActionTestCase.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/SearchActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/reports/GenerateReportActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/resources/spring-context-rss-servlet.xml
archiva-modules/archiva-web/archiva-webapp/src/test/resources/spring-context.xml
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceFactory.java
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavSessionProvider.java
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/RepositoryServlet.java
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/util/WebdavMethodUtil.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/ArchivaDavSessionProviderTest.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/MockServletAuthenticator.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletSecurityTest.java
archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-security/src/main/java/org/apache/archiva/web/xmlrpc/security/XmlRpcAuthenticator.java
archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-security/src/main/java/org/apache/archiva/web/xmlrpc/security/XmlRpcUserRepositories.java
archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-security/src/test/java/org/apache/archiva/xmlrpc/security/XmlRpcAuthenticatorTest.java
archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java

index 6adab675e4da937f558a9a2d921ae20a782b2915..2ddcdb8606e17c370b471172b022677a1815d285 100644 (file)
@@ -37,7 +37,7 @@ import org.apache.maven.archiva.configuration.Configuration;
 import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
 import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
-import org.apache.maven.archiva.security.ArchivaRoleConstants;
+import org.apache.archiva.security.ArchivaRoleConstants;
 import org.codehaus.plexus.redback.role.RoleManager;
 import org.codehaus.plexus.redback.role.RoleManagerException;
 import org.codehaus.plexus.redback.users.User;
index 534f1711798e9ad60348ea7a3189a76494e46381..ef1f7306643cbcb74f6d6abb225e04b058162433 100644 (file)
@@ -23,7 +23,7 @@ import org.apache.archiva.admin.mock.MockAuditListener;
 import org.apache.archiva.audit.AuditEvent;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.security.ArchivaRoleConstants;
+import org.apache.archiva.security.ArchivaRoleConstants;
 import org.codehaus.plexus.redback.role.RoleManager;
 import org.codehaus.plexus.redback.users.User;
 import org.codehaus.plexus.redback.users.memory.SimpleUser;
index cb592a2a98cced049bbb94828fe5ed3985e2108c..f530bbf5a4a916c1ab294c950c2f25007a882442 100644 (file)
@@ -21,8 +21,7 @@ package org.apache.archiva.rest.api.services;
 
 import org.apache.archiva.admin.repository.RepositoryAdminException;
 import org.apache.archiva.rest.api.model.ManagedRepository;
-import org.apache.archiva.rest.api.model.RemoteRepository;
-import org.apache.maven.archiva.security.ArchivaRoleConstants;
+import org.apache.archiva.security.ArchivaRoleConstants;
 import org.codehaus.plexus.redback.authorization.RedbackAuthorization;
 
 import javax.ws.rs.Consumes;
index e2ce301815059e29180cf621a4cae1a774f2fab3..1324388b6a2e93f18eceb52065823a2203a98285 100644 (file)
@@ -19,15 +19,11 @@ package org.apache.archiva.rest.api.services;
  * under the License.
  */
 
-import org.apache.archiva.admin.repository.RepositoryAdminException;
-import org.apache.archiva.rest.api.model.ManagedRepository;
 import org.apache.archiva.rest.api.model.RemoteRepository;
-import org.apache.maven.archiva.security.ArchivaRoleConstants;
+import org.apache.archiva.security.ArchivaRoleConstants;
 import org.codehaus.plexus.redback.authorization.RedbackAuthorization;
 
-import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
-import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/AccessDeniedException.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/AccessDeniedException.java
new file mode 100644 (file)
index 0000000..fe57169
--- /dev/null
@@ -0,0 +1,39 @@
+package org.apache.archiva.security;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * AccessDeniedException 
+ *
+ * @version $Id$
+ */
+public class AccessDeniedException
+    extends ArchivaSecurityException
+{
+    public AccessDeniedException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+
+    public AccessDeniedException( String message )
+    {
+        super( message );
+    }
+}
diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/ArchivaRoleConstants.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/ArchivaRoleConstants.java
new file mode 100644 (file)
index 0000000..1f8ca53
--- /dev/null
@@ -0,0 +1,86 @@
+package org.apache.archiva.security;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+public class ArchivaRoleConstants
+{
+    public static final String DELIMITER = " - ";
+
+    // globalish roles
+    public static final String SYSTEM_ADMINISTRATOR_ROLE = "System Administrator";
+
+    public static final String USER_ADMINISTRATOR_ROLE = "User Administrator";
+    
+    public static final String GLOBAL_REPOSITORY_MANAGER_ROLE = "Global Repository Manager";
+
+    public static final String GLOBAL_REPOSITORY_OBSERVER_ROLE = "Global Repository Observer";
+    
+    public static final String REGISTERED_USER_ROLE = "Registered User";
+
+    public static final String GUEST_ROLE = "Guest";
+    
+    // dynamic role prefixes
+    public static final String REPOSITORY_MANAGER_ROLE_PREFIX = "Repository Manager";
+
+    public static final String REPOSITORY_OBSERVER_ROLE_PREFIX = "Repository Observer";
+
+    // operations
+    public static final String OPERATION_MANAGE_USERS = "archiva-manage-users";
+
+    public static final String OPERATION_MANAGE_CONFIGURATION = "archiva-manage-configuration";
+
+    public static final String OPERATION_ACTIVE_GUEST = "archiva-guest";
+
+    public static final String OPERATION_RUN_INDEXER = "archiva-run-indexer";
+
+    public static final String OPERATION_REGENERATE_INDEX = "archiva-regenerate-index";
+
+    public static final String OPERATION_ACCESS_REPORT = "archiva-access-reports";
+
+    public static final String OPERATION_ADD_REPOSITORY = "archiva-add-repository";
+
+    public static final String OPERATION_REPOSITORY_ACCESS = "archiva-read-repository";
+
+    public static final String OPERATION_DELETE_REPOSITORY = "archiva-delete-repository";
+
+    public static final String OPERATION_EDIT_REPOSITORY = "archiva-edit-repository";
+
+    public static final String OPERATION_REPOSITORY_UPLOAD = "archiva-upload-repository";
+
+    public static final String OPERATION_REPOSITORY_DELETE = "archiva-delete-artifact";
+    
+    public static final String OPERATION_VIEW_AUDIT_LOG = "archiva-view-audit-logs";
+
+    // Role templates
+    public static final String TEMPLATE_REPOSITORY_MANAGER = "archiva-repository-manager";
+    
+    public static final String TEMPLATE_REPOSITORY_OBSERVER = "archiva-repository-observer";
+    
+    public static final String TEMPLATE_GLOBAL_REPOSITORY_OBSERVER = "archiva-global-repository-observer"; 
+    
+    public static final String TEMPLATE_SYSTEM_ADMIN = "archiva-system-administrator";
+    
+    public static final String TEMPLATE_GUEST = "archiva-guest";
+    
+    public static String toRepositoryObserverRoleName( String repoId )
+    {
+        return REPOSITORY_OBSERVER_ROLE_PREFIX + " - " + repoId;
+    }
+}
diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/ArchivaSecurityException.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/ArchivaSecurityException.java
new file mode 100644 (file)
index 0000000..07a4355
--- /dev/null
@@ -0,0 +1,41 @@
+package org.apache.archiva.security;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.common.ArchivaException;
+
+/**
+ * ArchivaSecurityException 
+ *
+ * @version $Id$
+ */
+public class ArchivaSecurityException
+    extends ArchivaException
+{
+    public ArchivaSecurityException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+
+    public ArchivaSecurityException( String message )
+    {
+        super( message );
+    }
+}
diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/ArchivaServletAuthenticator.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/ArchivaServletAuthenticator.java
new file mode 100644 (file)
index 0000000..8d00acb
--- /dev/null
@@ -0,0 +1,131 @@
+package org.apache.archiva.security;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+
+import org.codehaus.plexus.redback.authentication.AuthenticationException;
+import org.codehaus.plexus.redback.authentication.AuthenticationResult;
+import org.codehaus.plexus.redback.authorization.AuthorizationException;
+import org.codehaus.plexus.redback.authorization.AuthorizationResult;
+import org.codehaus.plexus.redback.authorization.UnauthorizedException;
+import org.codehaus.plexus.redback.policy.AccountLockedException;
+import org.codehaus.plexus.redback.policy.MustChangePasswordException;
+import org.codehaus.plexus.redback.system.DefaultSecuritySession;
+import org.codehaus.plexus.redback.system.SecuritySession;
+import org.codehaus.plexus.redback.system.SecuritySystem;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.redback.users.UserNotFoundException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+/**
+ * @version
+ * plexus.component role="org.apache.archiva.security.ServletAuthenticator" role-hint="default"
+ */
+@Service("servletAuthenticator")
+public class ArchivaServletAuthenticator
+    implements ServletAuthenticator
+{
+    private Logger log = LoggerFactory.getLogger( ArchivaServletAuthenticator.class );
+
+    /**
+     * plexus.requirement
+     */
+    @Inject
+    private SecuritySystem securitySystem;
+
+    public boolean isAuthenticated( HttpServletRequest request, AuthenticationResult result )
+        throws AuthenticationException, AccountLockedException, MustChangePasswordException
+    {
+        if ( result != null && !result.isAuthenticated() )
+        {
+            throw new AuthenticationException( "User Credentials Invalid" );
+        }
+
+        return true;
+    }
+
+    public boolean isAuthorized( HttpServletRequest request, SecuritySession securitySession, String repositoryId,
+                                 String permission )
+        throws AuthorizationException, UnauthorizedException
+    {
+        // TODO: also check for permission to proxy the resource when MRM-579 is implemented
+
+        AuthorizationResult authzResult = securitySystem.authorize( securitySession, permission, repositoryId );
+
+        if ( !authzResult.isAuthorized() )
+        {
+            if ( authzResult.getException() != null )
+            {
+                log.info( "Authorization Denied [ip=" + request.getRemoteAddr() + ",permission=" + permission
+                    + ",repo=" + repositoryId + "] : " + authzResult.getException().getMessage() );
+
+                throw new UnauthorizedException( "Access denied for repository " + repositoryId );
+            }
+            throw new UnauthorizedException( "User account is locked" );
+        }
+
+        return true;
+    }
+
+    public boolean isAuthorized( String principal, String repoId, String permission )
+        throws UnauthorizedException
+    {
+        try
+        {
+            User user = securitySystem.getUserManager().findUser( principal );
+            if ( user == null )
+            {
+                throw new UnauthorizedException( "The security system had an internal error - please check your system logs" );
+            }
+            if ( user.isLocked() )
+            {
+                throw new UnauthorizedException( "User account is locked." );
+            }
+
+            AuthenticationResult authn = new AuthenticationResult( true, principal, null );
+            SecuritySession securitySession = new DefaultSecuritySession( authn, user );
+
+            return securitySystem.isAuthorized( securitySession, permission, repoId );
+        }
+        catch ( UserNotFoundException e )
+        {
+            throw new UnauthorizedException( e.getMessage() );
+        }
+        catch ( AuthorizationException e )
+        {
+            throw new UnauthorizedException( e.getMessage() );
+        }
+    }
+
+
+    public SecuritySystem getSecuritySystem()
+    {
+        return securitySystem;
+    }
+
+    public void setSecuritySystem( SecuritySystem securitySystem )
+    {
+        this.securitySystem = securitySystem;
+    }
+}
diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/ArchivaStandardRolesCheck.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/ArchivaStandardRolesCheck.java
new file mode 100644 (file)
index 0000000..15b3e91
--- /dev/null
@@ -0,0 +1,109 @@
+package org.apache.archiva.security;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.List;
+
+import org.codehaus.plexus.redback.rbac.RBACManager;
+import org.codehaus.plexus.redback.system.check.EnvironmentCheck;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+/**
+ * ArchivaStandardRolesCheck tests for the existance of expected / standard roles and permissions. 
+ *
+ * @version $Id$
+ * 
+ * plexus.component role="org.codehaus.plexus.redback.system.check.EnvironmentCheck"
+ *                   role-hint="required-roles"
+ */
+@Service("environmentCheck#archiva-required-roles")
+public class ArchivaStandardRolesCheck
+    implements EnvironmentCheck
+{
+    private Logger log = LoggerFactory.getLogger( ArchivaStandardRolesCheck.class );
+    
+    /**
+     * plexus.requirement role-hint="cached"
+     */
+    @Inject @Named(value = "rBACManager#cached")
+    private RBACManager rbacManager;
+
+    /**
+     * boolean detailing if this environment check has been executed
+     */
+    private boolean checked = false;
+
+    public void validateEnvironment( List<String> violations )
+    {
+        if ( !checked )
+        {
+            String expectedRoles[] = new String[] {
+                ArchivaRoleConstants.SYSTEM_ADMINISTRATOR_ROLE,
+                ArchivaRoleConstants.GLOBAL_REPOSITORY_MANAGER_ROLE,
+                ArchivaRoleConstants.GLOBAL_REPOSITORY_OBSERVER_ROLE,
+                ArchivaRoleConstants.GUEST_ROLE,
+                ArchivaRoleConstants.REGISTERED_USER_ROLE,
+                ArchivaRoleConstants.USER_ADMINISTRATOR_ROLE };
+
+            log.info( "Checking the existance of required roles." );
+
+            for ( String roleName : expectedRoles )
+            {
+                if ( !rbacManager.roleExists( roleName ) )
+                {
+                    violations.add( "Unable to validate the existances of the '" + roleName + "' role." );
+                }
+            }
+
+            String expectedOperations[] = new String[] {
+                ArchivaRoleConstants.OPERATION_MANAGE_USERS,
+                ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION,
+                ArchivaRoleConstants.OPERATION_REGENERATE_INDEX,
+                ArchivaRoleConstants.OPERATION_RUN_INDEXER,
+                ArchivaRoleConstants.OPERATION_ACCESS_REPORT,
+                ArchivaRoleConstants.OPERATION_ADD_REPOSITORY,
+                ArchivaRoleConstants.OPERATION_DELETE_REPOSITORY,
+                ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS,
+                ArchivaRoleConstants.OPERATION_EDIT_REPOSITORY,
+                ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD,
+                ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS,
+                "archiva-guest" };
+
+            log.info( "Checking the existance of required operations." );
+
+            for ( String operation : expectedOperations )
+            {
+                if ( !rbacManager.operationExists( operation ) )
+                {
+                    violations.add( "Unable to validate the existances of the '" + operation + "' operation." );
+                }
+            }
+
+            checked = true;
+        }
+
+    }
+
+}
diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/ArchivaXworkUser.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/ArchivaXworkUser.java
new file mode 100644 (file)
index 0000000..65726bc
--- /dev/null
@@ -0,0 +1,64 @@
+package org.apache.archiva.security;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Map;
+
+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;
+
+/**
+ * ArchivaXworkUser
+ *
+ * @version $Id$
+ */
+public final class ArchivaXworkUser
+{
+    private ArchivaXworkUser()
+    {
+        // no touchy
+    }
+    
+    public static String getActivePrincipal( Map<String, ?> sessionMap )
+    {
+        if ( sessionMap == null )
+        {
+            return UserManager.GUEST_USERNAME;
+        }
+        
+        SecuritySession securitySession =
+            (SecuritySession) sessionMap.get( SecuritySystemConstants.SECURITY_SESSION_KEY );
+
+        if ( securitySession == null )
+        {
+            return UserManager.GUEST_USERNAME;
+        }
+
+        User user = securitySession.getUser();
+        if ( user == null )
+        {
+            return UserManager.GUEST_USERNAME;
+        }
+
+        return (String) user.getPrincipal();
+    }
+}
diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/DefaultUserRepositories.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/DefaultUserRepositories.java
new file mode 100644 (file)
index 0000000..983670f
--- /dev/null
@@ -0,0 +1,233 @@
+package org.apache.archiva.security;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import com.google.common.collect.Lists;
+import org.apache.maven.archiva.configuration.ArchivaConfiguration;
+import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.codehaus.plexus.redback.authentication.AuthenticationResult;
+import org.codehaus.plexus.redback.authorization.AuthorizationException;
+import org.codehaus.plexus.redback.role.RoleManager;
+import org.codehaus.plexus.redback.role.RoleManagerException;
+import org.codehaus.plexus.redback.system.DefaultSecuritySession;
+import org.codehaus.plexus.redback.system.SecuritySession;
+import org.codehaus.plexus.redback.system.SecuritySystem;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.redback.users.UserNotFoundException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * DefaultUserRepositories
+ *
+ * @version $Id$
+ *          plexus.component role="org.apache.archiva.security.UserRepositories" role-hint="default"
+ */
+@Service( "userRepositories" )
+public class DefaultUserRepositories
+    implements UserRepositories
+{
+    /**
+     * plexus.requirement
+     */
+    @Inject
+    private SecuritySystem securitySystem;
+
+    /**
+     * plexus.requirement role-hint="default"
+     */
+    @Inject
+    private RoleManager roleManager;
+
+    /**
+     * plexus.requirement
+     */
+    @Inject
+    private ArchivaConfiguration archivaConfiguration;
+
+    private Logger log = LoggerFactory.getLogger( DefaultUserRepositories.class );
+
+    public List<String> getObservableRepositoryIds( String principal )
+        throws PrincipalNotFoundException, AccessDeniedException, ArchivaSecurityException
+    {
+        String operation = ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS;
+
+        return getAccessibleRepositoryIds( principal, operation );
+    }
+
+    public List<String> getManagableRepositoryIds( String principal )
+        throws PrincipalNotFoundException, AccessDeniedException, ArchivaSecurityException
+    {
+        String operation = ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD;
+
+        return getAccessibleRepositoryIds( principal, operation );
+    }
+
+    private List<String> getAccessibleRepositoryIds( String principal, String operation )
+        throws ArchivaSecurityException, AccessDeniedException, PrincipalNotFoundException
+    {
+        SecuritySession securitySession = createSession( principal );
+
+        List<String> repoIds = new ArrayList<String>();
+
+        List<ManagedRepositoryConfiguration> repos = archivaConfiguration.getConfiguration().getManagedRepositories();
+
+        for ( ManagedRepositoryConfiguration repo : repos )
+        {
+            try
+            {
+                String repoId = repo.getId();
+                if ( securitySystem.isAuthorized( securitySession, operation, repoId ) )
+                {
+                    repoIds.add( repoId );
+                }
+            }
+            catch ( AuthorizationException e )
+            {
+                // swallow.
+                if ( log.isDebugEnabled() )
+                {
+                    log.debug( "Not authorizing '{}' for repository '{}': {}",
+                               Lists.<Object>newArrayList( principal, repo.getId(), e.getMessage() ) );
+                }
+            }
+        }
+
+        return repoIds;
+    }
+
+    private SecuritySession createSession( String principal )
+        throws ArchivaSecurityException, AccessDeniedException
+    {
+        User user;
+        try
+        {
+            user = securitySystem.getUserManager().findUser( principal );
+            if ( user == null )
+            {
+                throw new ArchivaSecurityException(
+                    "The security system had an internal error - please check your system logs" );
+            }
+        }
+        catch ( UserNotFoundException e )
+        {
+            throw new PrincipalNotFoundException( "Unable to find principal " + principal + "" );
+        }
+
+        if ( user.isLocked() )
+        {
+            throw new AccessDeniedException( "User " + principal + "(" + user.getFullName() + ") is locked." );
+        }
+
+        AuthenticationResult authn = new AuthenticationResult( true, principal, null );
+        return new DefaultSecuritySession( authn, user );
+    }
+
+    public void createMissingRepositoryRoles( String repoId )
+        throws ArchivaSecurityException
+    {
+        try
+        {
+            if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId ) )
+            {
+                roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
+            }
+
+            if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId ) )
+            {
+                roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
+            }
+        }
+        catch ( RoleManagerException e )
+        {
+            throw new ArchivaSecurityException( "Unable to create roles for configured repositories: " + e.getMessage(),
+                                                e );
+        }
+    }
+
+    public boolean isAuthorizedToUploadArtifacts( String principal, String repoId )
+        throws PrincipalNotFoundException, ArchivaSecurityException
+    {
+        try
+        {
+            SecuritySession securitySession = createSession( principal );
+
+            return securitySystem.isAuthorized( securitySession, ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD,
+                                                repoId );
+
+        }
+        catch ( AuthorizationException e )
+        {
+            throw new ArchivaSecurityException( e.getMessage() );
+        }
+    }
+
+    public boolean isAuthorizedToDeleteArtifacts( String principal, String repoId )
+        throws AccessDeniedException, ArchivaSecurityException
+    {
+        try
+        {
+            SecuritySession securitySession = createSession( principal );
+
+            return securitySystem.isAuthorized( securitySession, ArchivaRoleConstants.OPERATION_REPOSITORY_DELETE,
+                                                repoId );
+
+        }
+        catch ( AuthorizationException e )
+        {
+            throw new ArchivaSecurityException( e.getMessage() );
+        }
+    }
+
+    public SecuritySystem getSecuritySystem()
+    {
+        return securitySystem;
+    }
+
+    public void setSecuritySystem( SecuritySystem securitySystem )
+    {
+        this.securitySystem = securitySystem;
+    }
+
+    public RoleManager getRoleManager()
+    {
+        return roleManager;
+    }
+
+    public void setRoleManager( RoleManager roleManager )
+    {
+        this.roleManager = roleManager;
+    }
+
+    public ArchivaConfiguration getArchivaConfiguration()
+    {
+        return archivaConfiguration;
+    }
+
+    public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
+    {
+        this.archivaConfiguration = archivaConfiguration;
+    }
+}
diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/PrincipalNotFoundException.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/PrincipalNotFoundException.java
new file mode 100644 (file)
index 0000000..bc5ea07
--- /dev/null
@@ -0,0 +1,39 @@
+package org.apache.archiva.security;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * PrincipalNotFoundException 
+ *
+ * @version $Id$
+ */
+public class PrincipalNotFoundException
+    extends ArchivaSecurityException
+{
+    public PrincipalNotFoundException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+
+    public PrincipalNotFoundException( String message )
+    {
+        super( message );
+    }
+}
diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/ServletAuthenticator.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/ServletAuthenticator.java
new file mode 100644 (file)
index 0000000..58c4171
--- /dev/null
@@ -0,0 +1,79 @@
+package org.apache.archiva.security;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.codehaus.plexus.redback.authentication.AuthenticationException;
+import org.codehaus.plexus.redback.authentication.AuthenticationResult;
+import org.codehaus.plexus.redback.authorization.AuthorizationException;
+import org.codehaus.plexus.redback.authorization.UnauthorizedException;
+import org.codehaus.plexus.redback.policy.AccountLockedException;
+import org.codehaus.plexus.redback.policy.MustChangePasswordException;
+import org.codehaus.plexus.redback.system.SecuritySession;
+
+/**
+ * @version
+ */
+public interface ServletAuthenticator
+{
+    /**
+     * Authentication check for users.
+     * 
+     * @param request
+     * @param result
+     * @return
+     * @throws AuthenticationException
+     * @throws AccountLockedException
+     * @throws MustChangePasswordException
+     */
+    boolean isAuthenticated( HttpServletRequest request, AuthenticationResult result )
+        throws AuthenticationException, AccountLockedException, MustChangePasswordException;
+
+    /**
+     * Authorization check for valid users.
+     * 
+     * @param request
+     * @param securitySession
+     * @param repositoryId
+     * @param isWriteRequest
+     * @return
+     * @throws AuthorizationException
+     * @throws UnauthorizedException
+     */
+    boolean isAuthorized( HttpServletRequest request, SecuritySession securitySession, String repositoryId,
+        String permission ) throws AuthorizationException, UnauthorizedException;
+    
+    /**
+     * Authorization check specific for user guest, which doesn't go through 
+     * HttpBasicAuthentication#getAuthenticationResult( HttpServletRequest request, HttpServletResponse response )
+     * since no credentials are attached to the request. 
+     * 
+     * See also MRM-911
+     * 
+     * @param principal
+     * @param repoId
+     * @param isWriteRequest
+     * @return
+     * @throws UnauthorizedException
+     */
+    boolean isAuthorized( String principal, String repoId, String permission )
+        throws UnauthorizedException;
+}
diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/UserRepositories.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/UserRepositories.java
new file mode 100644 (file)
index 0000000..0535303
--- /dev/null
@@ -0,0 +1,88 @@
+package org.apache.archiva.security;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.List;
+
+/**
+ * UserRepositories 
+ *
+ * @version $Id$
+ */
+public interface UserRepositories
+{
+    /**
+     * Get the list of observable repository ids for the user specified.
+     * 
+     * @param principal the principle to obtain the observable repository ids from.
+     * @return the list of observable repository ids.
+     * @throws PrincipalNotFoundException
+     * @throws AccessDeniedException
+     * @throws ArchivaSecurityException
+     */
+    List<String> getObservableRepositoryIds( String principal )
+        throws PrincipalNotFoundException, AccessDeniedException, ArchivaSecurityException;
+    
+    /**
+     * Get the list of writable repository ids for the user specified.
+     * 
+     * @param principal the principle to obtain the observable repository ids from.
+     * @return the list of observable repository ids.
+     * @throws PrincipalNotFoundException
+     * @throws AccessDeniedException
+     * @throws ArchivaSecurityException
+     */
+    List<String> getManagableRepositoryIds( String principal )
+        throws PrincipalNotFoundException, AccessDeniedException, ArchivaSecurityException;
+    
+    /**
+     * Create any missing repository roles for the provided repository id.
+     * 
+     * @param repoId the repository id to work off of.
+     * @throws ArchivaSecurityException if there was a problem creating the repository roles.
+     */
+    void createMissingRepositoryRoles( String repoId )
+        throws ArchivaSecurityException;
+    
+    /**
+     * Check if user is authorized to upload artifacts in the repository.
+     * 
+     * @param principal
+     * @param repoId
+     * @return
+     * @throws PrincipalNotFoundException
+     * @throws ArchivaSecurityException
+     */
+    boolean isAuthorizedToUploadArtifacts( String principal, String repoId)
+        throws PrincipalNotFoundException, ArchivaSecurityException;
+     
+    /**
+     * Check if user is authorized to delete artifacts in the repository.
+     * 
+     * @param principal
+     * @param repoId
+     * @return
+     * @throws ArchivaSecurityException 
+     * @throws AccessDeniedException 
+     */
+    boolean isAuthorizedToDeleteArtifacts( String principal, String repoId )
+        throws AccessDeniedException, ArchivaSecurityException;
+    
+}
diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/AccessDeniedException.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/AccessDeniedException.java
deleted file mode 100644 (file)
index 6784aa6..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-package org.apache.maven.archiva.security;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * AccessDeniedException 
- *
- * @version $Id$
- */
-public class AccessDeniedException
-    extends ArchivaSecurityException
-{
-    public AccessDeniedException( String message, Throwable cause )
-    {
-        super( message, cause );
-    }
-
-    public AccessDeniedException( String message )
-    {
-        super( message );
-    }
-}
diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaRoleConstants.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaRoleConstants.java
deleted file mode 100644 (file)
index 396f925..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-package org.apache.maven.archiva.security;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-public class ArchivaRoleConstants
-{
-    public static final String DELIMITER = " - ";
-
-    // globalish roles
-    public static final String SYSTEM_ADMINISTRATOR_ROLE = "System Administrator";
-
-    public static final String USER_ADMINISTRATOR_ROLE = "User Administrator";
-    
-    public static final String GLOBAL_REPOSITORY_MANAGER_ROLE = "Global Repository Manager";
-
-    public static final String GLOBAL_REPOSITORY_OBSERVER_ROLE = "Global Repository Observer";
-    
-    public static final String REGISTERED_USER_ROLE = "Registered User";
-
-    public static final String GUEST_ROLE = "Guest";
-    
-    // dynamic role prefixes
-    public static final String REPOSITORY_MANAGER_ROLE_PREFIX = "Repository Manager";
-
-    public static final String REPOSITORY_OBSERVER_ROLE_PREFIX = "Repository Observer";
-
-    // operations
-    public static final String OPERATION_MANAGE_USERS = "archiva-manage-users";
-
-    public static final String OPERATION_MANAGE_CONFIGURATION = "archiva-manage-configuration";
-
-    public static final String OPERATION_ACTIVE_GUEST = "archiva-guest";
-
-    public static final String OPERATION_RUN_INDEXER = "archiva-run-indexer";
-
-    public static final String OPERATION_REGENERATE_INDEX = "archiva-regenerate-index";
-
-    public static final String OPERATION_ACCESS_REPORT = "archiva-access-reports";
-
-    public static final String OPERATION_ADD_REPOSITORY = "archiva-add-repository";
-
-    public static final String OPERATION_REPOSITORY_ACCESS = "archiva-read-repository";
-
-    public static final String OPERATION_DELETE_REPOSITORY = "archiva-delete-repository";
-
-    public static final String OPERATION_EDIT_REPOSITORY = "archiva-edit-repository";
-
-    public static final String OPERATION_REPOSITORY_UPLOAD = "archiva-upload-repository";
-
-    public static final String OPERATION_REPOSITORY_DELETE = "archiva-delete-artifact";
-    
-    public static final String OPERATION_VIEW_AUDIT_LOG = "archiva-view-audit-logs";
-
-    // Role templates
-    public static final String TEMPLATE_REPOSITORY_MANAGER = "archiva-repository-manager";
-    
-    public static final String TEMPLATE_REPOSITORY_OBSERVER = "archiva-repository-observer";
-    
-    public static final String TEMPLATE_GLOBAL_REPOSITORY_OBSERVER = "archiva-global-repository-observer"; 
-    
-    public static final String TEMPLATE_SYSTEM_ADMIN = "archiva-system-administrator";
-    
-    public static final String TEMPLATE_GUEST = "archiva-guest";
-    
-    public static String toRepositoryObserverRoleName( String repoId )
-    {
-        return REPOSITORY_OBSERVER_ROLE_PREFIX + " - " + repoId;
-    }
-}
diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaSecurityException.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaSecurityException.java
deleted file mode 100644 (file)
index 9621eeb..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-package org.apache.maven.archiva.security;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.maven.archiva.common.ArchivaException;
-
-/**
- * ArchivaSecurityException 
- *
- * @version $Id$
- */
-public class ArchivaSecurityException
-    extends ArchivaException
-{
-    public ArchivaSecurityException( String message, Throwable cause )
-    {
-        super( message, cause );
-    }
-
-    public ArchivaSecurityException( String message )
-    {
-        super( message );
-    }
-}
diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaServletAuthenticator.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaServletAuthenticator.java
deleted file mode 100644 (file)
index a73c9e4..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-package org.apache.maven.archiva.security;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import javax.inject.Inject;
-import javax.servlet.http.HttpServletRequest;
-
-import org.codehaus.plexus.redback.authentication.AuthenticationException;
-import org.codehaus.plexus.redback.authentication.AuthenticationResult;
-import org.codehaus.plexus.redback.authorization.AuthorizationException;
-import org.codehaus.plexus.redback.authorization.AuthorizationResult;
-import org.codehaus.plexus.redback.authorization.UnauthorizedException;
-import org.codehaus.plexus.redback.policy.AccountLockedException;
-import org.codehaus.plexus.redback.policy.MustChangePasswordException;
-import org.codehaus.plexus.redback.system.DefaultSecuritySession;
-import org.codehaus.plexus.redback.system.SecuritySession;
-import org.codehaus.plexus.redback.system.SecuritySystem;
-import org.codehaus.plexus.redback.users.User;
-import org.codehaus.plexus.redback.users.UserNotFoundException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Service;
-
-/**
- * @version
- * plexus.component role="org.apache.maven.archiva.security.ServletAuthenticator" role-hint="default"
- */
-@Service("servletAuthenticator")
-public class ArchivaServletAuthenticator
-    implements ServletAuthenticator
-{
-    private Logger log = LoggerFactory.getLogger( ArchivaServletAuthenticator.class );
-
-    /**
-     * plexus.requirement
-     */
-    @Inject
-    private SecuritySystem securitySystem;
-
-    public boolean isAuthenticated( HttpServletRequest request, AuthenticationResult result )
-        throws AuthenticationException, AccountLockedException, MustChangePasswordException
-    {
-        if ( result != null && !result.isAuthenticated() )
-        {
-            throw new AuthenticationException( "User Credentials Invalid" );
-        }
-
-        return true;
-    }
-
-    public boolean isAuthorized( HttpServletRequest request, SecuritySession securitySession, String repositoryId,
-                                 String permission )
-        throws AuthorizationException, UnauthorizedException
-    {
-        // TODO: also check for permission to proxy the resource when MRM-579 is implemented
-
-        AuthorizationResult authzResult = securitySystem.authorize( securitySession, permission, repositoryId );
-
-        if ( !authzResult.isAuthorized() )
-        {
-            if ( authzResult.getException() != null )
-            {
-                log.info( "Authorization Denied [ip=" + request.getRemoteAddr() + ",permission=" + permission
-                    + ",repo=" + repositoryId + "] : " + authzResult.getException().getMessage() );
-
-                throw new UnauthorizedException( "Access denied for repository " + repositoryId );
-            }
-            throw new UnauthorizedException( "User account is locked" );
-        }
-
-        return true;
-    }
-
-    public boolean isAuthorized( String principal, String repoId, String permission )
-        throws UnauthorizedException
-    {
-        try
-        {
-            User user = securitySystem.getUserManager().findUser( principal );
-            if ( user == null )
-            {
-                throw new UnauthorizedException( "The security system had an internal error - please check your system logs" );
-            }
-            if ( user.isLocked() )
-            {
-                throw new UnauthorizedException( "User account is locked." );
-            }
-
-            AuthenticationResult authn = new AuthenticationResult( true, principal, null );
-            SecuritySession securitySession = new DefaultSecuritySession( authn, user );
-
-            return securitySystem.isAuthorized( securitySession, permission, repoId );
-        }
-        catch ( UserNotFoundException e )
-        {
-            throw new UnauthorizedException( e.getMessage() );
-        }
-        catch ( AuthorizationException e )
-        {
-            throw new UnauthorizedException( e.getMessage() );
-        }
-    }
-
-
-    public SecuritySystem getSecuritySystem()
-    {
-        return securitySystem;
-    }
-
-    public void setSecuritySystem( SecuritySystem securitySystem )
-    {
-        this.securitySystem = securitySystem;
-    }
-}
diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaStandardRolesCheck.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaStandardRolesCheck.java
deleted file mode 100644 (file)
index 9554552..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-package org.apache.maven.archiva.security;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.List;
-
-import org.codehaus.plexus.redback.rbac.RBACManager;
-import org.codehaus.plexus.redback.system.check.EnvironmentCheck;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Service;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-/**
- * ArchivaStandardRolesCheck tests for the existance of expected / standard roles and permissions. 
- *
- * @version $Id$
- * 
- * plexus.component role="org.codehaus.plexus.redback.system.check.EnvironmentCheck"
- *                   role-hint="required-roles"
- */
-@Service("environmentCheck#archiva-required-roles")
-public class ArchivaStandardRolesCheck
-    implements EnvironmentCheck
-{
-    private Logger log = LoggerFactory.getLogger( ArchivaStandardRolesCheck.class );
-    
-    /**
-     * plexus.requirement role-hint="cached"
-     */
-    @Inject @Named(value = "rBACManager#cached")
-    private RBACManager rbacManager;
-
-    /**
-     * boolean detailing if this environment check has been executed
-     */
-    private boolean checked = false;
-
-    public void validateEnvironment( List<String> violations )
-    {
-        if ( !checked )
-        {
-            String expectedRoles[] = new String[] {
-                ArchivaRoleConstants.SYSTEM_ADMINISTRATOR_ROLE,
-                ArchivaRoleConstants.GLOBAL_REPOSITORY_MANAGER_ROLE,
-                ArchivaRoleConstants.GLOBAL_REPOSITORY_OBSERVER_ROLE,
-                ArchivaRoleConstants.GUEST_ROLE,
-                ArchivaRoleConstants.REGISTERED_USER_ROLE,
-                ArchivaRoleConstants.USER_ADMINISTRATOR_ROLE };
-
-            log.info( "Checking the existance of required roles." );
-
-            for ( String roleName : expectedRoles )
-            {
-                if ( !rbacManager.roleExists( roleName ) )
-                {
-                    violations.add( "Unable to validate the existances of the '" + roleName + "' role." );
-                }
-            }
-
-            String expectedOperations[] = new String[] {
-                ArchivaRoleConstants.OPERATION_MANAGE_USERS,
-                ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION,
-                ArchivaRoleConstants.OPERATION_REGENERATE_INDEX,
-                ArchivaRoleConstants.OPERATION_RUN_INDEXER,
-                ArchivaRoleConstants.OPERATION_ACCESS_REPORT,
-                ArchivaRoleConstants.OPERATION_ADD_REPOSITORY,
-                ArchivaRoleConstants.OPERATION_DELETE_REPOSITORY,
-                ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS,
-                ArchivaRoleConstants.OPERATION_EDIT_REPOSITORY,
-                ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD,
-                ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS,
-                "archiva-guest" };
-
-            log.info( "Checking the existance of required operations." );
-
-            for ( String operation : expectedOperations )
-            {
-                if ( !rbacManager.operationExists( operation ) )
-                {
-                    violations.add( "Unable to validate the existances of the '" + operation + "' operation." );
-                }
-            }
-
-            checked = true;
-        }
-
-    }
-
-}
diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaXworkUser.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaXworkUser.java
deleted file mode 100644 (file)
index 3176318..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-package org.apache.maven.archiva.security;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.Map;
-
-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;
-
-/**
- * ArchivaXworkUser
- *
- * @version $Id$
- */
-public final class ArchivaXworkUser
-{
-    private ArchivaXworkUser()
-    {
-        // no touchy
-    }
-    
-    public static String getActivePrincipal( Map<String, ?> sessionMap )
-    {
-        if ( sessionMap == null )
-        {
-            return UserManager.GUEST_USERNAME;
-        }
-        
-        SecuritySession securitySession =
-            (SecuritySession) sessionMap.get( SecuritySystemConstants.SECURITY_SESSION_KEY );
-
-        if ( securitySession == null )
-        {
-            return UserManager.GUEST_USERNAME;
-        }
-
-        User user = securitySession.getUser();
-        if ( user == null )
-        {
-            return UserManager.GUEST_USERNAME;
-        }
-
-        return (String) user.getPrincipal();
-    }
-}
diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/DefaultUserRepositories.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/DefaultUserRepositories.java
deleted file mode 100644 (file)
index c4603e4..0000000
+++ /dev/null
@@ -1,233 +0,0 @@
-package org.apache.maven.archiva.security;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import com.google.common.collect.Lists;
-import org.apache.maven.archiva.configuration.ArchivaConfiguration;
-import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
-import org.codehaus.plexus.redback.authentication.AuthenticationResult;
-import org.codehaus.plexus.redback.authorization.AuthorizationException;
-import org.codehaus.plexus.redback.role.RoleManager;
-import org.codehaus.plexus.redback.role.RoleManagerException;
-import org.codehaus.plexus.redback.system.DefaultSecuritySession;
-import org.codehaus.plexus.redback.system.SecuritySession;
-import org.codehaus.plexus.redback.system.SecuritySystem;
-import org.codehaus.plexus.redback.users.User;
-import org.codehaus.plexus.redback.users.UserNotFoundException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Service;
-
-import javax.inject.Inject;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * DefaultUserRepositories
- *
- * @version $Id$
- *          plexus.component role="org.apache.maven.archiva.security.UserRepositories" role-hint="default"
- */
-@Service( "userRepositories" )
-public class DefaultUserRepositories
-    implements UserRepositories
-{
-    /**
-     * plexus.requirement
-     */
-    @Inject
-    private SecuritySystem securitySystem;
-
-    /**
-     * plexus.requirement role-hint="default"
-     */
-    @Inject
-    private RoleManager roleManager;
-
-    /**
-     * plexus.requirement
-     */
-    @Inject
-    private ArchivaConfiguration archivaConfiguration;
-
-    private Logger log = LoggerFactory.getLogger( DefaultUserRepositories.class );
-
-    public List<String> getObservableRepositoryIds( String principal )
-        throws PrincipalNotFoundException, AccessDeniedException, ArchivaSecurityException
-    {
-        String operation = ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS;
-
-        return getAccessibleRepositoryIds( principal, operation );
-    }
-
-    public List<String> getManagableRepositoryIds( String principal )
-        throws PrincipalNotFoundException, AccessDeniedException, ArchivaSecurityException
-    {
-        String operation = ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD;
-
-        return getAccessibleRepositoryIds( principal, operation );
-    }
-
-    private List<String> getAccessibleRepositoryIds( String principal, String operation )
-        throws ArchivaSecurityException, AccessDeniedException, PrincipalNotFoundException
-    {
-        SecuritySession securitySession = createSession( principal );
-
-        List<String> repoIds = new ArrayList<String>();
-
-        List<ManagedRepositoryConfiguration> repos = archivaConfiguration.getConfiguration().getManagedRepositories();
-
-        for ( ManagedRepositoryConfiguration repo : repos )
-        {
-            try
-            {
-                String repoId = repo.getId();
-                if ( securitySystem.isAuthorized( securitySession, operation, repoId ) )
-                {
-                    repoIds.add( repoId );
-                }
-            }
-            catch ( AuthorizationException e )
-            {
-                // swallow.
-                if ( log.isDebugEnabled() )
-                {
-                    log.debug( "Not authorizing '{}' for repository '{}': {}",
-                               Lists.<Object>newArrayList( principal, repo.getId(), e.getMessage() ) );
-                }
-            }
-        }
-
-        return repoIds;
-    }
-
-    private SecuritySession createSession( String principal )
-        throws ArchivaSecurityException, AccessDeniedException
-    {
-        User user;
-        try
-        {
-            user = securitySystem.getUserManager().findUser( principal );
-            if ( user == null )
-            {
-                throw new ArchivaSecurityException(
-                    "The security system had an internal error - please check your system logs" );
-            }
-        }
-        catch ( UserNotFoundException e )
-        {
-            throw new PrincipalNotFoundException( "Unable to find principal " + principal + "" );
-        }
-
-        if ( user.isLocked() )
-        {
-            throw new AccessDeniedException( "User " + principal + "(" + user.getFullName() + ") is locked." );
-        }
-
-        AuthenticationResult authn = new AuthenticationResult( true, principal, null );
-        return new DefaultSecuritySession( authn, user );
-    }
-
-    public void createMissingRepositoryRoles( String repoId )
-        throws ArchivaSecurityException
-    {
-        try
-        {
-            if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId ) )
-            {
-                roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
-            }
-
-            if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId ) )
-            {
-                roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
-            }
-        }
-        catch ( RoleManagerException e )
-        {
-            throw new ArchivaSecurityException( "Unable to create roles for configured repositories: " + e.getMessage(),
-                                                e );
-        }
-    }
-
-    public boolean isAuthorizedToUploadArtifacts( String principal, String repoId )
-        throws PrincipalNotFoundException, ArchivaSecurityException
-    {
-        try
-        {
-            SecuritySession securitySession = createSession( principal );
-
-            return securitySystem.isAuthorized( securitySession, ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD,
-                                                repoId );
-
-        }
-        catch ( AuthorizationException e )
-        {
-            throw new ArchivaSecurityException( e.getMessage() );
-        }
-    }
-
-    public boolean isAuthorizedToDeleteArtifacts( String principal, String repoId )
-        throws AccessDeniedException, ArchivaSecurityException
-    {
-        try
-        {
-            SecuritySession securitySession = createSession( principal );
-
-            return securitySystem.isAuthorized( securitySession, ArchivaRoleConstants.OPERATION_REPOSITORY_DELETE,
-                                                repoId );
-
-        }
-        catch ( AuthorizationException e )
-        {
-            throw new ArchivaSecurityException( e.getMessage() );
-        }
-    }
-
-    public SecuritySystem getSecuritySystem()
-    {
-        return securitySystem;
-    }
-
-    public void setSecuritySystem( SecuritySystem securitySystem )
-    {
-        this.securitySystem = securitySystem;
-    }
-
-    public RoleManager getRoleManager()
-    {
-        return roleManager;
-    }
-
-    public void setRoleManager( RoleManager roleManager )
-    {
-        this.roleManager = roleManager;
-    }
-
-    public ArchivaConfiguration getArchivaConfiguration()
-    {
-        return archivaConfiguration;
-    }
-
-    public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
-    {
-        this.archivaConfiguration = archivaConfiguration;
-    }
-}
diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/PrincipalNotFoundException.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/PrincipalNotFoundException.java
deleted file mode 100644 (file)
index e08bd77..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-package org.apache.maven.archiva.security;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * PrincipalNotFoundException 
- *
- * @version $Id$
- */
-public class PrincipalNotFoundException
-    extends ArchivaSecurityException
-{
-    public PrincipalNotFoundException( String message, Throwable cause )
-    {
-        super( message, cause );
-    }
-
-    public PrincipalNotFoundException( String message )
-    {
-        super( message );
-    }
-}
diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ServletAuthenticator.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ServletAuthenticator.java
deleted file mode 100644 (file)
index 0dfdb00..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-package org.apache.maven.archiva.security;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.codehaus.plexus.redback.authentication.AuthenticationException;
-import org.codehaus.plexus.redback.authentication.AuthenticationResult;
-import org.codehaus.plexus.redback.authorization.AuthorizationException;
-import org.codehaus.plexus.redback.authorization.UnauthorizedException;
-import org.codehaus.plexus.redback.policy.AccountLockedException;
-import org.codehaus.plexus.redback.policy.MustChangePasswordException;
-import org.codehaus.plexus.redback.system.SecuritySession;
-
-/**
- * @version
- */
-public interface ServletAuthenticator
-{
-    /**
-     * Authentication check for users.
-     * 
-     * @param request
-     * @param result
-     * @return
-     * @throws AuthenticationException
-     * @throws AccountLockedException
-     * @throws MustChangePasswordException
-     */
-    boolean isAuthenticated( HttpServletRequest request, AuthenticationResult result )
-        throws AuthenticationException, AccountLockedException, MustChangePasswordException;
-
-    /**
-     * Authorization check for valid users.
-     * 
-     * @param request
-     * @param securitySession
-     * @param repositoryId
-     * @param isWriteRequest
-     * @return
-     * @throws AuthorizationException
-     * @throws UnauthorizedException
-     */
-    boolean isAuthorized( HttpServletRequest request, SecuritySession securitySession, String repositoryId,
-        String permission ) throws AuthorizationException, UnauthorizedException;
-    
-    /**
-     * Authorization check specific for user guest, which doesn't go through 
-     * HttpBasicAuthentication#getAuthenticationResult( HttpServletRequest request, HttpServletResponse response )
-     * since no credentials are attached to the request. 
-     * 
-     * See also MRM-911
-     * 
-     * @param principal
-     * @param repoId
-     * @param isWriteRequest
-     * @return
-     * @throws UnauthorizedException
-     */
-    boolean isAuthorized( String principal, String repoId, String permission )
-        throws UnauthorizedException;
-}
diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/UserRepositories.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/UserRepositories.java
deleted file mode 100644 (file)
index 35a5b19..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-package org.apache.maven.archiva.security;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.List;
-
-/**
- * UserRepositories 
- *
- * @version $Id$
- */
-public interface UserRepositories
-{
-    /**
-     * Get the list of observable repository ids for the user specified.
-     * 
-     * @param principal the principle to obtain the observable repository ids from.
-     * @return the list of observable repository ids.
-     * @throws PrincipalNotFoundException
-     * @throws AccessDeniedException
-     * @throws ArchivaSecurityException
-     */
-    List<String> getObservableRepositoryIds( String principal )
-        throws PrincipalNotFoundException, AccessDeniedException, ArchivaSecurityException;
-    
-    /**
-     * Get the list of writable repository ids for the user specified.
-     * 
-     * @param principal the principle to obtain the observable repository ids from.
-     * @return the list of observable repository ids.
-     * @throws PrincipalNotFoundException
-     * @throws AccessDeniedException
-     * @throws ArchivaSecurityException
-     */
-    List<String> getManagableRepositoryIds( String principal )
-        throws PrincipalNotFoundException, AccessDeniedException, ArchivaSecurityException;
-    
-    /**
-     * Create any missing repository roles for the provided repository id.
-     * 
-     * @param repoId the repository id to work off of.
-     * @throws ArchivaSecurityException if there was a problem creating the repository roles.
-     */
-    void createMissingRepositoryRoles( String repoId )
-        throws ArchivaSecurityException;
-    
-    /**
-     * Check if user is authorized to upload artifacts in the repository.
-     * 
-     * @param principal
-     * @param repoId
-     * @return
-     * @throws PrincipalNotFoundException
-     * @throws ArchivaSecurityException
-     */
-    boolean isAuthorizedToUploadArtifacts( String principal, String repoId)
-        throws PrincipalNotFoundException, ArchivaSecurityException;
-     
-    /**
-     * Check if user is authorized to delete artifacts in the repository.
-     * 
-     * @param principal
-     * @param repoId
-     * @return
-     * @throws ArchivaSecurityException 
-     * @throws AccessDeniedException 
-     */
-    boolean isAuthorizedToDeleteArtifacts( String principal, String repoId )
-        throws AccessDeniedException, ArchivaSecurityException;
-    
-}
index 5678a3a0d546d0b48f91fda850737b4122cd7e7b..3f0c8e5860633e4581a4fa101a7084db0d5e2a80 100644 (file)
@@ -28,6 +28,6 @@
        default-lazy-init="true">
 
   <context:annotation-config />
-  <context:component-scan base-package="org.apache.maven.archiva.security"/>
+  <context:component-scan base-package="org.apache.archiva.security"/>
  
 </beans>
\ No newline at end of file
diff --git a/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/archiva/security/AbstractSecurityTest.java b/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/archiva/security/AbstractSecurityTest.java
new file mode 100644 (file)
index 0000000..6f6fcea
--- /dev/null
@@ -0,0 +1,166 @@
+package org.apache.archiva.security;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import com.google.common.collect.Lists;
+import junit.framework.TestCase;
+import net.sf.ehcache.CacheManager;
+import org.apache.commons.io.FileUtils;
+import org.apache.maven.archiva.configuration.ArchivaConfiguration;
+import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.codehaus.plexus.redback.rbac.RBACManager;
+import org.codehaus.plexus.redback.rbac.RbacObjectNotFoundException;
+import org.codehaus.plexus.redback.rbac.UserAssignment;
+import org.codehaus.plexus.redback.role.RoleManager;
+import org.codehaus.plexus.redback.system.SecuritySystem;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.redback.users.UserManager;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import java.io.File;
+
+/**
+ * AbstractSecurityTest
+ *
+ * @version $Id: AbstractSecurityTest
+ */
+@RunWith( SpringJUnit4ClassRunner.class )
+@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
+public abstract class AbstractSecurityTest
+    extends TestCase
+{
+
+    protected Logger log = LoggerFactory.getLogger( getClass() );
+
+    protected static final String USER_GUEST = "guest";
+
+    protected static final String USER_ADMIN = "admin";
+
+    protected static final String USER_ALPACA = "alpaca";
+
+    @Inject
+    @Named( value = "securitySystem#testable" )
+    protected SecuritySystem securitySystem;
+
+    @Inject
+    @Named( value = "rBACManager#memory" )
+    protected RBACManager rbacManager;
+
+    @Inject
+    protected RoleManager roleManager;
+
+    @Inject
+    @Named( value = "archivaConfiguration#default" )
+    private ArchivaConfiguration archivaConfiguration;
+
+    @Inject
+    protected UserRepositories userRepos;
+
+    protected void setupRepository( String repoId )
+        throws Exception
+    {
+        // Add repo to configuration.
+        ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
+        repoConfig.setId( repoId );
+        repoConfig.setName( "Testable repo <" + repoId + ">" );
+        repoConfig.setLocation( new File( "./target/test-repo/" + repoId ).getPath() );
+        if ( !archivaConfiguration.getConfiguration().getManagedRepositoriesAsMap().containsKey( repoId ) )
+        {
+            archivaConfiguration.getConfiguration().addManagedRepository( repoConfig );
+        }
+
+        // Add repo roles to security.
+        userRepos.createMissingRepositoryRoles( repoId );
+    }
+
+    protected void assignRepositoryObserverRole( String principal, String repoId )
+        throws Exception
+    {
+        roleManager.assignTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId, principal );
+    }
+
+    protected User createUser( String principal, String fullname )
+    {
+        UserManager userManager = securitySystem.getUserManager();
+
+        User user = userManager.createUser( principal, fullname, principal + "@testable.archiva.apache.org" );
+        securitySystem.getPolicy().setEnabled( false );
+        userManager.addUser( user );
+        securitySystem.getPolicy().setEnabled( true );
+
+        return user;
+    }
+
+    @Override
+    @Before
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        File srcConfig = new File( "./src/test/resources/repository-archiva.xml" );
+        File destConfig = new File( "./target/test-conf/archiva.xml" );
+
+        destConfig.getParentFile().mkdirs();
+        destConfig.delete();
+
+        FileUtils.copyFile( srcConfig, destConfig );
+
+        // Some basic asserts.
+        assertNotNull( securitySystem );
+        assertNotNull( rbacManager );
+        assertNotNull( roleManager );
+        assertNotNull( userRepos );
+        assertNotNull( archivaConfiguration );
+
+        // Setup Admin User.
+        User adminUser = createUser( USER_ADMIN, "Admin User" );
+        roleManager.assignRole( ArchivaRoleConstants.TEMPLATE_SYSTEM_ADMIN, adminUser.getPrincipal().toString() );
+
+        // Setup Guest User.
+        User guestUser = createUser( USER_GUEST, "Guest User" );
+        roleManager.assignRole( ArchivaRoleConstants.TEMPLATE_GUEST, guestUser.getPrincipal().toString() );
+    }
+
+    protected void restoreGuestInitialValues( String userId )
+        throws Exception
+    {
+        UserAssignment userAssignment = null;
+        try
+        {
+            userAssignment = rbacManager.getUserAssignment( userId );
+        }
+        catch ( RbacObjectNotFoundException e )
+        {
+            log.info( "ignore RbacObjectNotFoundException for id {} during restoreGuestInitialValues", userId );
+            return;
+        }
+        userAssignment.setRoleNames( Lists.newArrayList( "Guest" ) );
+        rbacManager.saveUserAssignment( userAssignment );
+        CacheManager.getInstance().clearAll();
+    }
+}
diff --git a/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/archiva/security/ArchivaServletAuthenticatorTest.java b/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/archiva/security/ArchivaServletAuthenticatorTest.java
new file mode 100644 (file)
index 0000000..e6ed541
--- /dev/null
@@ -0,0 +1,258 @@
+package org.apache.archiva.security;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.codehaus.plexus.redback.authentication.AuthenticationException;
+import org.codehaus.plexus.redback.authentication.AuthenticationResult;
+import org.codehaus.plexus.redback.authorization.UnauthorizedException;
+import org.codehaus.plexus.redback.system.DefaultSecuritySession;
+import org.codehaus.plexus.redback.system.SecuritySession;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.redback.users.UserManager;
+import org.easymock.MockControl;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * ArchivaServletAuthenticatorTest
+ */
+public class ArchivaServletAuthenticatorTest
+    extends AbstractSecurityTest
+{
+    @Inject
+    @Named( value = "servletAuthenticator#test" )
+    private ServletAuthenticator servletAuth;
+
+    private MockControl httpServletRequestControl;
+
+    private HttpServletRequest request;
+
+    @Before
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        httpServletRequestControl = MockControl.createControl( HttpServletRequest.class );
+        request = (HttpServletRequest) httpServletRequestControl.getMock();
+
+        setupRepository( "corporate" );
+    }
+
+    protected String getPlexusConfigLocation()
+    {
+        return "org/apache/maven/archiva/security/ArchivaServletAuthenticatorTest.xml";
+    }
+
+    protected void assignRepositoryManagerRole( String principal, String repoId )
+        throws Exception
+    {
+        roleManager.assignTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId, principal );
+    }
+
+    @Test
+    public void testIsAuthenticatedUserExists()
+        throws Exception
+    {
+        AuthenticationResult result = new AuthenticationResult( true, "user", null );
+        boolean isAuthenticated = servletAuth.isAuthenticated( request, result );
+
+        assertTrue( isAuthenticated );
+    }
+
+    @Test
+    public void testIsAuthenticatedUserDoesNotExist()
+        throws Exception
+    {
+        AuthenticationResult result = new AuthenticationResult( false, "non-existing-user", null );
+        try
+        {
+            servletAuth.isAuthenticated( request, result );
+            fail( "Authentication exception should have been thrown." );
+        }
+        catch ( AuthenticationException e )
+        {
+            assertEquals( "User Credentials Invalid", e.getMessage() );
+        }
+    }
+
+    @Test
+    public void testIsAuthorizedUserHasWriteAccess()
+        throws Exception
+    {
+        createUser( USER_ALPACA, "Al 'Archiva' Paca" );
+
+        assignRepositoryManagerRole( USER_ALPACA, "corporate" );
+
+        UserManager userManager = securitySystem.getUserManager();
+        User user = userManager.findUser( USER_ALPACA );
+
+        AuthenticationResult result = new AuthenticationResult( true, USER_ALPACA, null );
+
+        SecuritySession session = new DefaultSecuritySession( result, user );
+        boolean isAuthorized =
+            servletAuth.isAuthorized( request, session, "corporate", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD );
+
+        assertTrue( isAuthorized );
+
+        restoreGuestInitialValues( USER_ALPACA );
+    }
+
+    @Test
+    public void testIsAuthorizedUserHasNoWriteAccess()
+        throws Exception
+    {
+        createUser( USER_ALPACA, "Al 'Archiva' Paca" );
+
+        assignRepositoryObserverRole( USER_ALPACA, "corporate" );
+
+        httpServletRequestControl.expectAndReturn( request.getRemoteAddr(), "192.168.111.111" );
+
+        UserManager userManager = securitySystem.getUserManager();
+        User user = userManager.findUser( USER_ALPACA );
+
+        AuthenticationResult result = new AuthenticationResult( true, USER_ALPACA, null );
+
+        SecuritySession session = new DefaultSecuritySession( result, user );
+
+        httpServletRequestControl.replay();
+
+        try
+        {
+            servletAuth.isAuthorized( request, session, "corporate", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD );
+            fail( "UnauthorizedException should have been thrown." );
+        }
+        catch ( UnauthorizedException e )
+        {
+            assertEquals( "Access denied for repository corporate", e.getMessage() );
+        }
+
+        httpServletRequestControl.verify();
+
+        restoreGuestInitialValues( USER_ALPACA );
+    }
+
+    @Test
+    public void testIsAuthorizedUserHasReadAccess()
+        throws Exception
+    {
+        createUser( USER_ALPACA, "Al 'Archiva' Paca" );
+
+        assignRepositoryObserverRole( USER_ALPACA, "corporate" );
+
+        UserManager userManager = securitySystem.getUserManager();
+        User user = userManager.findUser( USER_ALPACA );
+
+        AuthenticationResult result = new AuthenticationResult( true, USER_ALPACA, null );
+
+        SecuritySession session = new DefaultSecuritySession( result, user );
+        boolean isAuthorized =
+            servletAuth.isAuthorized( request, session, "corporate", ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS );
+
+        assertTrue( isAuthorized );
+
+        restoreGuestInitialValues( USER_ALPACA );
+    }
+
+    @Test
+    public void testIsAuthorizedUserHasNoReadAccess()
+        throws Exception
+    {
+        createUser( USER_ALPACA, "Al 'Archiva' Paca" );
+
+        UserManager userManager = securitySystem.getUserManager();
+        User user = userManager.findUser( USER_ALPACA );
+
+        AuthenticationResult result = new AuthenticationResult( true, USER_ALPACA, null );
+
+        SecuritySession session = new DefaultSecuritySession( result, user );
+        try
+        {
+            servletAuth.isAuthorized( request, session, "corporate", ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS );
+            fail( "UnauthorizedException should have been thrown." );
+        }
+        catch ( UnauthorizedException e )
+        {
+            assertEquals( "Access denied for repository corporate", e.getMessage() );
+        }
+
+        restoreGuestInitialValues( USER_ALPACA );
+    }
+
+    @Test
+    public void testIsAuthorizedGuestUserHasWriteAccess()
+        throws Exception
+    {
+        assignRepositoryManagerRole( USER_GUEST, "corporate" );
+        boolean isAuthorized =
+            servletAuth.isAuthorized( USER_GUEST, "corporate", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD );
+
+        assertTrue( isAuthorized );
+
+        // cleanup previously add karma
+        restoreGuestInitialValues(USER_GUEST);
+
+    }
+
+    @Test
+    public void testIsAuthorizedGuestUserHasNoWriteAccess()
+        throws Exception
+    {
+        assignRepositoryObserverRole( USER_GUEST, "corporate" );
+
+        boolean isAuthorized =
+            servletAuth.isAuthorized( USER_GUEST, "corporate", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD );
+        assertFalse( isAuthorized );
+
+        // cleanup previously add karma
+        restoreGuestInitialValues(USER_GUEST);
+
+    }
+
+    @Test
+    public void testIsAuthorizedGuestUserHasReadAccess()
+        throws Exception
+    {
+        assignRepositoryObserverRole( USER_GUEST, "corporate" );
+
+        boolean isAuthorized =
+            servletAuth.isAuthorized( USER_GUEST, "corporate", ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS );
+
+        assertTrue( isAuthorized );
+
+        // cleanup previously add karma
+        restoreGuestInitialValues(USER_GUEST);
+    }
+
+    @Test
+    public void testIsAuthorizedGuestUserHasNoReadAccess()
+        throws Exception
+    {
+        boolean isAuthorized =
+            servletAuth.isAuthorized( USER_GUEST, "corporate", ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS );
+
+        assertFalse( isAuthorized );
+    }
+
+}
diff --git a/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/archiva/security/DefaultUserRepositoriesTest.java b/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/archiva/security/DefaultUserRepositoriesTest.java
new file mode 100644 (file)
index 0000000..9d2c0ce
--- /dev/null
@@ -0,0 +1,107 @@
+package org.apache.archiva.security;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.lang.StringUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.List;
+
+/**
+ * DefaultUserRepositoriesTest
+ *
+ * @version $Id$
+ */
+public class DefaultUserRepositoriesTest
+    extends AbstractSecurityTest
+{
+
+
+    @Before
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+        restoreGuestInitialValues( USER_ALPACA );
+        restoreGuestInitialValues( USER_GUEST );
+        restoreGuestInitialValues( USER_ADMIN );
+    }
+
+    @Test
+    public void testGetObservableRepositoryIds()
+        throws Exception
+    {
+        // create some users.
+        createUser( USER_ALPACA, "Al 'Archiva' Paca" );
+
+        assertEquals( "Expected users", 3, securitySystem.getUserManager().getUsers().size() );
+
+        // some unassigned repo observer roles.
+        setupRepository( "central" );
+        setupRepository( "corporate" );
+        setupRepository( "internal" );
+        setupRepository( "snapshots" );
+        setupRepository( "secret" );
+
+        // some assigned repo observer roles.
+        assignRepositoryObserverRole( USER_ALPACA, "corporate" );
+        assignRepositoryObserverRole( USER_ALPACA, "central" );
+        assignRepositoryObserverRole( USER_GUEST, "corporate" );
+        // the global repo observer role.
+        assignGlobalRepositoryObserverRole( USER_ADMIN );
+
+        assertRepoIds( new String[]{ "central", "corporate" }, userRepos.getObservableRepositoryIds( USER_ALPACA ) );
+        assertRepoIds( new String[]{ "coporate" }, userRepos.getObservableRepositoryIds( USER_GUEST ) );
+        assertRepoIds( new String[]{ "central", "internal", "corporate", "snapshots", "secret" },
+                       userRepos.getObservableRepositoryIds( USER_ADMIN ) );
+
+    }
+
+    @After
+    public void tearDown()
+        throws Exception
+    {
+        super.tearDown();
+        restoreGuestInitialValues( USER_ALPACA );
+        restoreGuestInitialValues( USER_GUEST );
+        restoreGuestInitialValues( USER_ADMIN );
+    }
+
+    private void assertRepoIds( String[] expectedRepoIds, List<String> observableRepositoryIds )
+    {
+        assertNotNull( "Observable Repository Ids cannot be null.", observableRepositoryIds );
+
+        if ( expectedRepoIds.length != observableRepositoryIds.size() )
+        {
+            fail( "Size of Observable Repository Ids wrong, expected <" + expectedRepoIds.length + "> but got <"
+                      + observableRepositoryIds.size() + "> instead. \nExpected: ["
+                      + StringUtils.join( expectedRepoIds, "," ) + "]\nActual: ["
+                      + StringUtils.join( observableRepositoryIds.iterator(), "," ) + "]" );
+        }
+    }
+
+    private void assignGlobalRepositoryObserverRole( String principal )
+        throws Exception
+    {
+        roleManager.assignRole( ArchivaRoleConstants.TEMPLATE_GLOBAL_REPOSITORY_OBSERVER, principal );
+    }
+}
diff --git a/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/archiva/security/RoleManagerTest.java b/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/archiva/security/RoleManagerTest.java
new file mode 100644 (file)
index 0000000..8e0799f
--- /dev/null
@@ -0,0 +1,57 @@
+package org.apache.archiva.security;
+
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.TestCase;
+import org.codehaus.plexus.redback.role.RoleManager;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import javax.inject.Inject;
+
+/**
+ * RoleProfilesTest 
+ *
+ * @version $Id: RoleManagerTest.java 4330 2007-05-10 17:28:56Z jmcconnell $
+ */
+@RunWith( SpringJUnit4ClassRunner.class )
+@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
+public class RoleManagerTest
+    extends TestCase
+{
+
+    @Inject
+    RoleManager roleManager;
+    
+    @Test
+    public void testExpectedRoles()
+        throws Exception
+    {
+        assertNotNull( roleManager );
+        
+        assertTrue( roleManager.roleExists( "system-administrator" ) );
+        assertTrue( roleManager.roleExists( "user-administrator" ) );
+        assertTrue( roleManager.roleExists( "archiva-global-repository-observer" ) );
+        assertTrue( roleManager.roleExists( "archiva-guest" ) );        
+        assertTrue( roleManager.roleExists( "guest" ) );
+    }
+}
diff --git a/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/maven/archiva/security/AbstractSecurityTest.java b/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/maven/archiva/security/AbstractSecurityTest.java
deleted file mode 100644 (file)
index 6308f07..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-package org.apache.maven.archiva.security;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import com.google.common.collect.Lists;
-import junit.framework.TestCase;
-import net.sf.ehcache.CacheManager;
-import org.apache.commons.io.FileUtils;
-import org.apache.maven.archiva.configuration.ArchivaConfiguration;
-import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
-import org.codehaus.plexus.redback.rbac.RBACManager;
-import org.codehaus.plexus.redback.rbac.RbacObjectNotFoundException;
-import org.codehaus.plexus.redback.rbac.UserAssignment;
-import org.codehaus.plexus.redback.role.RoleManager;
-import org.codehaus.plexus.redback.system.SecuritySystem;
-import org.codehaus.plexus.redback.users.User;
-import org.codehaus.plexus.redback.users.UserManager;
-import org.junit.Before;
-import org.junit.runner.RunWith;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-import java.io.File;
-
-/**
- * AbstractSecurityTest
- *
- * @version $Id: AbstractSecurityTest
- */
-@RunWith( SpringJUnit4ClassRunner.class )
-@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
-public abstract class AbstractSecurityTest
-    extends TestCase
-{
-
-    protected Logger log = LoggerFactory.getLogger( getClass() );
-
-    protected static final String USER_GUEST = "guest";
-
-    protected static final String USER_ADMIN = "admin";
-
-    protected static final String USER_ALPACA = "alpaca";
-
-    @Inject
-    @Named( value = "securitySystem#testable" )
-    protected SecuritySystem securitySystem;
-
-    @Inject
-    @Named( value = "rBACManager#memory" )
-    protected RBACManager rbacManager;
-
-    @Inject
-    protected RoleManager roleManager;
-
-    @Inject
-    @Named( value = "archivaConfiguration#default" )
-    private ArchivaConfiguration archivaConfiguration;
-
-    @Inject
-    protected UserRepositories userRepos;
-
-    protected void setupRepository( String repoId )
-        throws Exception
-    {
-        // Add repo to configuration.
-        ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
-        repoConfig.setId( repoId );
-        repoConfig.setName( "Testable repo <" + repoId + ">" );
-        repoConfig.setLocation( new File( "./target/test-repo/" + repoId ).getPath() );
-        if ( !archivaConfiguration.getConfiguration().getManagedRepositoriesAsMap().containsKey( repoId ) )
-        {
-            archivaConfiguration.getConfiguration().addManagedRepository( repoConfig );
-        }
-
-        // Add repo roles to security.
-        userRepos.createMissingRepositoryRoles( repoId );
-    }
-
-    protected void assignRepositoryObserverRole( String principal, String repoId )
-        throws Exception
-    {
-        roleManager.assignTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId, principal );
-    }
-
-    protected User createUser( String principal, String fullname )
-    {
-        UserManager userManager = securitySystem.getUserManager();
-
-        User user = userManager.createUser( principal, fullname, principal + "@testable.archiva.apache.org" );
-        securitySystem.getPolicy().setEnabled( false );
-        userManager.addUser( user );
-        securitySystem.getPolicy().setEnabled( true );
-
-        return user;
-    }
-
-    @Override
-    @Before
-    public void setUp()
-        throws Exception
-    {
-        super.setUp();
-
-        File srcConfig = new File( "./src/test/resources/repository-archiva.xml" );
-        File destConfig = new File( "./target/test-conf/archiva.xml" );
-
-        destConfig.getParentFile().mkdirs();
-        destConfig.delete();
-
-        FileUtils.copyFile( srcConfig, destConfig );
-
-        // Some basic asserts.
-        assertNotNull( securitySystem );
-        assertNotNull( rbacManager );
-        assertNotNull( roleManager );
-        assertNotNull( userRepos );
-        assertNotNull( archivaConfiguration );
-
-        // Setup Admin User.
-        User adminUser = createUser( USER_ADMIN, "Admin User" );
-        roleManager.assignRole( ArchivaRoleConstants.TEMPLATE_SYSTEM_ADMIN, adminUser.getPrincipal().toString() );
-
-        // Setup Guest User.
-        User guestUser = createUser( USER_GUEST, "Guest User" );
-        roleManager.assignRole( ArchivaRoleConstants.TEMPLATE_GUEST, guestUser.getPrincipal().toString() );
-    }
-
-    protected void restoreGuestInitialValues( String userId )
-        throws Exception
-    {
-        UserAssignment userAssignment = null;
-        try
-        {
-            userAssignment = rbacManager.getUserAssignment( userId );
-        }
-        catch ( RbacObjectNotFoundException e )
-        {
-            log.info( "ignore RbacObjectNotFoundException for id {} during restoreGuestInitialValues", userId );
-            return;
-        }
-        userAssignment.setRoleNames( Lists.newArrayList( "Guest" ) );
-        rbacManager.saveUserAssignment( userAssignment );
-        CacheManager.getInstance().clearAll();
-    }
-}
diff --git a/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/maven/archiva/security/ArchivaServletAuthenticatorTest.java b/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/maven/archiva/security/ArchivaServletAuthenticatorTest.java
deleted file mode 100644 (file)
index a24bb82..0000000
+++ /dev/null
@@ -1,262 +0,0 @@
-package org.apache.maven.archiva.security;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import com.google.common.collect.Lists;
-import net.sf.ehcache.CacheManager;
-import org.codehaus.plexus.redback.authentication.AuthenticationException;
-import org.codehaus.plexus.redback.authentication.AuthenticationResult;
-import org.codehaus.plexus.redback.authorization.UnauthorizedException;
-import org.codehaus.plexus.redback.rbac.UserAssignment;
-import org.codehaus.plexus.redback.system.DefaultSecuritySession;
-import org.codehaus.plexus.redback.system.SecuritySession;
-import org.codehaus.plexus.redback.users.User;
-import org.codehaus.plexus.redback.users.UserManager;
-import org.easymock.MockControl;
-import org.junit.Before;
-import org.junit.Test;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.servlet.http.HttpServletRequest;
-import java.util.Arrays;
-
-/**
- * ArchivaServletAuthenticatorTest
- */
-public class ArchivaServletAuthenticatorTest
-    extends AbstractSecurityTest
-{
-    @Inject
-    @Named( value = "servletAuthenticator#test" )
-    private ServletAuthenticator servletAuth;
-
-    private MockControl httpServletRequestControl;
-
-    private HttpServletRequest request;
-
-    @Before
-    public void setUp()
-        throws Exception
-    {
-        super.setUp();
-
-        httpServletRequestControl = MockControl.createControl( HttpServletRequest.class );
-        request = (HttpServletRequest) httpServletRequestControl.getMock();
-
-        setupRepository( "corporate" );
-    }
-
-    protected String getPlexusConfigLocation()
-    {
-        return "org/apache/maven/archiva/security/ArchivaServletAuthenticatorTest.xml";
-    }
-
-    protected void assignRepositoryManagerRole( String principal, String repoId )
-        throws Exception
-    {
-        roleManager.assignTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId, principal );
-    }
-
-    @Test
-    public void testIsAuthenticatedUserExists()
-        throws Exception
-    {
-        AuthenticationResult result = new AuthenticationResult( true, "user", null );
-        boolean isAuthenticated = servletAuth.isAuthenticated( request, result );
-
-        assertTrue( isAuthenticated );
-    }
-
-    @Test
-    public void testIsAuthenticatedUserDoesNotExist()
-        throws Exception
-    {
-        AuthenticationResult result = new AuthenticationResult( false, "non-existing-user", null );
-        try
-        {
-            servletAuth.isAuthenticated( request, result );
-            fail( "Authentication exception should have been thrown." );
-        }
-        catch ( AuthenticationException e )
-        {
-            assertEquals( "User Credentials Invalid", e.getMessage() );
-        }
-    }
-
-    @Test
-    public void testIsAuthorizedUserHasWriteAccess()
-        throws Exception
-    {
-        createUser( USER_ALPACA, "Al 'Archiva' Paca" );
-
-        assignRepositoryManagerRole( USER_ALPACA, "corporate" );
-
-        UserManager userManager = securitySystem.getUserManager();
-        User user = userManager.findUser( USER_ALPACA );
-
-        AuthenticationResult result = new AuthenticationResult( true, USER_ALPACA, null );
-
-        SecuritySession session = new DefaultSecuritySession( result, user );
-        boolean isAuthorized =
-            servletAuth.isAuthorized( request, session, "corporate", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD );
-
-        assertTrue( isAuthorized );
-
-        restoreGuestInitialValues( USER_ALPACA );
-    }
-
-    @Test
-    public void testIsAuthorizedUserHasNoWriteAccess()
-        throws Exception
-    {
-        createUser( USER_ALPACA, "Al 'Archiva' Paca" );
-
-        assignRepositoryObserverRole( USER_ALPACA, "corporate" );
-
-        httpServletRequestControl.expectAndReturn( request.getRemoteAddr(), "192.168.111.111" );
-
-        UserManager userManager = securitySystem.getUserManager();
-        User user = userManager.findUser( USER_ALPACA );
-
-        AuthenticationResult result = new AuthenticationResult( true, USER_ALPACA, null );
-
-        SecuritySession session = new DefaultSecuritySession( result, user );
-
-        httpServletRequestControl.replay();
-
-        try
-        {
-            servletAuth.isAuthorized( request, session, "corporate", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD );
-            fail( "UnauthorizedException should have been thrown." );
-        }
-        catch ( UnauthorizedException e )
-        {
-            assertEquals( "Access denied for repository corporate", e.getMessage() );
-        }
-
-        httpServletRequestControl.verify();
-
-        restoreGuestInitialValues( USER_ALPACA );
-    }
-
-    @Test
-    public void testIsAuthorizedUserHasReadAccess()
-        throws Exception
-    {
-        createUser( USER_ALPACA, "Al 'Archiva' Paca" );
-
-        assignRepositoryObserverRole( USER_ALPACA, "corporate" );
-
-        UserManager userManager = securitySystem.getUserManager();
-        User user = userManager.findUser( USER_ALPACA );
-
-        AuthenticationResult result = new AuthenticationResult( true, USER_ALPACA, null );
-
-        SecuritySession session = new DefaultSecuritySession( result, user );
-        boolean isAuthorized =
-            servletAuth.isAuthorized( request, session, "corporate", ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS );
-
-        assertTrue( isAuthorized );
-
-        restoreGuestInitialValues( USER_ALPACA );
-    }
-
-    @Test
-    public void testIsAuthorizedUserHasNoReadAccess()
-        throws Exception
-    {
-        createUser( USER_ALPACA, "Al 'Archiva' Paca" );
-
-        UserManager userManager = securitySystem.getUserManager();
-        User user = userManager.findUser( USER_ALPACA );
-
-        AuthenticationResult result = new AuthenticationResult( true, USER_ALPACA, null );
-
-        SecuritySession session = new DefaultSecuritySession( result, user );
-        try
-        {
-            servletAuth.isAuthorized( request, session, "corporate", ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS );
-            fail( "UnauthorizedException should have been thrown." );
-        }
-        catch ( UnauthorizedException e )
-        {
-            assertEquals( "Access denied for repository corporate", e.getMessage() );
-        }
-
-        restoreGuestInitialValues( USER_ALPACA );
-    }
-
-    @Test
-    public void testIsAuthorizedGuestUserHasWriteAccess()
-        throws Exception
-    {
-        assignRepositoryManagerRole( USER_GUEST, "corporate" );
-        boolean isAuthorized =
-            servletAuth.isAuthorized( USER_GUEST, "corporate", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD );
-
-        assertTrue( isAuthorized );
-
-        // cleanup previously add karma
-        restoreGuestInitialValues(USER_GUEST);
-
-    }
-
-    @Test
-    public void testIsAuthorizedGuestUserHasNoWriteAccess()
-        throws Exception
-    {
-        assignRepositoryObserverRole( USER_GUEST, "corporate" );
-
-        boolean isAuthorized =
-            servletAuth.isAuthorized( USER_GUEST, "corporate", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD );
-        assertFalse( isAuthorized );
-
-        // cleanup previously add karma
-        restoreGuestInitialValues(USER_GUEST);
-
-    }
-
-    @Test
-    public void testIsAuthorizedGuestUserHasReadAccess()
-        throws Exception
-    {
-        assignRepositoryObserverRole( USER_GUEST, "corporate" );
-
-        boolean isAuthorized =
-            servletAuth.isAuthorized( USER_GUEST, "corporate", ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS );
-
-        assertTrue( isAuthorized );
-
-        // cleanup previously add karma
-        restoreGuestInitialValues(USER_GUEST);
-    }
-
-    @Test
-    public void testIsAuthorizedGuestUserHasNoReadAccess()
-        throws Exception
-    {
-        boolean isAuthorized =
-            servletAuth.isAuthorized( USER_GUEST, "corporate", ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS );
-
-        assertFalse( isAuthorized );
-    }
-
-}
diff --git a/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/maven/archiva/security/DefaultUserRepositoriesTest.java b/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/maven/archiva/security/DefaultUserRepositoriesTest.java
deleted file mode 100644 (file)
index 4c97075..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-package org.apache.maven.archiva.security;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.commons.lang.StringUtils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.List;
-
-/**
- * DefaultUserRepositoriesTest
- *
- * @version $Id$
- */
-public class DefaultUserRepositoriesTest
-    extends AbstractSecurityTest
-{
-
-
-    @Before
-    public void setUp()
-        throws Exception
-    {
-        super.setUp();
-        restoreGuestInitialValues( USER_ALPACA );
-        restoreGuestInitialValues( USER_GUEST );
-        restoreGuestInitialValues( USER_ADMIN );
-    }
-
-    @Test
-    public void testGetObservableRepositoryIds()
-        throws Exception
-    {
-        // create some users.
-        createUser( USER_ALPACA, "Al 'Archiva' Paca" );
-
-        assertEquals( "Expected users", 3, securitySystem.getUserManager().getUsers().size() );
-
-        // some unassigned repo observer roles.
-        setupRepository( "central" );
-        setupRepository( "corporate" );
-        setupRepository( "internal" );
-        setupRepository( "snapshots" );
-        setupRepository( "secret" );
-
-        // some assigned repo observer roles.
-        assignRepositoryObserverRole( USER_ALPACA, "corporate" );
-        assignRepositoryObserverRole( USER_ALPACA, "central" );
-        assignRepositoryObserverRole( USER_GUEST, "corporate" );
-        // the global repo observer role.
-        assignGlobalRepositoryObserverRole( USER_ADMIN );
-
-        assertRepoIds( new String[]{ "central", "corporate" }, userRepos.getObservableRepositoryIds( USER_ALPACA ) );
-        assertRepoIds( new String[]{ "coporate" }, userRepos.getObservableRepositoryIds( USER_GUEST ) );
-        assertRepoIds( new String[]{ "central", "internal", "corporate", "snapshots", "secret" },
-                       userRepos.getObservableRepositoryIds( USER_ADMIN ) );
-
-    }
-
-    @After
-    public void tearDown()
-        throws Exception
-    {
-        super.tearDown();
-        restoreGuestInitialValues( USER_ALPACA );
-        restoreGuestInitialValues( USER_GUEST );
-        restoreGuestInitialValues( USER_ADMIN );
-    }
-
-    private void assertRepoIds( String[] expectedRepoIds, List<String> observableRepositoryIds )
-    {
-        assertNotNull( "Observable Repository Ids cannot be null.", observableRepositoryIds );
-
-        if ( expectedRepoIds.length != observableRepositoryIds.size() )
-        {
-            fail( "Size of Observable Repository Ids wrong, expected <" + expectedRepoIds.length + "> but got <"
-                      + observableRepositoryIds.size() + "> instead. \nExpected: ["
-                      + StringUtils.join( expectedRepoIds, "," ) + "]\nActual: ["
-                      + StringUtils.join( observableRepositoryIds.iterator(), "," ) + "]" );
-        }
-    }
-
-    private void assignGlobalRepositoryObserverRole( String principal )
-        throws Exception
-    {
-        roleManager.assignRole( ArchivaRoleConstants.TEMPLATE_GLOBAL_REPOSITORY_OBSERVER, principal );
-    }
-}
diff --git a/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/maven/archiva/security/RoleManagerTest.java b/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/maven/archiva/security/RoleManagerTest.java
deleted file mode 100644 (file)
index f1b3894..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-package org.apache.maven.archiva.security;
-
-/* 
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import junit.framework.TestCase;
-import org.codehaus.plexus.redback.role.RoleManager;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-import javax.inject.Inject;
-
-/**
- * RoleProfilesTest 
- *
- * @version $Id: RoleManagerTest.java 4330 2007-05-10 17:28:56Z jmcconnell $
- */
-@RunWith( SpringJUnit4ClassRunner.class )
-@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
-public class RoleManagerTest
-    extends TestCase
-{
-
-    @Inject
-    RoleManager roleManager;
-    
-    @Test
-    public void testExpectedRoles()
-        throws Exception
-    {
-        assertNotNull( roleManager );
-        
-        assertTrue( roleManager.roleExists( "system-administrator" ) );
-        assertTrue( roleManager.roleExists( "user-administrator" ) );
-        assertTrue( roleManager.roleExists( "archiva-global-repository-observer" ) );
-        assertTrue( roleManager.roleExists( "archiva-guest" ) );        
-        assertTrue( roleManager.roleExists( "guest" ) );
-    }
-}
index 24723b1493a2b6355efebca4aebb965a364efce9..e35856f2be51dd1c80cf6d027adcad8c78a1f360 100644 (file)
@@ -34,7 +34,7 @@
 
   <alias name="securitySystem#testable" alias="securitySystem"/>
 
-  <bean name="userRepositories" class="org.apache.maven.archiva.security.DefaultUserRepositories">
+  <bean name="userRepositories" class="org.apache.archiva.security.DefaultUserRepositories">
     <property name="securitySystem" ref="securitySystem#testable"/>
     <property name="roleManager" ref="roleManager"/>
     <property name="archivaConfiguration" ref="archivaConfiguration"/>
@@ -72,7 +72,7 @@
 
   <alias name="roleTemplateProcessor" alias="roleTemplateProcessor#test"/>
 
-  <bean name="servletAuthenticator" class="org.apache.maven.archiva.security.ArchivaServletAuthenticator">
+  <bean name="servletAuthenticator" class="org.apache.archiva.security.ArchivaServletAuthenticator">
     <property name="securitySystem" ref="securitySystem#testable"/>
   </bean>
 
index a53251284b62898a55917117f75b4e52588cb6fc..4a1afabda34ceaaea2df690b2792169c44f584ef 100644 (file)
@@ -29,12 +29,12 @@ import org.apache.commons.codec.Decoder;
 import org.apache.commons.codec.DecoderException;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.lang.StringUtils;
-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.PrincipalNotFoundException;
-import org.apache.maven.archiva.security.ServletAuthenticator;
-import org.apache.maven.archiva.security.UserRepositories;
+import org.apache.archiva.security.AccessDeniedException;
+import org.apache.archiva.security.ArchivaRoleConstants;
+import org.apache.archiva.security.ArchivaSecurityException;
+import org.apache.archiva.security.PrincipalNotFoundException;
+import org.apache.archiva.security.ServletAuthenticator;
+import org.apache.archiva.security.UserRepositories;
 import org.codehaus.plexus.redback.authentication.AuthenticationException;
 import org.codehaus.plexus.redback.authentication.AuthenticationResult;
 import org.codehaus.plexus.redback.authorization.AuthorizationException;
index 0d69561785bb7878acf19b59b904441203c15446..3f3402afc1285c6acb4af0316ce4afa301e3677c 100644 (file)
@@ -25,7 +25,7 @@ import org.apache.maven.archiva.common.ArchivaException;
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
 import org.apache.maven.archiva.configuration.ConfigurationNames;
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
-import org.apache.maven.archiva.security.ArchivaRoleConstants;
+import org.apache.archiva.security.ArchivaRoleConstants;
 import org.codehaus.plexus.redback.rbac.RBACManager;
 import org.codehaus.plexus.redback.rbac.RbacManagerException;
 import org.codehaus.plexus.redback.rbac.UserAssignment;
index f468e94925b84fb977ff98a6fe292b7880d46afe..dca04351ef3f497754550c6fd7ee432696443226 100644 (file)
@@ -24,8 +24,8 @@ import org.apache.archiva.dependency.tree.maven2.DependencyTreeBuilder;
 import org.apache.commons.lang.StringUtils;
 import org.apache.maven.archiva.common.ArchivaException;
 import org.apache.maven.archiva.model.Keys;
-import org.apache.maven.archiva.security.ArchivaXworkUser;
-import org.apache.maven.archiva.security.UserRepositories;
+import org.apache.archiva.security.ArchivaXworkUser;
+import org.apache.archiva.security.UserRepositories;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.shared.dependency.tree.DependencyNode;
 import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
index 468b51087ebe9bc654eb82917dd0aaf8c50f69c8..aced6a79c1f4a75515e3c79582d8c74d37d64d8c 100644 (file)
@@ -27,7 +27,7 @@ import org.apache.archiva.audit.AuditListener;
 import org.apache.archiva.audit.Auditable;\r
 import org.apache.archiva.metadata.repository.RepositorySessionFactory;\r
 import org.apache.commons.lang.StringUtils;\r
-import org.apache.maven.archiva.security.ArchivaXworkUser;\r
+import org.apache.archiva.security.ArchivaXworkUser;\r
 import org.apache.struts2.ServletActionContext;\r
 import org.apache.struts2.interceptor.SessionAware;\r
 import org.codehaus.plexus.redback.users.User;\r
index c75f30c52cce277c1b084495f147c3180bad2e27..5bfcc036ece6c679cbba360f1a748d93344cbf4a 100644 (file)
@@ -19,10 +19,10 @@ package org.apache.maven.archiva.web.action;
  * under the License.
  */
 
-import org.apache.maven.archiva.security.AccessDeniedException;
-import org.apache.maven.archiva.security.ArchivaSecurityException;
-import org.apache.maven.archiva.security.PrincipalNotFoundException;
-import org.apache.maven.archiva.security.UserRepositories;
+import org.apache.archiva.security.AccessDeniedException;
+import org.apache.archiva.security.ArchivaSecurityException;
+import org.apache.archiva.security.PrincipalNotFoundException;
+import org.apache.archiva.security.UserRepositories;
 
 import javax.inject.Inject;
 import java.util.Collections;
index e370066ec4bb06feefbbeefbb20ff2965f056e19..d8e82635e0a85e499bc40a22b9a6a920bb34397f 100644 (file)
@@ -19,7 +19,6 @@ package org.apache.maven.archiva.web.action;
  * under the License.
  */
 
-import com.google.common.collect.Lists;
 import com.opensymphony.xwork2.Preparable;
 import com.opensymphony.xwork2.Validateable;
 import org.apache.archiva.audit.AuditEvent;
@@ -48,10 +47,10 @@ import org.apache.maven.archiva.repository.metadata.MetadataTools;
 import org.apache.maven.archiva.repository.metadata.RepositoryMetadataException;
 import org.apache.maven.archiva.repository.metadata.RepositoryMetadataReader;
 import org.apache.maven.archiva.repository.metadata.RepositoryMetadataWriter;
-import org.apache.maven.archiva.security.AccessDeniedException;
-import org.apache.maven.archiva.security.ArchivaSecurityException;
-import org.apache.maven.archiva.security.PrincipalNotFoundException;
-import org.apache.maven.archiva.security.UserRepositories;
+import org.apache.archiva.security.AccessDeniedException;
+import org.apache.archiva.security.ArchivaSecurityException;
+import org.apache.archiva.security.PrincipalNotFoundException;
+import org.apache.archiva.security.UserRepositories;
 import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Controller;
 
index 46d09dd46c559649c4d60e54b3e74595ae39cddf..d314ad29ef60e58189cc109f2ce0da5ccac3f7f1 100644 (file)
@@ -46,10 +46,10 @@ import org.apache.maven.archiva.repository.metadata.MetadataTools;
 import org.apache.maven.archiva.repository.metadata.RepositoryMetadataException;
 import org.apache.maven.archiva.repository.metadata.RepositoryMetadataReader;
 import org.apache.maven.archiva.repository.metadata.RepositoryMetadataWriter;
-import org.apache.maven.archiva.security.AccessDeniedException;
-import org.apache.maven.archiva.security.ArchivaSecurityException;
-import org.apache.maven.archiva.security.PrincipalNotFoundException;
-import org.apache.maven.archiva.security.UserRepositories;
+import org.apache.archiva.security.AccessDeniedException;
+import org.apache.archiva.security.ArchivaSecurityException;
+import org.apache.archiva.security.PrincipalNotFoundException;
+import org.apache.archiva.security.UserRepositories;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
 import org.codehaus.plexus.taskqueue.TaskQueueException;
index 9871e4d5aa4f9d3718891188975542a6d26dfd81..fe51db25f7fccb425abd2c0b9767dbde485212a6 100644 (file)
@@ -22,7 +22,7 @@ package org.apache.maven.archiva.web.action.admin;
 import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler;
 import org.apache.archiva.scheduler.repository.RepositoryTask;
 import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.security.ArchivaRoleConstants;
+import org.apache.archiva.security.ArchivaRoleConstants;
 import org.apache.maven.archiva.web.action.AbstractActionSupport;
 import org.codehaus.plexus.redback.rbac.Resource;
 import org.codehaus.plexus.taskqueue.TaskQueueException;
index 6b568603337f754fa80f987029ed6072ef2c7aef..87e2eb901a297a78c250bae1c764bd176e65868a 100644 (file)
@@ -21,7 +21,7 @@ package org.apache.maven.archiva.web.action.admin;
 
 import org.apache.archiva.repository.scanner.RepositoryScanner;
 import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.security.ArchivaRoleConstants;
+import org.apache.archiva.security.ArchivaRoleConstants;
 import org.apache.maven.archiva.web.action.AbstractActionSupport;
 import org.codehaus.plexus.cache.Cache;
 import org.codehaus.plexus.redback.rbac.Resource;
index d721c79148a2f2293bcef94dea25ebb4f50e44e0..c1114977a85d41c8cd653e268e3ac574399e899e 100644 (file)
@@ -24,7 +24,7 @@ import org.apache.commons.lang.StringUtils;
 import org.apache.maven.archiva.configuration.Configuration;
 import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
 import org.apache.maven.archiva.configuration.OrganisationInformation;
-import org.apache.maven.archiva.security.ArchivaRoleConstants;
+import org.apache.archiva.security.ArchivaRoleConstants;
 import org.codehaus.plexus.redback.rbac.Resource;
 import org.codehaus.plexus.registry.RegistryException;
 import org.codehaus.redback.integration.interceptor.SecureAction;
index bee78a0c96fe390d3927169ca42fd50e1885ad94..70632e31105373ae51a9ee203db71f10110c72fc 100644 (file)
@@ -27,7 +27,7 @@ import org.apache.maven.archiva.configuration.Configuration;
 import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
 import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
 import org.apache.maven.archiva.configuration.functors.ProxyConnectorSelectionPredicate;
-import org.apache.maven.archiva.security.ArchivaRoleConstants;
+import org.apache.archiva.security.ArchivaRoleConstants;
 import org.apache.maven.archiva.web.action.AbstractActionSupport;
 import org.codehaus.plexus.redback.rbac.Resource;
 import org.codehaus.plexus.registry.RegistryException;
index fc6089c82966769cca775614bd121caacbcc1401..1269ae720a129c2136201372f5e8b045de261752 100644 (file)
@@ -23,7 +23,7 @@ import com.opensymphony.xwork2.Preparable;
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;\r
 import org.apache.maven.archiva.configuration.Configuration;\r
 import org.apache.maven.archiva.configuration.LegacyArtifactPath;\r
-import org.apache.maven.archiva.security.ArchivaRoleConstants;\r
+import org.apache.archiva.security.ArchivaRoleConstants;\r
 import org.apache.maven.archiva.web.action.AbstractActionSupport;\r
 import org.apache.archiva.web.util.ContextUtils;\r
 import org.apache.struts2.interceptor.ServletRequestAware;\r
index d9cb4b2ef2714b849b1228cef7759198620be265..b8b2e2093cffe15ece016992844fe1f17bcf87b1 100644 (file)
@@ -29,7 +29,7 @@ import org.apache.maven.archiva.configuration.Configuration;
 import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
 import org.apache.maven.archiva.configuration.NetworkProxyConfiguration;
 import org.apache.maven.archiva.configuration.functors.NetworkProxySelectionPredicate;
-import org.apache.maven.archiva.security.ArchivaRoleConstants;
+import org.apache.archiva.security.ArchivaRoleConstants;
 import org.apache.maven.archiva.web.action.AbstractActionSupport;
 import org.codehaus.plexus.redback.rbac.Resource;
 import org.codehaus.plexus.registry.RegistryException;
index 5bfdd510d1d72ba1e9c4708ba02e264d14fcf57d..888edb846c46ac849cdc702540219bf805b9e413 100644 (file)
@@ -22,7 +22,7 @@ package org.apache.maven.archiva.web.action.admin.networkproxies;
 import com.opensymphony.xwork2.Preparable;
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
 import org.apache.maven.archiva.configuration.NetworkProxyConfiguration;
-import org.apache.maven.archiva.security.ArchivaRoleConstants;
+import org.apache.archiva.security.ArchivaRoleConstants;
 import org.apache.maven.archiva.web.action.AbstractActionSupport;
 import org.codehaus.plexus.redback.rbac.Resource;
 import org.codehaus.redback.integration.interceptor.SecureAction;
index 7af73b904d65c814d1c17cfeed6dbecb5a48cc5b..15f320f106d246ebd6c29e7c0aee47363fab8aa2 100644 (file)
@@ -19,7 +19,6 @@ package org.apache.maven.archiva.web.action.admin.repositories;
  * under the License.
  */
 
-import org.apache.archiva.admin.AuditInformation;
 import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin;
 import org.apache.archiva.audit.Auditable;
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
@@ -27,21 +26,17 @@ import org.apache.maven.archiva.configuration.Configuration;
 import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
 import org.apache.maven.archiva.configuration.InvalidConfigurationException;
 import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
-import org.apache.maven.archiva.security.ArchivaRoleConstants;
+import org.apache.archiva.security.ArchivaRoleConstants;
 import org.apache.maven.archiva.web.action.AbstractActionSupport;
 import org.codehaus.plexus.redback.rbac.Resource;
-import org.codehaus.plexus.redback.users.User;
 import org.codehaus.plexus.registry.RegistryException;
 import org.codehaus.redback.integration.interceptor.SecureAction;
 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
 import org.codehaus.redback.integration.interceptor.SecureActionException;
-import org.codehaus.redback.rest.services.RedbackAuthenticationThreadLocal;
-import org.codehaus.redback.rest.services.RedbackRequestInformation;
 
 import javax.inject.Inject;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 
 /**
index 490a0550ad4b9d6222663173f5abd3651c1df505..861deb37b77ad50b9b9eb99864bc6314c0c743e4 100644 (file)
@@ -30,7 +30,7 @@ import org.apache.maven.archiva.configuration.Configuration;
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
 import org.apache.maven.archiva.configuration.functors.RepositoryConfigurationComparator;
-import org.apache.maven.archiva.security.ArchivaRoleConstants;
+import org.apache.archiva.security.ArchivaRoleConstants;
 import org.apache.maven.archiva.web.action.AbstractActionSupport;
 import org.apache.archiva.web.util.ContextUtils;
 import org.apache.struts2.interceptor.ServletRequestAware;
index 04006431c502df03e5f5895ce57d088ac3f1f116..db484708722c56cb34b3d960b30b251451e123c1 100644 (file)
@@ -33,7 +33,7 @@ import org.apache.maven.archiva.configuration.IndeterminateConfigurationExceptio
 import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
 import org.apache.maven.archiva.configuration.functors.FiletypeSelectionPredicate;
 import org.apache.maven.archiva.configuration.functors.FiletypeToMapClosure;
-import org.apache.maven.archiva.security.ArchivaRoleConstants;
+import org.apache.archiva.security.ArchivaRoleConstants;
 import org.apache.maven.archiva.web.action.AbstractActionSupport;
 import org.codehaus.plexus.redback.rbac.Resource;
 import org.codehaus.plexus.registry.RegistryException;
index 04e887912a6f078f643d8e571c937a18edcbf1e8..981ad900e53759bc2487f530e59a5634377b849b 100644 (file)
@@ -30,7 +30,7 @@ import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.time.DateUtils;
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
-import org.apache.maven.archiva.security.ArchivaRoleConstants;
+import org.apache.archiva.security.ArchivaRoleConstants;
 import org.apache.maven.archiva.web.action.AbstractRepositoryBasedAction;
 import org.codehaus.plexus.redback.rbac.Resource;
 import org.codehaus.redback.integration.interceptor.SecureAction;
index 01617770c77620b304e3e65034472fd2b3434226..05912417444e6b8fe938358c57694d65b1ac74e7 100644 (file)
@@ -25,10 +25,10 @@ import org.apache.archiva.audit.AuditManager;
 import org.apache.archiva.metadata.repository.RepositorySession;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.time.DateUtils;
-import org.apache.maven.archiva.security.AccessDeniedException;
-import org.apache.maven.archiva.security.ArchivaSecurityException;
-import org.apache.maven.archiva.security.PrincipalNotFoundException;
-import org.apache.maven.archiva.security.UserRepositories;
+import org.apache.archiva.security.AccessDeniedException;
+import org.apache.archiva.security.ArchivaSecurityException;
+import org.apache.archiva.security.PrincipalNotFoundException;
+import org.apache.archiva.security.UserRepositories;
 import org.apache.maven.archiva.web.action.AbstractActionSupport;
 import org.apache.struts2.interceptor.ServletRequestAware;
 import org.codehaus.redback.integration.interceptor.SecureAction;
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/security/UserRepositoriesStub.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/security/UserRepositoriesStub.java
new file mode 100644 (file)
index 0000000..3e8cf50
--- /dev/null
@@ -0,0 +1,77 @@
+package org.apache.archiva.security;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * UserRepositories stub used for testing.
+ *
+ * @version $Id$
+ */
+public class UserRepositoriesStub
+    implements UserRepositories
+{
+    private List<String> repoIds = Collections.singletonList( "test-repo" );
+
+    public void createMissingRepositoryRoles( String repoId )
+        throws ArchivaSecurityException
+    {
+    }
+
+    public List<String> getObservableRepositoryIds( String principal )
+        throws ArchivaSecurityException
+    {
+        return repoIds;
+    }
+
+    public void setObservableRepositoryIds( List<String> repoIds )
+    {
+        this.repoIds = repoIds;
+    }
+
+    public boolean isAuthorizedToUploadArtifacts( String principal, String repoId )
+        throws ArchivaSecurityException
+    {
+        return false;
+    }
+
+    public boolean isAuthorizedToDeleteArtifacts( String principal, String repoId )
+    {
+        return false;
+    }
+
+    public List<String> getManagableRepositoryIds( String principal )
+        throws ArchivaSecurityException
+    {
+        return null;
+    }
+
+    public List<String> getRepoIds()
+    {
+        return repoIds;
+    }
+
+    public void setRepoIds( List<String> repoIds )
+    {
+        this.repoIds = repoIds;
+    }
+}
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/security/UserRepositoriesStub.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/security/UserRepositoriesStub.java
deleted file mode 100644 (file)
index eb6ab26..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-package org.apache.maven.archiva.security;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.Collections;
-import java.util.List;
-
-/**
- * UserRepositories stub used for testing.
- *
- * @version $Id$
- */
-public class UserRepositoriesStub
-    implements UserRepositories
-{
-    private List<String> repoIds = Collections.singletonList( "test-repo" );
-
-    public void createMissingRepositoryRoles( String repoId )
-        throws ArchivaSecurityException
-    {
-    }
-
-    public List<String> getObservableRepositoryIds( String principal )
-        throws ArchivaSecurityException
-    {
-        return repoIds;
-    }
-
-    public void setObservableRepositoryIds( List<String> repoIds )
-    {
-        this.repoIds = repoIds;
-    }
-
-    public boolean isAuthorizedToUploadArtifacts( String principal, String repoId )
-        throws ArchivaSecurityException
-    {
-        return false;
-    }
-
-    public boolean isAuthorizedToDeleteArtifacts( String principal, String repoId )
-    {
-        return false;
-    }
-
-    public List<String> getManagableRepositoryIds( String principal )
-        throws ArchivaSecurityException
-    {
-        return null;
-    }
-
-    public List<String> getRepoIds()
-    {
-        return repoIds;
-    }
-
-    public void setRepoIds( List<String> repoIds )
-    {
-        this.repoIds = repoIds;
-    }
-}
index cd3562ae6741a188ca9c1032ed821017c7be5078..20c9b49b78a78fdeb5681655fcd944ccfc340ca2 100644 (file)
@@ -36,10 +36,9 @@ import org.apache.archiva.metadata.model.Scm;
 import org.apache.archiva.metadata.repository.memory.TestMetadataResolver;
 import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
 import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectParent;
-import org.apache.maven.archiva.security.UserRepositoriesStub;
+import org.apache.archiva.security.UserRepositoriesStub;
 import org.apache.struts2.StrutsSpringTestCase;
 
-import java.io.File;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
index ba8994c33e33229dbda7999b8230af809d32cfb5..cb0c5aca087897186d3956e07ded7a970965a7d7 100644 (file)
@@ -31,7 +31,7 @@ import org.apache.archiva.metadata.repository.MetadataRepository;
 import org.apache.archiva.metadata.repository.RepositorySession;
 import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
-import org.apache.maven.archiva.security.UserRepositories;
+import org.apache.archiva.security.UserRepositories;
 import org.easymock.MockControl;
 
 import java.util.ArrayList;
index 06a1b354a90b2b7f6532f1783c518daee904727b..747f719db2f7a18034ba403baec889d8b7e91f11 100644 (file)
@@ -27,7 +27,7 @@ import org.apache.archiva.scheduler.repository.RepositoryTask;
 import org.apache.commons.io.FileUtils;
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
 import org.apache.maven.archiva.configuration.Configuration;
-import org.apache.maven.archiva.security.ArchivaRoleConstants;
+import org.apache.archiva.security.ArchivaRoleConstants;
 import org.apache.archiva.web.validator.utils.ValidatorUtil;
 import org.codehaus.plexus.redback.role.RoleManager;
 import org.codehaus.plexus.registry.Registry;
index e86898d8fd5d8cacbd071e32b6d502b4d2b2eacd..736073f1f972bbee3d153226ce9853b759612f33 100644 (file)
@@ -35,17 +35,14 @@ import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
 import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
 import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration;
-import org.apache.maven.archiva.security.ArchivaRoleConstants;
+import org.apache.archiva.security.ArchivaRoleConstants;
 import org.apache.maven.archiva.web.action.AbstractActionTestCase;
 import org.apache.maven.archiva.web.action.AuditEventArgumentsMatcher;
 import org.codehaus.plexus.redback.role.RoleManager;
 import org.codehaus.plexus.redback.role.RoleManagerException;
-import org.codehaus.plexus.redback.users.User;
-import org.codehaus.plexus.redback.users.jdo.JdoUser;
 import org.codehaus.plexus.registry.RegistryException;
 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
 import org.codehaus.redback.integration.interceptor.SecureActionException;
-import org.codehaus.redback.rest.services.RedbackRequestInformation;
 import org.easymock.MockControl;
 
 import java.io.File;
index 05c43951322680051793b9c4e0f633d8a01bc218..4b9bc7d25ad13903fe9660973b23300da5ac05c5 100644 (file)
@@ -34,7 +34,7 @@ import org.apache.commons.io.FileUtils;
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
 import org.apache.maven.archiva.configuration.Configuration;
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
-import org.apache.maven.archiva.security.ArchivaRoleConstants;
+import org.apache.archiva.security.ArchivaRoleConstants;
 import org.apache.archiva.web.validator.utils.ValidatorUtil;
 import org.codehaus.plexus.redback.role.RoleManager;
 import org.codehaus.plexus.registry.Registry;
index 6bc27bd8f87e5b3ea4304bc0db01a49449d47fc3..21ccd53b5fbe45a0da7872d20f56d1412892be01 100644 (file)
@@ -29,7 +29,7 @@ import org.apache.archiva.metadata.repository.stats.RepositoryStatistics;
 import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
 import org.apache.archiva.reports.RepositoryProblemFacet;
 import org.apache.commons.io.IOUtils;
-import org.apache.maven.archiva.security.UserRepositoriesStub;
+import org.apache.archiva.security.UserRepositoriesStub;
 import org.apache.maven.archiva.web.action.AbstractActionTestCase;
 import org.easymock.MockControl;
 import org.junit.After;
index 949aa6a6d7154df2dc7b55f053cfaf64d580f715..37834e2178656f213b0ad9abcfab4d43bb94e508 100644 (file)
@@ -34,7 +34,7 @@
 
   <alias name="repositorySessionFactory#test" alias="repositorySessionFactory"/>
 
-  <bean name="userRepositories#test" class="org.apache.maven.archiva.security.UserRepositoriesStub"/>
+  <bean name="userRepositories#test" class="org.apache.archiva.security.UserRepositoriesStub"/>
 
   <alias name="userRepositories#test" alias="userRepositories"/>
 
index 0c2f74e0e929c78ba483ddaac85dd6b7bee02a32..8c2633875294817aca86c182f5e90ba96191e77d 100644 (file)
@@ -34,7 +34,7 @@
 
   <alias name="repositorySessionFactory#test" alias="repositorySessionFactory"/>
 
-  <bean name="userRepositories#test" class="org.apache.maven.archiva.security.UserRepositoriesStub"/>
+  <bean name="userRepositories#test" class="org.apache.archiva.security.UserRepositoriesStub"/>
 
   <alias name="userRepositories#test" alias="userRepositories"/>
 
index 1b905855dabdbec4af86526f8b03d700cb24d880..5d97924f117868b9318da5734c5aa0f43d8944c2 100644 (file)
@@ -56,7 +56,7 @@ import org.apache.maven.archiva.repository.metadata.RepositoryMetadataException;
 import org.apache.maven.archiva.repository.metadata.RepositoryMetadataMerge;
 import org.apache.maven.archiva.repository.metadata.RepositoryMetadataReader;
 import org.apache.maven.archiva.repository.metadata.RepositoryMetadataWriter;
-import org.apache.maven.archiva.security.ServletAuthenticator;
+import org.apache.archiva.security.ServletAuthenticator;
 import org.apache.maven.archiva.webdav.util.MimeTypes;
 import org.apache.maven.archiva.webdav.util.RepositoryPathUtil;
 import org.apache.maven.archiva.webdav.util.WebdavMethodUtil;
index 536454dfe7adb65d8bbde9606ba0add073dea953..01d3fe91cb62229b4f2cc2534428200a7b8b7821 100644 (file)
@@ -23,7 +23,7 @@ import org.apache.jackrabbit.webdav.DavException;
 import org.apache.jackrabbit.webdav.DavServletRequest;
 import org.apache.jackrabbit.webdav.DavSessionProvider;
 import org.apache.jackrabbit.webdav.WebdavRequest;
-import org.apache.maven.archiva.security.ServletAuthenticator;
+import org.apache.archiva.security.ServletAuthenticator;
 import org.apache.maven.archiva.webdav.util.RepositoryPathUtil;
 import org.apache.maven.archiva.webdav.util.WebdavMethodUtil;
 import org.codehaus.plexus.redback.authentication.AuthenticationException;
index fed837c75d77c41d9a5986ba5bacded54b611e3d..59363bcf31bcf9bd7eff82fb2d9b5e9a2af04809 100644 (file)
@@ -35,7 +35,7 @@ import org.apache.maven.archiva.configuration.ArchivaConfiguration;
 import org.apache.maven.archiva.configuration.ConfigurationEvent;
 import org.apache.maven.archiva.configuration.ConfigurationListener;
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
-import org.apache.maven.archiva.security.ServletAuthenticator;
+import org.apache.archiva.security.ServletAuthenticator;
 import org.codehaus.redback.integration.filter.authentication.HttpAuthenticator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
index fad10e294be28687298492e55f54e4ebf9673a04..70e055e6cfbf35f3911f6e854232fcae12d7d435 100644 (file)
@@ -20,7 +20,7 @@ package org.apache.maven.archiva.webdav.util;
  */
 
 import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.security.ArchivaRoleConstants;
+import org.apache.archiva.security.ArchivaRoleConstants;
 
 import java.util.ArrayList;
 import java.util.List;
index c553cb4b6d8b3991563367812d1e4753267b185b..da5d15ac5e986335888f79cc3a9163f6ed791cbf 100644 (file)
@@ -23,7 +23,7 @@ import junit.framework.TestCase;
 import org.apache.jackrabbit.webdav.DavSessionProvider;
 import org.apache.jackrabbit.webdav.WebdavRequest;
 import org.apache.jackrabbit.webdav.WebdavRequestImpl;
-import org.apache.maven.archiva.security.ServletAuthenticator;
+import org.apache.archiva.security.ServletAuthenticator;
 import org.codehaus.plexus.redback.authentication.AuthenticationDataSource;
 import org.codehaus.plexus.redback.authentication.AuthenticationException;
 import org.codehaus.plexus.redback.authentication.AuthenticationResult;
index 0f1b8ab6adaf1519cafc8f894b93c7476ecf7757..1debad2d4349d4ab37e1e1c318b6e76c832b648c 100644 (file)
@@ -19,7 +19,7 @@ package org.apache.maven.archiva.webdav;
  * under the License.
  */
 
-import org.apache.maven.archiva.security.ArchivaServletAuthenticator;
+import org.apache.archiva.security.ArchivaServletAuthenticator;
 import org.codehaus.plexus.redback.authorization.UnauthorizedException;
 
 public class MockServletAuthenticator
index bb60f61bc6eb8c1b1a245087975a09890a6d130a..b437b886cb89d612abb90d17b6fa12ed9f2894de 100644 (file)
@@ -35,8 +35,8 @@ import org.apache.jackrabbit.webdav.DavSessionProvider;
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
 import org.apache.maven.archiva.configuration.Configuration;
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
-import org.apache.maven.archiva.security.ArchivaRoleConstants;
-import org.apache.maven.archiva.security.ServletAuthenticator;
+import org.apache.archiva.security.ArchivaRoleConstants;
+import org.apache.archiva.security.ServletAuthenticator;
 import org.codehaus.plexus.redback.authentication.AuthenticationException;
 import org.codehaus.plexus.redback.authentication.AuthenticationResult;
 import org.codehaus.plexus.redback.authorization.UnauthorizedException;
index 663a37e099a5f7861c876252e19923795e4af2dd..e3358e934318dec90a644cb49889d47f9981946b 100644 (file)
@@ -21,9 +21,9 @@ package org.apache.archiva.web.xmlrpc.security;
 \r
 import java.util.List;\r
 \r
-import org.apache.maven.archiva.security.ArchivaRoleConstants;\r
-import org.apache.maven.archiva.security.ArchivaSecurityException;\r
-import org.apache.maven.archiva.security.UserRepositories;\r
+import org.apache.archiva.security.ArchivaRoleConstants;\r
+import org.apache.archiva.security.ArchivaSecurityException;\r
+import org.apache.archiva.security.UserRepositories;\r
 import org.apache.xmlrpc.XmlRpcException;\r
 import org.apache.xmlrpc.XmlRpcRequest;\r
 import org.apache.xmlrpc.common.XmlRpcHttpRequestConfigImpl;\r
index 996458e95591017ff70b5e0581f49aa05252bf7c..65bd7996497903f1fc7334497e39579f40f62e36 100644 (file)
@@ -21,9 +21,9 @@ package org.apache.archiva.web.xmlrpc.security;
 
 import java.util.List;
 
-import org.apache.maven.archiva.security.ArchivaSecurityException;
-import org.apache.maven.archiva.security.PrincipalNotFoundException;
-import org.apache.maven.archiva.security.UserRepositories;
+import org.apache.archiva.security.ArchivaSecurityException;
+import org.apache.archiva.security.PrincipalNotFoundException;
+import org.apache.archiva.security.UserRepositories;
 import org.apache.xmlrpc.server.AbstractReflectiveHandlerMapping.AuthenticationHandler;
 
 public class XmlRpcUserRepositories
index a9f443a23c6fe2c5274157f123578a69cab2c009..eda25e2134e720891600d355ce8a84d5078c3941 100644 (file)
@@ -21,7 +21,7 @@ package org.apache.archiva.xmlrpc.security;
 \r
 import junit.framework.TestCase;\r
 import org.apache.archiva.web.xmlrpc.security.XmlRpcAuthenticator;\r
-import org.apache.maven.archiva.security.ArchivaRoleConstants;\r
+import org.apache.archiva.security.ArchivaRoleConstants;\r
 import org.apache.xmlrpc.XmlRpcRequest;\r
 import org.apache.xmlrpc.common.XmlRpcHttpRequestConfigImpl;\r
 import org.codehaus.plexus.redback.role.RoleManager;\r
index 886bbfc2bd9c3c8f8d6bb9909188d61b04289d8a..04fcbace588e3b083561201b4ddd46b6cf2dcc2a 100644 (file)
@@ -54,7 +54,7 @@ import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryConte
 import org.apache.maven.archiva.repository.content.ManagedLegacyRepositoryContent;
 import org.apache.maven.archiva.repository.content.PathParser;
 import org.apache.maven.archiva.repository.layout.LayoutException;
-import org.apache.maven.archiva.security.ArchivaRoleConstants;
+import org.apache.archiva.security.ArchivaRoleConstants;
 import org.codehaus.plexus.redback.role.RoleManager;
 import org.codehaus.plexus.registry.Registry;
 import org.easymock.MockControl;