]> source.dussan.org Git - archiva.git/commitdiff
merged from -r693694 (MRM-911: check first if guest is enabled for the repository...
authorMaria Odea B. Ching <oching@apache.org>
Wed, 10 Sep 2008 04:15:50 +0000 (04:15 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Wed, 10 Sep 2008 04:15:50 +0000 (04:15 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@693701 13f79535-47bb-0310-9956-ffa450edef68

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-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/test/java/org/apache/maven/archiva/webdav/ArchivaDavSessionProviderTest.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/UnauthenticatedDavSessionProvider.java

index 4e8c040b7f72c5f451b427f8fb9f2948160f3fa8..31d1245c93f175d7925b778cca6b575807558322 100644 (file)
@@ -93,7 +93,7 @@ public class ArchivaServletAuthenticator
         return true;
     }
 
-    public boolean isAuthorizedToAccessVirtualRepository( String principal, String repoId )
+    public boolean isAuthorized( String principal, String repoId )
         throws UnauthorizedException
     {
         try
index fb39b4bca2490db2cb7c0c42ea159ef515ce1dbe..2edda81208bb230af14a9066d363abf4ff985b86 100644 (file)
@@ -41,6 +41,6 @@ public interface ServletAuthenticator
     public boolean isAuthorized( HttpServletRequest request, SecuritySession securitySession, String repositoryId,
         boolean isWriteRequest ) throws AuthorizationException, UnauthorizedException;
     
-    public boolean isAuthorizedToAccessVirtualRepository( String principal, String repoId )
+    public boolean isAuthorized( String principal, String repoId )
         throws UnauthorizedException;
 }
index 7af32bee73923ef5efa9755e55849bbed6c38580..032f614fdbe1214fed3b31a479e7c6c7fe44409b 100644 (file)
@@ -733,6 +733,22 @@ public class ArchivaDavResourceFactory
         }
         catch ( AuthenticationException e )
         {
+            // safety check for MRM-911            
+            String guest = archivaXworkUser.getGuest();
+            try
+            {
+                if( servletAuth.isAuthorized( guest, 
+                      ( ( ArchivaDavResourceLocator ) request.getRequestLocator() ).getRepositoryId() ) )
+                {   
+                    return true;
+                }
+            }
+            catch ( UnauthorizedException ae )
+            {
+                throw new UnauthorizedDavException( repositoryId,
+                        "You are not authenticated and authorized to access any repository." );
+            }
+                        
             throw new UnauthorizedDavException( repositoryId, "You are not authenticated" );
         }
         catch ( MustChangePasswordException e )
@@ -801,7 +817,7 @@ public class ArchivaDavResourceFactory
                     // for the current user logged in
                     try
                     {
-                        if( servletAuth.isAuthorizedToAccessVirtualRepository( activePrincipal, repository ) )
+                        if( servletAuth.isAuthorized( activePrincipal, repository ) )
                         {
                             getResource( locator, mergedRepositoryContents, logicalResource, repository );
                         }
@@ -897,7 +913,7 @@ public class ArchivaDavResourceFactory
             {
                 try
                 {
-                    if( servletAuth.isAuthorizedToAccessVirtualRepository( activePrincipal, repository ) )
+                    if( servletAuth.isAuthorized( activePrincipal, repository ) )
                     {
                         allow = true;
                         break;
index ad96939d118b64702cf7b6137b38db44905a9e66..2c5a39d357e872711ef2bbcab14b1c1b752d16bb 100644 (file)
@@ -24,9 +24,11 @@ import org.apache.jackrabbit.webdav.WebdavRequest;
 import org.apache.jackrabbit.webdav.DavException;
 import org.apache.jackrabbit.webdav.DavServletRequest;
 import org.apache.maven.archiva.webdav.util.RepositoryPathUtil;
+import org.apache.maven.archiva.security.ArchivaXworkUser;
 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.authorization.UnauthorizedException;
 import org.codehaus.plexus.redback.policy.MustChangePasswordException;
 import org.codehaus.plexus.redback.policy.AccountLockedException;
 import org.codehaus.plexus.redback.xwork.filter.authentication.HttpAuthenticator;
@@ -45,10 +47,13 @@ public class ArchivaDavSessionProvider
 
     private HttpAuthenticator httpAuth;
     
-    public ArchivaDavSessionProvider( ServletAuthenticator servletAuth, HttpAuthenticator httpAuth )
+    private ArchivaXworkUser archivaXworkUser;
+    
+    public ArchivaDavSessionProvider( ServletAuthenticator servletAuth, HttpAuthenticator httpAuth, ArchivaXworkUser archivaXworkUser )
     {
         this.servletAuth = servletAuth;
         this.httpAuth = httpAuth;
+        this.archivaXworkUser = archivaXworkUser;
     }
 
     public boolean attachSession( WebdavRequest request )
@@ -67,7 +72,24 @@ public class ArchivaDavSessionProvider
         }
         catch ( AuthenticationException e )
         {   
-            throw new UnauthorizedDavException( repositoryId, "You are not authenticated" );            
+            // safety check for MRM-911            
+            String guest = archivaXworkUser.getGuest();
+            try
+            {
+                if( servletAuth.isAuthorized( guest, 
+                      ( ( ArchivaDavResourceLocator ) request.getRequestLocator() ).getRepositoryId() ) )
+                {
+                    request.setDavSession(new ArchivaDavSession());
+                    return true;
+                }
+            }
+            catch ( UnauthorizedException ae )
+            {
+                throw new UnauthorizedDavException( repositoryId,
+                    "You are not authenticated and authorized to access any repository." );
+            }
+            
+            throw new UnauthorizedDavException( repositoryId, "You are not authenticated." );            
         }
         catch ( MustChangePasswordException e )
         {         
index ca9aa5aedb5805301afacd5c189c90c0684b0c32..a73e72d5e948186302211ab58bc5bc99dcc1815c 100644 (file)
@@ -44,6 +44,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.ArchivaXworkUser;
 import org.apache.maven.archiva.security.ServletAuthenticator;
 import org.codehaus.plexus.redback.xwork.filter.authentication.HttpAuthenticator;
 import org.codehaus.plexus.spring.PlexusToSpringUtils;
@@ -195,7 +196,9 @@ public class RepositoryServlet
         HttpAuthenticator httpAuth =
             (HttpAuthenticator) wac.getBean( PlexusToSpringUtils.buildSpringId( HttpAuthenticator.ROLE, "basic" ) );
         
-        sessionProvider = new ArchivaDavSessionProvider( servletAuth, httpAuth );
+        ArchivaXworkUser archivaXworkUser =
+            (ArchivaXworkUser) wac.getBean( PlexusToSpringUtils.buildSpringId( ArchivaXworkUser.class.getName() ) );
+        sessionProvider = new ArchivaDavSessionProvider( servletAuth, httpAuth, archivaXworkUser );
     }
 
     public void configurationEvent( ConfigurationEvent event )
index 2a53bf99df1e64efc8a60ea0890a9021c02fcfb7..e882c5ad65ba4fa53478c81d6205024653eda4f6 100644 (file)
@@ -59,7 +59,7 @@ public class ArchivaDavSessionProviderTest extends TestCase
         throws Exception
     {
         super.setUp();
-        sessionProvider = new ArchivaDavSessionProvider(new ServletAuthenticatorMock(), new HttpAuthenticatorMock());
+        sessionProvider = new ArchivaDavSessionProvider(new ServletAuthenticatorMock(), new HttpAuthenticatorMock(), null);
         request = new WebdavRequestImpl(new HttpServletRequestMock(), null);
     }
     
@@ -362,7 +362,7 @@ public class ArchivaDavSessionProviderTest extends TestCase
             return true;
         }
 
-        public boolean isAuthorizedToAccessVirtualRepository(String arg0, String arg1)
+        public boolean isAuthorized(String arg0, String arg1)
             throws UnauthorizedException
         {
             return true;
index 13082cf4d575e9d0aa448fd214d287dba5b3b4d4..082d62dfca06050bac9dcb2cbdb69abe60850389 100644 (file)
@@ -29,7 +29,7 @@ public class UnauthenticatedDavSessionProvider extends ArchivaDavSessionProvider
 {
     public UnauthenticatedDavSessionProvider()
     {
-        super(null, null);
+        super(null, null, null);
     }
     
     @Override