]> source.dussan.org Git - archiva.git/commitdiff
format code
authorOlivier Lamy <olamy@apache.org>
Sun, 8 Apr 2012 15:32:07 +0000 (15:32 +0000)
committerOlivier Lamy <olamy@apache.org>
Sun, 8 Apr 2012 15:32:07 +0000 (15:32 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1311024 13f79535-47bb-0310-9956-ffa450edef68

redback-integrations/redback-jsecurity/src/main/java/org/codehaus/redback/jsecurity/PrincipalLockedException.java
redback-integrations/redback-jsecurity/src/main/java/org/codehaus/redback/jsecurity/PrincipalPasswordChangeRequiredException.java
redback-integrations/redback-jsecurity/src/main/java/org/codehaus/redback/jsecurity/RedbackRealm.java
redback-integrations/redback-jsecurity/src/test/java/org/codehaus/redback/jsecurity/RedbackRealmTest.java

index 788442b4f3beeca48a78f96946eddc47275dc55b..0fdbeb023b033366f7ffc2ebec183519ae1a86f2 100644 (file)
@@ -21,20 +21,21 @@ package org.codehaus.redback.jsecurity;
 
 import org.jsecurity.authc.AuthenticationException;
 
-public class PrincipalLockedException extends AuthenticationException
+public class PrincipalLockedException
+    extends AuthenticationException
 {
-    public PrincipalLockedException(String message, Throwable cause)
+    public PrincipalLockedException( String message, Throwable cause )
     {
-        super(message, cause);
+        super( message, cause );
     }
 
-    public PrincipalLockedException(String message)
+    public PrincipalLockedException( String message )
     {
-        super(message);
+        super( message );
     }
 
-    public PrincipalLockedException(Throwable cause)
+    public PrincipalLockedException( Throwable cause )
     {
-         super(cause);
+        super( cause );
     }
 }
index 8b1c0b2f32db990a9f3dcb058d45e7fe57847aae..1d2d2ff27733b497a8e6921921c270a7624df94e 100644 (file)
@@ -21,20 +21,21 @@ package org.codehaus.redback.jsecurity;
 
 import org.jsecurity.authc.AuthenticationException;
 
-public class PrincipalPasswordChangeRequiredException extends AuthenticationException
+public class PrincipalPasswordChangeRequiredException
+    extends AuthenticationException
 {
-    public PrincipalPasswordChangeRequiredException(String message, Throwable cause)
+    public PrincipalPasswordChangeRequiredException( String message, Throwable cause )
     {
-        super(message, cause);
+        super( message, cause );
     }
 
-    public PrincipalPasswordChangeRequiredException(String message)
+    public PrincipalPasswordChangeRequiredException( String message )
     {
-        super(message);
+        super( message );
     }
 
-    public PrincipalPasswordChangeRequiredException(Throwable cause)
+    public PrincipalPasswordChangeRequiredException( Throwable cause )
     {
-         super(cause);
+        super( cause );
     }
 }
index 5880d4305d8bfaf3412d9966d26ee03b103e3139..ecf23eb332cb23a1aa55d87a20a9cbf9bee42d34 100644 (file)
@@ -19,19 +19,15 @@ package org.codehaus.redback.jsecurity;
  * under the License.
  */
 
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
 import org.apache.archiva.redback.policy.AccountLockedException;
 import org.apache.archiva.redback.policy.UserSecurityPolicy;
 import org.apache.archiva.redback.rbac.Permission;
-import org.apache.archiva.redback.rbac.UserAssignment;
-import org.apache.archiva.redback.users.User;
-import org.apache.archiva.redback.users.UserNotFoundException;
 import org.apache.archiva.redback.rbac.RBACManager;
 import org.apache.archiva.redback.rbac.RbacManagerException;
+import org.apache.archiva.redback.rbac.UserAssignment;
+import org.apache.archiva.redback.users.User;
 import org.apache.archiva.redback.users.UserManager;
+import org.apache.archiva.redback.users.UserNotFoundException;
 import org.jsecurity.authc.AuthenticationException;
 import org.jsecurity.authc.AuthenticationInfo;
 import org.jsecurity.authc.AuthenticationToken;
@@ -45,9 +41,14 @@ import org.jsecurity.subject.PrincipalCollection;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class RedbackRealm extends AuthorizingRealm
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+public class RedbackRealm
+    extends AuthorizingRealm
 {
-    private Logger log = LoggerFactory.getLogger(RedbackRealm.class);
+    private Logger log = LoggerFactory.getLogger( RedbackRealm.class );
 
     private final UserManager userManager;
 
@@ -55,80 +56,81 @@ public class RedbackRealm extends AuthorizingRealm
 
     private final UserSecurityPolicy securityPolicy;
 
-    public RedbackRealm(UserManager userManager, RBACManager rbacManager, UserSecurityPolicy securityPolicy)
+    public RedbackRealm( UserManager userManager, RBACManager rbacManager, UserSecurityPolicy securityPolicy )
     {
         this.userManager = userManager;
         this.rbacManager = rbacManager;
         this.securityPolicy = securityPolicy;
     }
-    
+
     @Override
-    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals)
+    protected AuthorizationInfo doGetAuthorizationInfo( PrincipalCollection principals )
     {
-        final String username = (String) principals.fromRealm(getName()).iterator().next();
+        final String username = (String) principals.fromRealm( getName() ).iterator().next();
 
         try
         {
-            final UserAssignment assignment = rbacManager.getUserAssignment(username);
-            final Set<String> roleNames = new HashSet<String>(assignment.getRoleNames());
+            final UserAssignment assignment = rbacManager.getUserAssignment( username );
+            final Set<String> roleNames = new HashSet<String>( assignment.getRoleNames() );
             final Set<String> permissions = new HashSet<String>();
 
-            for (Iterator<Permission> it = rbacManager.getAssignedPermissions(username).iterator(); it.hasNext();)
+            for ( Iterator<Permission> it = rbacManager.getAssignedPermissions( username ).iterator(); it.hasNext(); )
             {
                 Permission permission = it.next();
-                permissions.add(permission.getName());
+                permissions.add( permission.getName() );
             }
 
-            SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo(roleNames);
-            authorizationInfo.setStringPermissions(permissions);
+            SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo( roleNames );
+            authorizationInfo.setStringPermissions( permissions );
 
             return authorizationInfo;
         }
-        catch (RbacManagerException e)
+        catch ( RbacManagerException e )
         {
-            log.error("Could not authenticate against data source", e);
+            log.error( "Could not authenticate against data source", e );
         }
-        
+
         return null;
     }
 
     @Override
-    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
+    protected AuthenticationInfo doGetAuthenticationInfo( AuthenticationToken token )
         throws AuthenticationException
     {
-        if (token == null)
+        if ( token == null )
         {
-            throw new AuthenticationException("AuthenticationToken cannot be null");
+            throw new AuthenticationException( "AuthenticationToken cannot be null" );
         }
-        
-        final UsernamePasswordToken passwordToken = (UsernamePasswordToken)token;
+
+        final UsernamePasswordToken passwordToken = (UsernamePasswordToken) token;
 
         User user = null;
         try
         {
-            user = userManager.findUser(passwordToken.getUsername());
+            user = userManager.findUser( passwordToken.getUsername() );
         }
-        catch (UserNotFoundException e)
+        catch ( UserNotFoundException e )
         {
-            log.error("Could not find user " + passwordToken.getUsername());
+            log.error( "Could not find user " + passwordToken.getUsername() );
         }
 
-        if (user == null)
+        if ( user == null )
         {
             return null;
         }
 
         if ( user.isLocked() && !user.isPasswordChangeRequired() )
         {
-            throw new PrincipalLockedException("User " + user.getPrincipal() + " is locked.");
+            throw new PrincipalLockedException( "User " + user.getPrincipal() + " is locked." );
         }
 
         if ( user.isPasswordChangeRequired() )
         {
-            throw new PrincipalPasswordChangeRequiredException("Password change is required for user " + user.getPrincipal());
+            throw new PrincipalPasswordChangeRequiredException(
+                "Password change is required for user " + user.getPrincipal() );
         }
 
-        return new RedbackAuthenticationInfo(user, getName());
+        return new RedbackAuthenticationInfo( user, getName() );
     }
 
     @Override
@@ -136,20 +138,21 @@ public class RedbackRealm extends AuthorizingRealm
     {
         return new CredentialsMatcher()
         {
-            public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info)
+            public boolean doCredentialsMatch( AuthenticationToken token, AuthenticationInfo info )
             {
-                final String credentials = new String((char[])token.getCredentials());
-                final boolean match = securityPolicy.getPasswordEncoder().encodePassword(credentials).equals((String)info.getCredentials());
-                if (!match)
+                final String credentials = new String( (char[]) token.getCredentials() );
+                final boolean match = securityPolicy.getPasswordEncoder().encodePassword( credentials ).equals(
+                    (String) info.getCredentials() );
+                if ( !match )
                 {
-                    User user = ((RedbackAuthenticationInfo)info).getUser();
+                    User user = ( (RedbackAuthenticationInfo) info ).getUser();
                     try
                     {
                         securityPolicy.extensionExcessiveLoginAttempts( user );
                     }
-                    catch (AccountLockedException e)
+                    catch ( AccountLockedException e )
                     {
-                        log.info("User{} has been locked", user.getUsername(), e);
+                        log.info( "User{} has been locked", user.getUsername(), e );
                     }
                     finally
                     {
@@ -157,9 +160,9 @@ public class RedbackRealm extends AuthorizingRealm
                         {
                             userManager.updateUser( user );
                         }
-                        catch (UserNotFoundException e)
+                        catch ( UserNotFoundException e )
                         {
-                            log.error("The user to be updated could not be found", e);
+                            log.error( "The user to be updated could not be found", e );
                         }
                     }
                 }
@@ -168,13 +171,14 @@ public class RedbackRealm extends AuthorizingRealm
         };
     }
 
-    final class RedbackAuthenticationInfo extends SimpleAuthenticationInfo
+    final class RedbackAuthenticationInfo
+        extends SimpleAuthenticationInfo
     {
         private final User user;
 
-        public RedbackAuthenticationInfo(User user, String realmName)
+        public RedbackAuthenticationInfo( User user, String realmName )
         {
-            super(user.getPrincipal(), user.getEncodedPassword(), realmName);
+            super( user.getPrincipal(), user.getEncodedPassword(), realmName );
             this.user = user;
         }
 
index 8289fca23f27641eaf98431a0dd6f85be302a3e2..c080c6384c759955f431bdde1d11956469e1856c 100644 (file)
@@ -21,13 +21,13 @@ package org.codehaus.redback.jsecurity;
 
 import junit.framework.TestCase;
 import org.apache.archiva.redback.policy.UserSecurityPolicy;
-import org.apache.archiva.redback.rbac.Role;
-import org.apache.archiva.redback.users.User;
 import org.apache.archiva.redback.rbac.Operation;
 import org.apache.archiva.redback.rbac.Permission;
 import org.apache.archiva.redback.rbac.RBACManager;
 import org.apache.archiva.redback.rbac.Resource;
+import org.apache.archiva.redback.rbac.Role;
 import org.apache.archiva.redback.rbac.UserAssignment;
+import org.apache.archiva.redback.users.User;
 import org.apache.archiva.redback.users.UserManager;
 import org.jsecurity.authc.IncorrectCredentialsException;
 import org.jsecurity.authc.UsernamePasswordToken;
@@ -75,8 +75,6 @@ public class RedbackRealmTest
         super.setUp();
         securityManager = new DefaultSecurityManager();
 
-
-
         realm = new RedbackRealm( userManager, rbacManager, userSecurityPolicy );
         securityManager.setRealm( realm );