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 2015/02/06 13:10:24 UTC

[1/7] archiva-redback-core git commit: cxf upgrade to 3.0.3

Repository: archiva-redback-core
Updated Branches:
  refs/heads/master 3791ad83d -> 47cd662af


cxf upgrade to 3.0.3


Project: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/commit/5bf9065c
Tree: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/tree/5bf9065c
Diff: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/diff/5bf9065c

Branch: refs/heads/master
Commit: 5bf9065c2ffd0081ac55237a897f8ac7e38b1523
Parents: 3791ad8
Author: Olivier Lamy <ol...@apache.org>
Authored: Thu Jan 29 22:13:22 2015 +1100
Committer: Olivier Lamy <ol...@apache.org>
Committed: Thu Feb 5 21:35:03 2015 +1100

----------------------------------------------------------------------
 pom.xml                                         | 36 ++++++++++++-------
 .../redback-common-integrations/pom.xml         |  1 -
 .../redback-rest/redback-rest-api/pom.xml       |  8 +----
 .../redback-rest/redback-rest-services/pom.xml  | 36 ++++++++++---------
 .../interceptors/AuthenticationInterceptor.java | 32 ++++++++++-------
 .../interceptors/PermissionsInterceptor.java    | 38 ++++++++++++--------
 .../services/RoleManagementServiceTest.java     | 16 ++++-----
 .../redback/rest/services/UserServiceTest.java  | 21 ++++++-----
 8 files changed, 107 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/5bf9065c/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 2e46d8a..45a52f3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -76,7 +76,7 @@
 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <gpg.useagent>true</gpg.useagent>
-    <cxfVersion>2.6.15</cxfVersion>
+    <cxf.version>3.0.3</cxf.version>
     <!--
     <redbackTestJdbcUrl>jdbc:derby:memory:users-test;create=true</redbackTestJdbcUrl>
     <redbackTestJdbcDriver>org.apache.derby.jdbc.EmbeddedDriver</redbackTestJdbcDriver>
@@ -632,19 +632,29 @@
       </dependency>
       <dependency>
         <groupId>org.apache.cxf</groupId>
-        <artifactId>cxf-bundle-jaxrs</artifactId>
-        <version>${cxfVersion}</version>
-        <exclusions>
-          <exclusion>
-            <groupId>org.eclipse.jetty</groupId>
-            <artifactId>jetty-server</artifactId>
-          </exclusion>
-          <exclusion>
-            <groupId>org.codehaus.jettison</groupId>
-            <artifactId>jettison</artifactId>
-          </exclusion>
-        </exclusions>
+        <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+        <version>${cxf.version}</version>
+      </dependency>
+
+      <dependency>
+        <groupId>org.apache.cxf</groupId>
+        <artifactId>cxf-rt-rs-client</artifactId>
+        <version>${cxf.version}</version>
+      </dependency>
+
+      <dependency>
+        <groupId>org.apache.cxf</groupId>
+        <artifactId>cxf-rt-rs-extension-providers</artifactId>
+        <version>${cxf.version}</version>
       </dependency>
+
+      <dependency>
+        <groupId>javax.mail</groupId>
+        <artifactId>mail</artifactId>
+        <version>1.4</version>
+        <scope>provided</scope>
+      </dependency>
+
       <dependency>
         <groupId>org.apache.velocity</groupId>
         <artifactId>velocity</artifactId>

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/5bf9065c/redback-integrations/redback-common-integrations/pom.xml
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-common-integrations/pom.xml b/redback-integrations/redback-common-integrations/pom.xml
index 004843c..5cdb42c 100644
--- a/redback-integrations/redback-common-integrations/pom.xml
+++ b/redback-integrations/redback-common-integrations/pom.xml
@@ -114,7 +114,6 @@
     <dependency>
       <groupId>javax.mail</groupId>
       <artifactId>mail</artifactId>
-      <version>1.4</version>
       <scope>provided</scope>
     </dependency>      
     <dependency>

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/5bf9065c/redback-integrations/redback-rest/redback-rest-api/pom.xml
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-api/pom.xml b/redback-integrations/redback-rest/redback-rest-api/pom.xml
index 153c41f..f717ad1 100644
--- a/redback-integrations/redback-rest/redback-rest-api/pom.xml
+++ b/redback-integrations/redback-rest/redback-rest-api/pom.xml
@@ -56,13 +56,7 @@
     <!-- normally not needed but here for wadl feature currently in cxf -->
     <dependency>
       <groupId>org.apache.cxf</groupId>
-      <artifactId>cxf-bundle-jaxrs</artifactId>
-      <exclusions>
-        <exclusion>
-          <groupId>org.eclipse.jetty</groupId>
-          <artifactId>jetty-server</artifactId>
-        </exclusion>
-      </exclusions>
+      <artifactId>cxf-rt-frontend-jaxrs</artifactId>
     </dependency>
   </dependencies>
 

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/5bf9065c/redback-integrations/redback-rest/redback-rest-services/pom.xml
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/pom.xml b/redback-integrations/redback-rest/redback-rest-services/pom.xml
index ccaf2c5..013db29 100644
--- a/redback-integrations/redback-rest/redback-rest-services/pom.xml
+++ b/redback-integrations/redback-rest/redback-rest-services/pom.xml
@@ -82,22 +82,26 @@
     </dependency>
     <dependency>
       <groupId>org.apache.cxf</groupId>
-      <artifactId>cxf-bundle-jaxrs</artifactId>
-      <exclusions>
-        <exclusion>
-          <groupId>org.eclipse.jetty</groupId>
-          <artifactId>jetty-server</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>org.apache.geronimo.specs</groupId>
-          <artifactId>geronimo-servlet_2.5_spec</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>org.codehaus.jettison</groupId>
-          <artifactId>jettison</artifactId>
-        </exclusion>
-      </exclusions>
+      <artifactId>cxf-rt-frontend-jaxrs</artifactId>
     </dependency>
+
+    <dependency>
+      <groupId>javax.mail</groupId>
+      <artifactId>mail</artifactId>
+      <scope>provided</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.cxf</groupId>
+      <artifactId>cxf-rt-rs-client</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.cxf</groupId>
+      <artifactId>cxf-rt-rs-extension-providers</artifactId>
+    </dependency>
+
     <dependency>
       <groupId>javax.ws.rs</groupId>
       <artifactId>jsr311-api</artifactId>
@@ -232,7 +236,7 @@
               org.apache.archiva.redback.users;version=${project.version},
               org.apache.commons.io;version="[1.4,2)",
               org.apache.commons.lang;version="[2.6,3)",
-              org.apache.cxf*;version="[2.6,3)",
+              org.apache.cxf*;version="[3.0.3)",
               com.fasterxml.jackson.databind;version="[2.2,3)",
               org.codehaus.plexus.util;version="[3,4)",
               org.springframework*;version="[3,4)",

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/5bf9065c/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AuthenticationInterceptor.java
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AuthenticationInterceptor.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AuthenticationInterceptor.java
index b839045..8074f75 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AuthenticationInterceptor.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AuthenticationInterceptor.java
@@ -34,8 +34,7 @@ import org.apache.archiva.redback.users.User;
 import org.apache.archiva.redback.users.UserManager;
 import org.apache.archiva.redback.users.UserManagerException;
 import org.apache.archiva.redback.users.UserNotFoundException;
-import org.apache.cxf.jaxrs.ext.RequestHandler;
-import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Message;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -45,7 +44,10 @@ import javax.inject.Inject;
 import javax.inject.Named;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
 import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.Provider;
 
 /**
  * This interceptor will check if the user is already logged in the session.
@@ -56,9 +58,10 @@ import javax.ws.rs.core.Response;
  * @since 1.3
  */
 @Service("authenticationInterceptor#rest")
+@Provider
 public class AuthenticationInterceptor
     extends AbstractInterceptor
-    implements RequestHandler
+    implements ContainerRequestFilter
 {
     @Inject
     @Named(value = "userManager#default")
@@ -70,9 +73,11 @@ public class AuthenticationInterceptor
 
     private Logger log = LoggerFactory.getLogger( getClass() );
 
-    public Response handleRequest( Message message, ClassResourceInfo classResourceInfo )
+    public void filter( ContainerRequestContext containerRequestContext )
     {
 
+        Message message = JAXRSUtils.getCurrentMessage();
+
         RedbackAuthorization redbackAuthorization = getRedbackAuthorization( message );
         if ( redbackAuthorization == null )
         {
@@ -80,7 +85,8 @@ public class AuthenticationInterceptor
                       message.get( Message.REQUEST_URI ) );
             // here we failed to authenticate so 403 as there is no detail on karma for this
             // it must be marked as it's exposed
-            return Response.status( Response.Status.FORBIDDEN ).build();
+            containerRequestContext.abortWith( Response.status( Response.Status.FORBIDDEN ).build() );
+            return;
         }
         HttpServletRequest request = getHttpServletRequest( message );
         HttpServletResponse response = getHttpServletResponse( message );
@@ -107,7 +113,7 @@ public class AuthenticationInterceptor
 
                     if ( ( authenticationResult == null ) || ( !authenticationResult.isAuthenticated() ) )
                     {
-                        return null;
+                        return;
                     }
 
                     User user = authenticationResult.getUser() == null ? userManager.findUser(
@@ -123,7 +129,7 @@ public class AuthenticationInterceptor
                     // ignore here
                 }
             }
-            return null;
+            return;
         }
 
         try
@@ -145,34 +151,34 @@ public class AuthenticationInterceptor
             RedbackAuthenticationThreadLocal.set( redbackRequestInformation );
             message.put( AuthenticationResult.class, authenticationResult );
 
-            return null;
+            return;
         }
         catch ( UserNotFoundException e )
         {
             log.debug( "UserNotFoundException for path {}", message.get( Message.REQUEST_URI ) );
-            return Response.status( Response.Status.FORBIDDEN ).build();
+            containerRequestContext.abortWith( Response.status( Response.Status.FORBIDDEN ).build() );
         }
         catch ( AccountLockedException e )
         {
             log.debug( "account locked for path {}", message.get( Message.REQUEST_URI ) );
-            return Response.status( Response.Status.FORBIDDEN ).build();
+            containerRequestContext.abortWith( Response.status( Response.Status.FORBIDDEN ).build() );
 
         }
         catch ( MustChangePasswordException e )
         {
             log.debug( "must change password for path {}", message.get( Message.REQUEST_URI ) );
-            return Response.status( Response.Status.FORBIDDEN ).build();
+            containerRequestContext.abortWith( Response.status( Response.Status.FORBIDDEN ).build() );
 
         }
         catch ( AuthenticationException e )
         {
             log.debug( "failed to authenticate for path {}", message.get( Message.REQUEST_URI ) );
-            return Response.status( Response.Status.FORBIDDEN ).build();
+            containerRequestContext.abortWith( Response.status( Response.Status.FORBIDDEN ).build() );
         }
         catch ( UserManagerException e )
         {
             log.debug( "UserManagerException: {} for path", e.getMessage(), message.get( Message.REQUEST_URI ) );
-            return Response.status( Response.Status.FORBIDDEN ).build();
+            containerRequestContext.abortWith( Response.status( Response.Status.FORBIDDEN ).build() );
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/5bf9065c/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java
index a55b07f..ae5b6ca 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java
@@ -26,8 +26,7 @@ import org.apache.archiva.redback.integration.filter.authentication.basic.HttpBa
 import org.apache.archiva.redback.system.SecuritySession;
 import org.apache.archiva.redback.system.SecuritySystem;
 import org.apache.commons.lang.StringUtils;
-import org.apache.cxf.jaxrs.ext.RequestHandler;
-import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Message;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -36,30 +35,36 @@ import org.springframework.stereotype.Service;
 import javax.inject.Inject;
 import javax.inject.Named;
 import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
 import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.Provider;
 
 /**
  * @author Olivier Lamy
  * @since 1.3
  */
-@Service ("permissionInterceptor#rest")
+@Service( "permissionInterceptor#rest" )
+@Provider
 public class PermissionsInterceptor
     extends AbstractInterceptor
-    implements RequestHandler
+    implements ContainerRequestFilter
 {
 
     @Inject
-    @Named (value = "securitySystem")
+    @Named( value = "securitySystem" )
     private SecuritySystem securitySystem;
 
     @Inject
-    @Named (value = "httpAuthenticator#basic")
+    @Named( value = "httpAuthenticator#basic" )
     private HttpBasicAuthentication httpAuthenticator;
 
     private Logger log = LoggerFactory.getLogger( getClass() );
 
-    public Response handleRequest( Message message, ClassResourceInfo classResourceInfo )
+    public void filter( ContainerRequestContext containerRequestContext )
     {
+        Message message = JAXRSUtils.getCurrentMessage();
+
         RedbackAuthorization redbackAuthorization = getRedbackAuthorization( message );
 
         if ( redbackAuthorization != null )
@@ -67,7 +72,7 @@ public class PermissionsInterceptor
             if ( redbackAuthorization.noRestriction() )
             {
                 // we are fine this services is marked as non restrictive acces
-                return null;
+                return;
             }
             String[] permissions = redbackAuthorization.permissions();
             //olamy: no value is an array with an empty String
@@ -92,7 +97,7 @@ public class PermissionsInterceptor
                                                                   ? null
                                                                   : redbackAuthorization.resource() ) )
                             {
-                                return null;
+                                return;
                             }
                             else
                             {
@@ -103,14 +108,18 @@ public class PermissionsInterceptor
                         catch ( AuthorizationException e )
                         {
                             log.debug( e.getMessage(), e );
-                            return Response.status( Response.Status.FORBIDDEN ).build();
+                            containerRequestContext.abortWith( Response.status( Response.Status.FORBIDDEN ).build() );
+                            return;
                         }
                     }
 
                 }
                 else
                 {
-                    log.debug( "user {} not authenticated", session.getUser().getUsername() );
+                    if ( session != null && session.getUser() != null )
+                    {
+                        log.debug( "user {} not authenticated", session.getUser().getUsername() );
+                    }
                 }
             }
             else
@@ -118,15 +127,16 @@ public class PermissionsInterceptor
                 if ( redbackAuthorization.noPermission() )
                 {
                     log.debug( "path {} doesn't need special permission", message.get( Message.REQUEST_URI ) );
-                    return null;
+                    return;
                 }
-                return Response.status( Response.Status.FORBIDDEN ).build();
+                containerRequestContext.abortWith( Response.status( Response.Status.FORBIDDEN ).build() );
+                return;
             }
         }
         log.warn( "http path {} doesn't contain any informations regarding permissions ",
                   message.get( Message.REQUEST_URI ) );
         // here we failed to authenticate so 403 as there is no detail on karma for this
         // it must be marked as it's exposed
-        return Response.status( Response.Status.FORBIDDEN ).build();
+        containerRequestContext.abortWith( Response.status( Response.Status.FORBIDDEN ).build() );
     }
 }

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/5bf9065c/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/RoleManagementServiceTest.java
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/RoleManagementServiceTest.java b/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/RoleManagementServiceTest.java
index 89d9663..1926314 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/RoleManagementServiceTest.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/RoleManagementServiceTest.java
@@ -18,15 +18,15 @@ package org.apache.archiva.redback.rest.services;
  * under the License.
  */
 
-import org.apache.commons.lang.StringUtils;
-import org.apache.cxf.jaxrs.client.ServerWebApplicationException;
 import org.apache.archiva.redback.rest.api.model.ApplicationRoles;
 import org.apache.archiva.redback.rest.api.model.Role;
 import org.apache.archiva.redback.rest.api.model.User;
 import org.apache.archiva.redback.rest.api.services.RoleManagementService;
 import org.apache.archiva.redback.rest.api.services.UserService;
+import org.apache.commons.lang.StringUtils;
 import org.junit.Test;
 
+import javax.ws.rs.ForbiddenException;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
@@ -47,7 +47,7 @@ public class RoleManagementServiceTest
         assertFalse( getRoleManagementService( authorizationHeader ).roleExists( "foo" ) );
     }
 
-    @Test( expected = ServerWebApplicationException.class )
+    @Test( expected = ForbiddenException.class )
     public void roleExistBadAuthz()
         throws Exception
     {
@@ -55,9 +55,9 @@ public class RoleManagementServiceTest
         {
             assertTrue( getRoleManagementService( null ).roleExists( "guest" ) );
         }
-        catch ( ServerWebApplicationException e )
+        catch ( ForbiddenException e )
         {
-            assertEquals( 403, e.getStatus() );
+            assertEquals( 403, e.getResponse().getStatus() );
             throw e;
         }
     }
@@ -85,9 +85,10 @@ public class RoleManagementServiceTest
                 getUserService( encode( "toto", "foo123" ) ).getUsers();
                 fail( "should fail with 403" );
             }
-            catch ( ServerWebApplicationException e )
+            catch ( ForbiddenException e )
             {
-                assertEquals( 403, e.getStatus() );
+                assertEquals( 403, e.getResponse().getStatus() );
+
 
             }
 
@@ -193,7 +194,6 @@ public class RoleManagementServiceTest
     {
         RoleManagementService roleManagementService = getRoleManagementService( authorizationHeader );
 
-
         List<Role> allRoles = roleManagementService.getAllRoles();
 
         assertNotNull( allRoles );

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/5bf9065c/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/UserServiceTest.java
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/UserServiceTest.java b/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/UserServiceTest.java
index 6481d0d..629e8fc 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/UserServiceTest.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/UserServiceTest.java
@@ -29,16 +29,17 @@ import org.apache.archiva.redback.rest.api.services.UserService;
 import org.apache.archiva.redback.rest.services.mock.EmailMessage;
 import org.apache.archiva.redback.rest.services.mock.ServicesAssert;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
-import org.apache.cxf.jaxrs.client.ServerWebApplicationException;
 import org.apache.cxf.jaxrs.client.WebClient;
-import static org.assertj.core.api.Assertions.assertThat;
 import org.junit.Test;
 
+import javax.ws.rs.ForbiddenException;
 import javax.ws.rs.core.MediaType;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
+import static org.assertj.core.api.Assertions.assertThat;
+
 
 /**
  * @author Olivier Lamy
@@ -69,7 +70,7 @@ public class UserServiceTest
         assertFalse( users.isEmpty() );
     }
 
-    @Test( expected = ServerWebApplicationException.class )
+    @Test( expected = ForbiddenException.class )
     public void getUsersWithoutAuthz()
         throws Exception
     {
@@ -78,9 +79,9 @@ public class UserServiceTest
         {
             userService.getUsers();
         }
-        catch ( ServerWebApplicationException e )
+        catch ( ForbiddenException e )
         {
-            assertEquals( 403, e.getStatus() );
+            assertEquals( 403, e.getResponse().getStatus() );
             throw e;
         }
 
@@ -95,9 +96,10 @@ public class UserServiceTest
         {
             getFakeCreateAdminService().testAuthzWithoutKarmasNeededButAuthz();
         }
-        catch ( ServerWebApplicationException e )
+        catch ( ForbiddenException e )
         {
-            assertEquals( 403, e.getStatus() );
+            assertEquals( 403, e.getResponse().getStatus() );
+            throw e;
         }
     }
 
@@ -115,9 +117,10 @@ public class UserServiceTest
             assertTrue( service.testAuthzWithoutKarmasNeededButAuthz().booleanValue() );
 
         }
-        catch ( ServerWebApplicationException e )
+        catch ( ForbiddenException e )
         {
-            assertEquals( 403, e.getStatus() );
+            assertEquals( 403, e.getResponse().getStatus() );
+            throw e;
         }
     }
 


[3/7] archiva-redback-core git commit: fix unit test

Posted by ol...@apache.org.
fix unit test


Project: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/commit/8bdcfbb8
Tree: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/tree/8bdcfbb8
Diff: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/diff/8bdcfbb8

Branch: refs/heads/master
Commit: 8bdcfbb8a0ceeed657a2a0c90797ab309948176e
Parents: 5bf9065
Author: Olivier Lamy <ol...@apache.org>
Authored: Fri Jan 30 12:02:30 2015 +1100
Committer: Olivier Lamy <ol...@apache.org>
Committed: Thu Feb 5 21:35:04 2015 +1100

----------------------------------------------------------------------
 .../redback-rest/redback-rest-services/pom.xml  |  4 +-
 .../interceptors/AuthenticationInterceptor.java |  8 +---
 .../interceptors/PermissionsInterceptor.java    | 45 +++++++++++++++++---
 .../rest/services/AbstractRestServicesTest.java | 13 ++++--
 4 files changed, 51 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/8bdcfbb8/redback-integrations/redback-rest/redback-rest-services/pom.xml
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/pom.xml b/redback-integrations/redback-rest/redback-rest-services/pom.xml
index 013db29..5bd18df 100644
--- a/redback-integrations/redback-rest/redback-rest-services/pom.xml
+++ b/redback-integrations/redback-rest/redback-rest-services/pom.xml
@@ -32,7 +32,8 @@
   <name>Redback :: Integration :: REST :: Services</name>
 
   <properties>
-    <tomcatVersion>7.0.54</tomcatVersion>
+    <tomcatVersion>7.0.57</tomcatVersion>
+    <rest.test.timeout>1000000</rest.test.timeout>
   </properties>
 
   <dependencies>
@@ -276,6 +277,7 @@
             <redback.jdbc.url>${redbackTestJdbcUrl}</redback.jdbc.url>
             <redback.jdbc.driver.name>${redbackTestJdbcDriver}</redback.jdbc.driver.name>
             <ldapPort>${ldapPort}</ldapPort>
+            <rest.test.timeout>${rest.test.timeout}</rest.test.timeout>
           </systemPropertyVariables>
         </configuration>
       </plugin>

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/8bdcfbb8/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AuthenticationInterceptor.java
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AuthenticationInterceptor.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AuthenticationInterceptor.java
index 8074f75..8489aef 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AuthenticationInterceptor.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AuthenticationInterceptor.java
@@ -156,29 +156,23 @@ public class AuthenticationInterceptor
         catch ( UserNotFoundException e )
         {
             log.debug( "UserNotFoundException for path {}", message.get( Message.REQUEST_URI ) );
-            containerRequestContext.abortWith( Response.status( Response.Status.FORBIDDEN ).build() );
         }
         catch ( AccountLockedException e )
         {
             log.debug( "account locked for path {}", message.get( Message.REQUEST_URI ) );
-            containerRequestContext.abortWith( Response.status( Response.Status.FORBIDDEN ).build() );
-
         }
         catch ( MustChangePasswordException e )
         {
             log.debug( "must change password for path {}", message.get( Message.REQUEST_URI ) );
-            containerRequestContext.abortWith( Response.status( Response.Status.FORBIDDEN ).build() );
-
         }
         catch ( AuthenticationException e )
         {
             log.debug( "failed to authenticate for path {}", message.get( Message.REQUEST_URI ) );
-            containerRequestContext.abortWith( Response.status( Response.Status.FORBIDDEN ).build() );
         }
         catch ( UserManagerException e )
         {
             log.debug( "UserManagerException: {} for path", e.getMessage(), message.get( Message.REQUEST_URI ) );
-            containerRequestContext.abortWith( Response.status( Response.Status.FORBIDDEN ).build() );
         }
+        containerRequestContext.abortWith( Response.status( Response.Status.FORBIDDEN ).build() );
     }
 }

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/8bdcfbb8/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java
index ae5b6ca..be877db 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java
@@ -19,10 +19,13 @@ package org.apache.archiva.redback.rest.services.interceptors;
  * under the License.
  */
 
+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.RedbackAuthorization;
 import org.apache.archiva.redback.integration.filter.authentication.basic.HttpBasicAuthentication;
+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.system.SecuritySystem;
 import org.apache.commons.lang.StringUtils;
@@ -71,7 +74,7 @@ public class PermissionsInterceptor
         {
             if ( redbackAuthorization.noRestriction() )
             {
-                // we are fine this services is marked as non restrictive acces
+                // we are fine this services is marked as non restrictive access
                 return;
             }
             String[] permissions = redbackAuthorization.permissions();
@@ -80,8 +83,32 @@ public class PermissionsInterceptor
                 permissions[0] ) ) )
             {
                 HttpServletRequest request = getHttpServletRequest( message );
-                SecuritySession session = httpAuthenticator.getSecuritySession( request.getSession() );
+                SecuritySession securitySession = httpAuthenticator.getSecuritySession( request.getSession( true ) );
                 AuthenticationResult authenticationResult = message.get( AuthenticationResult.class );
+
+                if ( authenticationResult == null )
+                {
+                    try
+                    {
+                        authenticationResult = httpAuthenticator.getAuthenticationResult( request, getHttpServletResponse( message ) );
+                    }
+                    catch ( AuthenticationException e )
+                    {
+                        log.debug( "failed to authenticate for path {}", message.get( Message.REQUEST_URI ) );
+                        containerRequestContext.abortWith( Response.status( Response.Status.FORBIDDEN ).build() );
+                    }
+                    catch ( AccountLockedException e )
+                    {
+                        log.debug( "account locked for path {}", message.get( Message.REQUEST_URI ) );
+                        containerRequestContext.abortWith( Response.status( Response.Status.FORBIDDEN ).build() );
+                    }
+                    catch ( MustChangePasswordException e )
+                    {
+                        log.debug( "must change password for path {}", message.get( Message.REQUEST_URI ) );
+                        containerRequestContext.abortWith( Response.status( Response.Status.FORBIDDEN ).build() );
+                    }
+                }
+
                 if ( authenticationResult != null && authenticationResult.isAuthenticated() )
                 {
                     for ( String permission : permissions )
@@ -92,7 +119,7 @@ public class PermissionsInterceptor
                         }
                         try
                         {
-                            if ( securitySystem.isAuthorized( session, permission,
+                            if ( securitySystem.isAuthorized( securitySession, permission,
                                                               StringUtils.isBlank( redbackAuthorization.resource() )
                                                                   ? null
                                                                   : redbackAuthorization.resource() ) )
@@ -101,8 +128,12 @@ public class PermissionsInterceptor
                             }
                             else
                             {
-                                log.debug( "user {} not authorized for permission {}", session.getUser().getUsername(),
-                                           permission );
+                                if ( securitySession != null && securitySession.getUser() != null )
+                                {
+                                    log.debug( "user {} not authorized for permission {}", //
+                                               securitySession.getUser().getUsername(), //
+                                               permission );
+                                }
                             }
                         }
                         catch ( AuthorizationException e )
@@ -116,9 +147,9 @@ public class PermissionsInterceptor
                 }
                 else
                 {
-                    if ( session != null && session.getUser() != null )
+                    if ( securitySession != null && securitySession.getUser() != null )
                     {
-                        log.debug( "user {} not authenticated", session.getUser().getUsername() );
+                        log.debug( "user {} not authenticated", securitySession.getUser().getUsername() );
                     }
                 }
             }

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/8bdcfbb8/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java b/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java
index 5918fe8..b0240c5 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java
@@ -62,6 +62,11 @@ public abstract class AbstractRestServicesTest
     public String authorizationHeader = getAdminAuthzHeader();
 
 
+    public long getTimeout()
+    {
+        return Long.getLong( "rest.test.timeout", 1000000 );
+    }
+
     public static String encode( String uid, String password )
     {
         return "Basic " + Base64Utility.encode( ( uid + ":" + password ).getBytes() );
@@ -159,7 +164,7 @@ public abstract class AbstractRestServicesTest
                                        UserService.class, Collections.singletonList( new JacksonJaxbJsonProvider() ) );
 
         // time out for debuging purpose
-        WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000 );
+        WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( getTimeout() );
 
         if ( authzHeader != null )
         {
@@ -180,7 +185,7 @@ public abstract class AbstractRestServicesTest
                                        Collections.singletonList( new JacksonJaxbJsonProvider() ) );
 
         // for debuging purpose
-        WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000 );
+        WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( getTimeout() );
 
         if ( authzHeader != null )
         {
@@ -200,7 +205,7 @@ public abstract class AbstractRestServicesTest
                                        LoginService.class, Collections.singletonList( new JacksonJaxbJsonProvider() ) );
 
         // for debuging purpose
-        WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000 );
+        WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( getTimeout() );
 
         if ( authzHeader != null )
         {
@@ -222,7 +227,7 @@ public abstract class AbstractRestServicesTest
                                        Collections.singletonList( new JacksonJaxbJsonProvider() ) );
 
         // for debuging purpose
-        WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000 );
+        WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( getTimeout() );
 
         if ( authzHeader != null )
         {


[6/7] archiva-redback-core git commit: fix unit test

Posted by ol...@apache.org.
fix unit test


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

Branch: refs/heads/master
Commit: f77d21b58956342acf102b71ab166eb1995e4503
Parents: 8edcb36
Author: Olivier Lamy <ol...@apache.org>
Authored: Fri Feb 6 23:09:37 2015 +1100
Committer: Olivier Lamy <ol...@apache.org>
Committed: Fri Feb 6 23:09:37 2015 +1100

----------------------------------------------------------------------
 .../interceptors/PermissionsInterceptor.java    | 37 ++++++++++++-----
 .../redback/rest/services/UserServiceTest.java  | 19 +++++++--
 .../src/test/resources/log4j2-test.xml          |  3 +-
 .../redback/system/DefaultSecuritySession.java  | 12 +++++-
 .../redback/system/DefaultSecuritySystem.java   | 42 ++++++++++++++------
 .../archiva/redback/system/SecuritySystem.java  |  4 ++
 6 files changed, 90 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/f77d21b5/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java
index f2d4284..fc2a11f 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java
@@ -22,6 +22,7 @@ package org.apache.archiva.redback.rest.services.interceptors;
 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.AuthorizationResult;
 import org.apache.archiva.redback.authorization.RedbackAuthorization;
 import org.apache.archiva.redback.integration.filter.authentication.basic.HttpBasicAuthentication;
 import org.apache.archiva.redback.policy.AccountLockedException;
@@ -75,6 +76,7 @@ public class PermissionsInterceptor
         {
             if ( redbackAuthorization.noRestriction() )
             {
+                log.debug( "redbackAuthorization.noRestriction() so skip permission check" );
                 // we are fine this services is marked as non restrictive access
                 return;
             }
@@ -84,48 +86,64 @@ public class PermissionsInterceptor
                 && !( permissions.length == 1 && StringUtils.isEmpty( permissions[0] ) ) )
             {
                 HttpServletRequest request = getHttpServletRequest( message );
-                SecuritySession securitySession = httpAuthenticator.getSecuritySession( request.getSession( true ) );
+                SecuritySession securitySession = httpAuthenticator.getSecuritySession( request.getSession() );
                 AuthenticationResult authenticationResult = message.get( AuthenticationResult.class );
 
+                log.debug( "authenticationResult from message: {}", authenticationResult );
+
                 if ( authenticationResult == null )
                 {
                     try
                     {
                         authenticationResult =
                             httpAuthenticator.getAuthenticationResult( request, getHttpServletResponse( message ) );
+
+                        log.debug( "authenticationResult from request: {}", authenticationResult );
                     }
                     catch ( AuthenticationException e )
                     {
                         log.debug( "failed to authenticate for path {}", message.get( Message.REQUEST_URI ) );
                         containerRequestContext.abortWith( Response.status( Response.Status.FORBIDDEN ).build() );
+                        return;
                     }
                     catch ( AccountLockedException e )
                     {
                         log.debug( "account locked for path {}", message.get( Message.REQUEST_URI ) );
                         containerRequestContext.abortWith( Response.status( Response.Status.FORBIDDEN ).build() );
+                        return;
                     }
                     catch ( MustChangePasswordException e )
                     {
                         log.debug( "must change password for path {}", message.get( Message.REQUEST_URI ) );
                         containerRequestContext.abortWith( Response.status( Response.Status.FORBIDDEN ).build() );
+                        return;
                     }
                 }
 
                 if ( authenticationResult != null && authenticationResult.isAuthenticated() )
                 {
+                    message.put( AuthenticationResult.class, authenticationResult );
                     for ( String permission : permissions )
                     {
+                        log.debug( "check permission: {} with securitySession {}", permission, securitySession );
                         if ( StringUtils.isBlank( permission ) )
                         {
                             continue;
                         }
                         try
                         {
-                            if ( securitySystem.isAuthorized( securitySession, permission,
-                                                              StringUtils.isBlank( redbackAuthorization.resource() )
-                                                                  ? null
-                                                                  : redbackAuthorization.resource() ) )
+                            AuthorizationResult authorizationResult =
+                                securitySystem.authorize( authenticationResult.getUser(), permission, //
+                                                          StringUtils.isBlank( redbackAuthorization.resource() ) //
+                                                              ? null : redbackAuthorization.resource() );
+                            /*
+                            if ( securitySystem.isAuthorized( securitySession, permission, //
+                                                              StringUtils.isBlank( redbackAuthorization.resource() ) //
+                                                                  ? null : redbackAuthorization.resource() ) )
+                                                                  */
+                            if ( authenticationResult != null && authorizationResult.isAuthorized() )
                             {
+                                log.debug( "isAuthorized for permission {}", permission );
                                 return;
                             }
                             else
@@ -140,13 +158,12 @@ public class PermissionsInterceptor
                         }
                         catch ( AuthorizationException e )
                         {
-                            log.debug( e.getMessage(), e );
-
+                            log.debug( " AuthorizationException " + e.getMessage() //
+                                           + " checking permission " + permission, e );
+                            containerRequestContext.abortWith( Response.status( Response.Status.FORBIDDEN ).build() );
+                            return;
                         }
                     }
-                    containerRequestContext.abortWith( Response.status( Response.Status.FORBIDDEN ).build() );
-                    return;
-
                 }
                 else
                 {

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/f77d21b5/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/UserServiceTest.java
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/UserServiceTest.java b/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/UserServiceTest.java
index 629e8fc..b5a80d2 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/UserServiceTest.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/UserServiceTest.java
@@ -25,6 +25,7 @@ import org.apache.archiva.redback.rest.api.model.Permission;
 import org.apache.archiva.redback.rest.api.model.ResetPasswordRequest;
 import org.apache.archiva.redback.rest.api.model.User;
 import org.apache.archiva.redback.rest.api.model.UserRegistrationRequest;
+import org.apache.archiva.redback.rest.api.services.RedbackServiceException;
 import org.apache.archiva.redback.rest.api.services.UserService;
 import org.apache.archiva.redback.rest.services.mock.EmailMessage;
 import org.apache.archiva.redback.rest.services.mock.ServicesAssert;
@@ -178,7 +179,7 @@ public class UserServiceTest
         }
         finally
         {
-            getUserService( authorizationHeader ).deleteUser( "toto" );
+            deleteUserQuietly( "toto" );
         }
 
     }
@@ -237,7 +238,7 @@ public class UserServiceTest
         }
         finally
         {
-            getUserService( authorizationHeader ).deleteUser( "toto" );
+            deleteUserQuietly( "toto" );
         }
 
     }
@@ -307,11 +308,23 @@ public class UserServiceTest
         }
         finally
         {
-            getUserService( authorizationHeader ).deleteUser( "toto" );
+            deleteUserQuietly( "toto" );
         }
 
     }
 
+    private void deleteUserQuietly( String userName )
+    {
+        try
+        {
+            getUserService( authorizationHeader ).deleteUser( userName );
+        }
+        catch ( Exception e )
+        {
+            log.warn( "ignore fail to delete user " + e.getMessage(), e );
+        }
+    }
+
     @Test
     public void getAdminPermissions()
         throws Exception

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/f77d21b5/redback-integrations/redback-rest/redback-rest-services/src/test/resources/log4j2-test.xml
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/test/resources/log4j2-test.xml b/redback-integrations/redback-rest/redback-rest-services/src/test/resources/log4j2-test.xml
index eb55d39..e058bdb 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/test/resources/log4j2-test.xml
+++ b/redback-integrations/redback-rest/redback-rest-services/src/test/resources/log4j2-test.xml
@@ -21,7 +21,7 @@
 
   <appenders>
     <Console name="console" target="SYSTEM_OUT">
-      <PatternLayout pattern="%highlight{%d{HH:mm:ss.SSS} [%L] [%t] %-5level %logger{36} - %msg%n}" />
+      <PatternLayout pattern="%highlight{%d{HH:mm:ss.SSS} [%L] [%t] %-5level %logger{3} - %msg%n}" />
     </Console>
   </appenders>
 
@@ -32,6 +32,7 @@
     <logger name="org.apache.archiva.redback.components.cache" level="error"/>
     <logger name="org.apache.archiva.redback.rest.services.interceptors" level="debug"/>
     <logger name="org.apache.archiva.redback.rest.services" level="debug"/>
+    <logger name="org.apache.catalina" level="off" />
     <logger name="JPOX" level="ERROR"/>
     <root level="info">
       <appender-ref ref="console"/>

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/f77d21b5/redback-system/src/main/java/org/apache/archiva/redback/system/DefaultSecuritySession.java
----------------------------------------------------------------------
diff --git a/redback-system/src/main/java/org/apache/archiva/redback/system/DefaultSecuritySession.java b/redback-system/src/main/java/org/apache/archiva/redback/system/DefaultSecuritySession.java
index 2fc40c2..9acbec4 100644
--- a/redback-system/src/main/java/org/apache/archiva/redback/system/DefaultSecuritySession.java
+++ b/redback-system/src/main/java/org/apache/archiva/redback/system/DefaultSecuritySession.java
@@ -19,8 +19,8 @@ package org.apache.archiva.redback.system;
  * under the License.
  */
 
-import org.apache.archiva.redback.users.User;
 import org.apache.archiva.redback.authentication.AuthenticationResult;
+import org.apache.archiva.redback.users.User;
 import org.springframework.stereotype.Service;
 
 import java.io.Serializable;
@@ -74,4 +74,14 @@ public class DefaultSecuritySession
     {
         return ( ( user != null ) && authenticated );
     }
+
+    @Override
+    public String toString()
+    {
+        return "DefaultSecuritySession{" +
+            "authenticationResult=" + authenticationResult +
+            ", user=" + user +
+            ", authenticated=" + authenticated +
+            '}';
+    }
 }

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/f77d21b5/redback-system/src/main/java/org/apache/archiva/redback/system/DefaultSecuritySystem.java
----------------------------------------------------------------------
diff --git a/redback-system/src/main/java/org/apache/archiva/redback/system/DefaultSecuritySystem.java b/redback-system/src/main/java/org/apache/archiva/redback/system/DefaultSecuritySystem.java
index f5fc35c..c572089 100644
--- a/redback-system/src/main/java/org/apache/archiva/redback/system/DefaultSecuritySystem.java
+++ b/redback-system/src/main/java/org/apache/archiva/redback/system/DefaultSecuritySystem.java
@@ -19,13 +19,6 @@ package org.apache.archiva.redback.system;
  * under the License.
  */
 
-import org.apache.archiva.redback.keys.KeyManager;
-import org.apache.archiva.redback.policy.AccountLockedException;
-import org.apache.archiva.redback.policy.UserSecurityPolicy;
-import org.apache.archiva.redback.users.User;
-import org.apache.archiva.redback.users.UserManager;
-import org.apache.archiva.redback.users.UserManagerException;
-import org.apache.archiva.redback.users.UserNotFoundException;
 import org.apache.archiva.redback.authentication.AuthenticationDataSource;
 import org.apache.archiva.redback.authentication.AuthenticationException;
 import org.apache.archiva.redback.authentication.AuthenticationManager;
@@ -34,7 +27,14 @@ import org.apache.archiva.redback.authorization.AuthorizationDataSource;
 import org.apache.archiva.redback.authorization.AuthorizationException;
 import org.apache.archiva.redback.authorization.AuthorizationResult;
 import org.apache.archiva.redback.authorization.Authorizer;
+import org.apache.archiva.redback.keys.KeyManager;
+import org.apache.archiva.redback.policy.AccountLockedException;
 import org.apache.archiva.redback.policy.MustChangePasswordException;
+import org.apache.archiva.redback.policy.UserSecurityPolicy;
+import org.apache.archiva.redback.users.User;
+import org.apache.archiva.redback.users.UserManager;
+import org.apache.archiva.redback.users.UserManagerException;
+import org.apache.archiva.redback.users.UserNotFoundException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
@@ -47,7 +47,7 @@ import javax.inject.Named;
  *
  * @author: Jesse McConnell <je...@codehaus.org>
  */
-@Service("securitySystem")
+@Service( "securitySystem" )
 public class DefaultSecuritySystem
     implements SecuritySystem
 {
@@ -57,15 +57,15 @@ public class DefaultSecuritySystem
     private AuthenticationManager authnManager;
 
     @Inject
-    @Named(value = "authorizer#default")
+    @Named( value = "authorizer#default" )
     private Authorizer authorizer;
 
     @Inject
-    @Named(value = "userManager#default")
+    @Named( value = "userManager#default" )
     private UserManager userManager;
 
     @Inject
-    @Named(value = "keyManager#cached")
+    @Named( value = "keyManager#cached" )
     private KeyManager keyManager;
 
     @Inject
@@ -92,7 +92,6 @@ public class DefaultSecuritySystem
      * @throws UserNotFoundException
      * @throws MustChangePasswordException
      * @throws org.apache.archiva.redback.policy.AccountLockedException
-     *
      * @throws MustChangePasswordException
      */
     public SecuritySession authenticate( AuthenticationDataSource source )
@@ -176,6 +175,24 @@ public class DefaultSecuritySystem
         return authorizer.isAuthorized( source );
     }
 
+    public AuthorizationResult authorize( User user, String permission, String resource )
+        throws AuthorizationException
+    {
+        AuthorizationDataSource source = null;
+
+        if ( user != null )
+        {
+            source = new AuthorizationDataSource( user.getUsername(), user, permission, resource );
+        }
+
+        if ( source == null )
+        {
+            source = new AuthorizationDataSource( null, null, permission, resource );
+        }
+
+        return authorizer.isAuthorized( source );
+    }
+
     public boolean isAuthorized( SecuritySession session, String permission )
         throws AuthorizationException
     {
@@ -287,4 +304,5 @@ public class DefaultSecuritySystem
     {
         return userManager.isReadOnly();
     }
+
 }

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/f77d21b5/redback-system/src/main/java/org/apache/archiva/redback/system/SecuritySystem.java
----------------------------------------------------------------------
diff --git a/redback-system/src/main/java/org/apache/archiva/redback/system/SecuritySystem.java b/redback-system/src/main/java/org/apache/archiva/redback/system/SecuritySystem.java
index 66f775e..ad751cd 100644
--- a/redback-system/src/main/java/org/apache/archiva/redback/system/SecuritySystem.java
+++ b/redback-system/src/main/java/org/apache/archiva/redback/system/SecuritySystem.java
@@ -22,6 +22,7 @@ package org.apache.archiva.redback.system;
 import org.apache.archiva.redback.policy.AccountLockedException;
 import org.apache.archiva.redback.policy.MustChangePasswordException;
 import org.apache.archiva.redback.policy.UserSecurityPolicy;
+import org.apache.archiva.redback.users.User;
 import org.apache.archiva.redback.users.UserManagerException;
 import org.apache.archiva.redback.users.UserNotFoundException;
 import org.apache.archiva.redback.authentication.AuthenticationDataSource;
@@ -73,6 +74,9 @@ public interface SecuritySystem
     AuthorizationResult authorize( SecuritySession session, String permission, String resource )
         throws AuthorizationException;
 
+    AuthorizationResult authorize( User user, String permission, String resource )
+        throws AuthorizationException;
+
     boolean isAuthorized( SecuritySession session, String permission, String resource )
         throws AuthorizationException;
 


[4/7] archiva-redback-core git commit: fix unit test

Posted by ol...@apache.org.
fix unit test


Project: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/commit/88a2ef7a
Tree: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/tree/88a2ef7a
Diff: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/diff/88a2ef7a

Branch: refs/heads/master
Commit: 88a2ef7a1c903af4744d7d6e39ac9ff0be7ae10f
Parents: 0e1a45a
Author: Olivier Lamy <ol...@apache.org>
Authored: Fri Jan 30 22:14:42 2015 +1100
Committer: Olivier Lamy <ol...@apache.org>
Committed: Thu Feb 5 21:35:04 2015 +1100

----------------------------------------------------------------------
 .../redback/rest/services/DefaultUserService.java  |  2 +-
 .../services/interceptors/AbstractInterceptor.java | 10 ++++++++--
 .../interceptors/PermissionsInterceptor.java       | 17 +++++++++++------
 .../src/test/resources/log4j2-test.xml             |  2 +-
 4 files changed, 21 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/88a2ef7a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java
index 200eaa4..611b607 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java
@@ -80,7 +80,7 @@ public class DefaultUserService
     implements UserService
 {
 
-    private Logger log = LoggerFactory.getLogger( getClass() );
+    private final Logger log = LoggerFactory.getLogger( getClass() );
 
     private static final String VALID_USERNAME_CHARS = "[a-zA-Z_0-9\\-.@]*";
 

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/88a2ef7a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AbstractInterceptor.java
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AbstractInterceptor.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AbstractInterceptor.java
index 45b3031..5d2dd5e 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AbstractInterceptor.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AbstractInterceptor.java
@@ -19,9 +19,9 @@ package org.apache.archiva.redback.rest.services.interceptors;
  * under the License.
  */
 
+import org.apache.archiva.redback.authorization.RedbackAuthorization;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
 import org.apache.cxf.message.Message;
-import org.apache.archiva.redback.authorization.RedbackAuthorization;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -65,8 +65,14 @@ public abstract class AbstractInterceptor
 
         Method method = operationResourceInfo.getAnnotatedMethod();
 
-        log.debug( " method name {}", method == null ? "null" : method.getName() );
         RedbackAuthorization redbackAuthorization = method.getAnnotation( RedbackAuthorization.class );
+
+        log.debug( "class {}, resourceClass {}, method {}, redbackAuthorization {}", //
+                   operationResourceInfo.getClassResourceInfo().getServiceClass(), //
+                   operationResourceInfo.getClassResourceInfo().getResourceClass(), //
+                   method, //
+                   redbackAuthorization );
+
         return redbackAuthorization;
     }
 }

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/88a2ef7a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java
index 23fba4a..f2d4284 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java
@@ -66,6 +66,7 @@ public class PermissionsInterceptor
 
     public void filter( ContainerRequestContext containerRequestContext )
     {
+
         Message message = JAXRSUtils.getCurrentMessage();
 
         RedbackAuthorization redbackAuthorization = getRedbackAuthorization( message );
@@ -79,8 +80,8 @@ public class PermissionsInterceptor
             }
             String[] permissions = redbackAuthorization.permissions();
             //olamy: no value is an array with an empty String
-            if ( permissions != null && permissions.length > 0 && !( permissions.length == 1 && StringUtils.isEmpty(
-                permissions[0] ) ) )
+            if ( permissions != null && permissions.length > 0 //
+                && !( permissions.length == 1 && StringUtils.isEmpty( permissions[0] ) ) )
             {
                 HttpServletRequest request = getHttpServletRequest( message );
                 SecuritySession securitySession = httpAuthenticator.getSecuritySession( request.getSession( true ) );
@@ -90,7 +91,8 @@ public class PermissionsInterceptor
                 {
                     try
                     {
-                        authenticationResult = httpAuthenticator.getAuthenticationResult( request, getHttpServletResponse( message ) );
+                        authenticationResult =
+                            httpAuthenticator.getAuthenticationResult( request, getHttpServletResponse( message ) );
                     }
                     catch ( AuthenticationException e )
                     {
@@ -139,10 +141,11 @@ public class PermissionsInterceptor
                         catch ( AuthorizationException e )
                         {
                             log.debug( e.getMessage(), e );
-                            containerRequestContext.abortWith( Response.status( Response.Status.FORBIDDEN ).build() );
-                            return;
+
                         }
                     }
+                    containerRequestContext.abortWith( Response.status( Response.Status.FORBIDDEN ).build() );
+                    return;
 
                 }
                 else
@@ -165,10 +168,12 @@ public class PermissionsInterceptor
                 return;
             }
         }
-        log.warn( "http path {} doesn't contain any informations regarding permissions ",
+
+        log.warn( "http path {} doesn't contain any informations regarding permissions ", //
                   message.get( Message.REQUEST_URI ) );
         // here we failed to authenticate so 403 as there is no detail on karma for this
         // it must be marked as it's exposed
         containerRequestContext.abortWith( Response.status( Response.Status.FORBIDDEN ).build() );
+
     }
 }

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/88a2ef7a/redback-integrations/redback-rest/redback-rest-services/src/test/resources/log4j2-test.xml
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/test/resources/log4j2-test.xml b/redback-integrations/redback-rest/redback-rest-services/src/test/resources/log4j2-test.xml
index 33521cf..2d3ff01 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/test/resources/log4j2-test.xml
+++ b/redback-integrations/redback-rest/redback-rest-services/src/test/resources/log4j2-test.xml
@@ -21,7 +21,7 @@
 
   <appenders>
     <Console name="console" target="SYSTEM_OUT">
-      <PatternLayout pattern="%highlight{%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n}" />
+      <PatternLayout pattern="%highlight{%d{HH:mm:ss.SSS} [%L] [%t] %-5level %logger{36} - %msg%n}" />
     </Console>
   </appenders>
 


[2/7] archiva-redback-core git commit: formatting

Posted by ol...@apache.org.
formatting


Project: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/commit/8edcb36b
Tree: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/tree/8edcb36b
Diff: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/diff/8edcb36b

Branch: refs/heads/master
Commit: 8edcb36b955d650439e77de753c3acca0f151b9b
Parents: 88a2ef7
Author: Olivier Lamy <ol...@apache.org>
Authored: Thu Feb 5 21:34:46 2015 +1100
Committer: Olivier Lamy <ol...@apache.org>
Committed: Thu Feb 5 21:35:04 2015 +1100

----------------------------------------------------------------------
 .../rest/services/DefaultUserService.java       | 25 +++++++++++++-------
 .../src/test/resources/log4j2-test.xml          |  1 +
 2 files changed, 18 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/8edcb36b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java
index 611b607..6a405b7 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java
@@ -75,7 +75,7 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Set;
 
-@Service("userService#rest")
+@Service( "userService#rest" )
 public class DefaultUserService
     implements UserService
 {
@@ -89,7 +89,7 @@ public class DefaultUserService
     private SecuritySystem securitySystem;
 
     @Inject
-    @Named(value = "userConfiguration#default")
+    @Named( value = "userConfiguration#default" )
     private UserConfiguration config;
 
     @Inject
@@ -99,28 +99,28 @@ public class DefaultUserService
      * cache used for user assignments
      */
     @Inject
-    @Named(value = "cache#userAssignments")
+    @Named( value = "cache#userAssignments" )
     private Cache userAssignmentsCache;
 
     /**
      * cache used for user permissions
      */
     @Inject
-    @Named(value = "cache#userPermissions")
+    @Named( value = "cache#userPermissions" )
     private Cache userPermissionsCache;
 
     /**
      * Cache used for users
      */
     @Inject
-    @Named(value = "cache#users")
+    @Named( value = "cache#users" )
     private Cache usersCache;
 
     @Inject
     private Mailer mailer;
 
     @Inject
-    @Named(value = "rbacManager#default")
+    @Named( value = "rbacManager#default" )
     private RBACManager rbacManager;
 
     private HttpAuthenticator httpAuthenticator;
@@ -132,9 +132,9 @@ public class DefaultUserService
     private HttpServletRequest httpServletRequest;
 
     @Inject
-    public DefaultUserService( @Named(value = "userManager#default") UserManager userManager,
+    public DefaultUserService( @Named( value = "userManager#default" ) UserManager userManager,
                                SecuritySystem securitySystem,
-                               @Named("httpAuthenticator#basic") HttpAuthenticator httpAuthenticator )
+                               @Named( "httpAuthenticator#basic" ) HttpAuthenticator httpAuthenticator )
     {
         this.userManager = userManager;
         this.securitySystem = securitySystem;
@@ -306,6 +306,7 @@ public class DefaultUserService
         RedbackRequestInformation redbackRequestInformation = RedbackAuthenticationThreadLocal.get();
         if ( redbackRequestInformation == null || redbackRequestInformation.getUser() == null )
         {
+            log.warn( "RedbackRequestInformation from ThreadLocal is null" );
             throw new RedbackServiceException( new ErrorMessage( "you must be logged to update your profile" ),
                                                Response.Status.FORBIDDEN.getStatusCode() );
         }
@@ -789,6 +790,10 @@ public class DefaultUserService
         {
             userName = redbackRequestInformation.getUser().getUsername();
         }
+        else
+        {
+            log.warn( "RedbackRequestInformation from ThreadLocal is null" );
+        }
 
         return getUserPermissions( userName );
     }
@@ -802,6 +807,10 @@ public class DefaultUserService
         {
             userName = redbackRequestInformation.getUser().getUsername();
         }
+        else
+        {
+            log.warn( "RedbackRequestInformation from ThreadLocal is null" );
+        }
 
         return getUserOperations( userName );
     }

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/8edcb36b/redback-integrations/redback-rest/redback-rest-services/src/test/resources/log4j2-test.xml
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/test/resources/log4j2-test.xml b/redback-integrations/redback-rest/redback-rest-services/src/test/resources/log4j2-test.xml
index 2d3ff01..eb55d39 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/test/resources/log4j2-test.xml
+++ b/redback-integrations/redback-rest/redback-rest-services/src/test/resources/log4j2-test.xml
@@ -31,6 +31,7 @@
     <logger name="org.springframework" level="error"/>
     <logger name="org.apache.archiva.redback.components.cache" level="error"/>
     <logger name="org.apache.archiva.redback.rest.services.interceptors" level="debug"/>
+    <logger name="org.apache.archiva.redback.rest.services" level="debug"/>
     <logger name="JPOX" level="ERROR"/>
     <root level="info">
       <appender-ref ref="console"/>


[7/7] archiva-redback-core git commit: add @since

Posted by ol...@apache.org.
add @since


Project: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/commit/47cd662a
Tree: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/tree/47cd662a
Diff: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/diff/47cd662a

Branch: refs/heads/master
Commit: 47cd662af744fd4eb6e4baaf38aeacadca96e27a
Parents: f77d21b
Author: Olivier Lamy <ol...@apache.org>
Authored: Fri Feb 6 23:10:16 2015 +1100
Committer: Olivier Lamy <ol...@apache.org>
Committed: Fri Feb 6 23:10:16 2015 +1100

----------------------------------------------------------------------
 .../rest/services/interceptors/PermissionsInterceptor.java   | 7 +------
 .../org/apache/archiva/redback/system/SecuritySystem.java    | 8 ++++++++
 2 files changed, 9 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/47cd662a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java
index fc2a11f..7c35753 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java
@@ -136,12 +136,7 @@ public class PermissionsInterceptor
                                 securitySystem.authorize( authenticationResult.getUser(), permission, //
                                                           StringUtils.isBlank( redbackAuthorization.resource() ) //
                                                               ? null : redbackAuthorization.resource() );
-                            /*
-                            if ( securitySystem.isAuthorized( securitySession, permission, //
-                                                              StringUtils.isBlank( redbackAuthorization.resource() ) //
-                                                                  ? null : redbackAuthorization.resource() ) )
-                                                                  */
-                            if ( authenticationResult != null && authorizationResult.isAuthorized() )
+                             if ( authenticationResult != null && authorizationResult.isAuthorized() )
                             {
                                 log.debug( "isAuthorized for permission {}", permission );
                                 return;

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/47cd662a/redback-system/src/main/java/org/apache/archiva/redback/system/SecuritySystem.java
----------------------------------------------------------------------
diff --git a/redback-system/src/main/java/org/apache/archiva/redback/system/SecuritySystem.java b/redback-system/src/main/java/org/apache/archiva/redback/system/SecuritySystem.java
index ad751cd..270ece7 100644
--- a/redback-system/src/main/java/org/apache/archiva/redback/system/SecuritySystem.java
+++ b/redback-system/src/main/java/org/apache/archiva/redback/system/SecuritySystem.java
@@ -74,6 +74,14 @@ public interface SecuritySystem
     AuthorizationResult authorize( SecuritySession session, String permission, String resource )
         throws AuthorizationException;
 
+    /**
+     * @since 2.3
+     * @param user
+     * @param permission
+     * @param resource
+     * @return
+     * @throws AuthorizationException
+     */
     AuthorizationResult authorize( User user, String permission, String resource )
         throws AuthorizationException;
 


[5/7] archiva-redback-core git commit: make test logging working

Posted by ol...@apache.org.
make test logging working


Project: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/commit/0e1a45a7
Tree: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/tree/0e1a45a7
Diff: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/diff/0e1a45a7

Branch: refs/heads/master
Commit: 0e1a45a71650a3d872d899d7b62501ca751c0984
Parents: 8bdcfbb
Author: Olivier Lamy <ol...@apache.org>
Authored: Fri Jan 30 14:59:15 2015 +1100
Committer: Olivier Lamy <ol...@apache.org>
Committed: Thu Feb 5 21:35:04 2015 +1100

----------------------------------------------------------------------
 pom.xml                                              |  7 ++++---
 .../redback-rest/redback-rest-services/pom.xml       | 15 ++++++++++++++-
 .../services/interceptors/AbstractInterceptor.java   |  2 +-
 .../interceptors/AuthenticationInterceptor.java      |  2 +-
 .../interceptors/DebugJAXRSInInterceptor.java        |  3 ++-
 .../interceptors/PermissionsInterceptor.java         |  3 ++-
 .../interceptors/ThreadLocalUserCleaner.java         |  4 +++-
 .../rest/services/AbstractRestServicesTest.java      |  5 +++++
 .../src/test/resources/log4j2-test.xml               | 14 ++++++++------
 9 files changed, 40 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0e1a45a7/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 45a52f3..da8f481 100644
--- a/pom.xml
+++ b/pom.xml
@@ -71,7 +71,7 @@
 
   <properties>
     <springVersion>4.1.4.RELEASE</springVersion>
-    <slf4jVersion>1.7.7</slf4jVersion>
+    <slf4jVersion>1.7.10</slf4jVersion>
     <log4j2Version>2.1</log4j2Version>
 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -663,7 +663,7 @@
       <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
-        <version>4.11</version>
+        <version>4.12</version>
       </dependency>
       <dependency>
         <groupId>xmlunit</groupId>
@@ -673,7 +673,7 @@
       <dependency>
         <groupId>org.assertj</groupId>
         <artifactId>assertj-core</artifactId>
-        <version>1.6.0</version>
+        <version>1.7.1</version>
       </dependency>
     </dependencies>
   </dependencyManagement>
@@ -739,6 +739,7 @@
         <artifactId>maven-surefire-plugin</artifactId>
         <configuration>
           <argLine>-Xmx256m -Xms256m</argLine>
+          <runOrder>alphabetical</runOrder>
         </configuration>
       </plugin>
       <plugin>

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0e1a45a7/redback-integrations/redback-rest/redback-rest-services/pom.xml
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/pom.xml b/redback-integrations/redback-rest/redback-rest-services/pom.xml
index 5bd18df..d7c21cc 100644
--- a/redback-integrations/redback-rest/redback-rest-services/pom.xml
+++ b/redback-integrations/redback-rest/redback-rest-services/pom.xml
@@ -176,6 +176,19 @@
     </dependency>
 
     <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-core</artifactId>
+      <version>${log4j2Version}</version>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>jul-to-slf4j</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
       <groupId>org.hsqldb</groupId>
       <artifactId>hsqldb</artifactId>
       <scope>test</scope>
@@ -237,7 +250,7 @@
               org.apache.archiva.redback.users;version=${project.version},
               org.apache.commons.io;version="[1.4,2)",
               org.apache.commons.lang;version="[2.6,3)",
-              org.apache.cxf*;version="[3.0.3)",
+              org.apache.cxf*;version="[3.0.3,4)",
               com.fasterxml.jackson.databind;version="[2.2,3)",
               org.codehaus.plexus.util;version="[3,4)",
               org.springframework*;version="[3,4)",

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0e1a45a7/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AbstractInterceptor.java
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AbstractInterceptor.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AbstractInterceptor.java
index 040f381..45b3031 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AbstractInterceptor.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AbstractInterceptor.java
@@ -37,7 +37,7 @@ import java.lang.reflect.Method;
 public abstract class AbstractInterceptor
 {
 
-    private Logger log = LoggerFactory.getLogger( getClass() );
+    private final Logger log = LoggerFactory.getLogger( getClass() );
 
     @Context
     private HttpServletRequest httpServletRequest;

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0e1a45a7/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AuthenticationInterceptor.java
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AuthenticationInterceptor.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AuthenticationInterceptor.java
index 8489aef..ae16637 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AuthenticationInterceptor.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AuthenticationInterceptor.java
@@ -71,7 +71,7 @@ public class AuthenticationInterceptor
     @Named(value = "httpAuthenticator#basic")
     private HttpBasicAuthentication httpAuthenticator;
 
-    private Logger log = LoggerFactory.getLogger( getClass() );
+    private final Logger log = LoggerFactory.getLogger( getClass() );
 
     public void filter( ContainerRequestContext containerRequestContext )
     {

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0e1a45a7/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/DebugJAXRSInInterceptor.java
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/DebugJAXRSInInterceptor.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/DebugJAXRSInInterceptor.java
index 994db06..340d6a1 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/DebugJAXRSInInterceptor.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/DebugJAXRSInInterceptor.java
@@ -26,7 +26,8 @@ import org.apache.cxf.message.Message;
  * @author Olivier Lamy
  * @since 1.3
  */
-public class DebugJAXRSInInterceptor extends JAXRSInInterceptor
+public class DebugJAXRSInInterceptor
+    extends JAXRSInInterceptor
 {
     @Override
     public void handleMessage( Message message )

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0e1a45a7/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java
index be877db..23fba4a 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java
@@ -62,7 +62,7 @@ public class PermissionsInterceptor
     @Named( value = "httpAuthenticator#basic" )
     private HttpBasicAuthentication httpAuthenticator;
 
-    private Logger log = LoggerFactory.getLogger( getClass() );
+    private final Logger log = LoggerFactory.getLogger( getClass() );
 
     public void filter( ContainerRequestContext containerRequestContext )
     {
@@ -151,6 +151,7 @@ public class PermissionsInterceptor
                     {
                         log.debug( "user {} not authenticated", securitySession.getUser().getUsername() );
                     }
+                    return;
                 }
             }
             else

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0e1a45a7/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/ThreadLocalUserCleaner.java
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/ThreadLocalUserCleaner.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/ThreadLocalUserCleaner.java
index d938938..861ef0c 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/ThreadLocalUserCleaner.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/ThreadLocalUserCleaner.java
@@ -32,17 +32,19 @@ import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 
 import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.Provider;
 
 /**
  * @author Olivier Lamy
  * @since 1.4
  */
 @Service( "threadLocalUserCleaner#rest" )
+@Provider
 public class ThreadLocalUserCleaner
     extends AbstractPhaseInterceptor<Message>
     implements PhaseInterceptor<Message>
 {
-    private Logger log = LoggerFactory.getLogger( getClass() );
+    private final Logger log = LoggerFactory.getLogger( getClass() );
 
     public ThreadLocalUserCleaner( String phase )
     {

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0e1a45a7/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java b/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java
index b0240c5..806f322 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java
@@ -41,6 +41,7 @@ import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.slf4j.bridge.SLF4JBridgeHandler;
 import org.springframework.web.context.ContextLoaderListener;
 
 import javax.ws.rs.core.MediaType;
@@ -98,6 +99,10 @@ public abstract class AbstractRestServicesTest
         throws Exception
     {
 
+        SLF4JBridgeHandler.removeHandlersForRootLogger();
+
+        SLF4JBridgeHandler.install();
+
         tomcat = new Tomcat();
         tomcat.setBaseDir( System.getProperty( "java.io.tmpdir" ) );
         tomcat.setPort( 0 );

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0e1a45a7/redback-integrations/redback-rest/redback-rest-services/src/test/resources/log4j2-test.xml
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/test/resources/log4j2-test.xml b/redback-integrations/redback-rest/redback-rest-services/src/test/resources/log4j2-test.xml
index 8496a73..33521cf 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/test/resources/log4j2-test.xml
+++ b/redback-integrations/redback-rest/redback-rest-services/src/test/resources/log4j2-test.xml
@@ -17,24 +17,26 @@
   ~ specific language governing permissions and limitations
   ~ under the License.
   -->
+<configuration>  <!--  status="debug" -->
 
-
-<configuration status="debug">
   <appenders>
     <Console name="console" target="SYSTEM_OUT">
-      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
+      <PatternLayout pattern="%highlight{%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n}" />
     </Console>
   </appenders>
-  <loggers>
 
+  <loggers>
     <logger name="org.springframework" level="info"/>
-
     <logger name="org.apache.cxf" level="info"/>
-
+    <logger name="org.springframework" level="error"/>
+    <logger name="org.apache.archiva.redback.components.cache" level="error"/>
+    <logger name="org.apache.archiva.redback.rest.services.interceptors" level="debug"/>
+    <logger name="JPOX" level="ERROR"/>
     <root level="info">
       <appender-ref ref="console"/>
     </root>
   </loggers>
+
 </configuration>