]> source.dussan.org Git - archiva.git/commitdiff
[MRM-773]
authorMaria Odea B. Ching <oching@apache.org>
Sun, 11 May 2008 03:22:48 +0000 (03:22 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Sun, 11 May 2008 03:22:48 +0000 (03:22 +0000)
-remove archiva-security dependency to xwork-integration

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@655233 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-security/pom.xml
archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaServletAuthenticator.java
archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ServletAuthenticator.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/rss/RssFeedServlet.java
archiva-modules/archiva-web/archiva-webdav/pom.xml
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavSessionProvider.java

index e4ae7fc3160898684eb8d674332c66155ff21680..ff409d8ef609c58b25358bb0fb9b8277c6d8b695 100644 (file)
         </exclusion>
       </exclusions>
     </dependency>
-    <dependency>
-      <groupId>org.codehaus.plexus.redback</groupId>
-      <artifactId>redback-xwork-integration</artifactId>
-      <exclusions>
-        <exclusion>
-          <groupId>org.codehaus.plexus</groupId>
-          <artifactId>plexus-container-default</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency> 
-    <dependency>
-      <groupId>org.apache.derby</groupId>
-      <artifactId>derby</artifactId>
-      <scope>provided</scope>
-    </dependency>   
   </dependencies>
 </project>
index c3420d3ea3aa964b711c45592c50a4ab74657fcc..21dcc3e8013b55f7e3a49855a5e238d21c36ccd4 100644 (file)
@@ -30,7 +30,6 @@ import org.codehaus.plexus.redback.policy.AccountLockedException;
 import org.codehaus.plexus.redback.policy.MustChangePasswordException;
 import org.codehaus.plexus.redback.system.SecuritySession;
 import org.codehaus.plexus.redback.system.SecuritySystem;
-import org.codehaus.plexus.redback.xwork.filter.authentication.HttpAuthenticator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -42,44 +41,36 @@ public class ArchivaServletAuthenticator
     implements ServletAuthenticator
 {
     private Logger log = LoggerFactory.getLogger( ArchivaServletAuthenticator.class );
-    
-    /**
-     * @plexus.requirement role-hint="basic"
-     */
-    private HttpAuthenticator httpAuth;
 
     /**
      * @plexus.requirement 
      */
     private SecuritySystem securitySystem;
-   
-    public boolean isAuthenticated( HttpServletRequest request, String repositoryId )
-        throws AuthenticationException, AccountLockedException, MustChangePasswordException   
-    {        
-        AuthenticationResult result = httpAuth.getAuthenticationResult( request, null );
-        
+
+    public boolean isAuthenticated( HttpServletRequest request, AuthenticationResult result, String repositoryId )
+        throws AuthenticationException, AccountLockedException, MustChangePasswordException
+    {
         if ( result != null && !result.isAuthenticated() )
         {
-            throw new AuthenticationException( "User Credentials Invalid" );            
-        }        
+            throw new AuthenticationException( "User Credentials Invalid" );
+        }
 
         return true;
     }
 
-    public boolean isAuthorized( HttpServletRequest request, String repositoryId, boolean isWriteRequest )
+    public boolean isAuthorized( HttpServletRequest request, SecuritySession securitySession, String repositoryId,
+                                 boolean isWriteRequest )
         throws AuthorizationException
-    {           
-        SecuritySession securitySession = httpAuth.getSecuritySession();
-        
+    {
         String permission = ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS;
 
         if ( isWriteRequest )
         {
             permission = ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD;
         }
-        
+
         AuthorizationResult authzResult = securitySystem.authorize( securitySession, permission, repositoryId );
-        
+
         if ( !authzResult.isAuthorized() )
         {
             if ( authzResult.getException() != null )
@@ -87,9 +78,9 @@ public class ArchivaServletAuthenticator
                 log.info( "Authorization Denied [ip=" + request.getRemoteAddr() + ",isWriteRequest=" + isWriteRequest +
                     ",permission=" + permission + ",repo=" + repositoryId + "] : " +
                     authzResult.getException().getMessage() );
-            }            
+            }
         }
 
         return true;
-    }    
+    }
 }
index 11530c094ee5e521f9420fa07a82c3c54501056c..4c78235ea8ef4cd217fe84c8367b502ae948d878 100644 (file)
@@ -22,20 +22,21 @@ package org.apache.maven.archiva.security;
 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.policy.AccountLockedException;
 import org.codehaus.plexus.redback.policy.MustChangePasswordException;
+import org.codehaus.plexus.redback.system.SecuritySession;
 
 /**
- * 
  * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
- * @version 
+ * @version
  */
 public interface ServletAuthenticator
 {
-    public boolean isAuthenticated( HttpServletRequest request, String repositoryId )
+    public boolean isAuthenticated( HttpServletRequest request, AuthenticationResult result, String repositoryId )
         throws AuthenticationException, AccountLockedException, MustChangePasswordException;
-    
-    public boolean isAuthorized( HttpServletRequest request, String repositoryId, boolean isWriteRequest )
-        throws AuthorizationException;
+
+    public boolean isAuthorized( HttpServletRequest request, SecuritySession securitySession, String repositoryId,
+        boolean isWriteRequest ) throws AuthorizationException;
 }
index d26a2bc600b500a1d73f318a91ce8a9817b129b3..c3af4ceb2cb8c395db82906f39230ccff05aabe9 100644 (file)
@@ -42,10 +42,13 @@ import org.apache.maven.archiva.security.PrincipalNotFoundException;
 import org.apache.maven.archiva.security.ServletAuthenticator;
 import org.apache.maven.archiva.security.UserRepositories;
 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.policy.AccountLockedException;
 import org.codehaus.plexus.redback.policy.MustChangePasswordException;
+import org.codehaus.plexus.redback.system.SecuritySession;
 import org.codehaus.plexus.redback.users.UserNotFoundException;
+import org.codehaus.plexus.redback.xwork.filter.authentication.HttpAuthenticator;
 import org.codehaus.plexus.spring.PlexusToSpringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -83,19 +86,19 @@ public class RssFeedServlet
 
     private ServletAuthenticator servletAuth;
 
+    private HttpAuthenticator httpAuth;
+
     public void init( javax.servlet.ServletConfig servletConfig )
         throws ServletException
     {
         super.init( servletConfig );
         wac = WebApplicationContextUtils.getRequiredWebApplicationContext( servletConfig.getServletContext() );
-        // securitySystem =
-        // (SecuritySystem) wac.getBean( PlexusToSpringUtils.buildSpringId( SecuritySystem.class.getName() ) );
         userRepositories =
             (UserRepositories) wac.getBean( PlexusToSpringUtils.buildSpringId( UserRepositories.class.getName() ) );
-        // httpAuth =
-        // (HttpAuthenticator) wac.getBean( PlexusToSpringUtils.buildSpringId( HttpAuthenticator.ROLE, "basic" ) );
         servletAuth =
             (ServletAuthenticator) wac.getBean( PlexusToSpringUtils.buildSpringId( ServletAuthenticator.class.getName() ) );
+        httpAuth =
+            (HttpAuthenticator) wac.getBean( PlexusToSpringUtils.buildSpringId( HttpAuthenticator.ROLE, "basic" ) );
     }
 
     public void doGet( HttpServletRequest req, HttpServletResponse res )
@@ -246,7 +249,11 @@ public class RssFeedServlet
         {
             try
             {
-                if ( servletAuth.isAuthenticated( req, repoId ) && servletAuth.isAuthorized( req, repoId, false ) )
+                AuthenticationResult result = httpAuth.getAuthenticationResult( req, null );
+                SecuritySession securitySession = httpAuth.getSecuritySession();
+
+                if ( servletAuth.isAuthenticated( req, result, repoId ) &&
+                    servletAuth.isAuthorized( req, securitySession, repoId, false ) )
                 {
                     return true;
                 }
@@ -282,65 +289,4 @@ public class RssFeedServlet
         return Collections.emptyList();
     }
 
-    /*
-    private boolean isAuthenticated( HttpServletRequest request, String repositoryId )
-    {
-        try
-        {
-            AuthenticationResult result = httpAuth.getAuthenticationResult( request, null );
-
-            if ( result != null && !result.isAuthenticated() )
-            {
-                log.error( "User credentials is invalid." );
-                return false;
-            }
-        }
-        catch ( AuthenticationException e )
-        {
-            log.error( "User is not authenticated." );
-            return false;
-        }
-        catch ( AccountLockedException e )
-        {
-            log.error( "User account is locked." );
-            return false;
-        }
-        catch ( MustChangePasswordException e )
-        {
-            log.error( "Password must be changed." );
-            return false;
-        }
-
-        return true;
-    }
-
-    private boolean isAuthorized( HttpServletRequest request, String repositoryId )
-    {
-        SecuritySession securitySession = httpAuth.getSecuritySession();
-
-        try
-        {
-            String permission = ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS;
-
-            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() );
-                }
-                return false;
-            }
-        }
-        catch ( AuthorizationException e )
-        {
-            log.error( "Error in authorization : " + e.getMessage() );
-            return false;
-        }
-
-        return true;
-    }
-     */
 }
index 147cff7c10d16e7459639c4209478a474016b175..ed8b416fe1069eda1a98ffa4030fbd36506b2ed6 100644 (file)
       <groupId>joda-time</groupId>
       <artifactId>joda-time</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus.redback</groupId>
+      <artifactId>redback-xwork-integration</artifactId>
+      <exclusions>
+        <exclusion>
+          <groupId>org.codehaus.plexus</groupId>
+          <artifactId>plexus-container-default</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
   </dependencies>
 
   <!-- Required by it.could classes -->
index 5325354e861769b3d1d049d13560986e9b84519b..ed78e4fd69bb5246dc0b2778d47b7f3c081814ac 100644 (file)
@@ -27,8 +27,11 @@ import org.apache.maven.archiva.webdav.util.WebdavMethodUtil;
 import org.apache.maven.archiva.webdav.util.RepositoryPathUtil;
 import org.apache.maven.archiva.security.ServletAuthenticator;
 import org.codehaus.plexus.redback.authentication.AuthenticationException;
+import org.codehaus.plexus.redback.authentication.AuthenticationResult;
 import org.codehaus.plexus.redback.policy.MustChangePasswordException;
 import org.codehaus.plexus.redback.policy.AccountLockedException;
+import org.codehaus.plexus.redback.system.SecuritySession;
+import org.codehaus.plexus.redback.xwork.filter.authentication.HttpAuthenticator;
 import org.codehaus.plexus.redback.authorization.AuthorizationException;
 import org.codehaus.plexus.spring.PlexusToSpringUtils;
 import org.springframework.web.context.WebApplicationContext;
@@ -45,10 +48,14 @@ public class ArchivaDavSessionProvider implements DavSessionProvider
     private Logger log = LoggerFactory.getLogger(ArchivaDavSessionProvider.class);
     
     private ServletAuthenticator servletAuth;    
+    
+    private HttpAuthenticator httpAuth;
             
     public ArchivaDavSessionProvider(WebApplicationContext applicationContext)
     {
         servletAuth = (ServletAuthenticator) applicationContext.getBean( PlexusToSpringUtils.buildSpringId( ServletAuthenticator.class.getName() ) );
+        httpAuth =
+            (HttpAuthenticator) applicationContext.getBean( PlexusToSpringUtils.buildSpringId( HttpAuthenticator.ROLE, "basic" ) );
     }
 
     public boolean attachSession(WebdavRequest request) throws DavException
@@ -57,8 +64,11 @@ public class ArchivaDavSessionProvider implements DavSessionProvider
         
         try
         {
-            return servletAuth.isAuthenticated(request, repositoryId) && 
-                servletAuth.isAuthorized(request, repositoryId, WebdavMethodUtil.isWriteMethod( request.getMethod() ) );
+            AuthenticationResult result = httpAuth.getAuthenticationResult( request, null );
+            SecuritySession securitySession = httpAuth.getSecuritySession();
+            
+            return servletAuth.isAuthenticated(request, result, repositoryId) && 
+                servletAuth.isAuthorized(request, securitySession, repositoryId, WebdavMethodUtil.isWriteMethod( request.getMethod() ) );
         }
         catch ( AuthenticationException e )
         {