summaryrefslogtreecommitdiffstats
path: root/redback-integrations/redback-jsecurity
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2012-04-08 15:32:07 +0000
committerOlivier Lamy <olamy@apache.org>2012-04-08 15:32:07 +0000
commit67059a5bb8b57de619d060004c84703bc5a5c569 (patch)
tree40bbbba936a636149f27ee876e161141847057a2 /redback-integrations/redback-jsecurity
parent80f7784e607297a26eb3374f40ad95af3198f12e (diff)
downloadarchiva-67059a5bb8b57de619d060004c84703bc5a5c569.tar.gz
archiva-67059a5bb8b57de619d060004c84703bc5a5c569.zip
format code
git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1311024 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'redback-integrations/redback-jsecurity')
-rw-r--r--redback-integrations/redback-jsecurity/src/main/java/org/codehaus/redback/jsecurity/PrincipalLockedException.java15
-rw-r--r--redback-integrations/redback-jsecurity/src/main/java/org/codehaus/redback/jsecurity/PrincipalPasswordChangeRequiredException.java15
-rw-r--r--redback-integrations/redback-jsecurity/src/main/java/org/codehaus/redback/jsecurity/RedbackRealm.java96
-rw-r--r--redback-integrations/redback-jsecurity/src/test/java/org/codehaus/redback/jsecurity/RedbackRealmTest.java6
4 files changed, 68 insertions, 64 deletions
diff --git a/redback-integrations/redback-jsecurity/src/main/java/org/codehaus/redback/jsecurity/PrincipalLockedException.java b/redback-integrations/redback-jsecurity/src/main/java/org/codehaus/redback/jsecurity/PrincipalLockedException.java
index 788442b4f..0fdbeb023 100644
--- a/redback-integrations/redback-jsecurity/src/main/java/org/codehaus/redback/jsecurity/PrincipalLockedException.java
+++ b/redback-integrations/redback-jsecurity/src/main/java/org/codehaus/redback/jsecurity/PrincipalLockedException.java
@@ -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 );
}
}
diff --git a/redback-integrations/redback-jsecurity/src/main/java/org/codehaus/redback/jsecurity/PrincipalPasswordChangeRequiredException.java b/redback-integrations/redback-jsecurity/src/main/java/org/codehaus/redback/jsecurity/PrincipalPasswordChangeRequiredException.java
index 8b1c0b2f3..1d2d2ff27 100644
--- a/redback-integrations/redback-jsecurity/src/main/java/org/codehaus/redback/jsecurity/PrincipalPasswordChangeRequiredException.java
+++ b/redback-integrations/redback-jsecurity/src/main/java/org/codehaus/redback/jsecurity/PrincipalPasswordChangeRequiredException.java
@@ -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 );
}
}
diff --git a/redback-integrations/redback-jsecurity/src/main/java/org/codehaus/redback/jsecurity/RedbackRealm.java b/redback-integrations/redback-jsecurity/src/main/java/org/codehaus/redback/jsecurity/RedbackRealm.java
index 5880d4305..ecf23eb33 100644
--- a/redback-integrations/redback-jsecurity/src/main/java/org/codehaus/redback/jsecurity/RedbackRealm.java
+++ b/redback-integrations/redback-jsecurity/src/main/java/org/codehaus/redback/jsecurity/RedbackRealm.java
@@ -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;
}
diff --git a/redback-integrations/redback-jsecurity/src/test/java/org/codehaus/redback/jsecurity/RedbackRealmTest.java b/redback-integrations/redback-jsecurity/src/test/java/org/codehaus/redback/jsecurity/RedbackRealmTest.java
index 8289fca23..c080c6384 100644
--- a/redback-integrations/redback-jsecurity/src/test/java/org/codehaus/redback/jsecurity/RedbackRealmTest.java
+++ b/redback-integrations/redback-jsecurity/src/test/java/org/codehaus/redback/jsecurity/RedbackRealmTest.java
@@ -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 );