You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ol...@apache.org on 2014/10/13 07:35:14 UTC

[1/2] git commit: make this servlet thread safe!!

Repository: archiva
Updated Branches:
  refs/heads/master c2f9100dd -> 4e331298e


make this servlet thread safe!!


Project: http://git-wip-us.apache.org/repos/asf/archiva/repo
Commit: http://git-wip-us.apache.org/repos/asf/archiva/commit/70bc09fb
Tree: http://git-wip-us.apache.org/repos/asf/archiva/tree/70bc09fb
Diff: http://git-wip-us.apache.org/repos/asf/archiva/diff/70bc09fb

Branch: refs/heads/master
Commit: 70bc09fbb965a922808dcf77708fabdd4216455b
Parents: c2f9100
Author: Olivier Lamy <ol...@apache.org>
Authored: Mon Oct 13 16:19:42 2014 +1100
Committer: Olivier Lamy <ol...@apache.org>
Committed: Mon Oct 13 16:19:42 2014 +1100

----------------------------------------------------------------------
 .../main/java/org/apache/archiva/web/rss/RssFeedServlet.java   | 4 ++--
 .../java/org/apache/archiva/web/rss/RssFeedServletTest.java    | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/archiva/blob/70bc09fb/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/rss/RssFeedServlet.java
----------------------------------------------------------------------
diff --git a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/rss/RssFeedServlet.java b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/rss/RssFeedServlet.java
index ddf22be..bc26d36 100644
--- a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/rss/RssFeedServlet.java
+++ b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/rss/RssFeedServlet.java
@@ -78,8 +78,6 @@ public class RssFeedServlet
 
     private Logger log = LoggerFactory.getLogger( RssFeedServlet.class );
 
-    private RssFeedProcessor processor;
-
     private WebApplicationContext wac;
 
     private UserRepositories userRepositories;
@@ -131,6 +129,8 @@ public class RssFeedServlet
             return;
         }
 
+        RssFeedProcessor processor = null;
+
         try
         {
             Map<String, String> map = new HashMap<>();

http://git-wip-us.apache.org/repos/asf/archiva/blob/70bc09fb/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/web/rss/RssFeedServletTest.java
----------------------------------------------------------------------
diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/web/rss/RssFeedServletTest.java b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/web/rss/RssFeedServletTest.java
index f11620a..54dab14 100644
--- a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/web/rss/RssFeedServletTest.java
+++ b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/web/rss/RssFeedServletTest.java
@@ -431,7 +431,7 @@ public class RssFeedServletTest
     }
 
     @Ignore
-    public void XXX_testInvalidRequest()
+    public void testInvalidRequest()
         throws Exception
     {
         //RssFeedServlet servlet =
@@ -450,7 +450,7 @@ public class RssFeedServletTest
     }
 
     @Ignore
-    public void XXX_testInvalidAuthenticationRequest()
+    public void testInvalidAuthenticationRequest()
         throws Exception
     {
         //RssFeedServlet servlet =
@@ -476,7 +476,7 @@ public class RssFeedServletTest
     }
 
     @Ignore
-    public void XXX_testUnauthorizedRequest()
+    public void testUnauthorizedRequest()
         throws Exception
     {
 


[2/2] git commit: no need to lookup those beans for each request

Posted by ol...@apache.org.
no need to lookup those beans for each request


Project: http://git-wip-us.apache.org/repos/asf/archiva/repo
Commit: http://git-wip-us.apache.org/repos/asf/archiva/commit/4e331298
Tree: http://git-wip-us.apache.org/repos/asf/archiva/tree/4e331298
Diff: http://git-wip-us.apache.org/repos/asf/archiva/diff/4e331298

Branch: refs/heads/master
Commit: 4e331298e4abdaf9e571cd34c7f31de67ee5a835
Parents: 70bc09f
Author: Olivier Lamy <ol...@apache.org>
Authored: Mon Oct 13 16:35:00 2014 +1100
Committer: Olivier Lamy <ol...@apache.org>
Committed: Mon Oct 13 16:35:00 2014 +1100

----------------------------------------------------------------------
 .../NewVersionsOfArtifactRssFeedProcessor.java  |  3 --
 .../apache/archiva/web/rss/RssFeedServlet.java  | 33 +++++++++++++-------
 2 files changed, 21 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/archiva/blob/4e331298/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java
----------------------------------------------------------------------
diff --git a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java
index c6b0466..f9c24bd 100644
--- a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java
+++ b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java
@@ -54,9 +54,6 @@ public class NewVersionsOfArtifactRssFeedProcessor
 
     private static final String desc = "These are the new versions of artifact ";
 
-    /**
-     *
-     */
     @Inject
     private RssFeedGenerator generator;
 

http://git-wip-us.apache.org/repos/asf/archiva/blob/4e331298/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/rss/RssFeedServlet.java
----------------------------------------------------------------------
diff --git a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/rss/RssFeedServlet.java b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/rss/RssFeedServlet.java
index bc26d36..958ad28 100644
--- a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/rss/RssFeedServlet.java
+++ b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/rss/RssFeedServlet.java
@@ -25,8 +25,13 @@ import com.sun.syndication.io.SyndFeedOutput;
 import org.apache.archiva.metadata.repository.RepositorySession;
 import org.apache.archiva.metadata.repository.RepositorySessionFactory;
 import org.apache.archiva.redback.authentication.AuthenticationException;
+import org.apache.archiva.redback.authentication.AuthenticationResult;
+import org.apache.archiva.redback.authorization.AuthorizationException;
+import org.apache.archiva.redback.authorization.UnauthorizedException;
+import org.apache.archiva.redback.integration.filter.authentication.HttpAuthenticator;
 import org.apache.archiva.redback.policy.AccountLockedException;
 import org.apache.archiva.redback.policy.MustChangePasswordException;
+import org.apache.archiva.redback.system.SecuritySession;
 import org.apache.archiva.redback.users.UserManager;
 import org.apache.archiva.redback.users.UserNotFoundException;
 import org.apache.archiva.rss.processor.RssFeedProcessor;
@@ -40,11 +45,6 @@ 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.archiva.redback.authentication.AuthenticationResult;
-import org.apache.archiva.redback.authorization.AuthorizationException;
-import org.apache.archiva.redback.authorization.UnauthorizedException;
-import org.apache.archiva.redback.system.SecuritySession;
-import org.apache.archiva.redback.integration.filter.authentication.HttpAuthenticator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.web.context.WebApplicationContext;
@@ -86,6 +86,10 @@ public class RssFeedServlet
 
     private HttpAuthenticator httpAuth;
 
+    private RssFeedProcessor newArtifactsprocessor;
+
+    private RssFeedProcessor newVersionsprocessor;
+
     /**
      * FIXME: this could be multiple implementations and needs to be configured.
      */
@@ -102,6 +106,9 @@ public class RssFeedServlet
         httpAuth = wac.getBean( "httpAuthenticator#basic", HttpAuthenticator.class );
         // TODO: what if there are other types?
         repositorySessionFactory = wac.getBean( "repositorySessionFactory", RepositorySessionFactory.class );
+
+        newArtifactsprocessor = wac.getBean( "rssFeedProcessor#new-artifacts", RssFeedProcessor.class );
+        newVersionsprocessor = wac.getBean( "rssFeedProcessor#new-versions", RssFeedProcessor.class );
     }
 
     @Override
@@ -141,14 +148,14 @@ public class RssFeedServlet
                 if ( repoId != null )
                 {
                     // new artifacts in repo feed request
-                    processor = wac.getBean( "rssFeedProcessor#new-artifacts", RssFeedProcessor.class );
+                    processor = newArtifactsprocessor;
                     map.put( RssFeedProcessor.KEY_REPO_ID, repoId );
                 }
                 else if ( ( groupId != null ) && ( artifactId != null ) )
                 {
                     // TODO: this only works for guest - we could pass in the list of repos
                     // new versions of artifact feed request
-                    processor = wac.getBean( "rssFeedProcessor#new-versions", RssFeedProcessor.class );
+                    processor = newVersionsprocessor;
                     map.put( RssFeedProcessor.KEY_GROUP_ID, groupId );
                     map.put( RssFeedProcessor.KEY_ARTIFACT_ID, artifactId );
                 }
@@ -296,20 +303,22 @@ public class RssFeedServlet
                 AuthenticationResult result = httpAuth.getAuthenticationResult( req, null );
                 SecuritySession securitySession = httpAuth.getSecuritySession( req.getSession( true ) );
 
-                if ( servletAuth.isAuthenticated( req, result ) && servletAuth.isAuthorized( req, securitySession,
-                                                                                             repoId,
-                                                                                             ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS ) )
+                if ( servletAuth.isAuthenticated( req, result ) //
+                    && servletAuth.isAuthorized( req, //
+                                                 securitySession, //
+                                                 repoId, //
+                                                 ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS ) )
                 {
                     return true;
                 }
             }
             catch ( AuthorizationException e )
             {
-
+                log.debug( "AuthorizationException for repoId: {}", repoId );
             }
             catch ( UnauthorizedException e )
             {
-
+                log.debug( "UnauthorizedException for repoId: {}", repoId );
             }
         }