Browse Source

SEC-97: Format Acegi Security source code in accordance with latest Jalopy configuration.

Ben Alex 19 years ago
parent
commit
ab12817b7a
100 changed files with 2581 additions and 3402 deletions
  1. 22 36
      adapters/cas/src/main/java/org/acegisecurity/adapters/cas/CasPasswordHandler.java
  2. 26 55
      adapters/cas/src/main/java/org/acegisecurity/adapters/cas/CasPasswordHandlerProxy.java
  3. 58 68
      adapters/cas/src/main/java/org/acegisecurity/adapters/cas3/CasAuthenticationHandler.java
  4. 13 18
      adapters/cas/src/test/java/org/acegisecurity/adapters/cas/CasPasswordHandlerProxyTests.java
  5. 13 19
      adapters/cas/src/test/java/org/acegisecurity/adapters/cas/CasPasswordHandlerTests.java
  6. 82 62
      adapters/cas/src/test/java/org/acegisecurity/adapters/cas3/CasAuthenticationHandlerTests.java
  7. 60 75
      adapters/catalina/src/main/java/org/acegisecurity/adapters/catalina/CatalinaAcegiUserRealm.java
  8. 47 67
      adapters/catalina/src/test/java/org/acegisecurity/adapters/catalina/CatalinaAcegiUserRealmTests.java
  9. 26 51
      adapters/jboss/src/main/java/org/acegisecurity/adapters/jboss/JbossAcegiLoginModule.java
  10. 33 44
      adapters/jboss/src/main/java/org/acegisecurity/adapters/jboss/JbossIntegrationFilter.java
  11. 28 47
      adapters/jboss/src/test/java/org/acegisecurity/adapters/jboss/JbossAcegiLoginModuleTests.java
  12. 38 45
      adapters/jboss/src/test/java/org/acegisecurity/adapters/jboss/JbossIntegrationFilterTests.java
  13. 21 21
      adapters/jboss/src/test/java/org/acegisecurity/adapters/jboss/MockInitialContext.java
  14. 6 6
      adapters/jboss/src/test/java/org/acegisecurity/adapters/jboss/MockJbossIntegrationFilter.java
  15. 30 42
      adapters/jetty/src/main/java/org/acegisecurity/adapters/jetty/JettyAcegiUserRealm.java
  16. 7 8
      adapters/jetty/src/main/java/org/acegisecurity/adapters/jetty/JettyAcegiUserToken.java
  17. 26 34
      adapters/jetty/src/test/java/org/acegisecurity/adapters/jetty/JettyAcegiUserRealmTests.java
  18. 9 11
      adapters/jetty/src/test/java/org/acegisecurity/adapters/jetty/JettyAcegiUserTokenTests.java
  19. 36 49
      adapters/resin/src/main/java/org/acegisecurity/adapters/resin/ResinAcegiAuthenticator.java
  20. 33 56
      adapters/resin/src/test/java/org/acegisecurity/adapters/resin/ResinAcegiAuthenticatorTests.java
  21. 2 4
      core-tiger/src/main/java/org/acegisecurity/annotation/Secured.java
  22. 92 98
      core-tiger/src/main/java/org/acegisecurity/annotation/SecurityAnnotationAttributes.java
  23. 4 4
      core-tiger/src/test/java/org/acegisecurity/Entity.java
  24. 8 8
      core-tiger/src/test/java/org/acegisecurity/Organisation.java
  25. 24 1
      core-tiger/src/test/java/org/acegisecurity/OrganisationService.java
  26. 25 4
      core-tiger/src/test/java/org/acegisecurity/OrganisationServiceImpl.java
  27. 8 8
      core-tiger/src/test/java/org/acegisecurity/Person.java
  28. 24 1
      core-tiger/src/test/java/org/acegisecurity/PersonService.java
  29. 25 4
      core-tiger/src/test/java/org/acegisecurity/PersonServiceImpl.java
  30. 2 2
      core-tiger/src/test/java/org/acegisecurity/Service.java
  31. 37 13
      core-tiger/src/test/java/org/acegisecurity/ServiceImpl.java
  32. 34 13
      core-tiger/src/test/java/org/acegisecurity/annotation/BusinessService.java
  33. 61 68
      core-tiger/src/test/java/org/acegisecurity/annotation/SecurityAnnotationAttributesTests.java
  34. 34 46
      core-tiger/src/test/java/org/acegisecurity/intercept/method/MethodDefinitionSourceEditorTigerTests.java
  35. 18 32
      core/src/main/java/org/acegisecurity/AbstractAuthenticationManager.java
  36. 19 29
      core/src/main/java/org/acegisecurity/AccessDecisionManager.java
  37. 5 6
      core/src/main/java/org/acegisecurity/AccessDeniedException.java
  38. 6 7
      core/src/main/java/org/acegisecurity/AccountExpiredException.java
  39. 6 11
      core/src/main/java/org/acegisecurity/AcegiMessageSource.java
  40. 6 11
      core/src/main/java/org/acegisecurity/AcegiSecurityException.java
  41. 22 36
      core/src/main/java/org/acegisecurity/AfterInvocationManager.java
  42. 44 74
      core/src/main/java/org/acegisecurity/Authentication.java
  43. 7 8
      core/src/main/java/org/acegisecurity/AuthenticationCredentialsNotFoundException.java
  44. 9 12
      core/src/main/java/org/acegisecurity/AuthenticationException.java
  45. 14 34
      core/src/main/java/org/acegisecurity/AuthenticationManager.java
  46. 6 10
      core/src/main/java/org/acegisecurity/AuthenticationServiceException.java
  47. 20 30
      core/src/main/java/org/acegisecurity/AuthenticationTrustResolver.java
  48. 20 28
      core/src/main/java/org/acegisecurity/AuthenticationTrustResolverImpl.java
  49. 6 11
      core/src/main/java/org/acegisecurity/AuthorizationServiceException.java
  50. 9 11
      core/src/main/java/org/acegisecurity/BadCredentialsException.java
  51. 11 20
      core/src/main/java/org/acegisecurity/ConfigAttribute.java
  52. 25 36
      core/src/main/java/org/acegisecurity/ConfigAttributeDefinition.java
  53. 6 11
      core/src/main/java/org/acegisecurity/ConfigAttributeEditor.java
  54. 6 7
      core/src/main/java/org/acegisecurity/CredentialsExpiredException.java
  55. 6 7
      core/src/main/java/org/acegisecurity/DisabledException.java
  56. 11 19
      core/src/main/java/org/acegisecurity/GrantedAuthority.java
  57. 5 9
      core/src/main/java/org/acegisecurity/GrantedAuthorityImpl.java
  58. 9 16
      core/src/main/java/org/acegisecurity/InsufficientAuthenticationException.java
  59. 6 6
      core/src/main/java/org/acegisecurity/LockedException.java
  60. 6 8
      core/src/main/java/org/acegisecurity/MockAuthenticationManager.java
  61. 17 27
      core/src/main/java/org/acegisecurity/RunAsManager.java
  62. 8 8
      core/src/main/java/org/acegisecurity/SecurityConfig.java
  63. 2 1
      core/src/main/java/org/acegisecurity/acl/AclEntry.java
  64. 11 18
      core/src/main/java/org/acegisecurity/acl/AclManager.java
  65. 19 34
      core/src/main/java/org/acegisecurity/acl/AclProvider.java
  66. 28 39
      core/src/main/java/org/acegisecurity/acl/AclProviderManager.java
  67. 108 138
      core/src/main/java/org/acegisecurity/acl/basic/AbstractBasicAclEntry.java
  68. 5 8
      core/src/main/java/org/acegisecurity/acl/basic/AclObjectIdentity.java
  69. 3 4
      core/src/main/java/org/acegisecurity/acl/basic/AclObjectIdentityAware.java
  70. 9 15
      core/src/main/java/org/acegisecurity/acl/basic/BasicAclDao.java
  71. 53 72
      core/src/main/java/org/acegisecurity/acl/basic/BasicAclEntry.java
  72. 9 17
      core/src/main/java/org/acegisecurity/acl/basic/BasicAclEntryCache.java
  73. 39 31
      core/src/main/java/org/acegisecurity/acl/basic/BasicAclExtendedDao.java
  74. 146 212
      core/src/main/java/org/acegisecurity/acl/basic/BasicAclProvider.java
  75. 8 12
      core/src/main/java/org/acegisecurity/acl/basic/EffectiveAclsResolver.java
  76. 26 49
      core/src/main/java/org/acegisecurity/acl/basic/GrantedAuthorityEffectiveAclsResolver.java
  77. 13 25
      core/src/main/java/org/acegisecurity/acl/basic/NamedEntityObjectIdentity.java
  78. 11 10
      core/src/main/java/org/acegisecurity/acl/basic/SimpleAclEntry.java
  79. 11 19
      core/src/main/java/org/acegisecurity/acl/basic/cache/BasicAclEntryHolder.java
  80. 8 13
      core/src/main/java/org/acegisecurity/acl/basic/cache/EhCacheBasedAclEntryCache.java
  81. 5 11
      core/src/main/java/org/acegisecurity/acl/basic/cache/NullAclEntryCache.java
  82. 66 136
      core/src/main/java/org/acegisecurity/acl/basic/jdbc/JdbcDaoImpl.java
  83. 51 96
      core/src/main/java/org/acegisecurity/acl/basic/jdbc/JdbcExtendedDaoImpl.java
  84. 35 43
      core/src/main/java/org/acegisecurity/adapters/AbstractAdapterAuthenticationToken.java
  85. 5 6
      core/src/main/java/org/acegisecurity/adapters/AuthByAdapter.java
  86. 11 22
      core/src/main/java/org/acegisecurity/adapters/AuthByAdapterProvider.java
  87. 16 31
      core/src/main/java/org/acegisecurity/adapters/HttpRequestIntegrationFilter.java
  88. 8 10
      core/src/main/java/org/acegisecurity/adapters/PrincipalAcegiUserToken.java
  89. 14 22
      core/src/main/java/org/acegisecurity/afterinvocation/AfterInvocationProvider.java
  90. 47 71
      core/src/main/java/org/acegisecurity/afterinvocation/AfterInvocationProviderManager.java
  91. 93 133
      core/src/main/java/org/acegisecurity/afterinvocation/BasicAclEntryAfterInvocationCollectionFilteringProvider.java
  92. 50 85
      core/src/main/java/org/acegisecurity/afterinvocation/BasicAclEntryAfterInvocationProvider.java
  93. 8 12
      core/src/main/java/org/acegisecurity/captcha/AlwaysTestAfterMaxRequestsCaptchaChannelProcessor.java
  94. 12 17
      core/src/main/java/org/acegisecurity/captcha/AlwaysTestAfterTimeInMillisCaptchaChannelProcessor.java
  95. 12 18
      core/src/main/java/org/acegisecurity/captcha/AlwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor.java
  96. 56 67
      core/src/main/java/org/acegisecurity/captcha/CaptchaChannelProcessorTemplate.java
  97. 191 229
      core/src/main/java/org/acegisecurity/captcha/CaptchaEntryPoint.java
  98. 14 16
      core/src/main/java/org/acegisecurity/captcha/CaptchaSecurityContext.java
  99. 48 42
      core/src/main/java/org/acegisecurity/captcha/CaptchaSecurityContextImpl.java
  100. 3 6
      core/src/main/java/org/acegisecurity/captcha/CaptchaServiceProxy.java

+ 22 - 36
adapters/cas/src/main/java/org/acegisecurity/adapters/cas/CasPasswordHandler.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package org.acegisecurity.adapters.cas;
 import org.acegisecurity.Authentication;
 import org.acegisecurity.Authentication;
 import org.acegisecurity.AuthenticationException;
 import org.acegisecurity.AuthenticationException;
 import org.acegisecurity.AuthenticationManager;
 import org.acegisecurity.AuthenticationManager;
+
 import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
 import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
 
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.Log;
@@ -29,51 +30,32 @@ import javax.servlet.ServletRequest;
 
 
 
 
 /**
 /**
- * Provides actual CAS authentication by delegation to an
- * <code>AuthenticationManager</code>.
- * 
- * <P>
- * Do not use this class directly. Instead configure CAS to use the {@link
- * CasPasswordHandlerProxy}.
- * </p>
+ * Provides actual CAS authentication by delegation to an <code>AuthenticationManager</code>.<P>Do not use this
+ * class directly. Instead configure CAS to use the {@link CasPasswordHandlerProxy}.</p>
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public final class CasPasswordHandler implements InitializingBean {
 public final class CasPasswordHandler implements InitializingBean {
-    //~ Static fields/initializers =============================================
+    //~ Static fields/initializers =====================================================================================
 
 
     private static final Log logger = LogFactory.getLog(CasPasswordHandler.class);
     private static final Log logger = LogFactory.getLog(CasPasswordHandler.class);
 
 
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private AuthenticationManager authenticationManager;
     private AuthenticationManager authenticationManager;
 
 
-    //~ Methods ================================================================
-
-    public void setAuthenticationManager(
-        AuthenticationManager authenticationManager) {
-        this.authenticationManager = authenticationManager;
-    }
-
-    public AuthenticationManager getAuthenticationManager() {
-        return authenticationManager;
-    }
+    //~ Methods ========================================================================================================
 
 
     public void afterPropertiesSet() throws Exception {
     public void afterPropertiesSet() throws Exception {
         if (this.authenticationManager == null) {
         if (this.authenticationManager == null) {
-            throw new IllegalArgumentException(
-                "An AuthenticationManager is required");
+            throw new IllegalArgumentException("An AuthenticationManager is required");
         }
         }
     }
     }
 
 
     /**
     /**
-     * Called by <code>CasPasswordHandlerProxy</code> for individual
-     * authentication requests.
-     * 
-     * <P>
-     * Delegates to the configured <code>AuthenticationManager</code>.
-     * </p>
+     * Called by <code>CasPasswordHandlerProxy</code> for individual authentication requests.<P>Delegates to
+     * the configured <code>AuthenticationManager</code>.</p>
      *
      *
      * @param servletRequest as provided by CAS
      * @param servletRequest as provided by CAS
      * @param username provided to CAS
      * @param username provided to CAS
@@ -81,8 +63,7 @@ public final class CasPasswordHandler implements InitializingBean {
      *
      *
      * @return whether authentication was successful or not
      * @return whether authentication was successful or not
      */
      */
-    public boolean authenticate(ServletRequest servletRequest, String username,
-        String password) {
+    public boolean authenticate(ServletRequest servletRequest, String username, String password) {
         if ((username == null) || "".equals(username)) {
         if ((username == null) || "".equals(username)) {
             return false;
             return false;
         }
         }
@@ -91,26 +72,31 @@ public final class CasPasswordHandler implements InitializingBean {
             password = "";
             password = "";
         }
         }
 
 
-        Authentication request = new UsernamePasswordAuthenticationToken(username
-                .toString(), password.toString());
+        Authentication request = new UsernamePasswordAuthenticationToken(username.toString(), password.toString());
         Authentication response = null;
         Authentication response = null;
 
 
         try {
         try {
             response = authenticationManager.authenticate(request);
             response = authenticationManager.authenticate(request);
         } catch (AuthenticationException failed) {
         } catch (AuthenticationException failed) {
             if (logger.isDebugEnabled()) {
             if (logger.isDebugEnabled()) {
-                logger.debug("Authentication request for user: " + username
-                    + " failed: " + failed.toString());
+                logger.debug("Authentication request for user: " + username + " failed: " + failed.toString());
             }
             }
 
 
             return false;
             return false;
         }
         }
 
 
         if (logger.isDebugEnabled()) {
         if (logger.isDebugEnabled()) {
-            logger.debug("Authentication request for user: " + username
-                + " successful");
+            logger.debug("Authentication request for user: " + username + " successful");
         }
         }
 
 
         return true;
         return true;
     }
     }
+
+    public AuthenticationManager getAuthenticationManager() {
+        return authenticationManager;
+    }
+
+    public void setAuthenticationManager(AuthenticationManager authenticationManager) {
+        this.authenticationManager = authenticationManager;
+    }
 }
 }

+ 26 - 55
adapters/cas/src/main/java/org/acegisecurity/adapters/cas/CasPasswordHandlerProxy.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -31,62 +31,39 @@ import javax.servlet.http.HttpServletRequest;
 
 
 
 
 /**
 /**
- * Enables CAS to use the Acegi Security System for authentication.
- * 
- * <P>
- * This class works along with {@link CasPasswordHandler} to enable users to
- * easily migrate from stand-alone Acegi Security System deployments to
- * enterprise-wide CAS deployments.
- * </p>
- * 
- * <p>
- * It should be noted that the Acegi Security System will operate as a CAS
- * client irrespective of the <code>PasswordHandler</code> used on the CAS
- * server. In other words, this class need <B>not</B> be used on the CAS
- * server if not desired. It exists solely for the convenience of users
- * wishing have CAS delegate to an Acegi Security System-based
- * <code>AuthenticationManager</code>.
- * </p>
- * 
- * <p>
- * This class works requires a properly configured
- * <code>CasPasswordHandler</code>. On the first authentication request, the
- * class will use Spring's {@link
- * WebApplicationContextUtils#getWebApplicationContext(ServletContext sc)}
- * method to obtain an <code>ApplicationContext</code> instance, inside which
- * must be a configured <code>CasPasswordHandler</code> instance. The
- * <code>CasPasswordHandlerProxy</code> will then delegate authentication
- * requests to that instance.
- * </p>
- * 
- * <p>
- * To configure CAS to use this class, edit CAS' <code>web.xml</code> and
- * define the <code>edu.yale.its.tp.cas.authHandler</code> context parameter
- * with the value
- * <code>org.acegisecurity.adapters.cas.CasPasswordHandlerProxy</code>.
- * </p>
+ * Enables CAS to use the Acegi Security System for authentication.<P>This class works along with {@link
+ * CasPasswordHandler} to enable users to easily migrate from stand-alone Acegi Security System deployments to
+ * enterprise-wide CAS deployments.</p>
+ *  <p>It should be noted that the Acegi Security System will operate as a CAS client irrespective of the
+ * <code>PasswordHandler</code> used on the CAS server. In other words, this class need <B>not</B> be used on the CAS
+ * server if not desired. It exists solely for the convenience of users wishing have CAS delegate to an Acegi Security
+ * System-based <code>AuthenticationManager</code>.</p>
+ *  <p>This class works requires a properly configured <code>CasPasswordHandler</code>. On the first authentication
+ * request, the class will use Spring's {@link WebApplicationContextUtils#getWebApplicationContext(ServletContext sc)}
+ * method to obtain an <code>ApplicationContext</code> instance, inside which must be a configured
+ * <code>CasPasswordHandler</code> instance. The <code>CasPasswordHandlerProxy</code> will then delegate
+ * authentication requests to that instance.</p>
+ *  <p>To configure CAS to use this class, edit CAS' <code>web.xml</code> and define the
+ * <code>edu.yale.its.tp.cas.authHandler</code> context parameter with the value
+ * <code>org.acegisecurity.adapters.cas.CasPasswordHandlerProxy</code>.</p>
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public class CasPasswordHandlerProxy implements PasswordHandler {
 public class CasPasswordHandlerProxy implements PasswordHandler {
-    //~ Static fields/initializers =============================================
+    //~ Static fields/initializers =====================================================================================
 
 
     private static final Log logger = LogFactory.getLog(CasPasswordHandlerProxy.class);
     private static final Log logger = LogFactory.getLog(CasPasswordHandlerProxy.class);
 
 
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private ApplicationContext ctx;
     private ApplicationContext ctx;
     private CasPasswordHandler handler;
     private CasPasswordHandler handler;
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
-     * Called by CAS when authentication is required.
-     * 
-     * <P>
-     * Delegates to the <code>CasPasswordHandler</code>.
-     * </p>
+     * Called by CAS when authentication is required.<P>Delegates to the <code>CasPasswordHandler</code>.</p>
      *
      *
      * @param request as provided by CAS
      * @param request as provided by CAS
      * @param username provided to CAS
      * @param username provided to CAS
@@ -94,17 +71,13 @@ public class CasPasswordHandlerProxy implements PasswordHandler {
      *
      *
      * @return whether authentication was successful or not
      * @return whether authentication was successful or not
      *
      *
-     * @throws IllegalArgumentException if the application context does not
-     *         contain a <code>CasPasswordHandler</code> or the
-     *         <code>ServletRequest</code> was not of type
-     *         <code>HttpServletRequest</code>
+     * @throws IllegalArgumentException if the application context does not contain a <code>CasPasswordHandler</code>
+     *         or the <code>ServletRequest</code> was not of type <code>HttpServletRequest</code>
      */
      */
-    public boolean authenticate(ServletRequest request, String username,
-        String password) {
+    public boolean authenticate(ServletRequest request, String username, String password) {
         if (ctx == null) {
         if (ctx == null) {
             if (!(request instanceof HttpServletRequest)) {
             if (!(request instanceof HttpServletRequest)) {
-                throw new IllegalArgumentException(
-                    "Can only process HttpServletRequest");
+                throw new IllegalArgumentException("Can only process HttpServletRequest");
             }
             }
 
 
             HttpServletRequest httpRequest = (HttpServletRequest) request;
             HttpServletRequest httpRequest = (HttpServletRequest) request;
@@ -130,13 +103,11 @@ public class CasPasswordHandlerProxy implements PasswordHandler {
     /**
     /**
      * Allows test cases to override where application context obtained from.
      * Allows test cases to override where application context obtained from.
      *
      *
-     * @param httpRequest which can be used to find the
-     *        <code>ServletContext</code>
+     * @param httpRequest which can be used to find the <code>ServletContext</code>
      *
      *
      * @return the Spring application context
      * @return the Spring application context
      */
      */
     protected ApplicationContext getContext(HttpServletRequest httpRequest) {
     protected ApplicationContext getContext(HttpServletRequest httpRequest) {
-        return WebApplicationContextUtils.getRequiredWebApplicationContext(httpRequest.getSession()
-                                                                                      .getServletContext());
+        return WebApplicationContextUtils.getRequiredWebApplicationContext(httpRequest.getSession().getServletContext());
     }
     }
 }
 }

+ 58 - 68
adapters/cas/src/main/java/org/acegisecurity/adapters/cas3/CasAuthenticationHandler.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -12,90 +12,80 @@
  * See the License for the specific language governing permissions and
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * limitations under the License.
  */
  */
+
 package org.acegisecurity.adapters.cas3;
 package org.acegisecurity.adapters.cas3;
 
 
 import org.acegisecurity.Authentication;
 import org.acegisecurity.Authentication;
 import org.acegisecurity.AuthenticationManager;
 import org.acegisecurity.AuthenticationManager;
+
 import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
 import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.logging.LogFactory;
+
 import org.jasig.cas.authentication.handler.AuthenticationException;
 import org.jasig.cas.authentication.handler.AuthenticationException;
 import org.jasig.cas.authentication.handler.AuthenticationHandler;
 import org.jasig.cas.authentication.handler.AuthenticationHandler;
 import org.jasig.cas.authentication.handler.support.AbstractUsernamePasswordAuthenticationHandler;
 import org.jasig.cas.authentication.handler.support.AbstractUsernamePasswordAuthenticationHandler;
 import org.jasig.cas.authentication.principal.UsernamePasswordCredentials;
 import org.jasig.cas.authentication.principal.UsernamePasswordCredentials;
+
 import org.springframework.util.Assert;
 import org.springframework.util.Assert;
 
 
+
 /**
 /**
- * <p>
- * Provides JA-SIG CAS 3 authentication by delegating to the Acegi
- * <code>AuthenticationManager</code>.
- * </p>
- * <p>
- * This class would be configured in the
- * <code>webapp/WEB-INF/deployerConfigContext.xml</code> file in the CAS
- * distribution.
- * </p>
- * 
+ * <p>Provides JA-SIG CAS 3 authentication by delegating to the Acegi <code>AuthenticationManager</code>.</p>
+ *  <p>This class would be configured in the <code>webapp/WEB-INF/deployerConfigContext.xml</code> file in the CAS
+ * distribution.</p>
+ *
  * @author Scott Battaglia
  * @author Scott Battaglia
  * @version $Id$
  * @version $Id$
- * 
+ *
  * @see AuthenticationHandler
  * @see AuthenticationHandler
  * @see AuthenticationManager
  * @see AuthenticationManager
  */
  */
-public final class CasAuthenticationHandler extends
-		AbstractUsernamePasswordAuthenticationHandler {
-
-	private Log log = LogFactory.getLog(this.getClass());
-
-	private AuthenticationManager authenticationManager;
-
-	protected boolean authenticateUsernamePasswordInternal(
-			final UsernamePasswordCredentials credentials)
-			throws AuthenticationException {
-
-		final Authentication authenticationRequest = new UsernamePasswordAuthenticationToken(
-				credentials.getUsername(), credentials.getPassword());
-
-		if (log.isDebugEnabled()) {
-			log.debug("Attempting to authenticate for user: "
-					+ credentials.getUsername());
-		}
-
-		try {
-			this.authenticationManager.authenticate(authenticationRequest);
-		} catch (final org.acegisecurity.AuthenticationException e) {
-			if (log.isDebugEnabled()) {
-				log
-						.debug("Authentication request for "
-								+ credentials.getUsername() + "failed: "
-								+ e.toString());
-			}
-			return false;
-		}
-
-		if (log.isDebugEnabled()) {
-			log.debug("Authentication request for " + credentials.getUsername()
-					+ " successful.");
-		}
-
-		return true;
-	}
-
-	protected void afterPropertiesSetInternal() throws Exception {
-		Assert.notNull(this.authenticationManager,
-				"authenticationManager cannot be null.");
-	}
-
-	/**
-	 * Method to set the Acegi <code>AuthenticationManager</code> to delegate
-	 * to.
-	 * 
-	 * @param authenticationManager
-	 *            the Acegi AuthenticationManager that knows how to authenticate
-	 *            users.
-	 */
-	public void setAuthenticationManager(
-			final AuthenticationManager authenticationManager) {
-		this.authenticationManager = authenticationManager;
-	}
+public final class CasAuthenticationHandler extends AbstractUsernamePasswordAuthenticationHandler {
+    //~ Instance fields ================================================================================================
+
+    private AuthenticationManager authenticationManager;
+    private Log log = LogFactory.getLog(this.getClass());
+
+    //~ Methods ========================================================================================================
+
+    protected void afterPropertiesSetInternal() throws Exception {
+        Assert.notNull(this.authenticationManager, "authenticationManager cannot be null.");
+    }
+
+    protected boolean authenticateUsernamePasswordInternal(final UsernamePasswordCredentials credentials)
+        throws AuthenticationException {
+        final Authentication authenticationRequest = new UsernamePasswordAuthenticationToken(credentials.getUsername(),
+                credentials.getPassword());
+
+        if (log.isDebugEnabled()) {
+            log.debug("Attempting to authenticate for user: " + credentials.getUsername());
+        }
+
+        try {
+            this.authenticationManager.authenticate(authenticationRequest);
+        } catch (final org.acegisecurity.AuthenticationException e) {
+            if (log.isDebugEnabled()) {
+                log.debug("Authentication request for " + credentials.getUsername() + "failed: " + e.toString());
+            }
+
+            return false;
+        }
+
+        if (log.isDebugEnabled()) {
+            log.debug("Authentication request for " + credentials.getUsername() + " successful.");
+        }
+
+        return true;
+    }
+
+    /**
+     * Method to set the Acegi <code>AuthenticationManager</code> to delegate to.
+     *
+     * @param authenticationManager the Acegi AuthenticationManager that knows how to authenticate users.
+     */
+    public void setAuthenticationManager(final AuthenticationManager authenticationManager) {
+        this.authenticationManager = authenticationManager;
+    }
 }
 }

+ 13 - 18
adapters/cas/src/test/java/org/acegisecurity/adapters/cas/CasPasswordHandlerProxyTests.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -32,7 +32,7 @@ import javax.servlet.http.HttpServletRequest;
  * @version $Id$
  * @version $Id$
  */
  */
 public class CasPasswordHandlerProxyTests extends TestCase {
 public class CasPasswordHandlerProxyTests extends TestCase {
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
     public CasPasswordHandlerProxyTests() {
     public CasPasswordHandlerProxyTests() {
         super();
         super();
@@ -42,16 +42,16 @@ public class CasPasswordHandlerProxyTests extends TestCase {
         super(arg0);
         super(arg0);
     }
     }
 
 
-    //~ Methods ================================================================
-
-    public final void setUp() throws Exception {
-        super.setUp();
-    }
+    //~ Methods ========================================================================================================
 
 
     public static void main(String[] args) {
     public static void main(String[] args) {
         junit.textui.TestRunner.run(CasPasswordHandlerProxyTests.class);
         junit.textui.TestRunner.run(CasPasswordHandlerProxyTests.class);
     }
     }
 
 
+    public final void setUp() throws Exception {
+        super.setUp();
+    }
+
     public void testDetectsIfHttpServletRequestNotPassed() {
     public void testDetectsIfHttpServletRequestNotPassed() {
         CasPasswordHandlerProxy proxy = new MockCasPasswordHandlerProxy(
         CasPasswordHandlerProxy proxy = new MockCasPasswordHandlerProxy(
                 "org/acegisecurity/adapters/cas/applicationContext-valid.xml");
                 "org/acegisecurity/adapters/cas/applicationContext-valid.xml");
@@ -60,8 +60,7 @@ public class CasPasswordHandlerProxyTests extends TestCase {
             proxy.authenticate(null, "x", "y");
             proxy.authenticate(null, "x", "y");
             fail("Should have thrown IllegalArgumentException");
             fail("Should have thrown IllegalArgumentException");
         } catch (IllegalArgumentException expected) {
         } catch (IllegalArgumentException expected) {
-            assertEquals("Can only process HttpServletRequest",
-                expected.getMessage());
+            assertEquals("Can only process HttpServletRequest", expected.getMessage());
         }
         }
     }
     }
 
 
@@ -73,23 +72,19 @@ public class CasPasswordHandlerProxyTests extends TestCase {
             proxy.authenticate(new MockHttpServletRequest(), "x", "y");
             proxy.authenticate(new MockHttpServletRequest(), "x", "y");
             fail("Should have thrown IllegalArgumentException");
             fail("Should have thrown IllegalArgumentException");
         } catch (IllegalArgumentException expected) {
         } catch (IllegalArgumentException expected) {
-            assertEquals("Bean context must contain at least one bean of type CasPasswordHandler",
-                expected.getMessage());
+            assertEquals("Bean context must contain at least one bean of type CasPasswordHandler", expected.getMessage());
         }
         }
     }
     }
 
 
     public void testNormalOperation() {
     public void testNormalOperation() {
         CasPasswordHandlerProxy proxy = new MockCasPasswordHandlerProxy(
         CasPasswordHandlerProxy proxy = new MockCasPasswordHandlerProxy(
                 "org/acegisecurity/adapters/cas/applicationContext-valid.xml");
                 "org/acegisecurity/adapters/cas/applicationContext-valid.xml");
-        assertTrue(proxy.authenticate(new MockHttpServletRequest(), "marissa",
-                "koala"));
-        assertFalse(proxy.authenticate(new MockHttpServletRequest(), "marissa",
-                "WRONG_PASSWORD"));
-        assertFalse(proxy.authenticate(new MockHttpServletRequest(),
-                "INVALID_USER_NAME", "WRONG_PASSWORD"));
+        assertTrue(proxy.authenticate(new MockHttpServletRequest(), "marissa", "koala"));
+        assertFalse(proxy.authenticate(new MockHttpServletRequest(), "marissa", "WRONG_PASSWORD"));
+        assertFalse(proxy.authenticate(new MockHttpServletRequest(), "INVALID_USER_NAME", "WRONG_PASSWORD"));
     }
     }
 
 
-    //~ Inner Classes ==========================================================
+    //~ Inner Classes ==================================================================================================
 
 
     /**
     /**
      * Mock object so that application context source can be specified.
      * Mock object so that application context source can be specified.

+ 13 - 19
adapters/cas/src/test/java/org/acegisecurity/adapters/cas/CasPasswordHandlerTests.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -29,7 +29,7 @@ import org.springframework.mock.web.MockHttpServletRequest;
  * @version $Id$
  * @version $Id$
  */
  */
 public class CasPasswordHandlerTests extends TestCase {
 public class CasPasswordHandlerTests extends TestCase {
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
     public CasPasswordHandlerTests() {
     public CasPasswordHandlerTests() {
         super();
         super();
@@ -39,24 +39,23 @@ public class CasPasswordHandlerTests extends TestCase {
         super(arg0);
         super(arg0);
     }
     }
 
 
-    //~ Methods ================================================================
-
-    public final void setUp() throws Exception {
-        super.setUp();
-    }
+    //~ Methods ========================================================================================================
 
 
     public static void main(String[] args) {
     public static void main(String[] args) {
         junit.textui.TestRunner.run(CasPasswordHandlerTests.class);
         junit.textui.TestRunner.run(CasPasswordHandlerTests.class);
     }
     }
 
 
+    public final void setUp() throws Exception {
+        super.setUp();
+    }
+
     public void testDeniesAccessWhenAuthenticationManagerThrowsException()
     public void testDeniesAccessWhenAuthenticationManagerThrowsException()
         throws Exception {
         throws Exception {
         CasPasswordHandler handler = new CasPasswordHandler();
         CasPasswordHandler handler = new CasPasswordHandler();
         handler.setAuthenticationManager(new MockAuthenticationManager(false));
         handler.setAuthenticationManager(new MockAuthenticationManager(false));
         handler.afterPropertiesSet();
         handler.afterPropertiesSet();
 
 
-        assertFalse(handler.authenticate(new MockHttpServletRequest(),
-                "username", "password"));
+        assertFalse(handler.authenticate(new MockHttpServletRequest(), "username", "password"));
     }
     }
 
 
     public void testDetectsEmptyAuthenticationManager()
     public void testDetectsEmptyAuthenticationManager()
@@ -67,8 +66,7 @@ public class CasPasswordHandlerTests extends TestCase {
             handler.afterPropertiesSet();
             handler.afterPropertiesSet();
             fail("Should have thrown IllegalArgumentException");
             fail("Should have thrown IllegalArgumentException");
         } catch (IllegalArgumentException expected) {
         } catch (IllegalArgumentException expected) {
-            assertEquals("An AuthenticationManager is required",
-                expected.getMessage());
+            assertEquals("An AuthenticationManager is required", expected.getMessage());
         }
         }
     }
     }
 
 
@@ -85,14 +83,11 @@ public class CasPasswordHandlerTests extends TestCase {
         handler.afterPropertiesSet();
         handler.afterPropertiesSet();
 
 
         // If empty or null username we return false
         // If empty or null username we return false
-        assertFalse(handler.authenticate(new MockHttpServletRequest(), "",
-                "password"));
-        assertFalse(handler.authenticate(new MockHttpServletRequest(), null,
-                "password"));
+        assertFalse(handler.authenticate(new MockHttpServletRequest(), "", "password"));
+        assertFalse(handler.authenticate(new MockHttpServletRequest(), null, "password"));
 
 
         // We authenticate with null passwords (they might not have one)
         // We authenticate with null passwords (they might not have one)
-        assertTrue(handler.authenticate(new MockHttpServletRequest(), "user",
-                null));
+        assertTrue(handler.authenticate(new MockHttpServletRequest(), "user", null));
         assertTrue(handler.authenticate(new MockHttpServletRequest(), "user", ""));
         assertTrue(handler.authenticate(new MockHttpServletRequest(), "user", ""));
     }
     }
 
 
@@ -101,7 +96,6 @@ public class CasPasswordHandlerTests extends TestCase {
         handler.setAuthenticationManager(new MockAuthenticationManager(true));
         handler.setAuthenticationManager(new MockAuthenticationManager(true));
         handler.afterPropertiesSet();
         handler.afterPropertiesSet();
 
 
-        assertTrue(handler.authenticate(new MockHttpServletRequest(),
-                "username", "password"));
+        assertTrue(handler.authenticate(new MockHttpServletRequest(), "username", "password"));
     }
     }
 }
 }

+ 82 - 62
adapters/cas/src/test/java/org/acegisecurity/adapters/cas3/CasAuthenticationHandlerTests.java

@@ -1,77 +1,97 @@
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.acegisecurity.adapters.cas3;
 package org.acegisecurity.adapters.cas3;
 
 
 import org.acegisecurity.AuthenticationManager;
 import org.acegisecurity.AuthenticationManager;
+
 import org.jasig.cas.authentication.handler.AuthenticationException;
 import org.jasig.cas.authentication.handler.AuthenticationException;
 import org.jasig.cas.authentication.principal.UsernamePasswordCredentials;
 import org.jasig.cas.authentication.principal.UsernamePasswordCredentials;
+
 import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
 import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
 
 
+
 /**
 /**
  * Tests {@link CasAuthenticationHandler}
  * Tests {@link CasAuthenticationHandler}
+ *
  * @author Scott Battaglia
  * @author Scott Battaglia
  * @version $Id$
  * @version $Id$
- *
  */
  */
 public class CasAuthenticationHandlerTests extends AbstractDependencyInjectionSpringContextTests {
 public class CasAuthenticationHandlerTests extends AbstractDependencyInjectionSpringContextTests {
+    //~ Instance fields ================================================================================================
+
+    private AuthenticationManager authenticationManager;
+    private CasAuthenticationHandler casAuthenticationHandler;
+
+    //~ Methods ========================================================================================================
+
+    protected String[] getConfigLocations() {
+        return new String[] {"/org/acegisecurity/adapters/cas/applicationContext-valid.xml"};
+    }
+
+    private UsernamePasswordCredentials getCredentialsFor(final String username, final String password) {
+        final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials();
+        credentials.setUsername(username);
+        credentials.setPassword(password);
+
+        return credentials;
+    }
+
+    protected void onSetUp() throws Exception {
+        this.casAuthenticationHandler = new CasAuthenticationHandler();
+        this.casAuthenticationHandler.setAuthenticationManager(authenticationManager);
+        this.casAuthenticationHandler.afterPropertiesSet();
+    }
+
+    public void setAuthenticationManager(final AuthenticationManager authenticationManager) {
+        this.authenticationManager = authenticationManager;
+    }
+
+    public void testAfterPropertiesSet() throws Exception {
+        this.casAuthenticationHandler.setAuthenticationManager(null);
+
+        try {
+            this.casAuthenticationHandler.afterPropertiesSet();
+            fail("IllegalArgumenException expected when no AuthenticationManager is set.");
+        } catch (final IllegalArgumentException e) {
+            // this is okay
+        }
+    }
+
+    public void testGracefullyHandlesInvalidInput() {
+        try {
+            assertFalse(this.casAuthenticationHandler.authenticate(getCredentialsFor("", "")));
+            assertFalse(this.casAuthenticationHandler.authenticate(getCredentialsFor(null, null)));
+        } catch (final AuthenticationException e) {
+            fail("AuthenticationException not expected.");
+        }
+    }
+
+    public void testInvalidUsernamePasswordCombination() {
+        try {
+            assertFalse(this.casAuthenticationHandler.authenticate(getCredentialsFor("scott", "scott")));
+        } catch (final AuthenticationException e) {
+            fail("AuthenticationException not expected.");
+        }
+    }
 
 
-	private AuthenticationManager authenticationManager;
-	
-	private CasAuthenticationHandler casAuthenticationHandler;
-	
-	public void setAuthenticationManager(final AuthenticationManager authenticationManager) {
-		this.authenticationManager = authenticationManager;
-	}
-
-	protected String[] getConfigLocations() {
-		return new String[] {"/org/acegisecurity/adapters/cas/applicationContext-valid.xml"};
-	}
-
-	protected void onSetUp() throws Exception {
-		this.casAuthenticationHandler = new CasAuthenticationHandler();
-		this.casAuthenticationHandler.setAuthenticationManager(authenticationManager);
-		this.casAuthenticationHandler.afterPropertiesSet();
-	}
-	
-	public void testAfterPropertiesSet() throws Exception {
-		this.casAuthenticationHandler.setAuthenticationManager(null);
-		try {
-			this.casAuthenticationHandler.afterPropertiesSet();
-			fail("IllegalArgumenException expected when no AuthenticationManager is set.");
-		} catch (final IllegalArgumentException e) {
-			// this is okay
-		}
-	}
-	
-	public void testValidUsernamePasswordCombination() {
-		try {
-			assertTrue(this.casAuthenticationHandler.authenticate(getCredentialsFor("scott", "wombat")));
-		} catch (final AuthenticationException  e) {
-			fail("AuthenticationException not expected.");
-		}
-	}
-	
-	public void testInvalidUsernamePasswordCombination() {
-		try {
-			assertFalse(this.casAuthenticationHandler.authenticate(getCredentialsFor("scott", "scott")));
-		} catch (final AuthenticationException  e) {
-			fail("AuthenticationException not expected.");
-		}
-	}
-	
-	public void testGracefullyHandlesInvalidInput() {
-
-		try {
-			assertFalse(this.casAuthenticationHandler.authenticate(getCredentialsFor("", "")));
-			assertFalse(this.casAuthenticationHandler.authenticate(getCredentialsFor(null, null)));
-		} catch (final AuthenticationException  e) {
-			fail("AuthenticationException not expected.");
-		}
-	}
-	
-	private UsernamePasswordCredentials getCredentialsFor(final String username, final String password) {
-		final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials();
-		credentials.setUsername(username);
-		credentials.setPassword(password);
-		
-		return credentials;
-	}
+    public void testValidUsernamePasswordCombination() {
+        try {
+            assertTrue(this.casAuthenticationHandler.authenticate(getCredentialsFor("scott", "wombat")));
+        } catch (final AuthenticationException e) {
+            fail("AuthenticationException not expected.");
+        }
+    }
 }
 }

+ 60 - 75
adapters/catalina/src/main/java/org/acegisecurity/adapters/catalina/CatalinaAcegiUserRealm.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -41,48 +41,27 @@ import java.util.Map;
 
 
 
 
 /**
 /**
- * Adapter to enable Catalina (Tomcat) to authenticate via the Acegi Security
- * System for Spring.
- * 
- * <p>
- * Returns a {@link PrincipalAcegiUserToken} to Catalina's authentication
- * system, which is subsequently available via
- * <code>HttpServletRequest.getUserPrincipal()</code>.
- * </p>
+ * Adapter to enable Catalina (Tomcat) to authenticate via the Acegi Security System for Spring.<p>Returns a {@link
+ * PrincipalAcegiUserToken} to Catalina's authentication system, which is subsequently available via
+ * <code>HttpServletRequest.getUserPrincipal()</code>.</p>
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public class CatalinaAcegiUserRealm extends RealmBase {
 public class CatalinaAcegiUserRealm extends RealmBase {
-    //~ Static fields/initializers =============================================
+    //~ Static fields/initializers =====================================================================================
 
 
     private static final Log logger = LogFactory.getLog(CatalinaAcegiUserRealm.class);
     private static final Log logger = LogFactory.getLog(CatalinaAcegiUserRealm.class);
 
 
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
-    protected final String name = "CatalinaSpringUserRealm / $Id$";
     private AuthenticationManager authenticationManager;
     private AuthenticationManager authenticationManager;
     private Container container;
     private Container container;
     private String appContextLocation;
     private String appContextLocation;
     private String key;
     private String key;
+    protected final String name = "CatalinaSpringUserRealm / $Id$";
 
 
-    //~ Methods ================================================================
-
-    public void setAppContextLocation(String appContextLocation) {
-        this.appContextLocation = appContextLocation;
-    }
-
-    public String getAppContextLocation() {
-        return appContextLocation;
-    }
-
-    public void setKey(String key) {
-        this.key = key;
-    }
-
-    public String getKey() {
-        return key;
-    }
+    //~ Methods ========================================================================================================
 
 
     public Principal authenticate(String username, String credentials) {
     public Principal authenticate(String username, String credentials) {
         if (username == null) {
         if (username == null) {
@@ -93,25 +72,21 @@ public class CatalinaAcegiUserRealm extends RealmBase {
             credentials = "";
             credentials = "";
         }
         }
 
 
-        Authentication request = new UsernamePasswordAuthenticationToken(username,
-                credentials);
+        Authentication request = new UsernamePasswordAuthenticationToken(username, credentials);
         Authentication response = null;
         Authentication response = null;
 
 
         try {
         try {
             response = authenticationManager.authenticate(request);
             response = authenticationManager.authenticate(request);
         } catch (AuthenticationException failed) {
         } catch (AuthenticationException failed) {
             if (logger.isDebugEnabled()) {
             if (logger.isDebugEnabled()) {
-                logger.debug("Authentication request for user: " + username
-                    + " failed: " + failed.toString());
+                logger.debug("Authentication request for user: " + username + " failed: " + failed.toString());
             }
             }
 
 
             return null;
             return null;
         }
         }
 
 
-        return new PrincipalAcegiUserToken(this.key,
-            response.getPrincipal().toString(),
-            response.getCredentials().toString(), response.getAuthorities(),
-            response.getPrincipal());
+        return new PrincipalAcegiUserToken(this.key, response.getPrincipal().toString(),
+            response.getCredentials().toString(), response.getAuthorities(), response.getPrincipal());
     }
     }
 
 
     public Principal authenticate(String username, byte[] credentials) {
     public Principal authenticate(String username, byte[] credentials) {
@@ -132,10 +107,9 @@ public class CatalinaAcegiUserRealm extends RealmBase {
      *
      *
      * @return DOCUMENT ME!
      * @return DOCUMENT ME!
      */
      */
-    public java.security.Principal authenticate(java.lang.String username,
-        java.lang.String digest, java.lang.String nonce, java.lang.String nc,
-        java.lang.String cnonce, java.lang.String qop, java.lang.String realm,
-        java.lang.String md5a2) {
+    public java.security.Principal authenticate(java.lang.String username, java.lang.String digest,
+        java.lang.String nonce, java.lang.String nc, java.lang.String cnonce, java.lang.String qop,
+        java.lang.String realm, java.lang.String md5a2) {
         return null;
         return null;
     }
     }
 
 
@@ -150,31 +124,12 @@ public class CatalinaAcegiUserRealm extends RealmBase {
         return null;
         return null;
     }
     }
 
 
-    public boolean hasRole(Principal principal, String role) {
-        if ((principal == null) || (role == null)) {
-            return false;
-        }
-
-        if (!(principal instanceof PrincipalAcegiUserToken)) {
-            logger.warn(
-                "Expected passed principal to be of type PrincipalAcegiUserToken but was "
-                + principal.getClass().getName());
-
-            return false;
-        }
-
-        PrincipalAcegiUserToken test = (PrincipalAcegiUserToken) principal;
-
-        return test.isUserInRole(role);
+    public String getAppContextLocation() {
+        return appContextLocation;
     }
     }
 
 
-    /**
-     * Provides the method that Catalina will use to start the container.
-     *
-     * @throws LifecycleException if a problem is detected
-     */
-    public void start() throws LifecycleException {
-        this.start(true);
+    public String getKey() {
+        return key;
     }
     }
 
 
     protected String getName() {
     protected String getName() {
@@ -203,14 +158,38 @@ public class CatalinaAcegiUserRealm extends RealmBase {
         return null;
         return null;
     }
     }
 
 
+    public boolean hasRole(Principal principal, String role) {
+        if ((principal == null) || (role == null)) {
+            return false;
+        }
+
+        if (!(principal instanceof PrincipalAcegiUserToken)) {
+            logger.warn("Expected passed principal to be of type PrincipalAcegiUserToken but was "
+                + principal.getClass().getName());
+
+            return false;
+        }
+
+        PrincipalAcegiUserToken test = (PrincipalAcegiUserToken) principal;
+
+        return test.isUserInRole(role);
+    }
+
+    public void setAppContextLocation(String appContextLocation) {
+        this.appContextLocation = appContextLocation;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
     /**
     /**
-     * Provides a method to load the container adapter without delegating to
-     * the superclass, which cannot operate outside the Catalina container.
+     * Provides the method that Catalina will use to start the container.
      *
      *
      * @throws LifecycleException if a problem is detected
      * @throws LifecycleException if a problem is detected
      */
      */
-    protected void startForTest() throws LifecycleException {
-        this.start(false);
+    public void start() throws LifecycleException {
+        this.start(true);
     }
     }
 
 
     private void start(boolean startParent) throws LifecycleException {
     private void start(boolean startParent) throws LifecycleException {
@@ -226,17 +205,13 @@ public class CatalinaAcegiUserRealm extends RealmBase {
             throw new LifecycleException("key must be defined");
             throw new LifecycleException("key must be defined");
         }
         }
 
 
-        File xml = new File(System.getProperty("catalina.base"),
-                appContextLocation);
+        File xml = new File(System.getProperty("catalina.base"), appContextLocation);
 
 
         if (!xml.exists()) {
         if (!xml.exists()) {
-            throw new LifecycleException(
-                "appContextLocation does not seem to exist in "
-                + xml.toString());
+            throw new LifecycleException("appContextLocation does not seem to exist in " + xml.toString());
         }
         }
 
 
-        FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(
-                "file:" + xml.getAbsolutePath());
+        FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext("file:" + xml.getAbsolutePath());
         Map beans = ctx.getBeansOfType(AuthenticationManager.class, true, true);
         Map beans = ctx.getBeansOfType(AuthenticationManager.class, true, true);
 
 
         if (beans.size() == 0) {
         if (beans.size() == 0) {
@@ -248,4 +223,14 @@ public class CatalinaAcegiUserRealm extends RealmBase {
         authenticationManager = (AuthenticationManager) beans.get(beanName);
         authenticationManager = (AuthenticationManager) beans.get(beanName);
         logger.info("CatalinaAcegiUserRealm Started");
         logger.info("CatalinaAcegiUserRealm Started");
     }
     }
+
+    /**
+     * Provides a method to load the container adapter without delegating to the superclass, which cannot
+     * operate outside the Catalina container.
+     *
+     * @throws LifecycleException if a problem is detected
+     */
+    protected void startForTest() throws LifecycleException {
+        this.start(false);
+    }
 }
 }

+ 47 - 67
adapters/catalina/src/test/java/org/acegisecurity/adapters/catalina/CatalinaAcegiUserRealmTests.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -38,11 +38,11 @@ import java.security.Principal;
  * @version $Id$
  * @version $Id$
  */
  */
 public class CatalinaAcegiUserRealmTests extends TestCase {
 public class CatalinaAcegiUserRealmTests extends TestCase {
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private final String ADAPTER_KEY = "my_key";
     private final String ADAPTER_KEY = "my_key";
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
     public CatalinaAcegiUserRealmTests() {
     public CatalinaAcegiUserRealmTests() {
         super();
         super();
@@ -52,21 +52,41 @@ public class CatalinaAcegiUserRealmTests extends TestCase {
         super(arg0);
         super(arg0);
     }
     }
 
 
-    //~ Methods ================================================================
-
-    public final void setUp() throws Exception {
-        super.setUp();
-    }
+    //~ Methods ========================================================================================================
 
 
     public static void main(String[] args) {
     public static void main(String[] args) {
         junit.textui.TestRunner.run(CatalinaAcegiUserRealmTests.class);
         junit.textui.TestRunner.run(CatalinaAcegiUserRealmTests.class);
     }
     }
 
 
+    private CatalinaAcegiUserRealm makeAdapter(String fileName)
+        throws Exception {
+        CatalinaAcegiUserRealm adapter = new CatalinaAcegiUserRealm();
+
+        URL url = Thread.currentThread().getContextClassLoader().getResource("org/acegisecurity/adapters/" + fileName);
+
+        if (url == null) {
+            throw new Exception("Could not find " + fileName + " - cannot continue");
+        }
+
+        File file = new File(url.getFile());
+
+        System.setProperty("catalina.base", file.getParentFile().getAbsolutePath());
+        System.out.println("catalina.base set to: " + System.getProperty("catalina.base"));
+        adapter.setAppContextLocation(fileName);
+        adapter.setKey(ADAPTER_KEY);
+        adapter.startForTest();
+
+        return adapter;
+    }
+
+    public final void setUp() throws Exception {
+        super.setUp();
+    }
+
     public void testAdapterAbortsIfAppContextDoesNotContainAnAuthenticationBean()
     public void testAdapterAbortsIfAppContextDoesNotContainAnAuthenticationBean()
         throws Exception {
         throws Exception {
         try {
         try {
-            CatalinaAcegiUserRealm adapter = makeAdapter(
-                    "catalinaAdapterTest-invalid.xml");
+            CatalinaAcegiUserRealm adapter = makeAdapter("catalinaAdapterTest-invalid.xml");
             fail("Should have thrown IllegalArgumentException");
             fail("Should have thrown IllegalArgumentException");
         } catch (IllegalArgumentException expected) {
         } catch (IllegalArgumentException expected) {
             assertTrue(true);
             assertTrue(true);
@@ -83,8 +103,7 @@ public class CatalinaAcegiUserRealmTests extends TestCase {
             adapter.startForTest();
             adapter.startForTest();
             fail("Should have thrown LifecycleException");
             fail("Should have thrown LifecycleException");
         } catch (LifecycleException expected) {
         } catch (LifecycleException expected) {
-            assertEquals("appContextLocation must be defined",
-                expected.getMessage());
+            assertEquals("appContextLocation must be defined", expected.getMessage());
         }
         }
 
 
         adapter.setAppContextLocation("");
         adapter.setAppContextLocation("");
@@ -93,8 +112,7 @@ public class CatalinaAcegiUserRealmTests extends TestCase {
             adapter.startForTest();
             adapter.startForTest();
             fail("Should have thrown LifecycleException");
             fail("Should have thrown LifecycleException");
         } catch (LifecycleException expected) {
         } catch (LifecycleException expected) {
-            assertEquals("appContextLocation must be defined",
-                expected.getMessage());
+            assertEquals("appContextLocation must be defined", expected.getMessage());
         }
         }
     }
     }
 
 
@@ -140,15 +158,13 @@ public class CatalinaAcegiUserRealmTests extends TestCase {
     }
     }
 
 
     public void testAdapterStartsUpSuccess() throws Exception {
     public void testAdapterStartsUpSuccess() throws Exception {
-        CatalinaAcegiUserRealm adapter = makeAdapter(
-                "catalinaAdapterTest-valid.xml");
+        CatalinaAcegiUserRealm adapter = makeAdapter("catalinaAdapterTest-valid.xml");
         assertTrue(true);
         assertTrue(true);
     }
     }
 
 
     public void testAuthenticateManyParamsReturnsNull() {
     public void testAuthenticateManyParamsReturnsNull() {
         CatalinaAcegiUserRealm adapter = new CatalinaAcegiUserRealm();
         CatalinaAcegiUserRealm adapter = new CatalinaAcegiUserRealm();
-        assertEquals(null,
-            adapter.authenticate(null, null, null, null, null, null, null, null));
+        assertEquals(null, adapter.authenticate(null, null, null, null, null, null, null, null));
     }
     }
 
 
     public void testAuthenticateX509ReturnsNull() {
     public void testAuthenticateX509ReturnsNull() {
@@ -158,22 +174,19 @@ public class CatalinaAcegiUserRealmTests extends TestCase {
 
 
     public void testAuthenticationFailsForIncorrectPassword()
     public void testAuthenticationFailsForIncorrectPassword()
         throws Exception {
         throws Exception {
-        CatalinaAcegiUserRealm adapter = makeAdapter(
-                "catalinaAdapterTest-valid.xml");
+        CatalinaAcegiUserRealm adapter = makeAdapter("catalinaAdapterTest-valid.xml");
         assertEquals(null, adapter.authenticate("marissa", "kangaroo"));
         assertEquals(null, adapter.authenticate("marissa", "kangaroo"));
     }
     }
 
 
     public void testAuthenticationFailsForIncorrectUserName()
     public void testAuthenticationFailsForIncorrectUserName()
         throws Exception {
         throws Exception {
-        CatalinaAcegiUserRealm adapter = makeAdapter(
-                "catalinaAdapterTest-valid.xml");
+        CatalinaAcegiUserRealm adapter = makeAdapter("catalinaAdapterTest-valid.xml");
         assertEquals(null, adapter.authenticate("melissa", "koala"));
         assertEquals(null, adapter.authenticate("melissa", "koala"));
     }
     }
 
 
     public void testAuthenticationUsingByteArrayForCredentials()
     public void testAuthenticationUsingByteArrayForCredentials()
         throws Exception {
         throws Exception {
-        CatalinaAcegiUserRealm adapter = makeAdapter(
-                "catalinaAdapterTest-valid.xml");
+        CatalinaAcegiUserRealm adapter = makeAdapter("catalinaAdapterTest-valid.xml");
         byte[] credentials = {'k', 'o', 'a', 'l', 'a'};
         byte[] credentials = {'k', 'o', 'a', 'l', 'a'};
         Principal result = adapter.authenticate("marissa", credentials);
         Principal result = adapter.authenticate("marissa", credentials);
 
 
@@ -184,17 +197,14 @@ public class CatalinaAcegiUserRealmTests extends TestCase {
         PrincipalAcegiUserToken castResult = (PrincipalAcegiUserToken) result;
         PrincipalAcegiUserToken castResult = (PrincipalAcegiUserToken) result;
         assertEquals("marissa", castResult.getPrincipal());
         assertEquals("marissa", castResult.getPrincipal());
         assertEquals("koala", castResult.getCredentials());
         assertEquals("koala", castResult.getCredentials());
-        assertEquals("ROLE_TELLER",
-            castResult.getAuthorities()[0].getAuthority());
-        assertEquals("ROLE_SUPERVISOR",
-            castResult.getAuthorities()[1].getAuthority());
+        assertEquals("ROLE_TELLER", castResult.getAuthorities()[0].getAuthority());
+        assertEquals("ROLE_SUPERVISOR", castResult.getAuthorities()[1].getAuthority());
         assertEquals(ADAPTER_KEY.hashCode(), castResult.getKeyHash());
         assertEquals(ADAPTER_KEY.hashCode(), castResult.getKeyHash());
     }
     }
 
 
     public void testAuthenticationUsingStringForCredentials()
     public void testAuthenticationUsingStringForCredentials()
         throws Exception {
         throws Exception {
-        CatalinaAcegiUserRealm adapter = makeAdapter(
-                "catalinaAdapterTest-valid.xml");
+        CatalinaAcegiUserRealm adapter = makeAdapter("catalinaAdapterTest-valid.xml");
         Principal result = adapter.authenticate("marissa", "koala");
         Principal result = adapter.authenticate("marissa", "koala");
 
 
         if (!(result instanceof PrincipalAcegiUserToken)) {
         if (!(result instanceof PrincipalAcegiUserToken)) {
@@ -204,24 +214,20 @@ public class CatalinaAcegiUserRealmTests extends TestCase {
         PrincipalAcegiUserToken castResult = (PrincipalAcegiUserToken) result;
         PrincipalAcegiUserToken castResult = (PrincipalAcegiUserToken) result;
         assertEquals("marissa", castResult.getPrincipal());
         assertEquals("marissa", castResult.getPrincipal());
         assertEquals("koala", castResult.getCredentials());
         assertEquals("koala", castResult.getCredentials());
-        assertEquals("ROLE_TELLER",
-            castResult.getAuthorities()[0].getAuthority());
-        assertEquals("ROLE_SUPERVISOR",
-            castResult.getAuthorities()[1].getAuthority());
+        assertEquals("ROLE_TELLER", castResult.getAuthorities()[0].getAuthority());
+        assertEquals("ROLE_SUPERVISOR", castResult.getAuthorities()[1].getAuthority());
         assertEquals(ADAPTER_KEY.hashCode(), castResult.getKeyHash());
         assertEquals(ADAPTER_KEY.hashCode(), castResult.getKeyHash());
     }
     }
 
 
     public void testAuthenticationWithNullPasswordHandledGracefully()
     public void testAuthenticationWithNullPasswordHandledGracefully()
         throws Exception {
         throws Exception {
-        CatalinaAcegiUserRealm adapter = makeAdapter(
-                "catalinaAdapterTest-valid.xml");
+        CatalinaAcegiUserRealm adapter = makeAdapter("catalinaAdapterTest-valid.xml");
         assertEquals(null, adapter.authenticate("marissa", (String) null));
         assertEquals(null, adapter.authenticate("marissa", (String) null));
     }
     }
 
 
     public void testAuthenticationWithNullUserNameHandledGracefully()
     public void testAuthenticationWithNullUserNameHandledGracefully()
         throws Exception {
         throws Exception {
-        CatalinaAcegiUserRealm adapter = makeAdapter(
-                "catalinaAdapterTest-valid.xml");
+        CatalinaAcegiUserRealm adapter = makeAdapter("catalinaAdapterTest-valid.xml");
         assertEquals(null, adapter.authenticate(null, "koala"));
         assertEquals(null, adapter.authenticate(null, "koala"));
     }
     }
 
 
@@ -258,38 +264,12 @@ public class CatalinaAcegiUserRealmTests extends TestCase {
     }
     }
 
 
     public void testHasRoleWithPrincipalAcegiUserToken() {
     public void testHasRoleWithPrincipalAcegiUserToken() {
-        PrincipalAcegiUserToken token = new PrincipalAcegiUserToken("KEY",
-                "Test", "Password",
-                new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_ONE"), new GrantedAuthorityImpl(
-                        "ROLE_TWO")}, null);
+        PrincipalAcegiUserToken token = new PrincipalAcegiUserToken("KEY", "Test", "Password",
+                new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_ONE"), new GrantedAuthorityImpl("ROLE_TWO")},
+                null);
         CatalinaAcegiUserRealm adapter = new CatalinaAcegiUserRealm();
         CatalinaAcegiUserRealm adapter = new CatalinaAcegiUserRealm();
         assertTrue(adapter.hasRole(token, "ROLE_ONE"));
         assertTrue(adapter.hasRole(token, "ROLE_ONE"));
         assertTrue(adapter.hasRole(token, "ROLE_TWO"));
         assertTrue(adapter.hasRole(token, "ROLE_TWO"));
         assertTrue(!adapter.hasRole(token, "ROLE_WE_DO_NOT_HAVE"));
         assertTrue(!adapter.hasRole(token, "ROLE_WE_DO_NOT_HAVE"));
     }
     }
-
-    private CatalinaAcegiUserRealm makeAdapter(String fileName)
-        throws Exception {
-        CatalinaAcegiUserRealm adapter = new CatalinaAcegiUserRealm();
-
-        URL url = Thread.currentThread().getContextClassLoader().getResource("org/acegisecurity/adapters/"
-                + fileName);
-
-        if (url == null) {
-            throw new Exception("Could not find " + fileName
-                + " - cannot continue");
-        }
-
-        File file = new File(url.getFile());
-
-        System.setProperty("catalina.base",
-            file.getParentFile().getAbsolutePath());
-        System.out.println("catalina.base set to: "
-            + System.getProperty("catalina.base"));
-        adapter.setAppContextLocation(fileName);
-        adapter.setKey(ADAPTER_KEY);
-        adapter.startForTest();
-
-        return adapter;
-    }
 }
 }

+ 26 - 51
adapters/jboss/src/main/java/org/acegisecurity/adapters/jboss/JbossAcegiLoginModule.java

@@ -52,28 +52,23 @@ import javax.security.auth.login.LoginException;
 
 
 
 
 /**
 /**
- * Adapter to enable JBoss to authenticate via the Acegi Security System for
- * Spring.
- * 
- * <p>
- * Returns a {@link PrincipalAcegiUserToken} to JBoss' authentication system,
- * which is subsequently available from
- * <code>java:comp/env/security/subject</code>.
- * </p>
+ * Adapter to enable JBoss to authenticate via the Acegi Security System for Spring.<p>Returns a {@link
+ * PrincipalAcegiUserToken} to JBoss' authentication system, which is subsequently available from
+ * <code>java:comp/env/security/subject</code>.</p>
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @author Sergio Bern�
  * @author Sergio Bern�
  * @version $Id$
  * @version $Id$
  */
  */
 public class JbossAcegiLoginModule extends AbstractServerLoginModule {
 public class JbossAcegiLoginModule extends AbstractServerLoginModule {
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private AuthenticationManager authenticationManager;
     private AuthenticationManager authenticationManager;
     private Principal identity;
     private Principal identity;
     private String key;
     private String key;
     private char[] credential;
     private char[] credential;
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     protected Principal getIdentity() {
     protected Principal getIdentity() {
         return this.identity;
         return this.identity;
@@ -87,8 +82,7 @@ public class JbossAcegiLoginModule extends AbstractServerLoginModule {
             Authentication user = (Authentication) this.identity;
             Authentication user = (Authentication) this.identity;
 
 
             for (int i = 0; i < user.getAuthorities().length; i++) {
             for (int i = 0; i < user.getAuthorities().length; i++) {
-                roles.addMember(new SimplePrincipal(
-                        user.getAuthorities()[i].getAuthority()));
+                roles.addMember(new SimplePrincipal(user.getAuthorities()[i].getAuthority()));
             }
             }
         }
         }
 
 
@@ -100,8 +94,7 @@ public class JbossAcegiLoginModule extends AbstractServerLoginModule {
 
 
         // prompt for a username and password
         // prompt for a username and password
         if (callbackHandler == null) {
         if (callbackHandler == null) {
-            throw new LoginException("Error: no CallbackHandler available "
-                + "to collect authentication information");
+            throw new LoginException("Error: no CallbackHandler available " + "to collect authentication information");
         }
         }
 
 
         NameCallback nc = new NameCallback("User name: ", "guest");
         NameCallback nc = new NameCallback("User name: ", "guest");
@@ -118,16 +111,14 @@ public class JbossAcegiLoginModule extends AbstractServerLoginModule {
 
 
             if (tmpPassword != null) {
             if (tmpPassword != null) {
                 credential = new char[tmpPassword.length];
                 credential = new char[tmpPassword.length];
-                System.arraycopy(tmpPassword, 0, credential, 0,
-                    tmpPassword.length);
+                System.arraycopy(tmpPassword, 0, credential, 0, tmpPassword.length);
                 pc.clearPassword();
                 pc.clearPassword();
                 password = new String(credential);
                 password = new String(credential);
             }
             }
         } catch (java.io.IOException ioe) {
         } catch (java.io.IOException ioe) {
             throw new LoginException(ioe.toString());
             throw new LoginException(ioe.toString());
         } catch (UnsupportedCallbackException uce) {
         } catch (UnsupportedCallbackException uce) {
-            throw new LoginException("CallbackHandler does not support: "
-                + uce.getCallback());
+            throw new LoginException("CallbackHandler does not support: " + uce.getCallback());
         }
         }
 
 
         info[0] = username;
         info[0] = username;
@@ -136,8 +127,7 @@ public class JbossAcegiLoginModule extends AbstractServerLoginModule {
         return info;
         return info;
     }
     }
 
 
-    public void initialize(Subject subject, CallbackHandler callbackHandler,
-        Map sharedState, Map options) {
+    public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) {
         super.initialize(subject, callbackHandler, sharedState, options);
         super.initialize(subject, callbackHandler, sharedState, options);
 
 
         if (super.log.isInfoEnabled()) {
         if (super.log.isInfoEnabled()) {
@@ -154,24 +144,21 @@ public class JbossAcegiLoginModule extends AbstractServerLoginModule {
 
 
         String appContextLocation = (String) options.get("appContextLocation");
         String appContextLocation = (String) options.get("appContextLocation");
 
 
-        if ((((singletonId == null) || "".equals(singletonId))
-            && (appContextLocation == null)) || "".equals(appContextLocation)) {
-            throw new IllegalArgumentException(
-                "appContextLocation must be defined");
+        if ((((singletonId == null) || "".equals(singletonId)) && (appContextLocation == null))
+            || "".equals(appContextLocation)) {
+            throw new IllegalArgumentException("appContextLocation must be defined");
         }
         }
 
 
         String beanName = (String) options.get("authenticationManager");
         String beanName = (String) options.get("authenticationManager");
 
 
         // Attempt to find the appContextLocation only if no singletonId was defined
         // Attempt to find the appContextLocation only if no singletonId was defined
         if ((singletonId == null) || "".equals(singletonId)) {
         if ((singletonId == null) || "".equals(singletonId)) {
-            if (Thread.currentThread().getContextClassLoader()
-                      .getResource(appContextLocation) == null) {
+            if (Thread.currentThread().getContextClassLoader().getResource(appContextLocation) == null) {
                 if (super.log.isInfoEnabled()) {
                 if (super.log.isInfoEnabled()) {
                     super.log.info("cannot locate " + appContextLocation);
                     super.log.info("cannot locate " + appContextLocation);
                 }
                 }
 
 
-                throw new IllegalArgumentException("Cannot locate "
-                    + appContextLocation);
+                throw new IllegalArgumentException("Cannot locate " + appContextLocation);
             }
             }
         }
         }
 
 
@@ -182,13 +169,10 @@ public class JbossAcegiLoginModule extends AbstractServerLoginModule {
                 ctx = new ClassPathXmlApplicationContext(appContextLocation);
                 ctx = new ClassPathXmlApplicationContext(appContextLocation);
             } catch (Exception e) {
             } catch (Exception e) {
                 if (super.log.isInfoEnabled()) {
                 if (super.log.isInfoEnabled()) {
-                    super.log.info("error loading spring context "
-                        + appContextLocation + " " + e);
+                    super.log.info("error loading spring context " + appContextLocation + " " + e);
                 }
                 }
 
 
-                throw new IllegalArgumentException(
-                    "error loading spring context " + appContextLocation + " "
-                    + e);
+                throw new IllegalArgumentException("error loading spring context " + appContextLocation + " " + e);
             }
             }
         } else {
         } else {
             if (super.log.isInfoEnabled()) {
             if (super.log.isInfoEnabled()) {
@@ -204,8 +188,7 @@ public class JbossAcegiLoginModule extends AbstractServerLoginModule {
                     super.log.info("singleton " + beanName + " does not exists");
                     super.log.info("singleton " + beanName + " does not exists");
                 }
                 }
 
 
-                throw new IllegalArgumentException("singleton " + singletonId
-                    + " does not exists");
+                throw new IllegalArgumentException("singleton " + singletonId + " does not exists");
             }
             }
         }
         }
 
 
@@ -213,15 +196,13 @@ public class JbossAcegiLoginModule extends AbstractServerLoginModule {
             Map beans = null;
             Map beans = null;
 
 
             try {
             try {
-                beans = ctx.getBeansOfType(AuthenticationManager.class, true,
-                        true);
+                beans = ctx.getBeansOfType(AuthenticationManager.class, true, true);
             } catch (Exception e) {
             } catch (Exception e) {
                 if (super.log.isInfoEnabled()) {
                 if (super.log.isInfoEnabled()) {
                     super.log.info("exception in getBeansOfType " + e);
                     super.log.info("exception in getBeansOfType " + e);
                 }
                 }
 
 
-                throw new IllegalStateException(
-                    "spring error in get beans by class");
+                throw new IllegalStateException("spring error in get beans by class");
             }
             }
 
 
             if (beans.size() == 0) {
             if (beans.size() == 0) {
@@ -248,8 +229,7 @@ public class JbossAcegiLoginModule extends AbstractServerLoginModule {
 
 
         if ((username == null) && (password == null)) {
         if ((username == null) && (password == null)) {
             identity = null;
             identity = null;
-            super.log.trace("Authenticating as unauthenticatedIdentity="
-                + identity);
+            super.log.trace("Authenticating as unauthenticatedIdentity=" + identity);
         }
         }
 
 
         if (username == null) {
         if (username == null) {
@@ -267,8 +247,7 @@ public class JbossAcegiLoginModule extends AbstractServerLoginModule {
         if (identity == null) {
         if (identity == null) {
             super.log.debug("creating usernamepassword token");
             super.log.debug("creating usernamepassword token");
 
 
-            Authentication request = new UsernamePasswordAuthenticationToken(username,
-                    password);
+            Authentication request = new UsernamePasswordAuthenticationToken(username, password);
             Authentication response = null;
             Authentication response = null;
 
 
             try {
             try {
@@ -290,8 +269,7 @@ public class JbossAcegiLoginModule extends AbstractServerLoginModule {
                     "The credential used to identify the user has expired");
                     "The credential used to identify the user has expired");
             } catch (AccountExpiredException cee) {
             } catch (AccountExpiredException cee) {
                 if (super.log.isDebugEnabled()) {
                 if (super.log.isDebugEnabled()) {
-                    super.log.debug(
-                        "Account has expired, throwing jaas exception");
+                    super.log.debug("Account has expired, throwing jaas exception");
                 }
                 }
 
 
                 throw new javax.security.auth.login.AccountExpiredException(
                 throw new javax.security.auth.login.AccountExpiredException(
@@ -301,14 +279,12 @@ public class JbossAcegiLoginModule extends AbstractServerLoginModule {
                     super.log.debug("Bad password for username=" + username);
                     super.log.debug("Bad password for username=" + username);
                 }
                 }
 
 
-                throw new FailedLoginException(
-                    "Password Incorrect/Password Required");
+                throw new FailedLoginException("Password Incorrect/Password Required");
             }
             }
 
 
             super.log.debug("user is logged. redirecting to jaas classes");
             super.log.debug("user is logged. redirecting to jaas classes");
 
 
-            identity = new PrincipalAcegiUserToken(this.key,
-                    response.getName(), response.getCredentials().toString(),
+            identity = new PrincipalAcegiUserToken(this.key, response.getName(), response.getCredentials().toString(),
                     response.getAuthorities(), response.getPrincipal());
                     response.getAuthorities(), response.getPrincipal());
         }
         }
 
 
@@ -319,8 +295,7 @@ public class JbossAcegiLoginModule extends AbstractServerLoginModule {
         }
         }
 
 
         super.loginOk = true;
         super.loginOk = true;
-        super.log.trace("User '" + identity + "' authenticated, loginOk="
-            + loginOk);
+        super.log.trace("User '" + identity + "' authenticated, loginOk=" + loginOk);
 
 
         return true;
         return true;
     }
     }

+ 33 - 44
adapters/jboss/src/main/java/org/acegisecurity/adapters/jboss/JbossIntegrationFilter.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
 package org.acegisecurity.adapters.jboss;
 package org.acegisecurity.adapters.jboss;
 
 
 import org.acegisecurity.Authentication;
 import org.acegisecurity.Authentication;
+
 import org.acegisecurity.context.SecurityContextHolder;
 import org.acegisecurity.context.SecurityContextHolder;
 
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.Log;
@@ -42,76 +43,45 @@ import javax.servlet.ServletResponse;
 
 
 
 
 /**
 /**
- * Populates a {@link org.acegisecurity.context.security.SecureContext} from
- * JBoss' <code>java:comp/env/security/subject</code>.
- * 
- * <p>
- * This filter <b>never</b> preserves the <code>Authentication</code> on the
- * <code>ContextHolder</code> - it is replaced every request.
- * </p>
- * 
- * <p>
- * See {@link HttpSessionContextIntegrationFilter} for further information.
- * </p>
+ * Populates a {@link org.acegisecurity.context.security.SecureContext} from JBoss'
+ * <code>java:comp/env/security/subject</code>.<p>This filter <b>never</b> preserves the
+ * <code>Authentication</code> on the <code>ContextHolder</code> - it is replaced every request.</p>
+ *  <p>See {@link HttpSessionContextIntegrationFilter} for further information.</p>
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public class JbossIntegrationFilter implements Filter {
 public class JbossIntegrationFilter implements Filter {
-    //~ Static fields/initializers =============================================
+    //~ Static fields/initializers =====================================================================================
 
 
     private static final Log logger = LogFactory.getLog(JbossIntegrationFilter.class);
     private static final Log logger = LogFactory.getLog(JbossIntegrationFilter.class);
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
      * Does nothing. We use IoC container lifecycle services instead.
      * Does nothing. We use IoC container lifecycle services instead.
      */
      */
     public void destroy() {}
     public void destroy() {}
 
 
-    public void doFilter(ServletRequest request, ServletResponse response,
-        FilterChain chain) throws IOException, ServletException {
+    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+        throws IOException, ServletException {
         Object principal = extractFromContainer(request);
         Object principal = extractFromContainer(request);
 
 
         if ((principal != null) && principal instanceof Authentication) {
         if ((principal != null) && principal instanceof Authentication) {
             SecurityContextHolder.getContext().setAuthentication((Authentication) principal);
             SecurityContextHolder.getContext().setAuthentication((Authentication) principal);
 
 
             if (logger.isDebugEnabled()) {
             if (logger.isDebugEnabled()) {
-                logger.debug(
-                    "ContextHolder updated with Authentication from container: '"
-                    + principal + "'");
+                logger.debug("ContextHolder updated with Authentication from container: '" + principal + "'");
             }
             }
         } else {
         } else {
             if (logger.isDebugEnabled()) {
             if (logger.isDebugEnabled()) {
-                logger.debug(
-                    "ContextHolder not set with new Authentication as Principal was: '"
-                    + principal + "'");
+                logger.debug("ContextHolder not set with new Authentication as Principal was: '" + principal + "'");
             }
             }
         }
         }
 
 
         chain.doFilter(request, response);
         chain.doFilter(request, response);
     }
     }
 
 
-    /**
-     * Does nothing. We use IoC container lifecycle services instead.
-     *
-     * @param arg0 ignored
-     *
-     * @throws ServletException ignored
-     */
-    public void init(FilterConfig arg0) throws ServletException {}
-
-    /**
-     * Provided so that unit tests can override.
-     *
-     * @return a <code>Context</code> that can be used for lookup
-     *
-     * @throws NamingException DOCUMENT ME!
-     */
-    protected Context getLookupContext() throws NamingException {
-        return new InitialContext();
-    }
-
     private Object extractFromContainer(ServletRequest request) {
     private Object extractFromContainer(ServletRequest request) {
         Subject subject = null;
         Subject subject = null;
 
 
@@ -133,8 +103,7 @@ public class JbossIntegrationFilter implements Filter {
             }
             }
         } catch (NamingException ne) {
         } catch (NamingException ne) {
             if (logger.isWarnEnabled()) {
             if (logger.isWarnEnabled()) {
-                logger.warn("Lookup on Subject failed "
-                    + ne.getLocalizedMessage());
+                logger.warn("Lookup on Subject failed " + ne.getLocalizedMessage());
             }
             }
         }
         }
 
 
@@ -152,4 +121,24 @@ public class JbossIntegrationFilter implements Filter {
 
 
         return null;
         return null;
     }
     }
+
+    /**
+     * Provided so that unit tests can override.
+     *
+     * @return a <code>Context</code> that can be used for lookup
+     *
+     * @throws NamingException DOCUMENT ME!
+     */
+    protected Context getLookupContext() throws NamingException {
+        return new InitialContext();
+    }
+
+    /**
+     * Does nothing. We use IoC container lifecycle services instead.
+     *
+     * @param arg0 ignored
+     *
+     * @throws ServletException ignored
+     */
+    public void init(FilterConfig arg0) throws ServletException {}
 }
 }

+ 28 - 47
adapters/jboss/src/test/java/org/acegisecurity/adapters/jboss/JbossAcegiLoginModuleTests.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -45,11 +45,11 @@ import javax.security.auth.login.LoginException;
  * @version $Id$
  * @version $Id$
  */
  */
 public class JbossAcegiLoginModuleTests extends TestCase {
 public class JbossAcegiLoginModuleTests extends TestCase {
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private final String ADAPTER_KEY = "my_key";
     private final String ADAPTER_KEY = "my_key";
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
     public JbossAcegiLoginModuleTests() {
     public JbossAcegiLoginModuleTests() {
         super();
         super();
@@ -59,23 +59,22 @@ public class JbossAcegiLoginModuleTests extends TestCase {
         super(arg0);
         super(arg0);
     }
     }
 
 
-    //~ Methods ================================================================
-
-    public final void setUp() throws Exception {
-        super.setUp();
-    }
+    //~ Methods ========================================================================================================
 
 
     public static void main(String[] args) {
     public static void main(String[] args) {
         junit.textui.TestRunner.run(JbossAcegiLoginModuleTests.class);
         junit.textui.TestRunner.run(JbossAcegiLoginModuleTests.class);
     }
     }
 
 
+    public final void setUp() throws Exception {
+        super.setUp();
+    }
+
     public void testAdapterAbortsIfAppContextDoesNotContainAnAuthenticationBean()
     public void testAdapterAbortsIfAppContextDoesNotContainAnAuthenticationBean()
         throws Exception {
         throws Exception {
         JbossAcegiLoginModule adapter = new JbossAcegiLoginModule();
         JbossAcegiLoginModule adapter = new JbossAcegiLoginModule();
         Properties props = new Properties();
         Properties props = new Properties();
         props.put("key", ADAPTER_KEY);
         props.put("key", ADAPTER_KEY);
-        props.put("appContextLocation",
-            "org/acegisecurity/adapters/adaptertest-invalid.xml");
+        props.put("appContextLocation", "org/acegisecurity/adapters/adaptertest-invalid.xml");
 
 
         try {
         try {
             adapter.initialize(null, null, null, props);
             adapter.initialize(null, null, null, props);
@@ -96,8 +95,7 @@ public class JbossAcegiLoginModuleTests extends TestCase {
             adapter.initialize(null, null, null, props);
             adapter.initialize(null, null, null, props);
             fail("Should have thrown IllegalArgumentException");
             fail("Should have thrown IllegalArgumentException");
         } catch (IllegalArgumentException expected) {
         } catch (IllegalArgumentException expected) {
-            assertEquals("appContextLocation must be defined",
-                expected.getMessage());
+            assertEquals("appContextLocation must be defined", expected.getMessage());
         }
         }
 
 
         props = new Properties();
         props = new Properties();
@@ -108,8 +106,7 @@ public class JbossAcegiLoginModuleTests extends TestCase {
             adapter.initialize(null, null, null, props);
             adapter.initialize(null, null, null, props);
             fail("Should have thrown IllegalArgumentException");
             fail("Should have thrown IllegalArgumentException");
         } catch (IllegalArgumentException expected) {
         } catch (IllegalArgumentException expected) {
-            assertEquals("appContextLocation must be defined",
-                expected.getMessage());
+            assertEquals("appContextLocation must be defined", expected.getMessage());
         }
         }
     }
     }
 
 
@@ -117,8 +114,7 @@ public class JbossAcegiLoginModuleTests extends TestCase {
         JbossAcegiLoginModule adapter = new JbossAcegiLoginModule();
         JbossAcegiLoginModule adapter = new JbossAcegiLoginModule();
 
 
         Properties props = new Properties();
         Properties props = new Properties();
-        props.put("appContextLocation",
-            "org/acegisecurity/adapters/adaptertest-valid.xml");
+        props.put("appContextLocation", "org/acegisecurity/adapters/adaptertest-valid.xml");
 
 
         try {
         try {
             adapter.initialize(null, null, null, props);
             adapter.initialize(null, null, null, props);
@@ -129,8 +125,7 @@ public class JbossAcegiLoginModuleTests extends TestCase {
 
 
         props = new Properties();
         props = new Properties();
         props.put("key", "");
         props.put("key", "");
-        props.put("appContextLocation",
-            "org/acegisecurity/adapters/adaptertest-valid.xml");
+        props.put("appContextLocation", "org/acegisecurity/adapters/adaptertest-valid.xml");
 
 
         try {
         try {
             adapter.initialize(null, null, null, props);
             adapter.initialize(null, null, null, props);
@@ -152,8 +147,7 @@ public class JbossAcegiLoginModuleTests extends TestCase {
             adapter.initialize(null, null, null, props);
             adapter.initialize(null, null, null, props);
             fail("Should have thrown IllegalArgumentException");
             fail("Should have thrown IllegalArgumentException");
         } catch (IllegalArgumentException expected) {
         } catch (IllegalArgumentException expected) {
-            assertTrue("Cannot locate INVALID_PATH".equals(
-                    expected.getMessage()));
+            assertTrue("Cannot locate INVALID_PATH".equals(expected.getMessage()));
         }
         }
     }
     }
 
 
@@ -162,8 +156,7 @@ public class JbossAcegiLoginModuleTests extends TestCase {
         JbossAcegiLoginModule adapter = new JbossAcegiLoginModule();
         JbossAcegiLoginModule adapter = new JbossAcegiLoginModule();
         Properties props = new Properties();
         Properties props = new Properties();
         props.put("key", ADAPTER_KEY);
         props.put("key", ADAPTER_KEY);
-        props.put("appContextLocation",
-            "org/acegisecurity/adapters/adaptertest-valid.xml");
+        props.put("appContextLocation", "org/acegisecurity/adapters/adaptertest-valid.xml");
 
 
         Subject subject = new Subject();
         Subject subject = new Subject();
 
 
@@ -181,8 +174,7 @@ public class JbossAcegiLoginModuleTests extends TestCase {
         JbossAcegiLoginModule adapter = new JbossAcegiLoginModule();
         JbossAcegiLoginModule adapter = new JbossAcegiLoginModule();
         Properties props = new Properties();
         Properties props = new Properties();
         props.put("key", ADAPTER_KEY);
         props.put("key", ADAPTER_KEY);
-        props.put("appContextLocation",
-            "org/acegisecurity/adapters/adaptertest-valid.xml");
+        props.put("appContextLocation", "org/acegisecurity/adapters/adaptertest-valid.xml");
         adapter.initialize(null, null, null, props);
         adapter.initialize(null, null, null, props);
         assertTrue(true);
         assertTrue(true);
     }
     }
@@ -192,8 +184,7 @@ public class JbossAcegiLoginModuleTests extends TestCase {
         JbossAcegiLoginModule adapter = new JbossAcegiLoginModule();
         JbossAcegiLoginModule adapter = new JbossAcegiLoginModule();
         Properties props = new Properties();
         Properties props = new Properties();
         props.put("key", ADAPTER_KEY);
         props.put("key", ADAPTER_KEY);
-        props.put("appContextLocation",
-            "org/acegisecurity/adapters/adaptertest-valid.xml");
+        props.put("appContextLocation", "org/acegisecurity/adapters/adaptertest-valid.xml");
 
 
         Subject subject = new Subject();
         Subject subject = new Subject();
         CallbackHandler callback = new MockCallbackHandler("marissa", "kangaroo");
         CallbackHandler callback = new MockCallbackHandler("marissa", "kangaroo");
@@ -213,8 +204,7 @@ public class JbossAcegiLoginModuleTests extends TestCase {
         JbossAcegiLoginModule adapter = new JbossAcegiLoginModule();
         JbossAcegiLoginModule adapter = new JbossAcegiLoginModule();
         Properties props = new Properties();
         Properties props = new Properties();
         props.put("key", ADAPTER_KEY);
         props.put("key", ADAPTER_KEY);
-        props.put("appContextLocation",
-            "org/acegisecurity/adapters/adaptertest-valid.xml");
+        props.put("appContextLocation", "org/acegisecurity/adapters/adaptertest-valid.xml");
 
 
         Subject subject = new Subject();
         Subject subject = new Subject();
         CallbackHandler callback = new MockCallbackHandler("melissa", "koala");
         CallbackHandler callback = new MockCallbackHandler("melissa", "koala");
@@ -233,8 +223,7 @@ public class JbossAcegiLoginModuleTests extends TestCase {
         JbossAcegiLoginModule adapter = new JbossAcegiLoginModule();
         JbossAcegiLoginModule adapter = new JbossAcegiLoginModule();
         Properties props = new Properties();
         Properties props = new Properties();
         props.put("key", ADAPTER_KEY);
         props.put("key", ADAPTER_KEY);
-        props.put("appContextLocation",
-            "org/acegisecurity/adapters/adaptertest-valid.xml");
+        props.put("appContextLocation", "org/acegisecurity/adapters/adaptertest-valid.xml");
 
 
         Subject subject = new Subject();
         Subject subject = new Subject();
         CallbackHandler callback = new MockCallbackHandler("marissa", "koala");
         CallbackHandler callback = new MockCallbackHandler("marissa", "koala");
@@ -251,10 +240,8 @@ public class JbossAcegiLoginModuleTests extends TestCase {
         PrincipalAcegiUserToken castResult = (PrincipalAcegiUserToken) result;
         PrincipalAcegiUserToken castResult = (PrincipalAcegiUserToken) result;
         assertEquals("marissa", castResult.getPrincipal());
         assertEquals("marissa", castResult.getPrincipal());
         assertEquals("koala", castResult.getCredentials());
         assertEquals("koala", castResult.getCredentials());
-        assertEquals("ROLE_TELLER",
-            castResult.getAuthorities()[0].getAuthority());
-        assertEquals("ROLE_SUPERVISOR",
-            castResult.getAuthorities()[1].getAuthority());
+        assertEquals("ROLE_TELLER", castResult.getAuthorities()[0].getAuthority());
+        assertEquals("ROLE_SUPERVISOR", castResult.getAuthorities()[1].getAuthority());
         assertEquals(ADAPTER_KEY.hashCode(), castResult.getKeyHash());
         assertEquals(ADAPTER_KEY.hashCode(), castResult.getKeyHash());
     }
     }
 
 
@@ -263,8 +250,7 @@ public class JbossAcegiLoginModuleTests extends TestCase {
         JbossAcegiLoginModule adapter = new JbossAcegiLoginModule();
         JbossAcegiLoginModule adapter = new JbossAcegiLoginModule();
         Properties props = new Properties();
         Properties props = new Properties();
         props.put("key", ADAPTER_KEY);
         props.put("key", ADAPTER_KEY);
-        props.put("appContextLocation",
-            "org/acegisecurity/adapters/adaptertest-valid.xml");
+        props.put("appContextLocation", "org/acegisecurity/adapters/adaptertest-valid.xml");
 
 
         Subject subject = new Subject();
         Subject subject = new Subject();
         CallbackHandler callback = new MockCallbackHandler("marissa", null);
         CallbackHandler callback = new MockCallbackHandler("marissa", null);
@@ -284,8 +270,7 @@ public class JbossAcegiLoginModuleTests extends TestCase {
         JbossAcegiLoginModule adapter = new JbossAcegiLoginModule();
         JbossAcegiLoginModule adapter = new JbossAcegiLoginModule();
         Properties props = new Properties();
         Properties props = new Properties();
         props.put("key", ADAPTER_KEY);
         props.put("key", ADAPTER_KEY);
-        props.put("appContextLocation",
-            "org/acegisecurity/adapters/adaptertest-valid.xml");
+        props.put("appContextLocation", "org/acegisecurity/adapters/adaptertest-valid.xml");
 
 
         Subject subject = new Subject();
         Subject subject = new Subject();
         CallbackHandler callback = new MockCallbackHandler(null, null);
         CallbackHandler callback = new MockCallbackHandler(null, null);
@@ -305,8 +290,7 @@ public class JbossAcegiLoginModuleTests extends TestCase {
         JbossAcegiLoginModule adapter = new JbossAcegiLoginModule();
         JbossAcegiLoginModule adapter = new JbossAcegiLoginModule();
         Properties props = new Properties();
         Properties props = new Properties();
         props.put("key", ADAPTER_KEY);
         props.put("key", ADAPTER_KEY);
-        props.put("appContextLocation",
-            "org/acegisecurity/adapters/adaptertest-valid.xml");
+        props.put("appContextLocation", "org/acegisecurity/adapters/adaptertest-valid.xml");
 
 
         Subject subject = new Subject();
         Subject subject = new Subject();
         CallbackHandler callback = new MockCallbackHandler(null, "kangaroo");
         CallbackHandler callback = new MockCallbackHandler(null, "kangaroo");
@@ -325,8 +309,7 @@ public class JbossAcegiLoginModuleTests extends TestCase {
         JbossAcegiLoginModule adapter = new JbossAcegiLoginModule();
         JbossAcegiLoginModule adapter = new JbossAcegiLoginModule();
         Properties props = new Properties();
         Properties props = new Properties();
         props.put("key", ADAPTER_KEY);
         props.put("key", ADAPTER_KEY);
-        props.put("appContextLocation",
-            "org/acegisecurity/adapters/adaptertest-valid.xml");
+        props.put("appContextLocation", "org/acegisecurity/adapters/adaptertest-valid.xml");
 
 
         Subject subject = new Subject();
         Subject subject = new Subject();
         CallbackHandler callback = new MockCallbackHandler("marissa", "koala");
         CallbackHandler callback = new MockCallbackHandler("marissa", "koala");
@@ -342,7 +325,7 @@ public class JbossAcegiLoginModuleTests extends TestCase {
         assertTrue(roles.isMember(new SimplePrincipal("ROLE_SUPERVISOR")));
         assertTrue(roles.isMember(new SimplePrincipal("ROLE_SUPERVISOR")));
     }
     }
 
 
-    //~ Inner Classes ==========================================================
+    //~ Inner Classes ==================================================================================================
 
 
     private class MockCallbackHandler implements CallbackHandler {
     private class MockCallbackHandler implements CallbackHandler {
         private String password;
         private String password;
@@ -357,8 +340,7 @@ public class JbossAcegiLoginModuleTests extends TestCase {
             super();
             super();
         }
         }
 
 
-        public void handle(Callback[] callbacks)
-            throws IOException, UnsupportedCallbackException {
+        public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
             for (int i = 0; i < callbacks.length; i++) {
             for (int i = 0; i < callbacks.length; i++) {
                 if (callbacks[i] instanceof NameCallback) {
                 if (callbacks[i] instanceof NameCallback) {
                     ((NameCallback) callbacks[i]).setName(username);
                     ((NameCallback) callbacks[i]).setName(username);
@@ -366,8 +348,7 @@ public class JbossAcegiLoginModuleTests extends TestCase {
                     if (this.password == null) {
                     if (this.password == null) {
                         ((PasswordCallback) callbacks[i]).setPassword(null);
                         ((PasswordCallback) callbacks[i]).setPassword(null);
                     } else {
                     } else {
-                        ((PasswordCallback) callbacks[i]).setPassword(password
-                            .toCharArray());
+                        ((PasswordCallback) callbacks[i]).setPassword(password.toCharArray());
                     }
                     }
                 } else {
                 } else {
                     throw new UnsupportedCallbackException(callbacks[i]);
                     throw new UnsupportedCallbackException(callbacks[i]);

+ 38 - 45
adapters/jboss/src/test/java/org/acegisecurity/adapters/jboss/JbossIntegrationFilterTests.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -53,7 +53,7 @@ import javax.servlet.ServletResponse;
  * @version $Id$
  * @version $Id$
  */
  */
 public class JbossIntegrationFilterTests extends TestCase {
 public class JbossIntegrationFilterTests extends TestCase {
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
     public JbossIntegrationFilterTests() {
     public JbossIntegrationFilterTests() {
         super();
         super();
@@ -63,35 +63,55 @@ public class JbossIntegrationFilterTests extends TestCase {
         super(arg0);
         super(arg0);
     }
     }
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
+
+    private void executeFilterInContainerSimulator(FilterConfig filterConfig, Filter filter, ServletRequest request,
+        ServletResponse response, FilterChain filterChain)
+        throws ServletException, IOException {
+        filter.init(filterConfig);
+        filter.doFilter(request, response, filterChain);
+        filter.destroy();
+    }
 
 
     public static void main(String[] args) {
     public static void main(String[] args) {
         junit.textui.TestRunner.run(JbossIntegrationFilterTests.class);
         junit.textui.TestRunner.run(JbossIntegrationFilterTests.class);
     }
     }
 
 
+    private Subject makeIntoSubject(Principal principal) {
+        Set principals = new HashSet();
+        principals.add(principal);
+
+        return new Subject(false, principals, new HashSet(), new HashSet());
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        SecurityContextHolder.setContext(new SecurityContextImpl());
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        SecurityContextHolder.setContext(new SecurityContextImpl());
+    }
+
     public void testCorrectOperation() throws Exception {
     public void testCorrectOperation() throws Exception {
-        PrincipalAcegiUserToken principal = new PrincipalAcegiUserToken("key",
-                "someone", "password",
-                new GrantedAuthority[] {new GrantedAuthorityImpl("SOME_ROLE")},
-                null);
+        PrincipalAcegiUserToken principal = new PrincipalAcegiUserToken("key", "someone", "password",
+                new GrantedAuthority[] {new GrantedAuthorityImpl("SOME_ROLE")}, null);
 
 
-        JbossIntegrationFilter filter = new MockJbossIntegrationFilter(new MockInitialContext(
-                    makeIntoSubject(principal)));
+        JbossIntegrationFilter filter = new MockJbossIntegrationFilter(new MockInitialContext(makeIntoSubject(principal)));
 
 
         MockHttpServletRequest request = new MockHttpServletRequest();
         MockHttpServletRequest request = new MockHttpServletRequest();
         MockFilterChain chain = new MockFilterChain();
         MockFilterChain chain = new MockFilterChain();
 
 
         filter.doFilter(request, null, chain);
         filter.doFilter(request, null, chain);
 
 
-        assertEquals(principal,
-            SecurityContextHolder.getContext().getAuthentication());
+        assertEquals(principal, SecurityContextHolder.getContext().getAuthentication());
         SecurityContextHolder.setContext(new SecurityContextImpl());
         SecurityContextHolder.setContext(new SecurityContextImpl());
     }
     }
 
 
     public void testReturnsNullIfContextReturnsSomethingOtherThanASubject()
     public void testReturnsNullIfContextReturnsSomethingOtherThanASubject()
         throws Exception {
         throws Exception {
-        JbossIntegrationFilter filter = new MockJbossIntegrationFilter(new MockInitialContext(
-                    "THIS_IS_NOT_A_SUBJECT"));
+        JbossIntegrationFilter filter = new MockJbossIntegrationFilter(new MockInitialContext("THIS_IS_NOT_A_SUBJECT"));
 
 
         MockHttpServletRequest request = new MockHttpServletRequest();
         MockHttpServletRequest request = new MockHttpServletRequest();
         MockFilterChain chain = new MockFilterChain();
         MockFilterChain chain = new MockFilterChain();
@@ -102,8 +122,7 @@ public class JbossIntegrationFilterTests extends TestCase {
 
 
     public void testReturnsNullIfInitialContextHasNullPrincipal()
     public void testReturnsNullIfInitialContextHasNullPrincipal()
         throws Exception {
         throws Exception {
-        JbossIntegrationFilter filter = new MockJbossIntegrationFilter(new MockInitialContext(
-                    makeIntoSubject(null)));
+        JbossIntegrationFilter filter = new MockJbossIntegrationFilter(new MockInitialContext(makeIntoSubject(null)));
 
 
         MockHttpServletRequest request = new MockHttpServletRequest();
         MockHttpServletRequest request = new MockHttpServletRequest();
         MockFilterChain chain = new MockFilterChain();
         MockFilterChain chain = new MockFilterChain();
@@ -114,8 +133,7 @@ public class JbossIntegrationFilterTests extends TestCase {
 
 
     public void testReturnsNullIfInitialContextHasNullSubject()
     public void testReturnsNullIfInitialContextHasNullSubject()
         throws Exception {
         throws Exception {
-        JbossIntegrationFilter filter = new MockJbossIntegrationFilter(new MockInitialContext(
-                    null));
+        JbossIntegrationFilter filter = new MockJbossIntegrationFilter(new MockInitialContext(null));
 
 
         MockHttpServletRequest request = new MockHttpServletRequest();
         MockHttpServletRequest request = new MockHttpServletRequest();
         MockFilterChain chain = new MockFilterChain();
         MockFilterChain chain = new MockFilterChain();
@@ -137,8 +155,8 @@ public class JbossIntegrationFilterTests extends TestCase {
 
 
     public void testReturnsNullIfPrincipalNotAnAuthenticationImplementation()
     public void testReturnsNullIfPrincipalNotAnAuthenticationImplementation()
         throws Exception {
         throws Exception {
-        JbossIntegrationFilter filter = new MockJbossIntegrationFilter(new MockInitialContext(
-                    makeIntoSubject(new Principal() {
+        JbossIntegrationFilter filter = new MockJbossIntegrationFilter(new MockInitialContext(makeIntoSubject(
+                        new Principal() {
                     public String getName() {
                     public String getName() {
                         return "MockPrincipal";
                         return "MockPrincipal";
                     }
                     }
@@ -157,32 +175,7 @@ public class JbossIntegrationFilterTests extends TestCase {
         assertTrue(filter.getLookupContext() instanceof Context);
         assertTrue(filter.getLookupContext() instanceof Context);
     }
     }
 
 
-    protected void setUp() throws Exception {
-        super.setUp();
-        SecurityContextHolder.setContext(new SecurityContextImpl());
-    }
-
-    protected void tearDown() throws Exception {
-        super.tearDown();
-        SecurityContextHolder.setContext(new SecurityContextImpl());
-    }
-
-    private void executeFilterInContainerSimulator(FilterConfig filterConfig,
-        Filter filter, ServletRequest request, ServletResponse response,
-        FilterChain filterChain) throws ServletException, IOException {
-        filter.init(filterConfig);
-        filter.doFilter(request, response, filterChain);
-        filter.destroy();
-    }
-
-    private Subject makeIntoSubject(Principal principal) {
-        Set principals = new HashSet();
-        principals.add(principal);
-
-        return new Subject(false, principals, new HashSet(), new HashSet());
-    }
-
-    //~ Inner Classes ==========================================================
+    //~ Inner Classes ==================================================================================================
 
 
     private class MockFilterChain implements FilterChain {
     private class MockFilterChain implements FilterChain {
         public void doFilter(ServletRequest arg0, ServletResponse arg1)
         public void doFilter(ServletRequest arg0, ServletResponse arg1)

+ 21 - 21
adapters/jboss/src/test/java/org/acegisecurity/adapters/jboss/MockInitialContext.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -25,18 +25,18 @@ import javax.naming.NamingException;
 
 
 
 
 /**
 /**
- * Mocks a <code>javax.naming.Context</code> and returns an <code>Object</code>
- * when queried for address <code>java:comp/env/security/subject</code>.
+ * Mocks a <code>javax.naming.Context</code> and returns an <code>Object</code> when queried for address
+ * <code>java:comp/env/security/subject</code>.
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public class MockInitialContext implements Context {
 public class MockInitialContext implements Context {
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private Object object;
     private Object object;
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
     public MockInitialContext(Object object) {
     public MockInitialContext(Object object) {
         this.object = object;
         this.object = object;
@@ -46,63 +46,63 @@ public class MockInitialContext implements Context {
         super();
         super();
     }
     }
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
-    public Hashtable getEnvironment() throws NamingException {
+    public Object addToEnvironment(String propName, Object propVal)
+        throws NamingException {
         throw new UnsupportedOperationException("mock method not implemented");
         throw new UnsupportedOperationException("mock method not implemented");
     }
     }
 
 
-    public String getNameInNamespace() throws NamingException {
+    public void bind(String name, Object obj) throws NamingException {
         throw new UnsupportedOperationException("mock method not implemented");
         throw new UnsupportedOperationException("mock method not implemented");
     }
     }
 
 
-    public NameParser getNameParser(String name) throws NamingException {
+    public void bind(Name name, Object obj) throws NamingException {
         throw new UnsupportedOperationException("mock method not implemented");
         throw new UnsupportedOperationException("mock method not implemented");
     }
     }
 
 
-    public NameParser getNameParser(Name name) throws NamingException {
+    public void close() throws NamingException {
         throw new UnsupportedOperationException("mock method not implemented");
         throw new UnsupportedOperationException("mock method not implemented");
     }
     }
 
 
-    public Object addToEnvironment(String propName, Object propVal)
+    public String composeName(String name, String prefix)
         throws NamingException {
         throws NamingException {
         throw new UnsupportedOperationException("mock method not implemented");
         throw new UnsupportedOperationException("mock method not implemented");
     }
     }
 
 
-    public void bind(String name, Object obj) throws NamingException {
+    public Name composeName(Name name, Name prefix) throws NamingException {
         throw new UnsupportedOperationException("mock method not implemented");
         throw new UnsupportedOperationException("mock method not implemented");
     }
     }
 
 
-    public void bind(Name name, Object obj) throws NamingException {
+    public Context createSubcontext(String name) throws NamingException {
         throw new UnsupportedOperationException("mock method not implemented");
         throw new UnsupportedOperationException("mock method not implemented");
     }
     }
 
 
-    public void close() throws NamingException {
+    public Context createSubcontext(Name name) throws NamingException {
         throw new UnsupportedOperationException("mock method not implemented");
         throw new UnsupportedOperationException("mock method not implemented");
     }
     }
 
 
-    public String composeName(String name, String prefix)
-        throws NamingException {
+    public void destroySubcontext(String name) throws NamingException {
         throw new UnsupportedOperationException("mock method not implemented");
         throw new UnsupportedOperationException("mock method not implemented");
     }
     }
 
 
-    public Name composeName(Name name, Name prefix) throws NamingException {
+    public void destroySubcontext(Name name) throws NamingException {
         throw new UnsupportedOperationException("mock method not implemented");
         throw new UnsupportedOperationException("mock method not implemented");
     }
     }
 
 
-    public Context createSubcontext(String name) throws NamingException {
+    public Hashtable getEnvironment() throws NamingException {
         throw new UnsupportedOperationException("mock method not implemented");
         throw new UnsupportedOperationException("mock method not implemented");
     }
     }
 
 
-    public Context createSubcontext(Name name) throws NamingException {
+    public String getNameInNamespace() throws NamingException {
         throw new UnsupportedOperationException("mock method not implemented");
         throw new UnsupportedOperationException("mock method not implemented");
     }
     }
 
 
-    public void destroySubcontext(String name) throws NamingException {
+    public NameParser getNameParser(String name) throws NamingException {
         throw new UnsupportedOperationException("mock method not implemented");
         throw new UnsupportedOperationException("mock method not implemented");
     }
     }
 
 
-    public void destroySubcontext(Name name) throws NamingException {
+    public NameParser getNameParser(Name name) throws NamingException {
         throw new UnsupportedOperationException("mock method not implemented");
         throw new UnsupportedOperationException("mock method not implemented");
     }
     }
 
 

+ 6 - 6
adapters/jboss/src/test/java/org/acegisecurity/adapters/jboss/MockJbossIntegrationFilter.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -20,18 +20,18 @@ import javax.naming.NamingException;
 
 
 
 
 /**
 /**
- * Provides mock of <code>JbossIntegrationFilter</code>, using a lookup
- * <code>Context</code> provided in the constructor.
+ * Provides mock of <code>JbossIntegrationFilter</code>, using a lookup <code>Context</code> provided in the
+ * constructor.
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public class MockJbossIntegrationFilter extends JbossIntegrationFilter {
 public class MockJbossIntegrationFilter extends JbossIntegrationFilter {
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private Context context;
     private Context context;
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
     public MockJbossIntegrationFilter(Context context) {
     public MockJbossIntegrationFilter(Context context) {
         this.context = context;
         this.context = context;
@@ -41,7 +41,7 @@ public class MockJbossIntegrationFilter extends JbossIntegrationFilter {
         super();
         super();
     }
     }
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     protected Context getLookupContext() throws NamingException {
     protected Context getLookupContext() throws NamingException {
         return this.context;
         return this.context;

+ 30 - 42
adapters/jetty/src/main/java/org/acegisecurity/adapters/jetty/JettyAcegiUserRealm.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package org.acegisecurity.adapters.jetty;
 import org.acegisecurity.Authentication;
 import org.acegisecurity.Authentication;
 import org.acegisecurity.AuthenticationException;
 import org.acegisecurity.AuthenticationException;
 import org.acegisecurity.AuthenticationManager;
 import org.acegisecurity.AuthenticationManager;
+
 import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
 import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
 
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.Log;
@@ -33,32 +34,27 @@ import java.util.Map;
 
 
 
 
 /**
 /**
- * Adapter to enable Jetty to authenticate via the Acegi Security System for
- * Spring.
- * 
- * <p>
- * Returns a {@link JettyAcegiUserToken} to Jetty's authentication system,
- * which is subsequently available via
- * <code>HttpServletRequest.getUserPrincipal()</code>.
- * </p>
+ * Adapter to enable Jetty to authenticate via the Acegi Security System for Spring.<p>Returns a {@link
+ * JettyAcegiUserToken} to Jetty's authentication system, which is subsequently available via
+ * <code>HttpServletRequest.getUserPrincipal()</code>.</p>
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public final class JettyAcegiUserRealm implements UserRealm {
 public final class JettyAcegiUserRealm implements UserRealm {
-    //~ Static fields/initializers =============================================
+    //~ Static fields/initializers =====================================================================================
 
 
     private static final Log logger = LogFactory.getLog(JettyAcegiUserRealm.class);
     private static final Log logger = LogFactory.getLog(JettyAcegiUserRealm.class);
 
 
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private AuthenticationManager authenticationManager;
     private AuthenticationManager authenticationManager;
     private String key;
     private String key;
     private String realm;
     private String realm;
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
-    /**
+/**
      * Construct a <code>SpringUserRealm</code>.
      * Construct a <code>SpringUserRealm</code>.
      *
      *
      * @param realm the name of the authentication realm (within Jetty)
      * @param realm the name of the authentication realm (within Jetty)
@@ -68,8 +64,7 @@ public final class JettyAcegiUserRealm implements UserRealm {
      *
      *
      * @throws IllegalArgumentException DOCUMENT ME!
      * @throws IllegalArgumentException DOCUMENT ME!
      */
      */
-    public JettyAcegiUserRealm(String realm, String providerKey,
-        String appContextLocation) {
+    public JettyAcegiUserRealm(String realm, String providerKey, String appContextLocation) {
         this.realm = realm;
         this.realm = realm;
         this.key = providerKey;
         this.key = providerKey;
 
 
@@ -82,13 +77,11 @@ public final class JettyAcegiUserRealm implements UserRealm {
         }
         }
 
 
         if ((appContextLocation == null) || "".equals(appContextLocation)) {
         if ((appContextLocation == null) || "".equals(appContextLocation)) {
-            throw new IllegalArgumentException(
-                "appContextLocation must be specified");
+            throw new IllegalArgumentException("appContextLocation must be specified");
         }
         }
 
 
         if (Thread.currentThread().getContextClassLoader().getResource(appContextLocation) == null) {
         if (Thread.currentThread().getContextClassLoader().getResource(appContextLocation) == null) {
-            throw new IllegalArgumentException("Cannot locate "
-                + appContextLocation);
+            throw new IllegalArgumentException("Cannot locate " + appContextLocation);
         }
         }
 
 
         ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(appContextLocation);
         ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(appContextLocation);
@@ -107,24 +100,9 @@ public final class JettyAcegiUserRealm implements UserRealm {
         throw new IllegalArgumentException("Cannot use default constructor");
         throw new IllegalArgumentException("Cannot use default constructor");
     }
     }
 
 
-    //~ Methods ================================================================
-
-    public AuthenticationManager getAuthenticationManager() {
-        return authenticationManager;
-    }
-
-    /**
-     * Accesses the realm name.
-     *
-     * @return the name of the realm as defined when
-     *         <code>SpringUserRealm</code> was created
-     */
-    public String getName() {
-        return this.realm;
-    }
+    //~ Methods ========================================================================================================
 
 
-    public UserPrincipal authenticate(String username, Object password,
-        HttpRequest httpRequest) {
+    public UserPrincipal authenticate(String username, Object password, HttpRequest httpRequest) {
         if (username == null) {
         if (username == null) {
             return null;
             return null;
         }
         }
@@ -133,23 +111,20 @@ public final class JettyAcegiUserRealm implements UserRealm {
             password = "";
             password = "";
         }
         }
 
 
-        Authentication request = new UsernamePasswordAuthenticationToken(username
-                .toString(), password.toString());
+        Authentication request = new UsernamePasswordAuthenticationToken(username.toString(), password.toString());
         Authentication response = null;
         Authentication response = null;
 
 
         try {
         try {
             response = authenticationManager.authenticate(request);
             response = authenticationManager.authenticate(request);
         } catch (AuthenticationException failed) {
         } catch (AuthenticationException failed) {
             if (logger.isDebugEnabled()) {
             if (logger.isDebugEnabled()) {
-                logger.debug("Authentication request for user: " + username
-                    + " failed: " + failed.toString());
+                logger.debug("Authentication request for user: " + username + " failed: " + failed.toString());
             }
             }
 
 
             return null;
             return null;
         }
         }
 
 
-        return new JettyAcegiUserToken(this.key,
-            response.getPrincipal().toString(),
+        return new JettyAcegiUserToken(this.key, response.getPrincipal().toString(),
             response.getCredentials().toString(), response.getAuthorities());
             response.getCredentials().toString(), response.getAuthorities());
     }
     }
 
 
@@ -157,6 +132,19 @@ public final class JettyAcegiUserRealm implements UserRealm {
         // No action required
         // No action required
     }
     }
 
 
+    public AuthenticationManager getAuthenticationManager() {
+        return authenticationManager;
+    }
+
+    /**
+     * Accesses the realm name.
+     *
+     * @return the name of the realm as defined when <code>SpringUserRealm</code> was created
+     */
+    public String getName() {
+        return this.realm;
+    }
+
     public void logout(UserPrincipal arg0) {
     public void logout(UserPrincipal arg0) {
         // Not supported
         // Not supported
     }
     }

+ 7 - 8
adapters/jetty/src/main/java/org/acegisecurity/adapters/jetty/JettyAcegiUserToken.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
 package org.acegisecurity.adapters.jetty;
 package org.acegisecurity.adapters.jetty;
 
 
 import org.acegisecurity.GrantedAuthority;
 import org.acegisecurity.GrantedAuthority;
+
 import org.acegisecurity.adapters.AbstractAdapterAuthenticationToken;
 import org.acegisecurity.adapters.AbstractAdapterAuthenticationToken;
 
 
 import org.mortbay.http.UserPrincipal;
 import org.mortbay.http.UserPrincipal;
@@ -27,17 +28,15 @@ import org.mortbay.http.UserPrincipal;
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
-public class JettyAcegiUserToken extends AbstractAdapterAuthenticationToken
-    implements UserPrincipal {
-    //~ Instance fields ========================================================
+public class JettyAcegiUserToken extends AbstractAdapterAuthenticationToken implements UserPrincipal {
+    //~ Instance fields ================================================================================================
 
 
     private String password;
     private String password;
     private String username;
     private String username;
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
-    public JettyAcegiUserToken(String key, String username, String password,
-        GrantedAuthority[] authorities) {
+    public JettyAcegiUserToken(String key, String username, String password, GrantedAuthority[] authorities) {
         super(key, authorities);
         super(key, authorities);
         this.username = username;
         this.username = username;
         this.password = password;
         this.password = password;
@@ -47,7 +46,7 @@ public class JettyAcegiUserToken extends AbstractAdapterAuthenticationToken
         throw new IllegalArgumentException("Cannot use default constructor");
         throw new IllegalArgumentException("Cannot use default constructor");
     }
     }
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     public Object getCredentials() {
     public Object getCredentials() {
         return this.password;
         return this.password;

+ 26 - 34
adapters/jetty/src/test/java/org/acegisecurity/adapters/jetty/JettyAcegiUserRealmTests.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -27,12 +27,12 @@ import org.mortbay.http.UserPrincipal;
  * @version $Id$
  * @version $Id$
  */
  */
 public class JettyAcegiUserRealmTests extends TestCase {
 public class JettyAcegiUserRealmTests extends TestCase {
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private final String ADAPTER_KEY = "my_key";
     private final String ADAPTER_KEY = "my_key";
     private final String REALM_NAME = "Acegi Powered Realm";
     private final String REALM_NAME = "Acegi Powered Realm";
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
     public JettyAcegiUserRealmTests() {
     public JettyAcegiUserRealmTests() {
         super();
         super();
@@ -42,16 +42,23 @@ public class JettyAcegiUserRealmTests extends TestCase {
         super(arg0);
         super(arg0);
     }
     }
 
 
-    //~ Methods ================================================================
-
-    public final void setUp() throws Exception {
-        super.setUp();
-    }
+    //~ Methods ========================================================================================================
 
 
     public static void main(String[] args) {
     public static void main(String[] args) {
         junit.textui.TestRunner.run(JettyAcegiUserRealmTests.class);
         junit.textui.TestRunner.run(JettyAcegiUserRealmTests.class);
     }
     }
 
 
+    private JettyAcegiUserRealm makeAdapter(String fileName)
+        throws Exception {
+        String useFile = "org/acegisecurity/adapters/" + fileName;
+
+        return new JettyAcegiUserRealm(REALM_NAME, ADAPTER_KEY, useFile);
+    }
+
+    public final void setUp() throws Exception {
+        super.setUp();
+    }
+
     public void testAdapterAbortsIfAppContextDoesNotContainAnAuthenticationBean()
     public void testAdapterAbortsIfAppContextDoesNotContainAnAuthenticationBean()
         throws Exception {
         throws Exception {
         try {
         try {
@@ -69,16 +76,14 @@ public class JettyAcegiUserRealmTests extends TestCase {
             new JettyAcegiUserRealm(REALM_NAME, ADAPTER_KEY, null);
             new JettyAcegiUserRealm(REALM_NAME, ADAPTER_KEY, null);
             fail("Should have thrown IllegalArgumentException");
             fail("Should have thrown IllegalArgumentException");
         } catch (IllegalArgumentException expected) {
         } catch (IllegalArgumentException expected) {
-            assertEquals("appContextLocation must be specified",
-                expected.getMessage());
+            assertEquals("appContextLocation must be specified", expected.getMessage());
         }
         }
 
 
         try {
         try {
             new JettyAcegiUserRealm(REALM_NAME, ADAPTER_KEY, "");
             new JettyAcegiUserRealm(REALM_NAME, ADAPTER_KEY, "");
             fail("Should have thrown IllegalArgumentException");
             fail("Should have thrown IllegalArgumentException");
         } catch (IllegalArgumentException expected) {
         } catch (IllegalArgumentException expected) {
-            assertEquals("appContextLocation must be specified",
-                expected.getMessage());
+            assertEquals("appContextLocation must be specified", expected.getMessage());
         }
         }
     }
     }
 
 
@@ -118,8 +123,7 @@ public class JettyAcegiUserRealmTests extends TestCase {
     public void testAdapterAbortsWithIncorrectApplicationContextLocation()
     public void testAdapterAbortsWithIncorrectApplicationContextLocation()
         throws Exception {
         throws Exception {
         try {
         try {
-            new JettyAcegiUserRealm(REALM_NAME, ADAPTER_KEY,
-                "SOME_INVALID_LOCATION");
+            new JettyAcegiUserRealm(REALM_NAME, ADAPTER_KEY, "SOME_INVALID_LOCATION");
             fail("Should have thrown IllegalArgumentException");
             fail("Should have thrown IllegalArgumentException");
         } catch (IllegalArgumentException expected) {
         } catch (IllegalArgumentException expected) {
             assertTrue(expected.getMessage().startsWith("Cannot locate"));
             assertTrue(expected.getMessage().startsWith("Cannot locate"));
@@ -160,10 +164,8 @@ public class JettyAcegiUserRealmTests extends TestCase {
         JettyAcegiUserToken castResult = (JettyAcegiUserToken) result;
         JettyAcegiUserToken castResult = (JettyAcegiUserToken) result;
         assertEquals("marissa", castResult.getPrincipal());
         assertEquals("marissa", castResult.getPrincipal());
         assertEquals("koala", castResult.getCredentials());
         assertEquals("koala", castResult.getCredentials());
-        assertEquals("ROLE_TELLER",
-            castResult.getAuthorities()[0].getAuthority());
-        assertEquals("ROLE_SUPERVISOR",
-            castResult.getAuthorities()[1].getAuthority());
+        assertEquals("ROLE_TELLER", castResult.getAuthorities()[0].getAuthority());
+        assertEquals("ROLE_SUPERVISOR", castResult.getAuthorities()[1].getAuthority());
         assertEquals(ADAPTER_KEY.hashCode(), castResult.getKeyHash());
         assertEquals(ADAPTER_KEY.hashCode(), castResult.getKeyHash());
     }
     }
 
 
@@ -217,29 +219,19 @@ public class JettyAcegiUserRealmTests extends TestCase {
         assertEquals(user, adapter.pushRole(user, "SOME_ROLE"));
         assertEquals(user, adapter.pushRole(user, "SOME_ROLE"));
     }
     }
 
 
-    private JettyAcegiUserRealm makeAdapter(String fileName)
-        throws Exception {
-        String useFile = "org/acegisecurity/adapters/" + fileName;
-
-        return new JettyAcegiUserRealm(REALM_NAME, ADAPTER_KEY, useFile);
-    }
-
-    //~ Inner Classes ==========================================================
+    //~ Inner Classes ==================================================================================================
 
 
     private class MockUserPrincipal implements UserPrincipal {
     private class MockUserPrincipal implements UserPrincipal {
-        public boolean isAuthenticated() {
-            throw new UnsupportedOperationException(
-                "mock method not implemented");
+        public String getName() {
+            throw new UnsupportedOperationException("mock method not implemented");
         }
         }
 
 
-        public String getName() {
-            throw new UnsupportedOperationException(
-                "mock method not implemented");
+        public boolean isAuthenticated() {
+            throw new UnsupportedOperationException("mock method not implemented");
         }
         }
 
 
         public boolean isUserInRole(String arg0) {
         public boolean isUserInRole(String arg0) {
-            throw new UnsupportedOperationException(
-                "mock method not implemented");
+            throw new UnsupportedOperationException("mock method not implemented");
         }
         }
     }
     }
 }
 }

+ 9 - 11
adapters/jetty/src/test/java/org/acegisecurity/adapters/jetty/JettyAcegiUserTokenTests.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@ import org.acegisecurity.GrantedAuthorityImpl;
  * @version $Id$
  * @version $Id$
  */
  */
 public class JettyAcegiUserTokenTests extends TestCase {
 public class JettyAcegiUserTokenTests extends TestCase {
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
     public JettyAcegiUserTokenTests() {
     public JettyAcegiUserTokenTests() {
         super();
         super();
@@ -38,21 +38,19 @@ public class JettyAcegiUserTokenTests extends TestCase {
         super(arg0);
         super(arg0);
     }
     }
 
 
-    //~ Methods ================================================================
-
-    public final void setUp() throws Exception {
-        super.setUp();
-    }
+    //~ Methods ========================================================================================================
 
 
     public static void main(String[] args) {
     public static void main(String[] args) {
         junit.textui.TestRunner.run(JettyAcegiUserTokenTests.class);
         junit.textui.TestRunner.run(JettyAcegiUserTokenTests.class);
     }
     }
 
 
+    public final void setUp() throws Exception {
+        super.setUp();
+    }
+
     public void testGetters() throws Exception {
     public void testGetters() throws Exception {
-        JettyAcegiUserToken token = new JettyAcegiUserToken("my_password",
-                "Test", "Password",
-                new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_ONE"), new GrantedAuthorityImpl(
-                        "ROLE_TWO")});
+        JettyAcegiUserToken token = new JettyAcegiUserToken("my_password", "Test", "Password",
+                new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_ONE"), new GrantedAuthorityImpl("ROLE_TWO")});
         assertEquals("Test", token.getPrincipal());
         assertEquals("Test", token.getPrincipal());
         assertEquals("Password", token.getCredentials());
         assertEquals("Password", token.getCredentials());
         assertEquals("my_password".hashCode(), token.getKeyHash());
         assertEquals("my_password".hashCode(), token.getKeyHash());

+ 36 - 49
adapters/resin/src/main/java/org/acegisecurity/adapters/resin/ResinAcegiAuthenticator.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -41,64 +41,34 @@ import javax.servlet.http.HttpServletResponse;
 
 
 
 
 /**
 /**
- * Adapter to enable Resin to authenticate via the Acegi Security System for
- * Spring.
- * 
- * <p>
- * Returns a {@link PrincipalAcegiUserToken} to Resin's authentication system,
- * which is subsequently available via
- * <code>HttpServletRequest.getUserPrincipal()</code>.
- * </p>
+ * Adapter to enable Resin to authenticate via the Acegi Security System for Spring.<p>Returns a {@link
+ * PrincipalAcegiUserToken} to Resin's authentication system, which is subsequently available via
+ * <code>HttpServletRequest.getUserPrincipal()</code>.</p>
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public class ResinAcegiAuthenticator extends AbstractAuthenticator {
 public class ResinAcegiAuthenticator extends AbstractAuthenticator {
-    //~ Static fields/initializers =============================================
+    //~ Static fields/initializers =====================================================================================
 
 
     private static final Log logger = LogFactory.getLog(ResinAcegiAuthenticator.class);
     private static final Log logger = LogFactory.getLog(ResinAcegiAuthenticator.class);
 
 
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private AuthenticationManager authenticationManager;
     private AuthenticationManager authenticationManager;
     private String appContextLocation;
     private String appContextLocation;
     private String key;
     private String key;
 
 
-    //~ Methods ================================================================
-
-    public void setAppContextLocation(String appContextLocation) {
-        this.appContextLocation = appContextLocation;
-    }
+    //~ Methods ========================================================================================================
 
 
     public String getAppContextLocation() {
     public String getAppContextLocation() {
         return appContextLocation;
         return appContextLocation;
     }
     }
 
 
-    public void setKey(String key) {
-        this.key = key;
-    }
-
     public String getKey() {
     public String getKey() {
         return key;
         return key;
     }
     }
 
 
-    public boolean isUserInRole(HttpServletRequest request,
-        HttpServletResponse response, ServletContext application,
-        Principal principal, String role) {
-        if (!(principal instanceof PrincipalAcegiUserToken)) {
-            if (logger.isWarnEnabled()) {
-                logger.warn(
-                    "Expected passed principal to be of type PrincipalAcegiUserToken");
-            }
-
-            return false;
-        }
-
-        PrincipalAcegiUserToken test = (PrincipalAcegiUserToken) principal;
-
-        return test.isUserInRole(role);
-    }
-
     public void init() throws ServletException {
     public void init() throws ServletException {
         super.init();
         super.init();
 
 
@@ -118,8 +88,7 @@ public class ResinAcegiAuthenticator extends AbstractAuthenticator {
         Map beans = ctx.getBeansOfType(AuthenticationManager.class, true, true);
         Map beans = ctx.getBeansOfType(AuthenticationManager.class, true, true);
 
 
         if (beans.size() == 0) {
         if (beans.size() == 0) {
-            throw new ServletException(
-                "Bean context must contain at least one bean of type AuthenticationManager");
+            throw new ServletException("Bean context must contain at least one bean of type AuthenticationManager");
         }
         }
 
 
         String beanName = (String) beans.keySet().iterator().next();
         String beanName = (String) beans.keySet().iterator().next();
@@ -127,6 +96,21 @@ public class ResinAcegiAuthenticator extends AbstractAuthenticator {
         logger.info("ResinAcegiAuthenticator Started");
         logger.info("ResinAcegiAuthenticator Started");
     }
     }
 
 
+    public boolean isUserInRole(HttpServletRequest request, HttpServletResponse response, ServletContext application,
+        Principal principal, String role) {
+        if (!(principal instanceof PrincipalAcegiUserToken)) {
+            if (logger.isWarnEnabled()) {
+                logger.warn("Expected passed principal to be of type PrincipalAcegiUserToken");
+            }
+
+            return false;
+        }
+
+        PrincipalAcegiUserToken test = (PrincipalAcegiUserToken) principal;
+
+        return test.isUserInRole(role);
+    }
+
     protected Principal loginImpl(String username, String credentials) {
     protected Principal loginImpl(String username, String credentials) {
         if (username == null) {
         if (username == null) {
             return null;
             return null;
@@ -136,30 +120,33 @@ public class ResinAcegiAuthenticator extends AbstractAuthenticator {
             credentials = "";
             credentials = "";
         }
         }
 
 
-        Authentication request = new UsernamePasswordAuthenticationToken(username,
-                credentials);
+        Authentication request = new UsernamePasswordAuthenticationToken(username, credentials);
         Authentication response = null;
         Authentication response = null;
 
 
         try {
         try {
             response = authenticationManager.authenticate(request);
             response = authenticationManager.authenticate(request);
         } catch (AuthenticationException failed) {
         } catch (AuthenticationException failed) {
             if (logger.isDebugEnabled()) {
             if (logger.isDebugEnabled()) {
-                logger.debug("Authentication request for user: " + username
-                    + " failed: " + failed.toString());
+                logger.debug("Authentication request for user: " + username + " failed: " + failed.toString());
             }
             }
 
 
             return null;
             return null;
         }
         }
 
 
-        return new PrincipalAcegiUserToken(this.key,
-            response.getPrincipal().toString(),
-            response.getCredentials().toString(), response.getAuthorities(),
-            response.getPrincipal());
+        return new PrincipalAcegiUserToken(this.key, response.getPrincipal().toString(),
+            response.getCredentials().toString(), response.getAuthorities(), response.getPrincipal());
     }
     }
 
 
-    protected Principal loginImpl(HttpServletRequest request,
-        HttpServletResponse response, ServletContext application,
+    protected Principal loginImpl(HttpServletRequest request, HttpServletResponse response, ServletContext application,
         String userName, String password) throws ServletException {
         String userName, String password) throws ServletException {
         return loginImpl(userName, password);
         return loginImpl(userName, password);
     }
     }
+
+    public void setAppContextLocation(String appContextLocation) {
+        this.appContextLocation = appContextLocation;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
 }
 }

+ 33 - 56
adapters/resin/src/test/java/org/acegisecurity/adapters/resin/ResinAcegiAuthenticatorTests.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -34,11 +34,11 @@ import javax.servlet.ServletException;
  * @version $Id$
  * @version $Id$
  */
  */
 public class ResinAcegiAuthenticatorTests extends TestCase {
 public class ResinAcegiAuthenticatorTests extends TestCase {
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private final String ADAPTER_KEY = "my_key";
     private final String ADAPTER_KEY = "my_key";
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
     public ResinAcegiAuthenticatorTests() {
     public ResinAcegiAuthenticatorTests() {
         super();
         super();
@@ -48,21 +48,20 @@ public class ResinAcegiAuthenticatorTests extends TestCase {
         super(arg0);
         super(arg0);
     }
     }
 
 
-    //~ Methods ================================================================
-
-    public final void setUp() throws Exception {
-        super.setUp();
-    }
+    //~ Methods ========================================================================================================
 
 
     public static void main(String[] args) {
     public static void main(String[] args) {
         junit.textui.TestRunner.run(ResinAcegiAuthenticatorTests.class);
         junit.textui.TestRunner.run(ResinAcegiAuthenticatorTests.class);
     }
     }
 
 
+    public final void setUp() throws Exception {
+        super.setUp();
+    }
+
     public void testAdapterAbortsIfAppContextDoesNotContainAnAuthenticationBean()
     public void testAdapterAbortsIfAppContextDoesNotContainAnAuthenticationBean()
         throws Exception {
         throws Exception {
         ResinAcegiAuthenticator adapter = new ResinAcegiAuthenticator();
         ResinAcegiAuthenticator adapter = new ResinAcegiAuthenticator();
-        adapter.setAppContextLocation(
-            "org/acegisecurity/adapters/adaptertest-invalid.xml");
+        adapter.setAppContextLocation("org/acegisecurity/adapters/adaptertest-invalid.xml");
         adapter.setKey(ADAPTER_KEY);
         adapter.setKey(ADAPTER_KEY);
 
 
         try {
         try {
@@ -83,8 +82,7 @@ public class ResinAcegiAuthenticatorTests extends TestCase {
             adapter.init();
             adapter.init();
             fail("Should have thrown ServletException");
             fail("Should have thrown ServletException");
         } catch (ServletException expected) {
         } catch (ServletException expected) {
-            assertEquals("appContextLocation must be defined",
-                expected.getMessage());
+            assertEquals("appContextLocation must be defined", expected.getMessage());
         }
         }
 
 
         adapter.setAppContextLocation("");
         adapter.setAppContextLocation("");
@@ -93,15 +91,13 @@ public class ResinAcegiAuthenticatorTests extends TestCase {
             adapter.init();
             adapter.init();
             fail("Should have thrown ServletException");
             fail("Should have thrown ServletException");
         } catch (ServletException expected) {
         } catch (ServletException expected) {
-            assertEquals("appContextLocation must be defined",
-                expected.getMessage());
+            assertEquals("appContextLocation must be defined", expected.getMessage());
         }
         }
     }
     }
 
 
     public void testAdapterAbortsIfNoKeySpecified() throws Exception {
     public void testAdapterAbortsIfNoKeySpecified() throws Exception {
         ResinAcegiAuthenticator adapter = new ResinAcegiAuthenticator();
         ResinAcegiAuthenticator adapter = new ResinAcegiAuthenticator();
-        adapter.setAppContextLocation(
-            "org/acegisecurity/adapters/adaptertest-valid.xml");
+        adapter.setAppContextLocation("org/acegisecurity/adapters/adaptertest-valid.xml");
 
 
         try {
         try {
             adapter.init();
             adapter.init();
@@ -136,8 +132,7 @@ public class ResinAcegiAuthenticatorTests extends TestCase {
 
 
     public void testAdapterStartsUpSuccess() throws Exception {
     public void testAdapterStartsUpSuccess() throws Exception {
         ResinAcegiAuthenticator adapter = new ResinAcegiAuthenticator();
         ResinAcegiAuthenticator adapter = new ResinAcegiAuthenticator();
-        adapter.setAppContextLocation(
-            "org/acegisecurity/adapters/adaptertest-valid.xml");
+        adapter.setAppContextLocation("org/acegisecurity/adapters/adaptertest-valid.xml");
         adapter.setKey(ADAPTER_KEY);
         adapter.setKey(ADAPTER_KEY);
         adapter.init();
         adapter.init();
         assertTrue(true);
         assertTrue(true);
@@ -146,8 +141,7 @@ public class ResinAcegiAuthenticatorTests extends TestCase {
     public void testAuthenticationFailsForIncorrectPassword()
     public void testAuthenticationFailsForIncorrectPassword()
         throws Exception {
         throws Exception {
         ResinAcegiAuthenticator adapter = new ResinAcegiAuthenticator();
         ResinAcegiAuthenticator adapter = new ResinAcegiAuthenticator();
-        adapter.setAppContextLocation(
-            "org/acegisecurity/adapters/adaptertest-valid.xml");
+        adapter.setAppContextLocation("org/acegisecurity/adapters/adaptertest-valid.xml");
         adapter.setKey(ADAPTER_KEY);
         adapter.setKey(ADAPTER_KEY);
         adapter.init();
         adapter.init();
         assertEquals(null, adapter.loginImpl("marissa", "kangaroo"));
         assertEquals(null, adapter.loginImpl("marissa", "kangaroo"));
@@ -156,8 +150,7 @@ public class ResinAcegiAuthenticatorTests extends TestCase {
     public void testAuthenticationFailsForIncorrectUserName()
     public void testAuthenticationFailsForIncorrectUserName()
         throws Exception {
         throws Exception {
         ResinAcegiAuthenticator adapter = new ResinAcegiAuthenticator();
         ResinAcegiAuthenticator adapter = new ResinAcegiAuthenticator();
-        adapter.setAppContextLocation(
-            "org/acegisecurity/adapters/adaptertest-valid.xml");
+        adapter.setAppContextLocation("org/acegisecurity/adapters/adaptertest-valid.xml");
         adapter.setKey(ADAPTER_KEY);
         adapter.setKey(ADAPTER_KEY);
         adapter.init();
         adapter.init();
         assertEquals(null, adapter.loginImpl("melissa", "koala"));
         assertEquals(null, adapter.loginImpl("melissa", "koala"));
@@ -165,8 +158,7 @@ public class ResinAcegiAuthenticatorTests extends TestCase {
 
 
     public void testAuthenticationSuccess() throws Exception {
     public void testAuthenticationSuccess() throws Exception {
         ResinAcegiAuthenticator adapter = new ResinAcegiAuthenticator();
         ResinAcegiAuthenticator adapter = new ResinAcegiAuthenticator();
-        adapter.setAppContextLocation(
-            "org/acegisecurity/adapters/adaptertest-valid.xml");
+        adapter.setAppContextLocation("org/acegisecurity/adapters/adaptertest-valid.xml");
         adapter.setKey(ADAPTER_KEY);
         adapter.setKey(ADAPTER_KEY);
         adapter.init();
         adapter.init();
 
 
@@ -179,23 +171,19 @@ public class ResinAcegiAuthenticatorTests extends TestCase {
         PrincipalAcegiUserToken castResult = (PrincipalAcegiUserToken) result;
         PrincipalAcegiUserToken castResult = (PrincipalAcegiUserToken) result;
         assertEquals("marissa", castResult.getPrincipal());
         assertEquals("marissa", castResult.getPrincipal());
         assertEquals("koala", castResult.getCredentials());
         assertEquals("koala", castResult.getCredentials());
-        assertEquals("ROLE_TELLER",
-            castResult.getAuthorities()[0].getAuthority());
-        assertEquals("ROLE_SUPERVISOR",
-            castResult.getAuthorities()[1].getAuthority());
+        assertEquals("ROLE_TELLER", castResult.getAuthorities()[0].getAuthority());
+        assertEquals("ROLE_SUPERVISOR", castResult.getAuthorities()[1].getAuthority());
         assertEquals(ADAPTER_KEY.hashCode(), castResult.getKeyHash());
         assertEquals(ADAPTER_KEY.hashCode(), castResult.getKeyHash());
     }
     }
 
 
     public void testAuthenticationSuccessUsingAlternateMethod()
     public void testAuthenticationSuccessUsingAlternateMethod()
         throws Exception {
         throws Exception {
         ResinAcegiAuthenticator adapter = new ResinAcegiAuthenticator();
         ResinAcegiAuthenticator adapter = new ResinAcegiAuthenticator();
-        adapter.setAppContextLocation(
-            "org/acegisecurity/adapters/adaptertest-valid.xml");
+        adapter.setAppContextLocation("org/acegisecurity/adapters/adaptertest-valid.xml");
         adapter.setKey(ADAPTER_KEY);
         adapter.setKey(ADAPTER_KEY);
         adapter.init();
         adapter.init();
 
 
-        Principal result = adapter.loginImpl(null, null, null, "marissa",
-                "koala");
+        Principal result = adapter.loginImpl(null, null, null, "marissa", "koala");
 
 
         if (!(result instanceof PrincipalAcegiUserToken)) {
         if (!(result instanceof PrincipalAcegiUserToken)) {
             fail("Should have returned PrincipalAcegiUserToken");
             fail("Should have returned PrincipalAcegiUserToken");
@@ -204,18 +192,15 @@ public class ResinAcegiAuthenticatorTests extends TestCase {
         PrincipalAcegiUserToken castResult = (PrincipalAcegiUserToken) result;
         PrincipalAcegiUserToken castResult = (PrincipalAcegiUserToken) result;
         assertEquals("marissa", castResult.getPrincipal());
         assertEquals("marissa", castResult.getPrincipal());
         assertEquals("koala", castResult.getCredentials());
         assertEquals("koala", castResult.getCredentials());
-        assertEquals("ROLE_TELLER",
-            castResult.getAuthorities()[0].getAuthority());
-        assertEquals("ROLE_SUPERVISOR",
-            castResult.getAuthorities()[1].getAuthority());
+        assertEquals("ROLE_TELLER", castResult.getAuthorities()[0].getAuthority());
+        assertEquals("ROLE_SUPERVISOR", castResult.getAuthorities()[1].getAuthority());
         assertEquals(ADAPTER_KEY.hashCode(), castResult.getKeyHash());
         assertEquals(ADAPTER_KEY.hashCode(), castResult.getKeyHash());
     }
     }
 
 
     public void testAuthenticationWithNullPasswordHandledGracefully()
     public void testAuthenticationWithNullPasswordHandledGracefully()
         throws Exception {
         throws Exception {
         ResinAcegiAuthenticator adapter = new ResinAcegiAuthenticator();
         ResinAcegiAuthenticator adapter = new ResinAcegiAuthenticator();
-        adapter.setAppContextLocation(
-            "org/acegisecurity/adapters/adaptertest-valid.xml");
+        adapter.setAppContextLocation("org/acegisecurity/adapters/adaptertest-valid.xml");
         adapter.setKey(ADAPTER_KEY);
         adapter.setKey(ADAPTER_KEY);
         adapter.init();
         adapter.init();
         assertEquals(null, adapter.loginImpl("marissa", null));
         assertEquals(null, adapter.loginImpl("marissa", null));
@@ -224,8 +209,7 @@ public class ResinAcegiAuthenticatorTests extends TestCase {
     public void testAuthenticationWithNullUserNameHandledGracefully()
     public void testAuthenticationWithNullUserNameHandledGracefully()
         throws Exception {
         throws Exception {
         ResinAcegiAuthenticator adapter = new ResinAcegiAuthenticator();
         ResinAcegiAuthenticator adapter = new ResinAcegiAuthenticator();
-        adapter.setAppContextLocation(
-            "org/acegisecurity/adapters/adaptertest-valid.xml");
+        adapter.setAppContextLocation("org/acegisecurity/adapters/adaptertest-valid.xml");
         adapter.setKey(ADAPTER_KEY);
         adapter.setKey(ADAPTER_KEY);
         adapter.init();
         adapter.init();
         assertEquals(null, adapter.loginImpl(null, "koala"));
         assertEquals(null, adapter.loginImpl(null, "koala"));
@@ -233,18 +217,15 @@ public class ResinAcegiAuthenticatorTests extends TestCase {
 
 
     public void testGetters() throws Exception {
     public void testGetters() throws Exception {
         ResinAcegiAuthenticator adapter = new ResinAcegiAuthenticator();
         ResinAcegiAuthenticator adapter = new ResinAcegiAuthenticator();
-        adapter.setAppContextLocation(
-            "org/acegisecurity/adapters/adaptertest-valid.xml");
+        adapter.setAppContextLocation("org/acegisecurity/adapters/adaptertest-valid.xml");
         adapter.setKey(ADAPTER_KEY);
         adapter.setKey(ADAPTER_KEY);
         assertEquals(ADAPTER_KEY, adapter.getKey());
         assertEquals(ADAPTER_KEY, adapter.getKey());
-        assertEquals("org/acegisecurity/adapters/adaptertest-valid.xml",
-            adapter.getAppContextLocation());
+        assertEquals("org/acegisecurity/adapters/adaptertest-valid.xml", adapter.getAppContextLocation());
     }
     }
 
 
     public void testHasRoleWithANullPrincipalFails() throws Exception {
     public void testHasRoleWithANullPrincipalFails() throws Exception {
         ResinAcegiAuthenticator adapter = new ResinAcegiAuthenticator();
         ResinAcegiAuthenticator adapter = new ResinAcegiAuthenticator();
-        adapter.setAppContextLocation(
-            "org/acegisecurity/adapters/adaptertest-valid.xml");
+        adapter.setAppContextLocation("org/acegisecurity/adapters/adaptertest-valid.xml");
         adapter.setKey(ADAPTER_KEY);
         adapter.setKey(ADAPTER_KEY);
         adapter.init();
         adapter.init();
         assertTrue(!adapter.isUserInRole(null, null, null, null, "ROLE_ONE"));
         assertTrue(!adapter.isUserInRole(null, null, null, null, "ROLE_ONE"));
@@ -253,8 +234,7 @@ public class ResinAcegiAuthenticatorTests extends TestCase {
     public void testHasRoleWithAPrincipalTheAdapterDidNotCreateFails()
     public void testHasRoleWithAPrincipalTheAdapterDidNotCreateFails()
         throws Exception {
         throws Exception {
         ResinAcegiAuthenticator adapter = new ResinAcegiAuthenticator();
         ResinAcegiAuthenticator adapter = new ResinAcegiAuthenticator();
-        adapter.setAppContextLocation(
-            "org/acegisecurity/adapters/adaptertest-valid.xml");
+        adapter.setAppContextLocation("org/acegisecurity/adapters/adaptertest-valid.xml");
         adapter.setKey(ADAPTER_KEY);
         adapter.setKey(ADAPTER_KEY);
         adapter.init();
         adapter.init();
         assertTrue(!adapter.isUserInRole(null, null, null,
         assertTrue(!adapter.isUserInRole(null, null, null,
@@ -267,18 +247,15 @@ public class ResinAcegiAuthenticatorTests extends TestCase {
 
 
     public void testHasRoleWithPrincipalAcegiUserToken()
     public void testHasRoleWithPrincipalAcegiUserToken()
         throws Exception {
         throws Exception {
-        PrincipalAcegiUserToken token = new PrincipalAcegiUserToken("KEY",
-                "Test", "Password",
-                new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_ONE"), new GrantedAuthorityImpl(
-                        "ROLE_TWO")}, null);
+        PrincipalAcegiUserToken token = new PrincipalAcegiUserToken("KEY", "Test", "Password",
+                new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_ONE"), new GrantedAuthorityImpl("ROLE_TWO")},
+                null);
         ResinAcegiAuthenticator adapter = new ResinAcegiAuthenticator();
         ResinAcegiAuthenticator adapter = new ResinAcegiAuthenticator();
-        adapter.setAppContextLocation(
-            "org/acegisecurity/adapters/adaptertest-valid.xml");
+        adapter.setAppContextLocation("org/acegisecurity/adapters/adaptertest-valid.xml");
         adapter.setKey(ADAPTER_KEY);
         adapter.setKey(ADAPTER_KEY);
         adapter.init();
         adapter.init();
         assertTrue(adapter.isUserInRole(null, null, null, token, "ROLE_ONE"));
         assertTrue(adapter.isUserInRole(null, null, null, token, "ROLE_ONE"));
         assertTrue(adapter.isUserInRole(null, null, null, token, "ROLE_ONE"));
         assertTrue(adapter.isUserInRole(null, null, null, token, "ROLE_ONE"));
-        assertTrue(!adapter.isUserInRole(null, null, null, token,
-                "ROLE_WE_DO_NOT_HAVE"));
+        assertTrue(!adapter.isUserInRole(null, null, null, token, "ROLE_WE_DO_NOT_HAVE"));
     }
     }
 }
 }

+ 2 - 4
core-tiger/src/main/java/org/acegisecurity/annotation/Secured.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -47,9 +47,7 @@ import java.lang.annotation.Target;
 @Inherited
 @Inherited
 @Documented
 @Documented
 public @interface Secured {
 public @interface Secured {
-    //~ Methods ================================================================
-
-    /**
+/**
      * Returns the list of security configuration attributes. 
      * Returns the list of security configuration attributes. 
      *   (i.e. ROLE_USER, ROLE_ADMIN etc.)
      *   (i.e. ROLE_USER, ROLE_ADMIN etc.)
      * @return String[] The secure method attributes 
      * @return String[] The secure method attributes 

+ 92 - 98
core-tiger/src/main/java/org/acegisecurity/annotation/SecurityAnnotationAttributes.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -12,54 +12,37 @@
  * See the License for the specific language governing permissions and
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * limitations under the License.
  */
  */
+
 package org.acegisecurity.annotation;
 package org.acegisecurity.annotation;
 
 
+import org.acegisecurity.SecurityConfig;
+
+import org.springframework.metadata.Attributes;
+
 import java.lang.annotation.Annotation;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.lang.reflect.Method;
+
 import java.util.Collection;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.HashSet;
 import java.util.Set;
 import java.util.Set;
 
 
-import org.acegisecurity.SecurityConfig;
-
-import org.springframework.metadata.Attributes;
 
 
 /**
 /**
- * Java 5 Annotation <code>Attributes</code> metadata implementation used for 
- * secure method interception. 
- * 
- * <p>This <code>Attributes</code> implementation will return security 
- * configuration for classes described using the <code>Secured</code> Java 5
- * annotation. 
- * 
- * <p>The <code>SecurityAnnotationAttributes</code> implementation can be used
- * to configure a <code>MethodDefinitionAttributes</code> and 
- * <code>MethodSecurityInterceptor</code> bean definition (see below).
- * 
- * <p>For example: 
- * <pre>
- * &lt;bean id="attributes" 
- *     class="org.acegisecurity.annotation.SecurityAnnotationAttributes"/>
- * 
- * &lt;bean id="objectDefinitionSource" 
- *     class="org.acegisecurity.intercept.method.MethodDefinitionAttributes">
- *     &lt;property name="attributes">
- *         &lt;ref local="attributes"/>
- *     &lt;/property>
- * &lt;/bean>
- * 
- * &lt;bean id="securityInterceptor" 
- *     class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">
- *      . . .
- *      &lt;property name="objectDefinitionSource">
- *          &lt;ref local="objectDefinitionSource"/>
- *      &lt;/property>
- * &lt;/bean>
- * </pre>
- * 
- * <p>These security annotations are similiar to the Commons Attributes
- * approach, however they are using Java 5 language-level metadata support.
+ * Java 5 Annotation <code>Attributes</code> metadata implementation used for  secure method interception.<p>This
+ * <code>Attributes</code> implementation will return security  configuration for classes described using the
+ * <code>Secured</code> Java 5 annotation.</p>
+ *  <p>The <code>SecurityAnnotationAttributes</code> implementation can be used to configure a
+ * <code>MethodDefinitionAttributes</code> and  <code>MethodSecurityInterceptor</code> bean definition (see below).</p>
+ *  <p>For example:<pre>&lt;bean id="attributes" 
+ *     class="org.acegisecurity.annotation.SecurityAnnotationAttributes"/>&lt;bean id="objectDefinitionSource" 
+ *     class="org.acegisecurity.intercept.method.MethodDefinitionAttributes">    &lt;property name="attributes">
+ *         &lt;ref local="attributes"/>    &lt;/property>&lt;/bean>&lt;bean id="securityInterceptor" 
+ *     class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">     . . .
+ *      &lt;property name="objectDefinitionSource">         &lt;ref local="objectDefinitionSource"/>     &lt;/property>
+ * &lt;/bean></pre></p>
+ *  <p>These security annotations are similiar to the Commons Attributes approach, however they are using Java 5
+ * language-level metadata support.</p>
  *
  *
  * @author Mark St.Godard
  * @author Mark St.Godard
  * @version $Id$
  * @version $Id$
@@ -67,66 +50,77 @@ import org.springframework.metadata.Attributes;
  * @see org.acegisecurity.annotation.Secured
  * @see org.acegisecurity.annotation.Secured
  */
  */
 public class SecurityAnnotationAttributes implements Attributes {
 public class SecurityAnnotationAttributes implements Attributes {
+    //~ Methods ========================================================================================================
+
+    /**
+     * Get the <code>Secured</code> attributes for a given target class.
+     *
+     * @param target The target method
+     *
+     * @return Collection of <code>SecurityConfig</code>
+     *
+     * @see Attributes#getAttributes
+     */
+    public Collection getAttributes(Class target) {
+        Set<SecurityConfig> attributes = new HashSet<SecurityConfig>();
+
+        for (Annotation annotation : target.getAnnotations()) {
+            // check for Secured annotations
+            if (annotation instanceof Secured) {
+                Secured attr = (Secured) annotation;
+
+                for (String auth : attr.value()) {
+                    attributes.add(new SecurityConfig(auth));
+                }
+
+                break;
+            }
+        }
+
+        return attributes;
+    }
+
+    public Collection getAttributes(Class clazz, Class filter) {
+        throw new UnsupportedOperationException("Unsupported operation");
+    }
+
+    /**
+     * Get the <code>Secured</code> attributes for a given target method.
+     *
+     * @param method The target method
+     *
+     * @return Collection of <code>SecurityConfig</code>
+     *
+     * @see Attributes#getAttributes
+     */
+    public Collection getAttributes(Method method) {
+        Set<SecurityConfig> attributes = new HashSet<SecurityConfig>();
+
+        for (Annotation annotation : method.getAnnotations()) {
+            // check for Secured annotations
+            if (annotation instanceof Secured) {
+                Secured attr = (Secured) annotation;
+
+                for (String auth : attr.value()) {
+                    attributes.add(new SecurityConfig(auth));
+                }
+
+                break;
+            }
+        }
+
+        return attributes;
+    }
+
+    public Collection getAttributes(Method method, Class clazz) {
+        throw new UnsupportedOperationException("Unsupported operation");
+    }
 
 
-	/**
-	 * Get the <code>Secured</code> attributes for a given target class.
-	 * @param method The target method
-	 * @return Collection of <code>SecurityConfig</code>
-	 * @see Attributes#getAttributes
-	 */
-	public Collection getAttributes(Class target) {
-
-		Set<SecurityConfig> attributes = new HashSet<SecurityConfig>();
-
-		for (Annotation annotation : target.getAnnotations()) {
-			// check for Secured annotations
-			if (annotation instanceof Secured) {
-				Secured attr = (Secured) annotation;
-				for (String auth : attr.value()) {
-					attributes.add(new SecurityConfig(auth));
-				}
-				break;
-			}
-		}
-		return attributes;
-	}
-
-	public Collection getAttributes(Class clazz, Class filter) {
-		throw new UnsupportedOperationException("Unsupported operation");
-	}
-
-	/**
-	 * Get the <code>Secured</code> attributes for a given target method.
-	 * @param method The target method
-	 * @return Collection of <code>SecurityConfig</code>
-	 * @see Attributes#getAttributes
-	 */	
-	public Collection getAttributes(Method method) {
-		Set<SecurityConfig> attributes = new HashSet<SecurityConfig>();
-
-		for (Annotation annotation : method.getAnnotations()) {
-			// check for Secured annotations
-			if (annotation instanceof Secured) {
-				Secured attr = (Secured) annotation;
-				for (String auth : attr.value()) {
-					attributes.add(new SecurityConfig(auth));
-				}
-				break;
-			}
-		}
-		return attributes;
-	}
-
-	public Collection getAttributes(Method method, Class clazz) {
-		throw new UnsupportedOperationException("Unsupported operation");
-	}
-
-	public Collection getAttributes(Field field) {
-		throw new UnsupportedOperationException("Unsupported operation");
-	}
-
-	public Collection getAttributes(Field field, Class clazz) {
-		throw new UnsupportedOperationException("Unsupported operation");
-	}
+    public Collection getAttributes(Field field) {
+        throw new UnsupportedOperationException("Unsupported operation");
+    }
 
 
+    public Collection getAttributes(Field field, Class clazz) {
+        throw new UnsupportedOperationException("Unsupported operation");
+    }
 }
 }

+ 4 - 4
core-tiger/src/test/java/org/acegisecurity/Entity.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -25,18 +25,18 @@ import org.springframework.util.Assert;
  * @version $Id$
  * @version $Id$
  */
  */
 public class Entity {
 public class Entity {
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     String info;
     String info;
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
     public Entity(String info) {
     public Entity(String info) {
         Assert.hasText(info, "Some information must be given!");
         Assert.hasText(info, "Some information must be given!");
         this.info = info;
         this.info = info;
     }
     }
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     public String getInfo() {
     public String getInfo() {
         return info;
         return info;

+ 8 - 8
core-tiger/src/test/java/org/acegisecurity/Organisation.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -22,23 +22,23 @@ package org.acegisecurity;
  * @version $Id$
  * @version $Id$
  */
  */
 public class Organisation extends Entity {
 public class Organisation extends Entity {
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private boolean active = true;
     private boolean active = true;
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
     public Organisation(String name) {
     public Organisation(String name) {
         super(name);
         super(name);
     }
     }
 
 
-    //~ Methods ================================================================
-
-    public boolean isActive() {
-        return this.active;
-    }
+    //~ Methods ========================================================================================================
 
 
     void deactive() {
     void deactive() {
         this.active = true;
         this.active = true;
     }
     }
+
+    public boolean isActive() {
+        return this.active;
+    }
 }
 }

+ 24 - 1
core-tiger/src/test/java/org/acegisecurity/OrganisationService.java

@@ -1,5 +1,28 @@
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.acegisecurity;
 package org.acegisecurity;
 
 
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+  */
 public interface OrganisationService extends Service<Organisation> {
 public interface OrganisationService extends Service<Organisation> {
-	public void deactive(Organisation org);
+    //~ Methods ========================================================================================================
+
+    public void deactive(Organisation org);
 }
 }

+ 25 - 4
core-tiger/src/test/java/org/acegisecurity/OrganisationServiceImpl.java

@@ -1,9 +1,30 @@
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.acegisecurity;
 package org.acegisecurity;
 
 
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+  */
 public class OrganisationServiceImpl extends ServiceImpl<Organisation> implements OrganisationService {
 public class OrganisationServiceImpl extends ServiceImpl<Organisation> implements OrganisationService {
+    //~ Methods ========================================================================================================
 
 
-	public void deactive(Organisation org) {
-		org.deactive();
-	}
-
+    public void deactive(Organisation org) {
+        org.deactive();
+    }
 }
 }

+ 8 - 8
core-tiger/src/test/java/org/acegisecurity/Person.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -22,23 +22,23 @@ package org.acegisecurity;
  * @version $Id$
  * @version $Id$
  */
  */
 public class Person extends Entity {
 public class Person extends Entity {
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private boolean active = true;
     private boolean active = true;
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
     public Person(String name) {
     public Person(String name) {
         super(name);
         super(name);
     }
     }
 
 
-    //~ Methods ================================================================
-
-    public boolean isActive() {
-        return this.active;
-    }
+    //~ Methods ========================================================================================================
 
 
     void deactive() {
     void deactive() {
         this.active = true;
         this.active = true;
     }
     }
+
+    public boolean isActive() {
+        return this.active;
+    }
 }
 }

+ 24 - 1
core-tiger/src/test/java/org/acegisecurity/PersonService.java

@@ -1,5 +1,28 @@
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.acegisecurity;
 package org.acegisecurity;
 
 
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+  */
 public interface PersonService extends Service<Person> {
 public interface PersonService extends Service<Person> {
-	public void deactive(Person person);
+    //~ Methods ========================================================================================================
+
+    public void deactive(Person person);
 }
 }

+ 25 - 4
core-tiger/src/test/java/org/acegisecurity/PersonServiceImpl.java

@@ -1,9 +1,30 @@
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.acegisecurity;
 package org.acegisecurity;
 
 
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+  */
 public class PersonServiceImpl extends ServiceImpl<Person> implements PersonService {
 public class PersonServiceImpl extends ServiceImpl<Person> implements PersonService {
+    //~ Methods ========================================================================================================
 
 
-	public void deactive(Person person) {
-		person.deactive();
-	}
-
+    public void deactive(Person person) {
+        person.deactive();
+    }
 }
 }

+ 2 - 2
core-tiger/src/test/java/org/acegisecurity/Service.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@ import java.util.Collection;
  * @version $Id$
  * @version $Id$
  */
  */
 public interface Service<E extends Entity> {
 public interface Service<E extends Entity> {
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     public int countElements(Collection<E> ids);
     public int countElements(Collection<E> ids);
 
 

+ 37 - 13
core-tiger/src/test/java/org/acegisecurity/ServiceImpl.java

@@ -1,23 +1,47 @@
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.acegisecurity;
 package org.acegisecurity;
 
 
 import java.util.Collection;
 import java.util.Collection;
 
 
-public class ServiceImpl<E extends Entity> implements Service<E> {
 
 
-	public int countElements(Collection<E> ids) {
-		return 0;
-	}
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+  *
+ * @param <E> DOCUMENT ME!
+ */
+public class ServiceImpl<E extends Entity> implements Service<E> {
+    //~ Methods ========================================================================================================
 
 
-	public void makeLowerCase(E input) {
-		input.makeLowercase();
-	}
+    public int countElements(Collection<E> ids) {
+        return 0;
+    }
 
 
-	public void makeUpperCase(E input) {
-		input.makeUppercase();
-	}
+    public void makeLowerCase(E input) {
+        input.makeLowercase();
+    }
 
 
-	public void publicMakeLowerCase(E input) {
-		input.makeUppercase();
-	}
+    public void makeUpperCase(E input) {
+        input.makeUppercase();
+    }
 
 
+    public void publicMakeLowerCase(E input) {
+        input.makeUppercase();
+    }
 }
 }

+ 34 - 13
core-tiger/src/test/java/org/acegisecurity/annotation/BusinessService.java

@@ -1,18 +1,39 @@
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.acegisecurity.annotation;
 package org.acegisecurity.annotation;
 
 
-@Secured ({"ROLE_USER"})
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+  */
+@Secured({"ROLE_USER"})
 public interface BusinessService {
 public interface BusinessService {
-	
-	@Secured ({"ROLE_USER"})
-	public void someUserMethod1();
+    //~ Methods ========================================================================================================
+
+    @Secured({"ROLE_ADMIN"})
+    public void someAdminMethod();
+
+    @Secured({"ROLE_USER", "ROLE_ADMIN"})
+    public void someUserAndAdminMethod();
+
+    @Secured({"ROLE_USER"})
+    public void someUserMethod1();
 
 
-	@Secured ({"ROLE_USER"})
-	public void someUserMethod2();	
-	
-	@Secured ({"ROLE_USER","ROLE_ADMIN"})
-	public void someUserAndAdminMethod();
-	
-	@Secured ({"ROLE_ADMIN"})
-	public void someAdminMethod();
-	
+    @Secured({"ROLE_USER"})
+    public void someUserMethod2();
 }
 }

+ 61 - 68
core-tiger/src/test/java/org/acegisecurity/annotation/SecurityAnnotationAttributesTests.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -15,15 +15,17 @@
 
 
 package org.acegisecurity.annotation;
 package org.acegisecurity.annotation;
 
 
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.Collection;
-
 import junit.framework.TestCase;
 import junit.framework.TestCase;
+
 import org.acegisecurity.SecurityConfig;
 import org.acegisecurity.SecurityConfig;
 
 
 import org.springframework.metadata.Attributes;
 import org.springframework.metadata.Attributes;
 
 
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import java.util.Collection;
+
 
 
 /**
 /**
  * Tests for {@link org.acegisecurity.annotation.SecurityAnnotationAttributes}
  * Tests for {@link org.acegisecurity.annotation.SecurityAnnotationAttributes}
@@ -32,17 +34,22 @@ import org.springframework.metadata.Attributes;
  * @version $Revision$
  * @version $Revision$
  */
  */
 public class SecurityAnnotationAttributesTests extends TestCase {
 public class SecurityAnnotationAttributesTests extends TestCase {
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private Attributes attributes;
     private Attributes attributes;
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
+
+    protected void setUp() throws Exception {
+        // create the Annotations impl
+        this.attributes = new SecurityAnnotationAttributes();
+    }
 
 
     public void testGetAttributesClass() {
     public void testGetAttributesClass() {
         Collection attrs = this.attributes.getAttributes(BusinessService.class);
         Collection attrs = this.attributes.getAttributes(BusinessService.class);
 
 
         assertNotNull(attrs);
         assertNotNull(attrs);
-        
+
         // expect 1 annotation
         // expect 1 annotation
         assertTrue(attrs.size() == 1);
         assertTrue(attrs.size() == 1);
 
 
@@ -53,90 +60,76 @@ public class SecurityAnnotationAttributesTests extends TestCase {
     }
     }
 
 
     public void testGetAttributesClassClass() {
     public void testGetAttributesClassClass() {
-    	try{
-    		this.attributes.getAttributes(BusinessService.class, null);
-    		fail("Unsupported method should have thrown an exception!");
-    		
-    	}catch(UnsupportedOperationException expected){
-    	}
+        try {
+            this.attributes.getAttributes(BusinessService.class, null);
+            fail("Unsupported method should have thrown an exception!");
+        } catch (UnsupportedOperationException expected) {}
     }
     }
 
 
     public void testGetAttributesField() {
     public void testGetAttributesField() {
-    	try{
-    		Field field = null;
-    		this.attributes.getAttributes(field);
-    		fail("Unsupported method should have thrown an exception!");
-    		
-    	}catch(UnsupportedOperationException expected){
-    		
-    	}
-    	
+        try {
+            Field field = null;
+            this.attributes.getAttributes(field);
+            fail("Unsupported method should have thrown an exception!");
+        } catch (UnsupportedOperationException expected) {}
     }
     }
 
 
     public void testGetAttributesFieldClass() {
     public void testGetAttributesFieldClass() {
-    	try{
-    		Field field = null;
-    		this.attributes.getAttributes(field, null);
-    		fail("Unsupported method should have thrown an exception!");
-    		
-    	}catch(UnsupportedOperationException expected){
-    		
-    	}
-    	
+        try {
+            Field field = null;
+            this.attributes.getAttributes(field, null);
+            fail("Unsupported method should have thrown an exception!");
+        } catch (UnsupportedOperationException expected) {}
     }
     }
 
 
     public void testGetAttributesMethod() {
     public void testGetAttributesMethod() {
-    	
-    	Method method = null;
-    	try{
-    		method = BusinessService.class.getMethod("someUserAndAdminMethod",new Class[] {});
-    	}catch(NoSuchMethodException unexpected){
-    		fail("Should be a method called 'someUserAndAdminMethod' on class!");
-    	}
+        Method method = null;
+
+        try {
+            method = BusinessService.class.getMethod("someUserAndAdminMethod", new Class[] {});
+        } catch (NoSuchMethodException unexpected) {
+            fail("Should be a method called 'someUserAndAdminMethod' on class!");
+        }
+
         Collection attrs = this.attributes.getAttributes(method);
         Collection attrs = this.attributes.getAttributes(method);
 
 
         assertNotNull(attrs);
         assertNotNull(attrs);
-        
+
         // expect 2 attributes
         // expect 2 attributes
         assertTrue(attrs.size() == 2);
         assertTrue(attrs.size() == 2);
 
 
         boolean user = false;
         boolean user = false;
         boolean admin = false;
         boolean admin = false;
+
         // should have 2 SecurityConfigs 
         // should have 2 SecurityConfigs 
-        for(Object obj: attrs){
-        	assertTrue(obj instanceof SecurityConfig);
-        	SecurityConfig sc = (SecurityConfig)obj;
-        	if(sc.getAttribute().equals("ROLE_USER")){
-        		user = true;
-        	}else if(sc.getAttribute().equals("ROLE_ADMIN")){
-        		admin = true;
-        	}
+        for (Object obj : attrs) {
+            assertTrue(obj instanceof SecurityConfig);
+
+            SecurityConfig sc = (SecurityConfig) obj;
+
+            if (sc.getAttribute().equals("ROLE_USER")) {
+                user = true;
+            } else if (sc.getAttribute().equals("ROLE_ADMIN")) {
+                admin = true;
+            }
         }
         }
+
         // expect to have ROLE_USER and ROLE_ADMIN
         // expect to have ROLE_USER and ROLE_ADMIN
         assertTrue(user && admin);
         assertTrue(user && admin);
     }
     }
 
 
     public void testGetAttributesMethodClass() {
     public void testGetAttributesMethodClass() {
-    	
-    	Method method = null;
-    	try{
-    		method = BusinessService.class.getMethod("someUserAndAdminMethod",new Class[] {});
-    	}catch(NoSuchMethodException unexpected){
-    		fail("Should be a method called 'someUserAndAdminMethod' on class!");
-    	}
-    	
-    	try{
-    		this.attributes.getAttributes(method,null);
-    		fail("Unsupported method should have thrown an exception!");
-    		
-    	}catch(UnsupportedOperationException expected){
-    		
-    	}
-    	
-    }
+        Method method = null;
 
 
-    protected void setUp() throws Exception {
-        // create the Annotations impl
-        this.attributes = new SecurityAnnotationAttributes();
+        try {
+            method = BusinessService.class.getMethod("someUserAndAdminMethod", new Class[] {});
+        } catch (NoSuchMethodException unexpected) {
+            fail("Should be a method called 'someUserAndAdminMethod' on class!");
+        }
+
+        try {
+            this.attributes.getAttributes(method, null);
+            fail("Unsupported method should have thrown an exception!");
+        } catch (UnsupportedOperationException expected) {}
     }
     }
 }
 }

+ 34 - 46
core-tiger/src/test/java/org/acegisecurity/intercept/method/MethodDefinitionSourceEditorTigerTests.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -15,9 +15,6 @@
 
 
 package org.acegisecurity.intercept.method;
 package org.acegisecurity.intercept.method;
 
 
-import java.lang.reflect.AccessibleObject;
-import java.lang.reflect.Method;
-
 import junit.framework.TestCase;
 import junit.framework.TestCase;
 
 
 import org.acegisecurity.ConfigAttributeDefinition;
 import org.acegisecurity.ConfigAttributeDefinition;
@@ -28,18 +25,21 @@ import org.acegisecurity.PersonServiceImpl;
 import org.acegisecurity.SecurityConfig;
 import org.acegisecurity.SecurityConfig;
 import org.acegisecurity.Service;
 import org.acegisecurity.Service;
 import org.acegisecurity.ServiceImpl;
 import org.acegisecurity.ServiceImpl;
+
 import org.aopalliance.intercept.MethodInvocation;
 import org.aopalliance.intercept.MethodInvocation;
 
 
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Method;
+
 
 
 /**
 /**
- * Extra tests to demonstrate generics behaviour with
- * <code>MethodDefinitionMap</code>.
+ * Extra tests to demonstrate generics behaviour with <code>MethodDefinitionMap</code>.
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public class MethodDefinitionSourceEditorTigerTests extends TestCase {
 public class MethodDefinitionSourceEditorTigerTests extends TestCase {
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
     public MethodDefinitionSourceEditorTigerTests() {
     public MethodDefinitionSourceEditorTigerTests() {
         super();
         super();
@@ -49,16 +49,16 @@ public class MethodDefinitionSourceEditorTigerTests extends TestCase {
         super(arg0);
         super(arg0);
     }
     }
 
 
-    //~ Methods ================================================================
-
-    public final void setUp() throws Exception {
-        super.setUp();
-    }
+    //~ Methods ========================================================================================================
 
 
     public static void main(String[] args) {
     public static void main(String[] args) {
         junit.textui.TestRunner.run(MethodDefinitionSourceEditorTigerTests.class);
         junit.textui.TestRunner.run(MethodDefinitionSourceEditorTigerTests.class);
     }
     }
 
 
+    public final void setUp() throws Exception {
+        super.setUp();
+    }
+
     public void testConcreteClassInvocationsAlsoReturnDefinitionsAgainstInterface()
     public void testConcreteClassInvocationsAlsoReturnDefinitionsAgainstInterface()
         throws Exception {
         throws Exception {
         MethodDefinitionSourceEditor editor = new MethodDefinitionSourceEditor();
         MethodDefinitionSourceEditor editor = new MethodDefinitionSourceEditor();
@@ -68,21 +68,17 @@ public class MethodDefinitionSourceEditorTigerTests extends TestCase {
         MethodDefinitionMap map = (MethodDefinitionMap) editor.getValue();
         MethodDefinitionMap map = (MethodDefinitionMap) editor.getValue();
         assertEquals(3, map.getMethodMapSize());
         assertEquals(3, map.getMethodMapSize());
 
 
-        ConfigAttributeDefinition returnedMakeLower = map.getAttributes(new MockMethodInvocation(
-                    Service.class, "makeLowerCase", new Class[] {Entity.class}));
+        ConfigAttributeDefinition returnedMakeLower = map.getAttributes(new MockMethodInvocation(Service.class,
+                    "makeLowerCase", new Class[] {Entity.class}));
         ConfigAttributeDefinition expectedMakeLower = new ConfigAttributeDefinition();
         ConfigAttributeDefinition expectedMakeLower = new ConfigAttributeDefinition();
-        expectedMakeLower.addConfigAttribute(new SecurityConfig(
-                "ROLE_FROM_INTERFACE"));
+        expectedMakeLower.addConfigAttribute(new SecurityConfig("ROLE_FROM_INTERFACE"));
         assertEquals(expectedMakeLower, returnedMakeLower);
         assertEquals(expectedMakeLower, returnedMakeLower);
 
 
-        ConfigAttributeDefinition returnedMakeUpper = map.getAttributes(new MockMethodInvocation(
-                    ServiceImpl.class, "makeUpperCase",
-                    new Class[] {Entity.class}));
+        ConfigAttributeDefinition returnedMakeUpper = map.getAttributes(new MockMethodInvocation(ServiceImpl.class,
+                    "makeUpperCase", new Class[] {Entity.class}));
         ConfigAttributeDefinition expectedMakeUpper = new ConfigAttributeDefinition();
         ConfigAttributeDefinition expectedMakeUpper = new ConfigAttributeDefinition();
-        expectedMakeUpper.addConfigAttribute(new SecurityConfig(
-                "ROLE_FROM_IMPLEMENTATION"));
-        expectedMakeUpper.addConfigAttribute(new SecurityConfig(
-                "ROLE_FROM_INTERFACE"));
+        expectedMakeUpper.addConfigAttribute(new SecurityConfig("ROLE_FROM_IMPLEMENTATION"));
+        expectedMakeUpper.addConfigAttribute(new SecurityConfig("ROLE_FROM_INTERFACE"));
         assertEquals(expectedMakeUpper, returnedMakeUpper);
         assertEquals(expectedMakeUpper, returnedMakeUpper);
     }
     }
 
 
@@ -95,49 +91,41 @@ public class MethodDefinitionSourceEditorTigerTests extends TestCase {
         MethodDefinitionMap map = (MethodDefinitionMap) editor.getValue();
         MethodDefinitionMap map = (MethodDefinitionMap) editor.getValue();
         assertEquals(3, map.getMethodMapSize());
         assertEquals(3, map.getMethodMapSize());
 
 
-        ConfigAttributeDefinition returnedMakeLower = map.getAttributes(new MockMethodInvocation(
-                    PersonService.class, "makeLowerCase",
-                    new Class[] {Entity.class}));
+        ConfigAttributeDefinition returnedMakeLower = map.getAttributes(new MockMethodInvocation(PersonService.class,
+                    "makeLowerCase", new Class[] {Entity.class}));
         ConfigAttributeDefinition expectedMakeLower = new ConfigAttributeDefinition();
         ConfigAttributeDefinition expectedMakeLower = new ConfigAttributeDefinition();
-        expectedMakeLower.addConfigAttribute(new SecurityConfig(
-                "ROLE_FROM_INTERFACE"));
+        expectedMakeLower.addConfigAttribute(new SecurityConfig("ROLE_FROM_INTERFACE"));
         assertEquals(expectedMakeLower, returnedMakeLower);
         assertEquals(expectedMakeLower, returnedMakeLower);
 
 
         ConfigAttributeDefinition returnedMakeLower2 = map.getAttributes(new MockMethodInvocation(
         ConfigAttributeDefinition returnedMakeLower2 = map.getAttributes(new MockMethodInvocation(
-                    OrganisationService.class, "makeLowerCase",
-                    new Class[] {Entity.class}));
+                    OrganisationService.class, "makeLowerCase", new Class[] {Entity.class}));
         ConfigAttributeDefinition expectedMakeLower2 = new ConfigAttributeDefinition();
         ConfigAttributeDefinition expectedMakeLower2 = new ConfigAttributeDefinition();
-        expectedMakeLower2.addConfigAttribute(new SecurityConfig(
-                "ROLE_FROM_INTERFACE"));
+        expectedMakeLower2.addConfigAttribute(new SecurityConfig("ROLE_FROM_INTERFACE"));
         assertEquals(expectedMakeLower2, returnedMakeLower2);
         assertEquals(expectedMakeLower2, returnedMakeLower2);
 
 
         ConfigAttributeDefinition returnedMakeUpper = map.getAttributes(new MockMethodInvocation(
         ConfigAttributeDefinition returnedMakeUpper = map.getAttributes(new MockMethodInvocation(
-                    PersonServiceImpl.class, "makeUpperCase",
-                    new Class[] {Entity.class}));
+                    PersonServiceImpl.class, "makeUpperCase", new Class[] {Entity.class}));
         ConfigAttributeDefinition expectedMakeUpper = new ConfigAttributeDefinition();
         ConfigAttributeDefinition expectedMakeUpper = new ConfigAttributeDefinition();
-        expectedMakeUpper.addConfigAttribute(new SecurityConfig(
-                "ROLE_FROM_IMPLEMENTATION"));
-        expectedMakeUpper.addConfigAttribute(new SecurityConfig(
-                "ROLE_FROM_INTERFACE"));
+        expectedMakeUpper.addConfigAttribute(new SecurityConfig("ROLE_FROM_IMPLEMENTATION"));
+        expectedMakeUpper.addConfigAttribute(new SecurityConfig("ROLE_FROM_INTERFACE"));
         assertEquals(expectedMakeUpper, returnedMakeUpper);
         assertEquals(expectedMakeUpper, returnedMakeUpper);
     }
     }
 
 
-    //~ Inner Classes ==========================================================
+    //~ Inner Classes ==================================================================================================
 
 
     private class MockMethodInvocation implements MethodInvocation {
     private class MockMethodInvocation implements MethodInvocation {
         Method method;
         Method method;
 
 
-        public MockMethodInvocation(Class clazz, String methodName,
-            Class[] parameterTypes) throws NoSuchMethodException {
-            System.out.println(clazz + " " + methodName + " "
-                + parameterTypes[0]);
-            method = clazz.getMethod(methodName, parameterTypes);
-        }
-
         private MockMethodInvocation() {
         private MockMethodInvocation() {
             super();
             super();
         }
         }
 
 
+        public MockMethodInvocation(Class clazz, String methodName, Class[] parameterTypes)
+            throws NoSuchMethodException {
+            System.out.println(clazz + " " + methodName + " " + parameterTypes[0]);
+            method = clazz.getMethod(methodName, parameterTypes);
+        }
+
         public Object[] getArguments() {
         public Object[] getArguments() {
             return null;
             return null;
         }
         }

+ 18 - 32
core/src/main/java/org/acegisecurity/AbstractAuthenticationManager.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -17,27 +17,21 @@ package org.acegisecurity;
 
 
 import org.acegisecurity.providers.AbstractAuthenticationToken;
 import org.acegisecurity.providers.AbstractAuthenticationToken;
 
 
+
 /**
 /**
  * An abstract implementation of the {@link AuthenticationManager}.
  * An abstract implementation of the {@link AuthenticationManager}.
  *
  *
  * @author Wesley Hall
  * @author Wesley Hall
  * @version $Id$
  * @version $Id$
  */
  */
-public abstract class AbstractAuthenticationManager
-    implements AuthenticationManager {
-    //~ Methods ================================================================
+public abstract class AbstractAuthenticationManager implements AuthenticationManager {
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
-     * <p>
-     * An implementation of the <code>authenticate</code> method that calls the
-     * abstract method <code>doAuthenticatation</code> to do its work.
-     * </p>
-     * 
-     * <p>
-     * If doAuthenticate throws an <code>AuthenticationException</code> then
-     * the exception is populated with the failed <code>Authentication</code>
-     * object that failed.
-     * </p>
+     * <p>An implementation of the <code>authenticate</code> method that calls the abstract method
+     * <code>doAuthenticatation</code> to do its work.</p>
+     *  <p>If doAuthenticate throws an <code>AuthenticationException</code> then the exception is populated
+     * with the failed <code>Authentication</code> object that failed.</p>
      *
      *
      * @param authRequest the authentication request object
      * @param authRequest the authentication request object
      *
      *
@@ -59,32 +53,24 @@ public abstract class AbstractAuthenticationManager
     }
     }
 
 
     /**
     /**
-     * Copies the authentication details from a source Authentication object
-     * to a destination one, provided the latter does not already have one
-     * set.
+     * Copies the authentication details from a source Authentication object to a destination one, provided the
+     * latter does not already have one set.
      *
      *
      * @param source source authentication
      * @param source source authentication
      * @param dest the destination authentication object
      * @param dest the destination authentication object
      */
      */
     private void copyDetails(Authentication source, Authentication dest) {
     private void copyDetails(Authentication source, Authentication dest) {
-        if((dest instanceof AbstractAuthenticationToken)
-              && dest.getDetails() == null) {
-           AbstractAuthenticationToken token = (AbstractAuthenticationToken)dest;
+        if ((dest instanceof AbstractAuthenticationToken) && (dest.getDetails() == null)) {
+            AbstractAuthenticationToken token = (AbstractAuthenticationToken) dest;
 
 
-           token.setDetails(source.getDetails());
+            token.setDetails(source.getDetails());
         }
         }
     }
     }
 
 
     /**
     /**
-     * <p>
-     * Concrete implementations of this class override this method to provide
-     * the authentication service.
-     * </p>
-     * 
-     * <p>
-     * The contract for this method is documented in the {@link
-     * AuthenticationManager#authenticate(org.acegisecurity.Authentication)}.
-     * </p>
+     * <p>Concrete implementations of this class override this method to provide the authentication service.</p>
+     *  <p>The contract for this method is documented in the {@link
+     * AuthenticationManager#authenticate(org.acegisecurity.Authentication)}.</p>
      *
      *
      * @param authentication the authentication request object
      * @param authentication the authentication request object
      *
      *
@@ -92,6 +78,6 @@ public abstract class AbstractAuthenticationManager
      *
      *
      * @throws AuthenticationException if authentication fails
      * @throws AuthenticationException if authentication fails
      */
      */
-    protected abstract Authentication doAuthentication(
-        Authentication authentication) throws AuthenticationException;
+    protected abstract Authentication doAuthentication(Authentication authentication)
+        throws AuthenticationException;
 }
 }

+ 19 - 29
core/src/main/java/org/acegisecurity/AccessDecisionManager.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -22,54 +22,44 @@ package org.acegisecurity;
  * @version $Id$
  * @version $Id$
  */
  */
 public interface AccessDecisionManager {
 public interface AccessDecisionManager {
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
      * Resolves an access control decision for the passed parameters.
      * Resolves an access control decision for the passed parameters.
      *
      *
      * @param authentication the caller invoking the method
      * @param authentication the caller invoking the method
      * @param object the secured object being called
      * @param object the secured object being called
-     * @param config the configuration attributes associated with the secured
-     *        object being invoked
+     * @param config the configuration attributes associated with the secured object being invoked
      *
      *
-     * @throws AccessDeniedException if access is denied as the authentication
-     *         does not hold a required authority or ACL privilege
-     * @throws InsufficientAuthenticationException if access is denied as the
-     *         authentication does not provide a sufficient level of trust
+     * @throws AccessDeniedException if access is denied as the authentication does not hold a required authority or
+     *         ACL privilege
+     * @throws InsufficientAuthenticationException if access is denied as the authentication does not provide a
+     *         sufficient level of trust
      */
      */
-    public void decide(Authentication authentication, Object object,
-        ConfigAttributeDefinition config)
+    public void decide(Authentication authentication, Object object, ConfigAttributeDefinition config)
         throws AccessDeniedException, InsufficientAuthenticationException;
         throws AccessDeniedException, InsufficientAuthenticationException;
 
 
     /**
     /**
-     * Indicates whether this <code>AccessDecisionManager</code> is able to
-     * process authorization requests presented with the passed
-     * <code>ConfigAttribute</code>.
-     * 
-     * <p>
-     * This allows the <code>AbstractSecurityInterceptor</code> to check every
-     * configuration attribute can be consumed by the configured
-     * <code>AccessDecisionManager</code> and/or <code>RunAsManager</code>
-     * and/or <code>AfterInvocationManager</code>.
-     * </p>
+     * Indicates whether this <code>AccessDecisionManager</code> is able to process authorization requests
+     * presented with the passed <code>ConfigAttribute</code>.<p>This allows the
+     * <code>AbstractSecurityInterceptor</code> to check every configuration attribute can be consumed by the
+     * configured <code>AccessDecisionManager</code> and/or <code>RunAsManager</code> and/or
+     * <code>AfterInvocationManager</code>.</p>
      *
      *
-     * @param attribute a configuration attribute that has been configured
-     *        against the <code>AbstractSecurityInterceptor</code>
+     * @param attribute a configuration attribute that has been configured against the
+     *        <code>AbstractSecurityInterceptor</code>
      *
      *
-     * @return true if this <code>AccessDecisionManager</code> can support the
-     *         passed configuration attribute
+     * @return true if this <code>AccessDecisionManager</code> can support the passed configuration attribute
      */
      */
     public boolean supports(ConfigAttribute attribute);
     public boolean supports(ConfigAttribute attribute);
 
 
     /**
     /**
-     * Indicates whether the <code>AccessDecisionManager</code> implementation
-     * is able to provide access control decisions for the indicated secured
-     * object type.
+     * Indicates whether the <code>AccessDecisionManager</code> implementation is able to provide access
+     * control decisions for the indicated secured object type.
      *
      *
      * @param clazz the class that is being queried
      * @param clazz the class that is being queried
      *
      *
-     * @return <code>true</code> if the implementation can process the
-     *         indicated class
+     * @return <code>true</code> if the implementation can process the indicated class
      */
      */
     public boolean supports(Class clazz);
     public boolean supports(Class clazz);
 }
 }

+ 5 - 6
core/src/main/java/org/acegisecurity/AccessDeniedException.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -16,16 +16,15 @@
 package org.acegisecurity;
 package org.acegisecurity;
 
 
 /**
 /**
- * Thrown if an {@link Authentication} object does not hold a required
- * authority.
+ * Thrown if an {@link Authentication} object does not hold a required authority.
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public class AccessDeniedException extends AcegiSecurityException {
 public class AccessDeniedException extends AcegiSecurityException {
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
-    /**
+/**
      * Constructs an <code>AccessDeniedException</code> with the specified
      * Constructs an <code>AccessDeniedException</code> with the specified
      * message.
      * message.
      *
      *
@@ -35,7 +34,7 @@ public class AccessDeniedException extends AcegiSecurityException {
         super(msg);
         super(msg);
     }
     }
 
 
-    /**
+/**
      * Constructs an <code>AccessDeniedException</code> with the specified
      * Constructs an <code>AccessDeniedException</code> with the specified
      * message and root cause.
      * message and root cause.
      *
      *

+ 6 - 7
core/src/main/java/org/acegisecurity/AccountExpiredException.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -16,17 +16,16 @@
 package org.acegisecurity;
 package org.acegisecurity;
 
 
 /**
 /**
- * Thrown if an authentication request is rejected because the account has
- * expired. Makes no assertion as to whether or not the credentials were
- * valid.
+ * Thrown if an authentication request is rejected because the account has expired. Makes no assertion as to
+ * whether or not the credentials were valid.
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public class AccountExpiredException extends AuthenticationException {
 public class AccountExpiredException extends AuthenticationException {
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
-    /**
+/**
      * Constructs a <code>AccountExpiredException</code> with the specified
      * Constructs a <code>AccountExpiredException</code> with the specified
      * message.
      * message.
      *
      *
@@ -36,7 +35,7 @@ public class AccountExpiredException extends AuthenticationException {
         super(msg);
         super(msg);
     }
     }
 
 
-    /**
+/**
      * Constructs a <code>AccountExpiredException</code> with the specified
      * Constructs a <code>AccountExpiredException</code> with the specified
      * message and root cause.
      * message and root cause.
      *
      *

+ 6 - 11
core/src/main/java/org/acegisecurity/AcegiMessageSource.java

@@ -20,27 +20,22 @@ import org.springframework.context.support.ResourceBundleMessageSource;
 
 
 
 
 /**
 /**
- * The default <code>MessageSource</code> used by Acegi Security.
- * 
- * <p>
- * All Acegi Security classes requiring messge localization will by default use
- * this class. However, all such classes will also implement
- * <code>MessageSourceAware</code> so that the application context can inject
- * an alternative message source. Therefore this class is only used when the
- * deployment environment has not specified an alternative message source.
- * </p>
+ * The default <code>MessageSource</code> used by Acegi Security.<p>All Acegi Security classes requiring messge
+ * localization will by default use this class. However, all such classes will also implement
+ * <code>MessageSourceAware</code> so that the application context can inject an alternative message source. Therefore
+ * this class is only used when the deployment environment has not specified an alternative message source.</p>
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public class AcegiMessageSource extends ResourceBundleMessageSource {
 public class AcegiMessageSource extends ResourceBundleMessageSource {
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
     public AcegiMessageSource() {
     public AcegiMessageSource() {
         setBasename("org.acegisecurity.messages");
         setBasename("org.acegisecurity.messages");
     }
     }
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     public static MessageSourceAccessor getAccessor() {
     public static MessageSourceAccessor getAccessor() {
         return new MessageSourceAccessor(new AcegiMessageSource());
         return new MessageSourceAccessor(new AcegiMessageSource());

+ 6 - 11
core/src/main/java/org/acegisecurity/AcegiSecurityException.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -19,21 +19,16 @@ import org.springframework.core.NestedRuntimeException;
 
 
 
 
 /**
 /**
- * Abstract superclass for all exceptions thrown in the security package and
- * subpackages.
- * 
- * <p>
- * Note that this is a runtime (unchecked) exception. Security exceptions are
- * usually fatal; there is no reason for them to be checked.
- * </p>
+ * Abstract superclass for all exceptions thrown in the security package and subpackages.<p>Note that this is a
+ * runtime (unchecked) exception. Security exceptions are usually fatal; there is no reason for them to be checked.</p>
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public abstract class AcegiSecurityException extends NestedRuntimeException {
 public abstract class AcegiSecurityException extends NestedRuntimeException {
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
-    /**
+/**
      * Constructs an <code>AcegiSecurityException</code> with the specified
      * Constructs an <code>AcegiSecurityException</code> with the specified
      * message and root cause.
      * message and root cause.
      *
      *
@@ -44,7 +39,7 @@ public abstract class AcegiSecurityException extends NestedRuntimeException {
         super(msg, t);
         super(msg, t);
     }
     }
 
 
-    /**
+/**
      * Constructs an <code>AcegiSecurityException</code> with the specified
      * Constructs an <code>AcegiSecurityException</code> with the specified
      * message and no root cause.
      * message and no root cause.
      *
      *

+ 22 - 36
core/src/main/java/org/acegisecurity/AfterInvocationManager.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -43,61 +43,47 @@ package org.acegisecurity;
  * @version $Id$
  * @version $Id$
  */
  */
 public interface AfterInvocationManager {
 public interface AfterInvocationManager {
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
-     * Given the details of a secure object invocation including its returned
-     * <code>Object</code>, make an access control decision or optionally
-     * modify the returned <code>Object</code>.
+     * Given the details of a secure object invocation including its returned <code>Object</code>, make an
+     * access control decision or optionally modify the returned <code>Object</code>.
      *
      *
      * @param authentication the caller that invoked the method
      * @param authentication the caller that invoked the method
      * @param object the secured object that was called
      * @param object the secured object that was called
-     * @param config the configuration attributes associated with the secured
-     *        object that was invoked
-     * @param returnedObject the <code>Object</code> that was returned from the
-     *        secure object invocation
+     * @param config the configuration attributes associated with the secured object that was invoked
+     * @param returnedObject the <code>Object</code> that was returned from the secure object invocation
      *
      *
-     * @return the <code>Object</code> that will ultimately be returned to the
-     *         caller (if an implementation does not wish to modify the object
-     *         to be returned to the caller, the implementation should simply
-     *         return the same object it was passed by the
-     *         <code>returnedObject</code> method argument)
+     * @return the <code>Object</code> that will ultimately be returned to the caller (if an implementation does not
+     *         wish to modify the object to be returned to the caller, the implementation should simply return the
+     *         same object it was passed by the <code>returnedObject</code> method argument)
      *
      *
      * @throws AccessDeniedException if access is denied
      * @throws AccessDeniedException if access is denied
      */
      */
-    public Object decide(Authentication authentication, Object object,
-        ConfigAttributeDefinition config, Object returnedObject)
-        throws AccessDeniedException;
+    public Object decide(Authentication authentication, Object object, ConfigAttributeDefinition config,
+        Object returnedObject) throws AccessDeniedException;
 
 
     /**
     /**
-     * Indicates whether this <code>AfterInvocationManager</code> is able to
-     * process "after invocation" requests presented with the passed
-     * <code>ConfigAttribute</code>.
-     * 
-     * <p>
-     * This allows the <code>AbstractSecurityInterceptor</code> to check every
-     * configuration attribute can be consumed by the configured
-     * <code>AccessDecisionManager</code> and/or <code>RunAsManager</code>
-     * and/or <code>AfterInvocationManager</code>.
-     * </p>
+     * Indicates whether this <code>AfterInvocationManager</code> is able to process "after invocation"
+     * requests presented with the passed <code>ConfigAttribute</code>.<p>This allows the
+     * <code>AbstractSecurityInterceptor</code> to check every configuration attribute can be consumed by the
+     * configured <code>AccessDecisionManager</code> and/or <code>RunAsManager</code> and/or
+     * <code>AfterInvocationManager</code>.</p>
      *
      *
-     * @param attribute a configuration attribute that has been configured
-     *        against the <code>AbstractSecurityInterceptor</code>
+     * @param attribute a configuration attribute that has been configured against the
+     *        <code>AbstractSecurityInterceptor</code>
      *
      *
-     * @return true if this <code>AfterInvocationManager</code> can support the
-     *         passed configuration attribute
+     * @return true if this <code>AfterInvocationManager</code> can support the passed configuration attribute
      */
      */
     public boolean supports(ConfigAttribute attribute);
     public boolean supports(ConfigAttribute attribute);
 
 
     /**
     /**
-     * Indicates whether the <code>AfterInvocationManager</code> implementation
-     * is able to provide access control decisions for the indicated secured
-     * object type.
+     * Indicates whether the <code>AfterInvocationManager</code> implementation is able to provide access
+     * control decisions for the indicated secured object type.
      *
      *
      * @param clazz the class that is being queried
      * @param clazz the class that is being queried
      *
      *
-     * @return <code>true</code> if the implementation can process the
-     *         indicated class
+     * @return <code>true</code> if the implementation can process the indicated class
      */
      */
     public boolean supports(Class clazz);
     public boolean supports(Class clazz);
 }
 }

+ 44 - 74
core/src/main/java/org/acegisecurity/Authentication.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -37,101 +37,71 @@ import java.security.Principal;
  * @version $Id$
  * @version $Id$
  */
  */
 public interface Authentication extends Principal, Serializable {
 public interface Authentication extends Principal, Serializable {
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
-     * See {@link #isAuthenticated()} for a full description.
-     * 
-     * <p>
-     * Implementations should <b>always</b> allow this method to be called with
-     * a <code>false</code> parameter, as this is used by various classes to
-     * specify the authentication token should not be trusted. If an
-     * implementation wishes to reject an invocation with a <code>true</code>
-     * parameter (which would indicate the authentication token is trusted - a
-     * potential security risk) the implementation should throw an {@link
-     * IllegalArgumentException}.
-     * </p>
+     * Set by an <code>AuthenticationManager</code> to indicate the authorities that the principal has been
+     * granted. Note that classes should not rely on this value as being valid unless it has been set by a trusted
+     * <code>AuthenticationManager</code>.<p>Implementations should ensure that modifications to the returned
+     * array do not affect the state of the Authentication object (e.g. by returning an array copy).</p>
      *
      *
-     * @param isAuthenticated <code>true</code> if the token should be trusted
-     *        (which may result in an exception) or <code>false</code> if the
-     *        token should not be trusted
-     *
-     * @throws IllegalArgumentException if an attempt to make the
-     *         authentication token trusted (by passing <code>true</code> as
-     *         the argument) is rejected due to the implementation being
-     *         immutable or implementing its own alternative approach to
-     *         {@link #isAuthenticated()}
+     * @return the authorities granted to the principal, or <code>null</code> if authentication has not been completed
      */
      */
-    public void setAuthenticated(boolean isAuthenticated)
-        throws IllegalArgumentException;
+    public GrantedAuthority[] getAuthorities();
 
 
     /**
     /**
-     * Used to indicate to <code>AbstractSecurityInterceptor</code> whether it
-     * should present the authentication token to the
-     * <code>AuthenticationManager</code>. Typically an
-     * <code>AuthenticationManager</code> (or, more often, one of its
-     * <code>AuthenticationProvider</code>s) will return an immutable
-     * authentication token after successful authentication, in which case
-     * that token can safely return <code>true</code> to this method.
-     * Returning <code>true</code> will improve performance, as calling the
-     * <code>AuthenticationManager</code> for every request will no longer be
-     * necessary.
-     * 
-     * <p>
-     * For security reasons, implementations of this interface should be very
-     * careful about returning <code>true</code> to this method unless they
-     * are either immutable, or have some way of ensuring the properties have
-     * not been changed since original creation.
-     * </p>
+     * The credentials that prove the principal is correct. This is usually a password, but could be anything
+     * relevant to the <code>AuthenticationManager</code>. Callers are expected to populate the credentials.
      *
      *
-     * @return true if the token has been authenticated and the
-     *         <code>AbstractSecurityInterceptor</code> does not need to
-     *         represent the token for re-authentication to the
-     *         <code>AuthenticationManager</code>
+     * @return the credentials that prove the identity of the <code>Principal</code>
      */
      */
-    public boolean isAuthenticated();
+    public Object getCredentials();
 
 
     /**
     /**
-     * Set by an <code>AuthenticationManager</code> to indicate the authorities
-     * that the principal has been granted. Note that classes should not rely
-     * on this value as being valid unless it has been set by a trusted
-     * <code>AuthenticationManager</code>.
-     * <p>
-     * Implementations should ensure that modifications to the returned array
-     * do not affect the state of the Authentication object (e.g. by returning an
-     * array copy).
-     * </p>
+     * Stores additional details about the authentication request. These might be an IP address, certificate
+     * serial number etc.
      *
      *
-     * @return the authorities granted to the principal, or <code>null</code>
-     *         if authentication has not been completed
+     * @return additional details about the authentication request, or <code>null</code> if not used
      */
      */
-    public GrantedAuthority[] getAuthorities();
+    public Object getDetails();
 
 
     /**
     /**
-     * The credentials that prove the principal is correct. This is usually a
-     * password, but could be anything relevant to the
-     * <code>AuthenticationManager</code>. Callers are expected to populate
-     * the credentials.
+     * The identity of the principal being authenticated. This is usually a username. Callers are expected to
+     * populate the principal.
      *
      *
-     * @return the credentials that prove the identity of the
-     *         <code>Principal</code>
+     * @return the <code>Principal</code> being authenticated
      */
      */
-    public Object getCredentials();
+    public Object getPrincipal();
 
 
     /**
     /**
-     * Stores additional details about the authentication request. These might
-     * be an IP address, certificate serial number etc.
+     * Used to indicate to <code>AbstractSecurityInterceptor</code> whether it should present the
+     * authentication token to the <code>AuthenticationManager</code>. Typically an <code>AuthenticationManager</code>
+     * (or, more often, one of its <code>AuthenticationProvider</code>s) will return an immutable authentication token
+     * after successful authentication, in which case that token can safely return <code>true</code> to this method.
+     * Returning <code>true</code> will improve performance, as calling the <code>AuthenticationManager</code> for
+     * every request will no longer be necessary.<p>For security reasons, implementations of this interface
+     * should be very careful about returning <code>true</code> to this method unless they are either immutable, or
+     * have some way of ensuring the properties have not been changed since original creation.</p>
      *
      *
-     * @return additional details about the authentication request, or
-     *         <code>null</code> if not used
+     * @return true if the token has been authenticated and the <code>AbstractSecurityInterceptor</code> does not need
+     *         to represent the token for re-authentication to the <code>AuthenticationManager</code>
      */
      */
-    public Object getDetails();
+    public boolean isAuthenticated();
 
 
     /**
     /**
-     * The identity of the principal being authenticated. This is usually a
-     * username. Callers are expected to populate the principal.
+     * See {@link #isAuthenticated()} for a full description.<p>Implementations should <b>always</b> allow this
+     * method to be called with a <code>false</code> parameter, as this is used by various classes to specify the
+     * authentication token should not be trusted. If an implementation wishes to reject an invocation with a
+     * <code>true</code> parameter (which would indicate the authentication token is trusted - a potential security
+     * risk) the implementation should throw an {@link IllegalArgumentException}.</p>
      *
      *
-     * @return the <code>Principal</code> being authenticated
+     * @param isAuthenticated <code>true</code> if the token should be trusted (which may result in an exception) or
+     *        <code>false</code> if the token should not be trusted
+     *
+     * @throws IllegalArgumentException if an attempt to make the authentication token trusted (by passing
+     *         <code>true</code> as the argument) is rejected due to the implementation being immutable or
+     *         implementing its own alternative approach to {@link #isAuthenticated()}
      */
      */
-    public Object getPrincipal();
+    public void setAuthenticated(boolean isAuthenticated)
+        throws IllegalArgumentException;
 }
 }

+ 7 - 8
core/src/main/java/org/acegisecurity/AuthenticationCredentialsNotFoundException.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -16,17 +16,16 @@
 package org.acegisecurity;
 package org.acegisecurity;
 
 
 /**
 /**
- * Thrown if an authentication request is rejected because there is no {@link
- * Authentication} object in the  {@link org.acegisecurity.context.SecurityContext SecurityContext}.
+ * Thrown if an authentication request is rejected because there is no {@link Authentication} object in the  {@link
+ * org.acegisecurity.context.SecurityContext SecurityContext}.
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
-public class AuthenticationCredentialsNotFoundException
-    extends AuthenticationException {
-    //~ Constructors ===========================================================
+public class AuthenticationCredentialsNotFoundException extends AuthenticationException {
+    //~ Constructors ===================================================================================================
 
 
-    /**
+/**
      * Constructs an <code>AuthenticationCredentialsNotFoundException</code>
      * Constructs an <code>AuthenticationCredentialsNotFoundException</code>
      * with the specified message.
      * with the specified message.
      *
      *
@@ -36,7 +35,7 @@ public class AuthenticationCredentialsNotFoundException
         super(msg);
         super(msg);
     }
     }
 
 
-    /**
+/**
      * Constructs an <code>AuthenticationCredentialsNotFoundException</code>
      * Constructs an <code>AuthenticationCredentialsNotFoundException</code>
      * with the specified message and root cause.
      * with the specified message and root cause.
      *
      *

+ 9 - 12
core/src/main/java/org/acegisecurity/AuthenticationException.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -16,24 +16,21 @@
 package org.acegisecurity;
 package org.acegisecurity;
 
 
 /**
 /**
- * Abstract superclass for all exceptions related an {@link Authentication}
- * object being invalid for whatever reason.
+ * Abstract superclass for all exceptions related an {@link Authentication} object being invalid for whatever
+ * reason.
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public abstract class AuthenticationException extends AcegiSecurityException {
 public abstract class AuthenticationException extends AcegiSecurityException {
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
-    /**
-     * The authentication that related to this exception (may be
-     * <code>null</code>)
-     */
+    /** The authentication that related to this exception (may be <code>null</code>) */
     private Authentication authentication;
     private Authentication authentication;
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
-    /**
+/**
      * Constructs an <code>AuthenticationException</code> with the specified
      * Constructs an <code>AuthenticationException</code> with the specified
      * message and root cause.
      * message and root cause.
      *
      *
@@ -44,7 +41,7 @@ public abstract class AuthenticationException extends AcegiSecurityException {
         super(msg, t);
         super(msg, t);
     }
     }
 
 
-    /**
+/**
      * Constructs an <code>AuthenticationException</code> with the specified
      * Constructs an <code>AuthenticationException</code> with the specified
      * message and no root cause.
      * message and no root cause.
      *
      *
@@ -54,7 +51,7 @@ public abstract class AuthenticationException extends AcegiSecurityException {
         super(msg);
         super(msg);
     }
     }
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     public Authentication getAuthentication() {
     public Authentication getAuthentication() {
         return authentication;
         return authentication;

+ 14 - 34
core/src/main/java/org/acegisecurity/AuthenticationManager.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -22,41 +22,21 @@ package org.acegisecurity;
  * @version $Id$
  * @version $Id$
  */
  */
 public interface AuthenticationManager {
 public interface AuthenticationManager {
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
-     * Attempts to authenticate the passed {@link Authentication} object,
-     * returning a fully populated <code>Authentication</code> object
-     * (including granted authorities) if successful.
-     * 
-     * <p>
-     * An <code>AuthenticationManager</code> must honour the following contract
-     * concerning exceptions:
-     * </p>
-     * 
-     * <p>
-     * A {@link DisabledException} must be thrown if an account is disabled and
-     * the <code>AuthenticationManager</code> can test for this state.
-     * </p>
-     * 
-     * <p>
-     * A {@link LockedException} must be thrown if an account is locked and the
-     * <code>AuthenticationManager</code> can test for account locking.
-     * </p>
-     * 
-     * <p>
-     * A {@link BadCredentialsException} must be thrown if incorrect
-     * credentials are presented. Whilst the above exceptions are optional, an
-     * <code>AuthenticationManager</code> must <B>always</B> test credentials.
-     * </p>
-     * 
-     * <p>
-     * Exceptions should be tested for and if applicable thrown in the order
-     * expressed above (ie if an account is disabled or locked, the
-     * authentication request is immediately rejected and the credentials
-     * testing process is not performed). This prevents credentials being
-     * tested against  disabled or locked accounts.
-     * </p>
+     * Attempts to authenticate the passed {@link Authentication} object, returning a fully populated
+     * <code>Authentication</code> object (including granted authorities) if successful.<p>An
+     * <code>AuthenticationManager</code> must honour the following contract concerning exceptions:</p>
+     *  <p>A {@link DisabledException} must be thrown if an account is disabled and the
+     * <code>AuthenticationManager</code> can test for this state.</p>
+     *  <p>A {@link LockedException} must be thrown if an account is locked and the
+     * <code>AuthenticationManager</code> can test for account locking.</p>
+     *  <p>A {@link BadCredentialsException} must be thrown if incorrect credentials are presented. Whilst the
+     * above exceptions are optional, an <code>AuthenticationManager</code> must <B>always</B> test credentials.</p>
+     *  <p>Exceptions should be tested for and if applicable thrown in the order expressed above (ie if an
+     * account is disabled or locked, the authentication request is immediately rejected and the credentials testing
+     * process is not performed). This prevents credentials being tested against  disabled or locked accounts.</p>
      *
      *
      * @param authentication the authentication request object
      * @param authentication the authentication request object
      *
      *

+ 6 - 10
core/src/main/java/org/acegisecurity/AuthenticationServiceException.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -16,20 +16,16 @@
 package org.acegisecurity;
 package org.acegisecurity;
 
 
 /**
 /**
- * Thrown if an authentication request could not be processed due to a system
- * problem.
- * 
- * <p>
- * This might be thrown if a backend authentication repository is  unavailable.
- * </p>
+ * Thrown if an authentication request could not be processed due to a system problem.<p>This might be thrown if a
+ * backend authentication repository is  unavailable.</p>
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public class AuthenticationServiceException extends AuthenticationException {
 public class AuthenticationServiceException extends AuthenticationException {
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
-    /**
+/**
      * Constructs an <code>AuthenticationServiceException</code> with the
      * Constructs an <code>AuthenticationServiceException</code> with the
      * specified message.
      * specified message.
      *
      *
@@ -39,7 +35,7 @@ public class AuthenticationServiceException extends AuthenticationException {
         super(msg);
         super(msg);
     }
     }
 
 
-    /**
+/**
      * Constructs an <code>AuthenticationServiceException</code> with the
      * Constructs an <code>AuthenticationServiceException</code> with the
      * specified message and root cause.
      * specified message and root cause.
      *
      *

+ 20 - 30
core/src/main/java/org/acegisecurity/AuthenticationTrustResolver.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -22,45 +22,35 @@ package org.acegisecurity;
  * @version $Id$
  * @version $Id$
  */
  */
 public interface AuthenticationTrustResolver {
 public interface AuthenticationTrustResolver {
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
-     * Indicates whether the passed <code>Authentication</code> token
-     * represents an anonymous user. Typically the framework will call this
-     * method if it is trying to decide whether an
-     * <code>AccessDeniedException</code> should result in a final rejection
-     * (ie as would be the case if the principal was non-anonymous/fully
-     * authenticated) or direct the principal to attempt actual authentication
-     * (ie as would be the case if the <code>Authentication</code> was merely
-     * anonymous).
+     * Indicates whether the passed <code>Authentication</code> token represents an anonymous user. Typically
+     * the framework will call this method if it is trying to decide whether an <code>AccessDeniedException</code>
+     * should result in a final rejection (ie as would be the case if the principal was non-anonymous/fully
+     * authenticated) or direct the principal to attempt actual authentication (ie as would be the case if the
+     * <code>Authentication</code> was merely anonymous).
      *
      *
-     * @param authentication to test (may be <code>null</code> in which case
-     *        the method will always return <code>false</code>)
+     * @param authentication to test (may be <code>null</code> in which case the method will always return
+     *        <code>false</code>)
      *
      *
-     * @return <code>true</code> the passed authentication token represented an
-     *         anonymous principal, <code>false</code> otherwise
+     * @return <code>true</code> the passed authentication token represented an anonymous principal, <code>false</code>
+     *         otherwise
      */
      */
     public boolean isAnonymous(Authentication authentication);
     public boolean isAnonymous(Authentication authentication);
 
 
     /**
     /**
-     * Indicates whether the passed <code>Authentication</code> token
-     * represents user that has been remembered (ie not a user that has been
-     * fully authenticated).
-     * 
-     * <p>
-     * <b>No part of the framework uses this method</b>, as it is a weak
-     * definition of trust levels. The method is provided simply to assist
-     * with custom <code>AccessDecisionVoter</code>s and the like that you
-     * might develop. Of course, you don't need to use this method either and
-     * can develop your own "trust level" hierarchy instead.
-     * </p>
+     * Indicates whether the passed <code>Authentication</code> token represents user that has been remembered
+     * (ie not a user that has been fully authenticated).<p><b>No part of the framework uses this method</b>,
+     * as it is a weak definition of trust levels. The method is provided simply to assist with custom
+     * <code>AccessDecisionVoter</code>s and the like that you might develop. Of course, you don't need to use this
+     * method either and can develop your own "trust level" hierarchy instead.</p>
      *
      *
-     * @param authentication to test (may be <code>null</code> in which case
-     *        the method will always return <code>false</code>)
+     * @param authentication to test (may be <code>null</code> in which case the method will always return
+     *        <code>false</code>)
      *
      *
-     * @return <code>true</code> the passed authentication token represented a
-     *         principal authenticated using a remember-me token,
-     *         <code>false</code> otherwise
+     * @return <code>true</code> the passed authentication token represented a principal authenticated using a
+     *         remember-me token, <code>false</code> otherwise
      */
      */
     public boolean isRememberMe(Authentication authentication);
     public boolean isRememberMe(Authentication authentication);
 }
 }

+ 20 - 28
core/src/main/java/org/acegisecurity/AuthenticationTrustResolverImpl.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -20,29 +20,29 @@ import org.acegisecurity.providers.rememberme.RememberMeAuthenticationToken;
 
 
 
 
 /**
 /**
- * Basic implementation of {@link AuthenticationTrustResolver}.
- * 
- * <p>
- * Makes trust decisions based on whether the passed
- * <code>Authentication</code> is an instance of a defined class.
- * </p>
- * 
- * <p>
- * If {@link #anonymousClass} or {@link #rememberMeClass} is <code>null</code>,
- * the corresponding method will always return <code>false</code>.
- * </p>
+ * Basic implementation of {@link AuthenticationTrustResolver}.<p>Makes trust decisions based on whether the passed
+ * <code>Authentication</code> is an instance of a defined class.</p>
+ *  <p>If {@link #anonymousClass} or {@link #rememberMeClass} is <code>null</code>, the corresponding method will
+ * always return <code>false</code>.</p>
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
-public class AuthenticationTrustResolverImpl
-    implements AuthenticationTrustResolver {
-    //~ Instance fields ========================================================
+public class AuthenticationTrustResolverImpl implements AuthenticationTrustResolver {
+    //~ Instance fields ================================================================================================
 
 
     private Class anonymousClass = AnonymousAuthenticationToken.class;
     private Class anonymousClass = AnonymousAuthenticationToken.class;
     private Class rememberMeClass = RememberMeAuthenticationToken.class;
     private Class rememberMeClass = RememberMeAuthenticationToken.class;
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
+
+    public Class getAnonymousClass() {
+        return anonymousClass;
+    }
+
+    public Class getRememberMeClass() {
+        return rememberMeClass;
+    }
 
 
     public boolean isAnonymous(Authentication authentication) {
     public boolean isAnonymous(Authentication authentication) {
         if ((anonymousClass == null) || (authentication == null)) {
         if ((anonymousClass == null) || (authentication == null)) {
@@ -52,14 +52,6 @@ public class AuthenticationTrustResolverImpl
         return anonymousClass.isAssignableFrom(authentication.getClass());
         return anonymousClass.isAssignableFrom(authentication.getClass());
     }
     }
 
 
-    public void setAnonymousClass(Class anonymousClass) {
-        this.anonymousClass = anonymousClass;
-    }
-
-    public Class getAnonymousClass() {
-        return anonymousClass;
-    }
-
     public boolean isRememberMe(Authentication authentication) {
     public boolean isRememberMe(Authentication authentication) {
         if ((rememberMeClass == null) || (authentication == null)) {
         if ((rememberMeClass == null) || (authentication == null)) {
             return false;
             return false;
@@ -68,11 +60,11 @@ public class AuthenticationTrustResolverImpl
         return rememberMeClass.isAssignableFrom(authentication.getClass());
         return rememberMeClass.isAssignableFrom(authentication.getClass());
     }
     }
 
 
-    public void setRememberMeClass(Class rememberMeClass) {
-        this.rememberMeClass = rememberMeClass;
+    public void setAnonymousClass(Class anonymousClass) {
+        this.anonymousClass = anonymousClass;
     }
     }
 
 
-    public Class getRememberMeClass() {
-        return rememberMeClass;
+    public void setRememberMeClass(Class rememberMeClass) {
+        this.rememberMeClass = rememberMeClass;
     }
     }
 }
 }

+ 6 - 11
core/src/main/java/org/acegisecurity/AuthorizationServiceException.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -16,21 +16,16 @@
 package org.acegisecurity;
 package org.acegisecurity;
 
 
 /**
 /**
- * Thrown if an authorization request could not be processed due to a system
- * problem.
- * 
- * <p>
- * This might be thrown if an <code>AccessDecisionManager</code> implementation
- * could not locate a required method argument, for example.
- * </p>
+ * Thrown if an authorization request could not be processed due to a system problem.<p>This might be thrown if an
+ * <code>AccessDecisionManager</code> implementation could not locate a required method argument, for example.</p>
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public class AuthorizationServiceException extends AccessDeniedException {
 public class AuthorizationServiceException extends AccessDeniedException {
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
-    /**
+/**
      * Constructs an <code>AuthorizationServiceException</code> with the
      * Constructs an <code>AuthorizationServiceException</code> with the
      * specified message.
      * specified message.
      *
      *
@@ -40,7 +35,7 @@ public class AuthorizationServiceException extends AccessDeniedException {
         super(msg);
         super(msg);
     }
     }
 
 
-    /**
+/**
      * Constructs an <code>AuthorizationServiceException</code> with the
      * Constructs an <code>AuthorizationServiceException</code> with the
      * specified message and root cause.
      * specified message and root cause.
      *
      *

+ 9 - 11
core/src/main/java/org/acegisecurity/BadCredentialsException.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -16,21 +16,20 @@
 package org.acegisecurity;
 package org.acegisecurity;
 
 
 /**
 /**
- * Thrown if an authentication request is rejected because the credentials are
- * invalid. For this exception to be thrown, it means the account is neither
- * locked nor disabled.
+ * Thrown if an authentication request is rejected because the credentials are invalid. For this exception to be
+ * thrown, it means the account is neither locked nor disabled.
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public class BadCredentialsException extends AuthenticationException {
 public class BadCredentialsException extends AuthenticationException {
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private Object extraInformation;
     private Object extraInformation;
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
-    /**
+/**
      * Constructs a <code>BadCredentialsException</code> with the specified
      * Constructs a <code>BadCredentialsException</code> with the specified
      * message.
      * message.
      *
      *
@@ -45,7 +44,7 @@ public class BadCredentialsException extends AuthenticationException {
         this.extraInformation = extraInformation;
         this.extraInformation = extraInformation;
     }
     }
 
 
-    /**
+/**
      * Constructs a <code>BadCredentialsException</code> with the specified
      * Constructs a <code>BadCredentialsException</code> with the specified
      * message and root cause.
      * message and root cause.
      *
      *
@@ -56,11 +55,10 @@ public class BadCredentialsException extends AuthenticationException {
         super(msg, t);
         super(msg, t);
     }
     }
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
-     * Any additional information about the exception. Generally a
-     * <code>UserDetails</code> object.
+     * Any additional information about the exception. Generally a <code>UserDetails</code> object.
      *
      *
      * @return extra information or <code>null</code>
      * @return extra information or <code>null</code>
      */
      */

+ 11 - 20
core/src/main/java/org/acegisecurity/ConfigAttribute.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -38,28 +38,19 @@ import java.io.Serializable;
  * @version $Id$
  * @version $Id$
  */
  */
 public interface ConfigAttribute extends Serializable {
 public interface ConfigAttribute extends Serializable {
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
-     * If the <code>ConfigAttribute</code> can be represented as a
-     * <code>String</code> and that <code>String</code> is sufficient in
-     * precision to be relied upon as a configuration parameter by a {@link
-     * RunAsManager}, {@link AccessDecisionManager} or
-     * <code>AccessDecisionManager</code> delegate, this method should  return
-     * such a <code>String</code>.
-     * 
-     * <p>
-     * If the <code>ConfigAttribute</code> cannot be expressed with sufficient
-     * precision as a <code>String</code>,  <code>null</code> should be
-     * returned. Returning <code>null</code> will require any relying classes
-     * to specifically support the  <code>ConfigAttribute</code>
-     * implementation, so returning  <code>null</code> should be avoided
-     * unless actually  required.
-     * </p>
+     * If the <code>ConfigAttribute</code> can be represented as a <code>String</code> and that
+     * <code>String</code> is sufficient in precision to be relied upon as a configuration parameter by a {@link
+     * RunAsManager}, {@link AccessDecisionManager} or <code>AccessDecisionManager</code> delegate, this method should
+     * return such a <code>String</code>.<p>If the <code>ConfigAttribute</code> cannot be expressed with
+     * sufficient precision as a <code>String</code>,  <code>null</code> should be returned. Returning
+     * <code>null</code> will require any relying classes to specifically support the  <code>ConfigAttribute</code>
+     * implementation, so returning  <code>null</code> should be avoided unless actually  required.</p>
      *
      *
-     * @return a representation of the configuration attribute (or
-     *         <code>null</code> if the configuration attribute cannot be
-     *         expressed as a <code>String</code> with sufficient precision).
+     * @return a representation of the configuration attribute (or <code>null</code> if the configuration attribute
+     *         cannot be expressed as a <code>String</code> with sufficient precision).
      */
      */
     public String getAttribute();
     public String getAttribute();
 }
 }

+ 25 - 36
core/src/main/java/org/acegisecurity/ConfigAttributeDefinition.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -23,52 +23,29 @@ import java.util.Vector;
 
 
 
 
 /**
 /**
- * Holds a group of {@link ConfigAttribute}s that are associated with a given
- * secure object target.
- * 
- * <p>
- * All the <code>ConfigAttributeDefinition</code>s associated with a given
- * {@link org.acegisecurity.intercept.AbstractSecurityInterceptor} are
- * stored in an {@link org.acegisecurity.intercept.ObjectDefinitionSource}.
- * </p>
+ * Holds a group of {@link ConfigAttribute}s that are associated with a given secure object target.<p>All the
+ * <code>ConfigAttributeDefinition</code>s associated with a given {@link
+ * org.acegisecurity.intercept.AbstractSecurityInterceptor} are stored in an {@link
+ * org.acegisecurity.intercept.ObjectDefinitionSource}.</p>
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public class ConfigAttributeDefinition implements Serializable {
 public class ConfigAttributeDefinition implements Serializable {
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private List configAttributes = new Vector();
     private List configAttributes = new Vector();
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
     public ConfigAttributeDefinition() {
     public ConfigAttributeDefinition() {
         super();
         super();
     }
     }
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
-     * Returns an <code>Iterator</code> over all the
-     * <code>ConfigAttribute</code>s defined by this
-     * <code>ConfigAttributeDefinition</code>.
-     * 
-     * <P>
-     * Allows <code>AccessDecisionManager</code>s and other classes to loop
-     * through every configuration attribute associated with a target secure
-     * object.
-     * </p>
-     *
-     * @return all the configuration attributes stored by the instance, or
-     *         <code>null</code> if an <code>Iterator</code> is unavailable
-     */
-    public Iterator getConfigAttributes() {
-        return this.configAttributes.iterator();
-    }
-
-    /**
-     * Adds a <code>ConfigAttribute</code> that is related to the secure object
-     * method.
+     * Adds a <code>ConfigAttribute</code> that is related to the secure object method.
      *
      *
      * @param newConfigAttribute the new configuration attribute to add
      * @param newConfigAttribute the new configuration attribute to add
      */
      */
@@ -77,13 +54,13 @@ public class ConfigAttributeDefinition implements Serializable {
     }
     }
 
 
     /**
     /**
-     * Indicates whether the specified <code>ConfigAttribute</code> is
-     * contained within this <code>ConfigAttributeDefinition</code>.
+     * Indicates whether the specified <code>ConfigAttribute</code> is contained within this
+     * <code>ConfigAttributeDefinition</code>.
      *
      *
      * @param configAttribute the attribute to locate
      * @param configAttribute the attribute to locate
      *
      *
-     * @return <code>true</code> if the specified <code>ConfigAttribute</code>
-     *         is contained, <code>false</code> otherwise
+     * @return <code>true</code> if the specified <code>ConfigAttribute</code> is contained, <code>false</code>
+     *         otherwise
      */
      */
     public boolean contains(ConfigAttribute configAttribute) {
     public boolean contains(ConfigAttribute configAttribute) {
         return configAttributes.contains(configAttribute);
         return configAttributes.contains(configAttribute);
@@ -117,6 +94,18 @@ public class ConfigAttributeDefinition implements Serializable {
         return false;
         return false;
     }
     }
 
 
+    /**
+     * Returns an <code>Iterator</code> over all the <code>ConfigAttribute</code>s defined by this
+     * <code>ConfigAttributeDefinition</code>.<P>Allows <code>AccessDecisionManager</code>s and other classes
+     * to loop through every configuration attribute associated with a target secure object.</p>
+     *
+     * @return all the configuration attributes stored by the instance, or <code>null</code> if an
+     *         <code>Iterator</code> is unavailable
+     */
+    public Iterator getConfigAttributes() {
+        return this.configAttributes.iterator();
+    }
+
     /**
     /**
      * Returns the number of <code>ConfigAttribute</code>s defined by this
      * Returns the number of <code>ConfigAttribute</code>s defined by this
      * <code>ConfigAttributeDefinition</code>.
      * <code>ConfigAttributeDefinition</code>.

+ 6 - 11
core/src/main/java/org/acegisecurity/ConfigAttributeEditor.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -21,19 +21,15 @@ import java.beans.PropertyEditorSupport;
 
 
 
 
 /**
 /**
- * A property editor that can create a populated  {@link
- * ConfigAttributeDefinition} from a comma separated list of values.
- * 
- * <P>
- * Trims preceding and trailing spaces from presented command separated tokens,
- * as this can be a source of hard-to-spot configuration issues for end users.
- * </p>
+ * A property editor that can create a populated  {@link ConfigAttributeDefinition} from a comma separated list of
+ * values.<P>Trims preceding and trailing spaces from presented command separated tokens, as this can be a source
+ * of hard-to-spot configuration issues for end users.</p>
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public class ConfigAttributeEditor extends PropertyEditorSupport {
 public class ConfigAttributeEditor extends PropertyEditorSupport {
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     public void setAsText(String s) throws IllegalArgumentException {
     public void setAsText(String s) throws IllegalArgumentException {
         if ((s == null) || "".equals(s)) {
         if ((s == null) || "".equals(s)) {
@@ -43,8 +39,7 @@ public class ConfigAttributeEditor extends PropertyEditorSupport {
             ConfigAttributeDefinition configDefinition = new ConfigAttributeDefinition();
             ConfigAttributeDefinition configDefinition = new ConfigAttributeDefinition();
 
 
             for (int i = 0; i < tokens.length; i++) {
             for (int i = 0; i < tokens.length; i++) {
-                configDefinition.addConfigAttribute(new SecurityConfig(
-                        tokens[i].trim()));
+                configDefinition.addConfigAttribute(new SecurityConfig(tokens[i].trim()));
             }
             }
 
 
             setValue(configDefinition);
             setValue(configDefinition);

+ 6 - 7
core/src/main/java/org/acegisecurity/CredentialsExpiredException.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -16,17 +16,16 @@
 package org.acegisecurity;
 package org.acegisecurity;
 
 
 /**
 /**
- * Thrown if an authentication request is rejected because the account's
- * credentials have expired. Makes no assertion as to whether or not the
- * credentials were valid.
+ * Thrown if an authentication request is rejected because the account's credentials have expired. Makes no
+ * assertion as to whether or not the credentials were valid.
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public class CredentialsExpiredException extends AuthenticationException {
 public class CredentialsExpiredException extends AuthenticationException {
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
-    /**
+/**
      * Constructs a <code>CredentialsExpiredException</code> with the specified
      * Constructs a <code>CredentialsExpiredException</code> with the specified
      * message.
      * message.
      *
      *
@@ -36,7 +35,7 @@ public class CredentialsExpiredException extends AuthenticationException {
         super(msg);
         super(msg);
     }
     }
 
 
-    /**
+/**
      * Constructs a <code>CredentialsExpiredException</code> with the specified
      * Constructs a <code>CredentialsExpiredException</code> with the specified
      * message and root cause.
      * message and root cause.
      *
      *

+ 6 - 7
core/src/main/java/org/acegisecurity/DisabledException.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -16,17 +16,16 @@
 package org.acegisecurity;
 package org.acegisecurity;
 
 
 /**
 /**
- * Thrown if an authentication request is rejected because the account is
- * disabled. Makes no assertion as to whether or not the credentials were
- * valid.
+ * Thrown if an authentication request is rejected because the account is disabled. Makes no assertion as to
+ * whether or not the credentials were valid.
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public class DisabledException extends AuthenticationException {
 public class DisabledException extends AuthenticationException {
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
-    /**
+/**
      * Constructs a <code>DisabledException</code> with the specified message.
      * Constructs a <code>DisabledException</code> with the specified message.
      *
      *
      * @param msg the detail message
      * @param msg the detail message
@@ -35,7 +34,7 @@ public class DisabledException extends AuthenticationException {
         super(msg);
         super(msg);
     }
     }
 
 
-    /**
+/**
      * Constructs a <code>DisabledException</code> with the specified message
      * Constructs a <code>DisabledException</code> with the specified message
      * and root cause.
      * and root cause.
      *
      *

+ 11 - 19
core/src/main/java/org/acegisecurity/GrantedAuthority.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -28,27 +28,19 @@ package org.acegisecurity;
  * @version $Id$
  * @version $Id$
  */
  */
 public interface GrantedAuthority {
 public interface GrantedAuthority {
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
-     * If the <code>GrantedAuthority</code> can be represented as a
-     * <code>String</code> and that <code>String</code> is sufficient in
-     * precision to be relied upon for an access control decision by an {@link
-     * AccessDecisionManager} (or delegate), this method should return such a
-     * <code>String</code>.
-     * 
-     * <p>
-     * If the <code>GrantedAuthority</code> cannot be expressed with sufficient
-     * precision as a <code>String</code>,  <code>null</code> should be
-     * returned. Returning <code>null</code> will require an
-     * <code>AccessDecisionManager</code> (or delegate) to  specifically
-     * support the <code>GrantedAuthority</code> implementation,  so returning
-     * <code>null</code> should be avoided unless actually  required.
-     * </p>
+     * If the <code>GrantedAuthority</code> can be represented as a <code>String</code> and that
+     * <code>String</code> is sufficient in precision to be relied upon for an access control decision by an {@link
+     * AccessDecisionManager} (or delegate), this method should return such a <code>String</code>.<p>If the
+     * <code>GrantedAuthority</code> cannot be expressed with sufficient precision as a <code>String</code>,
+     * <code>null</code> should be returned. Returning <code>null</code> will require an
+     * <code>AccessDecisionManager</code> (or delegate) to  specifically support the <code>GrantedAuthority</code>
+     * implementation,  so returning <code>null</code> should be avoided unless actually  required.</p>
      *
      *
-     * @return a representation of the granted authority (or <code>null</code>
-     *         if the granted authority cannot be expressed as a
-     *         <code>String</code> with sufficient precision).
+     * @return a representation of the granted authority (or <code>null</code> if the granted authority cannot be
+     *         expressed as a <code>String</code> with sufficient precision).
      */
      */
     public String getAuthority();
     public String getAuthority();
 }
 }

+ 5 - 9
core/src/main/java/org/acegisecurity/GrantedAuthorityImpl.java

@@ -19,29 +19,25 @@ import java.io.Serializable;
 
 
 
 
 /**
 /**
- * Basic concrete implementation of a {@link GrantedAuthority}.
- * 
- * <p>
- * Stores a <code>String</code> representation of an authority granted to  the
- * {@link Authentication} object.
- * </p>
+ * Basic concrete implementation of a {@link GrantedAuthority}.<p>Stores a <code>String</code> representation of an
+ * authority granted to  the {@link Authentication} object.</p>
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public class GrantedAuthorityImpl implements GrantedAuthority, Serializable {
 public class GrantedAuthorityImpl implements GrantedAuthority, Serializable {
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private String role;
     private String role;
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
     public GrantedAuthorityImpl(String role) {
     public GrantedAuthorityImpl(String role) {
         super();
         super();
         this.role = role;
         this.role = role;
     }
     }
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     public boolean equals(Object obj) {
     public boolean equals(Object obj) {
         if (obj instanceof String) {
         if (obj instanceof String) {

+ 9 - 16
core/src/main/java/org/acegisecurity/InsufficientAuthenticationException.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -16,26 +16,19 @@
 package org.acegisecurity;
 package org.acegisecurity;
 
 
 /**
 /**
- * Thrown if an authentication request is rejected because the credentials are
- * not sufficiently trusted.
- * 
- * <p>
- * {@link org.acegisecurity.vote.AccessDecisionVoter}s will typically throw
- * this exception if they are dissatisfied with the level of the
- * authentication, such as if performed using a remember-me mechanism or
- * anonymously. The commonly used {@link
- * org.acegisecurity.ui.ExceptionTranslationFilter} will thus
- * cause the <code>AuthenticationEntryPoint</code> to be called, allowing the
- * principal to authenticate with a stronger level of authentication.
- * </p>
+ * Thrown if an authentication request is rejected because the credentials are not sufficiently trusted.<p>{{@link
+ * org.acegisecurity.vote.AccessDecisionVoter}s will typically throw this exception if they are dissatisfied with the
+ * level of the authentication, such as if performed using a remember-me mechanism or anonymously. The commonly used
+ * {@link org.acegisecurity.ui.ExceptionTranslationFilter} will thus cause the <code>AuthenticationEntryPoint</code>
+ * to be called, allowing the principal to authenticate with a stronger level of authentication.}</p>
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public class InsufficientAuthenticationException extends AuthenticationException {
 public class InsufficientAuthenticationException extends AuthenticationException {
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
-    /**
+/**
      * Constructs an <code>InsufficientAuthenticationException</code> with the
      * Constructs an <code>InsufficientAuthenticationException</code> with the
      * specified message.
      * specified message.
      *
      *
@@ -45,7 +38,7 @@ public class InsufficientAuthenticationException extends AuthenticationException
         super(msg);
         super(msg);
     }
     }
 
 
-    /**
+/**
      * Constructs an <code>InsufficientAuthenticationException</code> with the
      * Constructs an <code>InsufficientAuthenticationException</code> with the
      * specified message and root cause.
      * specified message and root cause.
      *
      *

+ 6 - 6
core/src/main/java/org/acegisecurity/LockedException.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -16,16 +16,16 @@
 package org.acegisecurity;
 package org.acegisecurity;
 
 
 /**
 /**
- * Thrown if an authentication request is rejected because the account is
- * locked. Makes no assertion as to whether or not the credentials were valid.
+ * Thrown if an authentication request is rejected because the account is locked. Makes no assertion as to whether
+ * or not the credentials were valid.
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public class LockedException extends AuthenticationException {
 public class LockedException extends AuthenticationException {
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
-    /**
+/**
      * Constructs a <code>LockedException</code> with the specified message.
      * Constructs a <code>LockedException</code> with the specified message.
      *
      *
      * @param msg the detail message.
      * @param msg the detail message.
@@ -34,7 +34,7 @@ public class LockedException extends AuthenticationException {
         super(msg);
         super(msg);
     }
     }
 
 
-    /**
+/**
      * Constructs a <code>LockedException</code> with the specified message and
      * Constructs a <code>LockedException</code> with the specified message and
      * root cause.
      * root cause.
      *
      *

+ 6 - 8
core/src/main/java/org/acegisecurity/MockAuthenticationManager.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -16,19 +16,18 @@
 package org.acegisecurity;
 package org.acegisecurity;
 
 
 /**
 /**
- * Simply accepts as valid whatever is passed to it, if
- * <code>grantAccess</code> is set to <code>true</code>.
+ * Simply accepts as valid whatever is passed to it, if <code>grantAccess</code> is set to <code>true</code>.
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @author Wesley Hall
  * @author Wesley Hall
  * @version $Id$
  * @version $Id$
  */
  */
 public class MockAuthenticationManager extends AbstractAuthenticationManager {
 public class MockAuthenticationManager extends AbstractAuthenticationManager {
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private boolean grantAccess = true;
     private boolean grantAccess = true;
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
     public MockAuthenticationManager(boolean grantAccess) {
     public MockAuthenticationManager(boolean grantAccess) {
         this.grantAccess = grantAccess;
         this.grantAccess = grantAccess;
@@ -38,15 +37,14 @@ public class MockAuthenticationManager extends AbstractAuthenticationManager {
         super();
         super();
     }
     }
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     public Authentication doAuthentication(Authentication authentication)
     public Authentication doAuthentication(Authentication authentication)
         throws AuthenticationException {
         throws AuthenticationException {
         if (grantAccess) {
         if (grantAccess) {
             return authentication;
             return authentication;
         } else {
         } else {
-            throw new BadCredentialsException(
-                "MockAuthenticationManager instructed to deny access");
+            throw new BadCredentialsException("MockAuthenticationManager instructed to deny access");
         }
         }
     }
     }
 }
 }

+ 17 - 27
core/src/main/java/org/acegisecurity/RunAsManager.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -58,47 +58,37 @@ package org.acegisecurity;
  * @version $Id$
  * @version $Id$
  */
  */
 public interface RunAsManager {
 public interface RunAsManager {
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
-     * Returns a replacement <code>Authentication</code> object for the current
-     * secure object invocation, or <code>null</code> if replacement not
-     * required.
+     * Returns a replacement <code>Authentication</code> object for the current secure object invocation, or
+     * <code>null</code> if replacement not required.
      *
      *
      * @param authentication the caller invoking the secure object
      * @param authentication the caller invoking the secure object
      * @param object the secured object being called
      * @param object the secured object being called
-     * @param config the configuration attributes associated with the secure
-     *        object being invoked
+     * @param config the configuration attributes associated with the secure object being invoked
      *
      *
-     * @return a replacement object to be used for duration of the secure
-     *         object invocation, or <code>null</code> if the
-     *         <code>Authentication</code> should be left as is
+     * @return a replacement object to be used for duration of the secure object invocation, or <code>null</code> if
+     *         the <code>Authentication</code> should be left as is
      */
      */
-    public Authentication buildRunAs(Authentication authentication,
-        Object object, ConfigAttributeDefinition config);
+    public Authentication buildRunAs(Authentication authentication, Object object, ConfigAttributeDefinition config);
 
 
     /**
     /**
-     * Indicates whether this <code>RunAsManager</code> is able to process the
-     * passed <code>ConfigAttribute</code>.
-     * 
-     * <p>
-     * This allows the <code>AbstractSecurityInterceptor</code> to check every
-     * configuration attribute can be consumed by the configured
-     * <code>AccessDecisionManager</code> and/or <code>RunAsManager</code>
-     * and/or <code>AfterInvocationManager</code>.
-     * </p>
+     * Indicates whether this <code>RunAsManager</code> is able to process the passed
+     * <code>ConfigAttribute</code>.<p>This allows the <code>AbstractSecurityInterceptor</code> to check every
+     * configuration attribute can be consumed by the configured <code>AccessDecisionManager</code> and/or
+     * <code>RunAsManager</code> and/or <code>AfterInvocationManager</code>.</p>
      *
      *
-     * @param attribute a configuration attribute that has been configured
-     *        against the <code>AbstractSecurityInterceptor</code>
+     * @param attribute a configuration attribute that has been configured against the
+     *        <code>AbstractSecurityInterceptor</code>
      *
      *
-     * @return <code>true</code> if this <code>RunAsManager</code> can support
-     *         the passed configuration attribute
+     * @return <code>true</code> if this <code>RunAsManager</code> can support the passed configuration attribute
      */
      */
     public boolean supports(ConfigAttribute attribute);
     public boolean supports(ConfigAttribute attribute);
 
 
     /**
     /**
-     * Indicates whether the <code>RunAsManager</code> implementation is able
-     * to provide run-as replacement for the indicated secure object type.
+     * Indicates whether the <code>RunAsManager</code> implementation is able to provide run-as replacement for
+     * the indicated secure object type.
      *
      *
      * @param clazz the class that is being queried
      * @param clazz the class that is being queried
      *
      *

+ 8 - 8
core/src/main/java/org/acegisecurity/SecurityConfig.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -22,21 +22,17 @@ package org.acegisecurity;
  * @version $Id$
  * @version $Id$
  */
  */
 public class SecurityConfig implements ConfigAttribute {
 public class SecurityConfig implements ConfigAttribute {
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private String attrib;
     private String attrib;
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
     public SecurityConfig(String config) {
     public SecurityConfig(String config) {
         this.attrib = config;
         this.attrib = config;
     }
     }
 
 
-    //~ Methods ================================================================
-
-    public String getAttribute() {
-        return this.attrib;
-    }
+    //~ Methods ========================================================================================================
 
 
     public boolean equals(Object obj) {
     public boolean equals(Object obj) {
         if (obj instanceof String) {
         if (obj instanceof String) {
@@ -52,6 +48,10 @@ public class SecurityConfig implements ConfigAttribute {
         return false;
         return false;
     }
     }
 
 
+    public String getAttribute() {
+        return this.attrib;
+    }
+
     public int hashCode() {
     public int hashCode() {
         return this.attrib.hashCode();
         return this.attrib.hashCode();
     }
     }

+ 2 - 1
core/src/main/java/org/acegisecurity/acl/AclEntry.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@ package org.acegisecurity.acl;
 
 
 import java.io.Serializable;
 import java.io.Serializable;
 
 
+
 /**
 /**
  * Marker interface representing an access control list entry associated with a
  * Marker interface representing an access control list entry associated with a
  * specific domain object instance.
  * specific domain object instance.

+ 11 - 18
core/src/main/java/org/acegisecurity/acl/AclManager.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -26,33 +26,26 @@ import org.acegisecurity.Authentication;
  * @version $Id$
  * @version $Id$
  */
  */
 public interface AclManager {
 public interface AclManager {
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
      * Obtains the ACLs that apply to the specified domain instance.
      * Obtains the ACLs that apply to the specified domain instance.
      *
      *
-     * @param domainInstance the instance for which ACL information is required
-     *        (never <code>null</code>)
+     * @param domainInstance the instance for which ACL information is required (never <code>null</code>)
      *
      *
-     * @return the ACLs that apply, or <code>null</code> if no ACLs apply to
-     *         the specified domain instance
+     * @return the ACLs that apply, or <code>null</code> if no ACLs apply to the specified domain instance
      */
      */
     public AclEntry[] getAcls(Object domainInstance);
     public AclEntry[] getAcls(Object domainInstance);
 
 
     /**
     /**
-     * Obtains the ACLs that apply to the specified domain instance, but only
-     * including those ACLs which have been granted to the presented
-     * <code>Authentication</code> object
+     * Obtains the ACLs that apply to the specified domain instance, but only including those ACLs which have
+     * been granted to the presented <code>Authentication</code> object
      *
      *
-     * @param domainInstance the instance for which ACL information is required
-     *        (never <code>null</code>)
-     * @param authentication the prncipal for which ACL information should be
-     *        filtered (never <code>null</code>)
+     * @param domainInstance the instance for which ACL information is required (never <code>null</code>)
+     * @param authentication the prncipal for which ACL information should be filtered (never <code>null</code>)
      *
      *
-     * @return only those ACLs applying to the domain instance that have been
-     *         granted to the principal (or <code>null</code>) if no such ACLs
-     *         are found
+     * @return only those ACLs applying to the domain instance that have been granted to the principal (or
+     *         <code>null</code>) if no such ACLs are found
      */
      */
-    public AclEntry[] getAcls(Object domainInstance,
-        Authentication authentication);
+    public AclEntry[] getAcls(Object domainInstance, Authentication authentication);
 }
 }

+ 19 - 34
core/src/main/java/org/acegisecurity/acl/AclProvider.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@ package org.acegisecurity.acl;
 
 
 import org.acegisecurity.Authentication;
 import org.acegisecurity.Authentication;
 
 
+
 /**
 /**
  * Indicates a class can process a given domain object instance and
  * Indicates a class can process a given domain object instance and
  * authoritatively return the ACLs that apply.
  * authoritatively return the ACLs that apply.
@@ -29,54 +30,38 @@ import org.acegisecurity.Authentication;
  * @version $Id$
  * @version $Id$
  */
  */
 public interface AclProvider {
 public interface AclProvider {
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
-     * Obtains the ACLs that apply to the specified domain instance.
-     * 
-     * <P>
-     * Will never be called unless the {@link #supports(Object)} method
-     * returned <code>true</code>.
-     * </p>
+     * Obtains the ACLs that apply to the specified domain instance.<P>Will never be called unless the {@link
+     * #supports(Object)} method returned <code>true</code>.</p>
      *
      *
-     * @param domainInstance the instance for which ACL information is required
-     *        (never <code>null</code>)
+     * @param domainInstance the instance for which ACL information is required (never <code>null</code>)
      *
      *
-     * @return the ACLs that apply, or <code>null</code> if no ACLs apply to
-     *         the specified domain instance
+     * @return the ACLs that apply, or <code>null</code> if no ACLs apply to the specified domain instance
      */
      */
     public AclEntry[] getAcls(Object domainInstance);
     public AclEntry[] getAcls(Object domainInstance);
 
 
     /**
     /**
-     * Obtains the ACLs that apply to the specified domain instance
-     * and presented <code>Authentication</code> object.
+     * Obtains the ACLs that apply to the specified domain instance and presented <code>Authentication</code>
+     * object.<P>Will never be called unless the {@link #supports(Object)} method returned <code>true</code>.</p>
      *
      *
-     * <P>
-     * Will never be called unless the {@link #supports(Object)} method
-     * returned <code>true</code>.
-     * </p>
-     * 
-     * @param domainInstance the instance for which ACL information is required
-     *        (never <code>null</code>)
-     * @param authentication the prncipal for which ACL information should be
-     *        filtered (never <code>null</code>)
+     * @param domainInstance the instance for which ACL information is required (never <code>null</code>)
+     * @param authentication the prncipal for which ACL information should be filtered (never <code>null</code>)
      *
      *
-     * @return only those ACLs applying to the domain instance that have been
-     *         granted to the principal (or <code>null</code>) if no such ACLs
-     *         are found
+     * @return only those ACLs applying to the domain instance that have been granted to the principal (or
+     *         <code>null</code>) if no such ACLs are found
      */
      */
-    public AclEntry[] getAcls(Object domainInstance,
-        Authentication authentication);
+    public AclEntry[] getAcls(Object domainInstance, Authentication authentication);
 
 
     /**
     /**
-     * Indicates whether this <code>AclProvider</code> can authoritatively
-     * return ACL information for the specified domain object instance.
+     * Indicates whether this <code>AclProvider</code> can authoritatively return ACL information for the
+     * specified domain object instance.
      *
      *
-     * @param domainInstance the instance for which ACL information is required
-     *        (never <code>null</code>)
+     * @param domainInstance the instance for which ACL information is required (never <code>null</code>)
      *
      *
-     * @return <code>true</code> if this provider is authoritative for the
-     *         specified domain object instance, <code>false</code> otherwise
+     * @return <code>true</code> if this provider is authoritative for the specified domain object instance,
+     *         <code>false</code> otherwise
      */
      */
     public boolean supports(Object domainInstance);
     public boolean supports(Object domainInstance);
 }
 }

+ 28 - 39
core/src/main/java/org/acegisecurity/acl/AclProviderManager.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.logging.LogFactory;
 
 
 import org.springframework.beans.factory.InitializingBean;
 import org.springframework.beans.factory.InitializingBean;
+
 import org.springframework.util.Assert;
 import org.springframework.util.Assert;
 
 
 import java.util.Iterator;
 import java.util.Iterator;
@@ -28,27 +29,31 @@ import java.util.List;
 
 
 
 
 /**
 /**
- * Iterates through a list of {@link AclProvider}s to locate the ACLs that
- * apply to a given domain object instance.
- * 
- * <P>
- * If no compatible provider is found, it is assumed that no ACLs apply for the
- * specified domain object instance and <code>null</code> is returned.
- * </p>
+ * Iterates through a list of {@link AclProvider}s to locate the ACLs that apply to a given domain object instance.<P>If
+ * no compatible provider is found, it is assumed that no ACLs apply for the specified domain object instance and
+ * <code>null</code> is returned.</p>
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public class AclProviderManager implements AclManager, InitializingBean {
 public class AclProviderManager implements AclManager, InitializingBean {
-    //~ Static fields/initializers =============================================
+    //~ Static fields/initializers =====================================================================================
 
 
     private static final Log logger = LogFactory.getLog(AclProviderManager.class);
     private static final Log logger = LogFactory.getLog(AclProviderManager.class);
 
 
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private List providers;
     private List providers;
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
+
+    public void afterPropertiesSet() throws Exception {
+        checkIfValidList(this.providers);
+    }
+
+    private void checkIfValidList(List listToCheck) {
+        Assert.notEmpty(listToCheck, "A list of AclManagers is required");
+    }
 
 
     public AclEntry[] getAcls(Object domainInstance) {
     public AclEntry[] getAcls(Object domainInstance) {
         Assert.notNull(domainInstance, "domainInstance is null - violating interface contract");
         Assert.notNull(domainInstance, "domainInstance is null - violating interface contract");
@@ -60,8 +65,7 @@ public class AclProviderManager implements AclManager, InitializingBean {
 
 
             if (provider.supports(domainInstance)) {
             if (provider.supports(domainInstance)) {
                 if (logger.isDebugEnabled()) {
                 if (logger.isDebugEnabled()) {
-                    logger.debug("ACL lookup using "
-                            + provider.getClass().getName());
+                    logger.debug("ACL lookup using " + provider.getClass().getName());
                 }
                 }
 
 
                 return provider.getAcls(domainInstance);
                 return provider.getAcls(domainInstance);
@@ -69,15 +73,13 @@ public class AclProviderManager implements AclManager, InitializingBean {
         }
         }
 
 
         if (logger.isDebugEnabled()) {
         if (logger.isDebugEnabled()) {
-            logger.debug("No AclProvider found for "
-                    + domainInstance.toString());
+            logger.debug("No AclProvider found for " + domainInstance.toString());
         }
         }
 
 
         return null;
         return null;
     }
     }
 
 
-    public AclEntry[] getAcls(Object domainInstance,
-        Authentication authentication) {
+    public AclEntry[] getAcls(Object domainInstance, Authentication authentication) {
         Assert.notNull(domainInstance, "domainInstance is null - violating interface contract");
         Assert.notNull(domainInstance, "domainInstance is null - violating interface contract");
         Assert.notNull(authentication, "authentication is null - violating interface contract");
         Assert.notNull(authentication, "authentication is null - violating interface contract");
 
 
@@ -88,34 +90,34 @@ public class AclProviderManager implements AclManager, InitializingBean {
 
 
             if (provider.supports(domainInstance)) {
             if (provider.supports(domainInstance)) {
                 if (logger.isDebugEnabled()) {
                 if (logger.isDebugEnabled()) {
-                    logger.debug("ACL lookup using "
-                            + provider.getClass().getName());
+                    logger.debug("ACL lookup using " + provider.getClass().getName());
                 }
                 }
 
 
                 return provider.getAcls(domainInstance, authentication);
                 return provider.getAcls(domainInstance, authentication);
             } else {
             } else {
                 if (logger.isDebugEnabled()) {
                 if (logger.isDebugEnabled()) {
-                    logger.debug("Provider " + provider.toString()
-                            + " does not support " + domainInstance);
+                    logger.debug("Provider " + provider.toString() + " does not support " + domainInstance);
                 }
                 }
             }
             }
         }
         }
 
 
         if (logger.isDebugEnabled()) {
         if (logger.isDebugEnabled()) {
-            logger.debug("No AclProvider found for "
-                    + domainInstance.toString());
+            logger.debug("No AclProvider found for " + domainInstance.toString());
         }
         }
 
 
         return null;
         return null;
     }
     }
 
 
+    public List getProviders() {
+        return this.providers;
+    }
+
     /**
     /**
      * Sets the {@link AclProvider} objects to be used for ACL determinations.
      * Sets the {@link AclProvider} objects to be used for ACL determinations.
      *
      *
      * @param newList that should be used for ACL determinations
      * @param newList that should be used for ACL determinations
      *
      *
-     * @throws IllegalArgumentException if an invalid provider was included in
-     *         the list
+     * @throws IllegalArgumentException if an invalid provider was included in the list
      */
      */
     public void setProviders(List newList) {
     public void setProviders(List newList) {
         checkIfValidList(newList);
         checkIfValidList(newList);
@@ -130,24 +132,11 @@ public class AclProviderManager implements AclManager, InitializingBean {
 
 
                 AclProvider attemptToCast = (AclProvider) currentObject;
                 AclProvider attemptToCast = (AclProvider) currentObject;
             } catch (ClassCastException cce) {
             } catch (ClassCastException cce) {
-                throw new IllegalArgumentException("AclProvider "
-                    + currentObject.getClass().getName()
+                throw new IllegalArgumentException("AclProvider " + currentObject.getClass().getName()
                     + " must implement AclProvider");
                     + " must implement AclProvider");
             }
             }
         }
         }
 
 
         this.providers = newList;
         this.providers = newList;
     }
     }
-
-    public List getProviders() {
-        return this.providers;
-    }
-
-    public void afterPropertiesSet() throws Exception {
-        checkIfValidList(this.providers);
-    }
-
-    private void checkIfValidList(List listToCheck) {
-        Assert.notEmpty(listToCheck, "A list of AclManagers is required");
-    }
 }
 }

+ 108 - 138
core/src/main/java/org/acegisecurity/acl/basic/AbstractBasicAclEntry.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -17,27 +17,24 @@ package org.acegisecurity.acl.basic;
 
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.logging.LogFactory;
+
 import org.springframework.util.Assert;
 import org.springframework.util.Assert;
 
 
 import java.util.Arrays;
 import java.util.Arrays;
 
 
 
 
 /**
 /**
- * Abstract implementation of {@link BasicAclEntry}.
- * 
- * <P>
- * Provides core bit mask handling methods.
- * </p>
+ * Abstract implementation of {@link BasicAclEntry}.<P>Provides core bit mask handling methods.</p>
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public abstract class AbstractBasicAclEntry implements BasicAclEntry {
 public abstract class AbstractBasicAclEntry implements BasicAclEntry {
-    //~ Static fields/initializers =============================================
+    //~ Static fields/initializers =====================================================================================
 
 
     private static final Log logger = LogFactory.getLog(AbstractBasicAclEntry.class);
     private static final Log logger = LogFactory.getLog(AbstractBasicAclEntry.class);
 
 
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private AclObjectIdentity aclObjectIdentity;
     private AclObjectIdentity aclObjectIdentity;
     private AclObjectIdentity aclObjectParentIdentity;
     private AclObjectIdentity aclObjectParentIdentity;
@@ -45,10 +42,9 @@ public abstract class AbstractBasicAclEntry implements BasicAclEntry {
     private int[] validPermissions;
     private int[] validPermissions;
     private int mask = 0; // default means no permissions
     private int mask = 0; // default means no permissions
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
-    public AbstractBasicAclEntry(Object recipient,
-        AclObjectIdentity aclObjectIdentity,
+    public AbstractBasicAclEntry(Object recipient, AclObjectIdentity aclObjectIdentity,
         AclObjectIdentity aclObjectParentIdentity, int mask) {
         AclObjectIdentity aclObjectParentIdentity, int mask) {
         Assert.notNull(recipient, "recipient cannot be null");
         Assert.notNull(recipient, "recipient cannot be null");
 
 
@@ -59,10 +55,8 @@ public abstract class AbstractBasicAclEntry implements BasicAclEntry {
 
 
         for (int i = 0; i < validPermissions.length; i++) {
         for (int i = 0; i < validPermissions.length; i++) {
             if (logger.isDebugEnabled()) {
             if (logger.isDebugEnabled()) {
-                logger.debug("Valid permission:   "
-                        + printPermissionsBlock(validPermissions[i]) + " "
-                        + printBinary(validPermissions[i]) + " ("
-                        + validPermissions[i] + ")");
+                logger.debug("Valid permission:   " + printPermissionsBlock(validPermissions[i]) + " "
+                    + printBinary(validPermissions[i]) + " (" + validPermissions[i] + ")");
             }
             }
         }
         }
 
 
@@ -72,7 +66,7 @@ public abstract class AbstractBasicAclEntry implements BasicAclEntry {
         this.mask = mask;
         this.mask = mask;
     }
     }
 
 
-    /**
+/**
      * A protected constructor for use by Hibernate.
      * A protected constructor for use by Hibernate.
      */
      */
     protected AbstractBasicAclEntry() {
     protected AbstractBasicAclEntry() {
@@ -80,86 +74,7 @@ public abstract class AbstractBasicAclEntry implements BasicAclEntry {
         Arrays.sort(validPermissions);
         Arrays.sort(validPermissions);
     }
     }
 
 
-    //~ Methods ================================================================
-
-    public void setAclObjectIdentity(AclObjectIdentity aclObjectIdentity) {
-        this.aclObjectIdentity = aclObjectIdentity;
-    }
-
-    public AclObjectIdentity getAclObjectIdentity() {
-        return this.aclObjectIdentity;
-    }
-
-    public void setAclObjectParentIdentity(
-        AclObjectIdentity aclObjectParentIdentity) {
-        this.aclObjectParentIdentity = aclObjectParentIdentity;
-    }
-
-    public AclObjectIdentity getAclObjectParentIdentity() {
-        return this.aclObjectParentIdentity;
-    }
-
-    /**
-     * Subclasses must indicate the permissions they support. Each base
-     * permission should be an integer with a base 2. ie: the first permission
-     * is 2^^0 (1), the second permission is 2^^1 (2), the third permission is
-     * 2^^2 (4) etc. Each base permission should be exposed by the subclass as
-     * a <code>public static final int</code>. It is further recommended that
-     * valid combinations of permissions are also exposed as <code>public
-     * static final int</code>s.
-     * 
-     * <P>
-     * This method returns all permission integers that are allowed to be used
-     * together. <B>This must include any combinations of valid
-     * permissions</b>. So if the permissions indicated by 2^^2 (4) and 2^^1
-     * (2) can be used together, one of the integers returned by this method
-     * must be 6 (4 + 2). Otherwise attempts to set the permission will be
-     * rejected, as the final resulting mask will be rejected.
-     * </p>
-     * 
-     * <P>
-     * Whilst it may seem unduly time onerous to return every valid permission
-     * <B>combination</B>, doing so delivers maximum flexibility in ensuring
-     * ACLs only reflect logical combinations. For example, it would be
-     * inappropriate to grant a "read" and "write" permission along with an
-     * "unrestricted" permission, as the latter implies the former
-     * permissions.
-     * </p>
-     *
-     * @return <b>every</b> valid combination of permissions
-     */
-    public abstract int[] getValidPermissions();
-
-    /**
-     * Outputs the permissions in a human-friendly format. For example, this
-     * method may return "CR-D" to indicate the passed integer permits create,
-     * permits read, does not permit update, and permits delete.
-     *
-     * @param i the integer containing the mask which should be printed
-     *
-     * @return the human-friend formatted block
-     */
-    public abstract String printPermissionsBlock(int i);
-
-    public void setMask(int mask) {
-        this.mask = mask;
-    }
-
-    public int getMask() {
-        return this.mask;
-    }
-
-    public boolean isPermitted(int permissionToCheck) {
-        return isPermitted(this.mask, permissionToCheck);
-    }
-
-    public void setRecipient(Object recipient) {
-        this.recipient = recipient;
-    }
-
-    public Object getRecipient() {
-        return this.recipient;
-    }
+    //~ Methods ========================================================================================================
 
 
     public int addPermission(int permissionToAdd) {
     public int addPermission(int permissionToAdd) {
         return addPermissions(new int[] {permissionToAdd});
         return addPermissions(new int[] {permissionToAdd});
@@ -167,29 +82,25 @@ public abstract class AbstractBasicAclEntry implements BasicAclEntry {
 
 
     public int addPermissions(int[] permissionsToAdd) {
     public int addPermissions(int[] permissionsToAdd) {
         if (logger.isDebugEnabled()) {
         if (logger.isDebugEnabled()) {
-            logger.debug("BEFORE Permissions: " + printPermissionsBlock(mask)
-                + " " + printBinary(mask) + " (" + mask + ")");
+            logger.debug("BEFORE Permissions: " + printPermissionsBlock(mask) + " " + printBinary(mask) + " (" + mask
+                + ")");
         }
         }
 
 
         for (int i = 0; i < permissionsToAdd.length; i++) {
         for (int i = 0; i < permissionsToAdd.length; i++) {
             if (logger.isDebugEnabled()) {
             if (logger.isDebugEnabled()) {
-                logger.debug("Add     permission: "
-                    + printPermissionsBlock(permissionsToAdd[i]) + " "
-                    + printBinary(permissionsToAdd[i]) + " ("
-                    + permissionsToAdd[i] + ")");
+                logger.debug("Add     permission: " + printPermissionsBlock(permissionsToAdd[i]) + " "
+                    + printBinary(permissionsToAdd[i]) + " (" + permissionsToAdd[i] + ")");
             }
             }
 
 
             this.mask |= permissionsToAdd[i];
             this.mask |= permissionsToAdd[i];
         }
         }
 
 
         if (Arrays.binarySearch(validPermissions, this.mask) < 0) {
         if (Arrays.binarySearch(validPermissions, this.mask) < 0) {
-            throw new IllegalArgumentException(
-                "Resulting permission set will be invalid.");
+            throw new IllegalArgumentException("Resulting permission set will be invalid.");
         } else {
         } else {
             if (logger.isDebugEnabled()) {
             if (logger.isDebugEnabled()) {
-                logger.debug("AFTER  Permissions: "
-                    + printPermissionsBlock(mask) + " " + printBinary(mask)
-                    + " (" + mask + ")");
+                logger.debug("AFTER  Permissions: " + printPermissionsBlock(mask) + " " + printBinary(mask) + " ("
+                    + mask + ")");
             }
             }
 
 
             return this.mask;
             return this.mask;
@@ -202,38 +113,98 @@ public abstract class AbstractBasicAclEntry implements BasicAclEntry {
 
 
     public int deletePermissions(int[] permissionsToDelete) {
     public int deletePermissions(int[] permissionsToDelete) {
         if (logger.isDebugEnabled()) {
         if (logger.isDebugEnabled()) {
-            logger.debug("BEFORE Permissions: " + printPermissionsBlock(mask)
-                + " " + printBinary(mask) + " (" + mask + ")");
+            logger.debug("BEFORE Permissions: " + printPermissionsBlock(mask) + " " + printBinary(mask) + " (" + mask
+                + ")");
         }
         }
 
 
         for (int i = 0; i < permissionsToDelete.length; i++) {
         for (int i = 0; i < permissionsToDelete.length; i++) {
             if (logger.isDebugEnabled()) {
             if (logger.isDebugEnabled()) {
-                logger.debug("Delete  permission: "
-                    + printPermissionsBlock(permissionsToDelete[i]) + " "
-                    + printBinary(permissionsToDelete[i]) + " ("
-                    + permissionsToDelete[i] + ")");
+                logger.debug("Delete  permission: " + printPermissionsBlock(permissionsToDelete[i]) + " "
+                    + printBinary(permissionsToDelete[i]) + " (" + permissionsToDelete[i] + ")");
             }
             }
 
 
             this.mask &= ~permissionsToDelete[i];
             this.mask &= ~permissionsToDelete[i];
         }
         }
 
 
         if (Arrays.binarySearch(validPermissions, this.mask) < 0) {
         if (Arrays.binarySearch(validPermissions, this.mask) < 0) {
-            throw new IllegalArgumentException(
-                "Resulting permission set will be invalid.");
+            throw new IllegalArgumentException("Resulting permission set will be invalid.");
         } else {
         } else {
             if (logger.isDebugEnabled()) {
             if (logger.isDebugEnabled()) {
-                logger.debug("AFTER  Permissions: "
-                    + printPermissionsBlock(mask) + " " + printBinary(mask)
-                    + " (" + mask + ")");
+                logger.debug("AFTER  Permissions: " + printPermissionsBlock(mask) + " " + printBinary(mask) + " ("
+                    + mask + ")");
             }
             }
 
 
             return this.mask;
             return this.mask;
         }
         }
     }
     }
 
 
+    public AclObjectIdentity getAclObjectIdentity() {
+        return this.aclObjectIdentity;
+    }
+
+    public AclObjectIdentity getAclObjectParentIdentity() {
+        return this.aclObjectParentIdentity;
+    }
+
+    public int getMask() {
+        return this.mask;
+    }
+
+    public Object getRecipient() {
+        return this.recipient;
+    }
+
+    /**
+     * Subclasses must indicate the permissions they support. Each base permission should be an integer with a
+     * base 2. ie: the first permission is 2^^0 (1), the second permission is 2^^1 (2), the third permission is 2^^2
+     * (4) etc. Each base permission should be exposed by the subclass as a <code>public static final int</code>. It
+     * is further recommended that valid combinations of permissions are also exposed as <code>public static final
+     * int</code>s.<P>This method returns all permission integers that are allowed to be used together. <B>This
+     * must include any combinations of valid permissions</b>. So if the permissions indicated by 2^^2 (4) and 2^^1
+     * (2) can be used together, one of the integers returned by this method must be 6 (4 + 2). Otherwise attempts to
+     * set the permission will be rejected, as the final resulting mask will be rejected.</p>
+     *  <P>Whilst it may seem unduly time onerous to return every valid permission <B>combination</B>, doing so
+     * delivers maximum flexibility in ensuring ACLs only reflect logical combinations. For example, it would be
+     * inappropriate to grant a "read" and "write" permission along with an "unrestricted" permission, as the latter
+     * implies the former permissions.</p>
+     *
+     * @return <b>every</b> valid combination of permissions
+     */
+    public abstract int[] getValidPermissions();
+
+    public boolean isPermitted(int permissionToCheck) {
+        return isPermitted(this.mask, permissionToCheck);
+    }
+
+    protected boolean isPermitted(int maskToCheck, int permissionToCheck) {
+        return ((maskToCheck & permissionToCheck) == permissionToCheck);
+    }
+
+    private String printBinary(int i) {
+        String s = Integer.toString(i, 2);
+
+        String pattern = "................................";
+
+        String temp1 = pattern.substring(0, pattern.length() - s.length());
+
+        String temp2 = temp1 + s;
+
+        return temp2.replace('0', '.');
+    }
+
+    /**
+     * Outputs the permissions in a human-friendly format. For example, this method may return "CR-D" to
+     * indicate the passed integer permits create, permits read, does not permit update, and permits delete.
+     *
+     * @param i the integer containing the mask which should be printed
+     *
+     * @return the human-friend formatted block
+     */
+    public abstract String printPermissionsBlock(int i);
+
     /**
     /**
-     * Outputs the permissions in human-friendly format for the current
-     * <code>AbstractBasicAclEntry</code>'s mask.
+     * Outputs the permissions in human-friendly format for the current <code>AbstractBasicAclEntry</code>'s
+     * mask.
      *
      *
      * @return the human-friendly formatted block for this instance
      * @return the human-friendly formatted block for this instance
      */
      */
@@ -241,6 +212,22 @@ public abstract class AbstractBasicAclEntry implements BasicAclEntry {
         return printPermissionsBlock(this.mask);
         return printPermissionsBlock(this.mask);
     }
     }
 
 
+    public void setAclObjectIdentity(AclObjectIdentity aclObjectIdentity) {
+        this.aclObjectIdentity = aclObjectIdentity;
+    }
+
+    public void setAclObjectParentIdentity(AclObjectIdentity aclObjectParentIdentity) {
+        this.aclObjectParentIdentity = aclObjectParentIdentity;
+    }
+
+    public void setMask(int mask) {
+        this.mask = mask;
+    }
+
+    public void setRecipient(Object recipient) {
+        this.recipient = recipient;
+    }
+
     public String toString() {
     public String toString() {
         StringBuffer sb = new StringBuffer();
         StringBuffer sb = new StringBuffer();
         sb.append(getClass().getName());
         sb.append(getClass().getName());
@@ -256,26 +243,9 @@ public abstract class AbstractBasicAclEntry implements BasicAclEntry {
         this.mask ^= permissionToToggle;
         this.mask ^= permissionToToggle;
 
 
         if (Arrays.binarySearch(validPermissions, this.mask) < 0) {
         if (Arrays.binarySearch(validPermissions, this.mask) < 0) {
-            throw new IllegalArgumentException(
-                "Resulting permission set will be invalid.");
+            throw new IllegalArgumentException("Resulting permission set will be invalid.");
         } else {
         } else {
             return this.mask;
             return this.mask;
         }
         }
     }
     }
-
-    protected boolean isPermitted(int maskToCheck, int permissionToCheck) {
-        return ((maskToCheck & permissionToCheck) == permissionToCheck);
-    }
-
-    private String printBinary(int i) {
-        String s = Integer.toString(i, 2);
-
-        String pattern = "................................";
-
-        String temp1 = pattern.substring(0, pattern.length() - s.length());
-
-        String temp2 = temp1 + s;
-
-        return temp2.replace('0', '.');
-    }
 }
 }

+ 5 - 8
core/src/main/java/org/acegisecurity/acl/basic/AclObjectIdentity.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -44,22 +44,19 @@ import java.io.Serializable;
  * @version $Id$
  * @version $Id$
  */
  */
 public interface AclObjectIdentity extends Serializable {
 public interface AclObjectIdentity extends Serializable {
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
-     * Refer to the <code>java.lang.Object</code> documentation for the
-     * interface contract.
+     * Refer to the <code>java.lang.Object</code> documentation for the interface contract.
      *
      *
      * @param obj to be compared
      * @param obj to be compared
      *
      *
-     * @return <code>true</code> if the objects are equal, <code>false</code>
-     *         otherwise
+     * @return <code>true</code> if the objects are equal, <code>false</code> otherwise
      */
      */
     public boolean equals(Object obj);
     public boolean equals(Object obj);
 
 
     /**
     /**
-     * Refer to the <code>java.lang.Object</code> documentation for the
-     * interface contract.
+     * Refer to the <code>java.lang.Object</code> documentation for the interface contract.
      *
      *
      * @return a hash code representation of this object
      * @return a hash code representation of this object
      */
      */

+ 3 - 4
core/src/main/java/org/acegisecurity/acl/basic/AclObjectIdentityAware.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -30,13 +30,12 @@ package org.acegisecurity.acl.basic;
  * @version $Id$
  * @version $Id$
  */
  */
 public interface AclObjectIdentityAware {
 public interface AclObjectIdentityAware {
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
      * Retrieves the <code>AclObjectIdentity</code> for this instance.
      * Retrieves the <code>AclObjectIdentity</code> for this instance.
      *
      *
-     * @return the ACL object identity for this instance (can never be
-     *         <code>null</code>)
+     * @return the ACL object identity for this instance (can never be <code>null</code>)
      */
      */
     public AclObjectIdentity getAclObjectIdentity();
     public AclObjectIdentity getAclObjectIdentity();
 }
 }

+ 9 - 15
core/src/main/java/org/acegisecurity/acl/basic/BasicAclDao.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -35,24 +35,18 @@ package org.acegisecurity.acl.basic;
  * @version $Id$
  * @version $Id$
  */
  */
 public interface BasicAclDao {
 public interface BasicAclDao {
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
-     * Obtains the ACLs that apply to the specified domain instance.
-     * 
-     * <P>
-     * Does <b>not</b> perform caching, include ACLs from any inheritance
-     * hierarchy or filter returned objects based on effective permissions.
-     * Implementations are solely responsible for returning ACLs found in the
-     * ACL repository for the specified object identity.
-     * </p>
+     * Obtains the ACLs that apply to the specified domain instance.<P>Does <b>not</b> perform caching, include
+     * ACLs from any inheritance hierarchy or filter returned objects based on effective permissions. Implementations
+     * are solely responsible for returning ACLs found in the ACL repository for the specified object identity.</p>
      *
      *
-     * @param aclObjectIdentity the domain object instance that ACL information
-     *        is being requested for (never <code>null</code>)
+     * @param aclObjectIdentity the domain object instance that ACL information is being requested for (never
+     *        <code>null</code>)
      *
      *
-     * @return the ACLs that apply (no <code>null</code>s are permitted in the
-     *         array), or <code>null</code> if no ACLs could be found for the
-     *         specified ACL object identity
+     * @return the ACLs that apply (no <code>null</code>s are permitted in the array), or <code>null</code> if no ACLs
+     *         could be found for the specified ACL object identity
      */
      */
     public BasicAclEntry[] getAcls(AclObjectIdentity aclObjectIdentity);
     public BasicAclEntry[] getAcls(AclObjectIdentity aclObjectIdentity);
 }
 }

+ 53 - 72
core/src/main/java/org/acegisecurity/acl/basic/BasicAclEntry.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -25,110 +25,91 @@ import org.acegisecurity.acl.AclEntry;
  * @version $Id$
  * @version $Id$
  */
  */
 public interface BasicAclEntry extends AclEntry {
 public interface BasicAclEntry extends AclEntry {
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
-     * This setter should <B>only</B> be used by DAO implementations.
+     * Indicates the domain object instance that is subject of this <code>BasicAclEntry</code>. This
+     * information may be of interest to relying classes (voters and business methods) that wish to know the actual
+     * origination of the ACL entry (so as to distinguish individual ACL entries from others contributed by the
+     * inheritance hierarchy).
      *
      *
-     * @param aclObjectIdentity an object which can be used to uniquely
-     *        identify the domain object instance subject of this ACL entry
+     * @return the ACL object identity that is subject of this ACL entry (never <code>null</code>)
      */
      */
-    public void setAclObjectIdentity(AclObjectIdentity aclObjectIdentity);
+    public AclObjectIdentity getAclObjectIdentity();
 
 
     /**
     /**
-     * Indicates the domain object instance that is subject of this
-     * <code>BasicAclEntry</code>. This information may be of interest to
-     * relying classes (voters and business methods) that wish to know the
-     * actual origination of the ACL entry (so as to distinguish individual
-     * ACL entries from others contributed by the inheritance hierarchy).
+     * Indicates any ACL parent of the domain object instance. This is used by <code>BasicAclProvider</code> to
+     * walk the inheritance hierarchy. An domain object instance need <b>not</b> have a parent.
      *
      *
-     * @return the ACL object identity that is subject of this ACL entry (never
-     *         <code>null</code>)
+     * @return the ACL object identity that is the parent of this ACL entry (may be <code>null</code> if no parent
+     *         should be consulted)
      */
      */
-    public AclObjectIdentity getAclObjectIdentity();
+    public AclObjectIdentity getAclObjectParentIdentity();
 
 
     /**
     /**
-     * This setter should <B>only</B> be used by DAO implementations.
+     * Access control lists in this package are based on bit masking. The integer value of the bit mask can be
+     * obtained from this method.
      *
      *
-     * @param aclObjectParentIdentity an object which represents the parent of
-     *        the domain object instance subject of this ACL entry, or
-     *        <code>null</code> if either the domain object instance has no
-     *        parent or its parent should be not used to compute an
-     *        inheritance hierarchy
+     * @return the bit mask applicable to this ACL entry (zero indicates a bit mask where no permissions have been
+     *         granted)
      */
      */
-    public void setAclObjectParentIdentity(
-        AclObjectIdentity aclObjectParentIdentity);
+    public int getMask();
 
 
     /**
     /**
-     * Indicates any ACL parent of the domain object instance. This is used by
-     * <code>BasicAclProvider</code> to walk the inheritance hierarchy. An
-     * domain object instance need <b>not</b> have a parent.
+     * A domain object instance will usually have multiple <code>BasicAclEntry</code>s. Each separate
+     * <code>BasicAclEntry</code> applies to a particular "recipient". Typical examples of recipients include (but do
+     * not necessarily have to include) usernames, role names, complex granted authorities etc.<P><B>It is
+     * essential that only one <code>BasicAclEntry</code> exists for a given recipient</B>. Otherwise conflicts as to
+     * the mask that should apply to a given recipient will occur.</p>
+     *  <P>This method indicates which recipient this <code>BasicAclEntry</code> applies to. The returned
+     * object type will vary depending on the type of recipient. For instance, it might be a <code>String</code>
+     * containing a username, or a <code>GrantedAuthorityImpl</code> containing a complex granted authority that is
+     * being granted the permissions contained in this access control entry. The {@link EffectiveAclsResolver} and
+     * {@link BasicAclProvider#getAcls(Object, Authentication)} can process the different recipient types and return
+     * only those that apply to a specified <code>Authentication</code> object.</p>
      *
      *
-     * @return the ACL object identity that is the parent of this ACL entry
-     *         (may be <code>null</code> if no parent should be consulted)
+     * @return the recipient of this access control list entry (never <code>null</code>)
      */
      */
-    public AclObjectIdentity getAclObjectParentIdentity();
+    public Object getRecipient();
 
 
     /**
     /**
-     * This setter should <B>only</B> be used by DAO implementations.
+     * Determine if the mask of this entry includes this permission or not
      *
      *
-     * @param mask the integer representing the permissions bit mask
+     * @param permissionToCheck
+     *
+     * @return if the entry's mask includes this permission
      */
      */
-    public void setMask(int mask);
+    public boolean isPermitted(int permissionToCheck);
 
 
     /**
     /**
-     * Access control lists in this package are based on bit masking. The
-     * integer value of the bit mask can be obtained from this method.
+     * This setter should <B>only</B> be used by DAO implementations.
      *
      *
-     * @return the bit mask applicable to this ACL entry (zero indicates a bit
-     *         mask where no permissions have been granted)
+     * @param aclObjectIdentity an object which can be used to uniquely identify the domain object instance subject of
+     *        this ACL entry
      */
      */
-    public int getMask();
+    public void setAclObjectIdentity(AclObjectIdentity aclObjectIdentity);
 
 
     /**
     /**
      * This setter should <B>only</B> be used by DAO implementations.
      * This setter should <B>only</B> be used by DAO implementations.
      *
      *
-     * @param recipient a representation of the recipient of this ACL entry
-     *        that makes sense to an <code>EffectiveAclsResolver</code>
-     *        implementation
+     * @param aclObjectParentIdentity an object which represents the parent of the domain object instance subject of
+     *        this ACL entry, or <code>null</code> if either the domain object instance has no parent or its parent
+     *        should be not used to compute an inheritance hierarchy
      */
      */
-    public void setRecipient(Object recipient);
+    public void setAclObjectParentIdentity(AclObjectIdentity aclObjectParentIdentity);
 
 
     /**
     /**
-     * A domain object instance will usually have multiple
-     * <code>BasicAclEntry</code>s. Each separate <code>BasicAclEntry</code>
-     * applies to a particular "recipient". Typical examples of recipients
-     * include (but do not necessarily have to include) usernames, role names,
-     * complex granted authorities etc.
-     * 
-     * <P>
-     * <B>It is essential that only one <code>BasicAclEntry</code> exists for a
-     * given recipient</B>. Otherwise conflicts as to the mask that should
-     * apply to a given recipient will occur.
-     * </p>
-     * 
-     * <P>
-     * This method indicates which recipient this <code>BasicAclEntry</code>
-     * applies to. The returned object type will vary depending on the type of
-     * recipient. For instance, it might be a <code>String</code> containing a
-     * username, or a <code>GrantedAuthorityImpl</code> containing a complex
-     * granted authority that is being granted the permissions contained in
-     * this access control entry. The {@link EffectiveAclsResolver} and {@link
-     * BasicAclProvider#getAcls(Object, Authentication)} can process the
-     * different recipient types and return only those that apply to a
-     * specified <code>Authentication</code> object.
-     * </p>
+     * This setter should <B>only</B> be used by DAO implementations.
      *
      *
-     * @return the recipient of this access control list entry (never
-     *         <code>null</code>)
+     * @param mask the integer representing the permissions bit mask
      */
      */
-    public Object getRecipient();
-    
+    public void setMask(int mask);
+
     /**
     /**
-     * Determine if the mask of this entry includes this permission or not
-     * 
-     * @param permissionToCheck
-     * @return if the entry's mask includes this permission
+     * This setter should <B>only</B> be used by DAO implementations.
+     *
+     * @param recipient a representation of the recipient of this ACL entry that makes sense to an
+     *        <code>EffectiveAclsResolver</code> implementation
      */
      */
-    public boolean isPermitted(int permissionToCheck);
+    public void setRecipient(Object recipient);
 }
 }

+ 9 - 17
core/src/main/java/org/acegisecurity/acl/basic/BasicAclEntryCache.java

@@ -31,37 +31,29 @@ package org.acegisecurity.acl.basic;
  * @version $Id$
  * @version $Id$
  */
  */
 public interface BasicAclEntryCache {
 public interface BasicAclEntryCache {
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
      * Obtains an array of {@link BasicAclEntry}s from the cache.
      * Obtains an array of {@link BasicAclEntry}s from the cache.
      *
      *
      * @param aclObjectIdentity which should be obtained from the cache
      * @param aclObjectIdentity which should be obtained from the cache
      *
      *
-     * @return any applicable <code>BasicAclEntry</code>s (no
-     *         <code>null</code>s are permitted in the returned array) or
-     *         <code>null</code> if the object identity could not be found or
-     *         if the cache entry has expired
+     * @return any applicable <code>BasicAclEntry</code>s (no <code>null</code>s are permitted in the returned array)
+     *         or <code>null</code> if the object identity could not be found or if the cache entry has expired
      */
      */
-    public BasicAclEntry[] getEntriesFromCache(
-        AclObjectIdentity aclObjectIdentity);
+    public BasicAclEntry[] getEntriesFromCache(AclObjectIdentity aclObjectIdentity);
 
 
     /**
     /**
-     * Places an array of {@link BasicAclEntry}s in the cache.
-     * 
-     * <P>
-     * No <code>null</code>s are allowed in the passed array. If any
-     * <code>null</code> is passed, the implementation may throw an exception.
-     * </p>
+     * Places an array of {@link BasicAclEntry}s in the cache.<P>No <code>null</code>s are allowed in the
+     * passed array. If any <code>null</code> is passed, the implementation may throw an exception.</p>
      *
      *
-     * @param basicAclEntry the ACL entries to cache (the key will be extracted
-     *        from the {@link BasicAclEntry#getAclObjectIdentity()} method
+     * @param basicAclEntry the ACL entries to cache (the key will be extracted from the {@link
+     *        BasicAclEntry#getAclObjectIdentity()} method
      */
      */
     public void putEntriesInCache(BasicAclEntry[] basicAclEntry);
     public void putEntriesInCache(BasicAclEntry[] basicAclEntry);
 
 
     /**
     /**
-     * Removes all ACL entries related to an {@link AclObjectIdentity} from the
-     * cache.
+     * Removes all ACL entries related to an {@link AclObjectIdentity} from the cache.
      *
      *
      * @param aclObjectIdentity which should be removed from the cache
      * @param aclObjectIdentity which should be removed from the cache
      */
      */

+ 39 - 31
core/src/main/java/org/acegisecurity/acl/basic/BasicAclExtendedDao.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@ package org.acegisecurity.acl.basic;
 
 
 import org.springframework.dao.DataAccessException;
 import org.springframework.dao.DataAccessException;
 
 
+
 /**
 /**
  * Represents a more extensive data access object
  * Represents a more extensive data access object
  * for {@link BasicAclEntry}s.
  * for {@link BasicAclEntry}s.
@@ -30,35 +31,42 @@ import org.springframework.dao.DataAccessException;
  * @version $Id$
  * @version $Id$
  */
  */
 public interface BasicAclExtendedDao extends BasicAclDao {
 public interface BasicAclExtendedDao extends BasicAclDao {
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
+
+    /**
+     * Changes the permission mask assigned to the <code>BasicAclEntry</code> associated with the specified
+     * <code>AclObjectIdentity</code> and recipient <code>Object</code>.
+     *
+     * @param aclObjectIdentity to locate the relevant <code>BasicAclEntry</code>
+     * @param recipient to locate the relevant <code>BasicAclEntry</code>
+     * @param newMask indicating the new permission
+     *
+     * @throws DataAccessException DOCUMENT ME!
+     */
+    public void changeMask(AclObjectIdentity aclObjectIdentity, Object recipient, Integer newMask)
+        throws DataAccessException;
+
+    public void create(BasicAclEntry basicAclEntry) throws DataAccessException;
+
+    /**
+     * Deletes <b>all</b> entries associated with the specified <code>AclObjectIdentity</code>.
+     *
+     * @param aclObjectIdentity to delete, including any <code>BasicAclEntry</code>s
+     *
+     * @throws DataAccessException DOCUMENT ME!
+     */
+    public void delete(AclObjectIdentity aclObjectIdentity)
+        throws DataAccessException;
 
 
-	public void create(BasicAclEntry basicAclEntry)  throws DataAccessException;
-	
-	/**
-	 * Deletes <b>all</b> entries associated with the
-	 * specified <code>AclObjectIdentity</code>.
-	 * 
-	 * @param aclObjectIdentity to delete, including any <code>BasicAclEntry</code>s
-	 */
-	public void delete(AclObjectIdentity aclObjectIdentity) throws DataAccessException;
-	
-	/**
-	 * Deletes the <code>BasicAclEntry</code> associated with the specified
-	 * <code>AclObjectIdentity</code> and recipient <code>Object</code>.
-	 * 
-	 * @param aclObjectIdentity to delete
-	 * @param recipient to delete
-	 */
-	public void delete(AclObjectIdentity aclObjectIdentity, Object recipient) throws DataAccessException;
-	
-	/**
-	 * Changes the permission mask assigned to the <code>BasicAclEntry</code>
-	 * associated with the specified
-	 * <code>AclObjectIdentity</code> and recipient <code>Object</code>.
-	 * 
-	 * @param aclObjectIdentity to locate the relevant <code>BasicAclEntry</code>
-	 * @param recipient to locate the relevant <code>BasicAclEntry</code>
-	 * @param newMask indicating the new permission
-	 */
-	public void changeMask(AclObjectIdentity aclObjectIdentity, Object recipient, Integer newMask) throws DataAccessException;
+    /**
+     * Deletes the <code>BasicAclEntry</code> associated with the specified <code>AclObjectIdentity</code> and
+     * recipient <code>Object</code>.
+     *
+     * @param aclObjectIdentity to delete
+     * @param recipient to delete
+     *
+     * @throws DataAccessException DOCUMENT ME!
+     */
+    public void delete(AclObjectIdentity aclObjectIdentity, Object recipient)
+        throws DataAccessException;
 }
 }

+ 146 - 212
core/src/main/java/org/acegisecurity/acl/basic/BasicAclProvider.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
 package org.acegisecurity.acl.basic;
 package org.acegisecurity.acl.basic;
 
 
 import org.acegisecurity.Authentication;
 import org.acegisecurity.Authentication;
+
 import org.acegisecurity.acl.AclEntry;
 import org.acegisecurity.acl.AclEntry;
 import org.acegisecurity.acl.AclProvider;
 import org.acegisecurity.acl.AclProvider;
 import org.acegisecurity.acl.basic.cache.NullAclEntryCache;
 import org.acegisecurity.acl.basic.cache.NullAclEntryCache;
@@ -24,6 +25,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.logging.LogFactory;
 
 
 import org.springframework.beans.factory.InitializingBean;
 import org.springframework.beans.factory.InitializingBean;
+
 import org.springframework.util.Assert;
 import org.springframework.util.Assert;
 
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Constructor;
@@ -34,70 +36,59 @@ import java.util.Map;
 
 
 
 
 /**
 /**
- * <P>
- * Retrieves access control lists (ACL) entries for domain object instances
- * from a data access object (DAO).
- * </p>
- * 
- * <P>
- * This implementation will provide ACL lookup services for any object that it
- * can determine the {@link AclObjectIdentity} for by calling the {@link
- * #obtainIdentity(Object)} method. Subclasses can override this method if
- * they only want the <code>BasicAclProvider</code> responding to particular
- * domain object instances.
- * </p>
- * 
- * <P>
- * <code>BasicAclProvider</code> will walk an inheritance hierarchy if a
- * <code>BasicAclEntry</code> returned by the DAO indicates it has a parent.
- * NB: inheritance occurs at a <I>domain instance object</I> level. It does
- * not occur at an ACL recipient level. This means
- * <B>all</B><code>BasicAclEntry</code>s for a given domain instance object
- * <B>must</B> have the <B>same</B> parent identity, or
- * <B>all</B><code>BasicAclEntry</code>s must have <code>null</code> as their
- * parent identity.
- * </p>
- * 
- * <P>
- * A cache should be used. This is provided by the {@link BasicAclEntryCache}.
- * <code>BasicAclProvider</code> by default is setup to use the {@link
- * NullAclEntryCache}, which performs no caching.
- * </p>
- * 
- * <P>
- * To implement the {@link #getAcls(Object, Authentication)} method,
- * <code>BasicAclProvider</code> requires a {@link EffectiveAclsResolver} to
- * be configured against it. By default the {@link
- * GrantedAuthorityEffectiveAclsResolver} is used.
- * </p>
+ * <P>Retrieves access control lists (ACL) entries for domain object instances from a data access object (DAO).</p>
+ *  <P>This implementation will provide ACL lookup services for any object that it can determine the {@link
+ * AclObjectIdentity} for by calling the {@link #obtainIdentity(Object)} method. Subclasses can override this method
+ * if they only want the <code>BasicAclProvider</code> responding to particular domain object instances.</p>
+ *  <P><code>BasicAclProvider</code> will walk an inheritance hierarchy if a <code>BasicAclEntry</code> returned by
+ * the DAO indicates it has a parent. NB: inheritance occurs at a <I>domain instance object</I> level. It does not
+ * occur at an ACL recipient level. This means <B>all</B><code>BasicAclEntry</code>s for a given domain instance
+ * object <B>must</B> have the <B>same</B> parent identity, or <B>all</B><code>BasicAclEntry</code>s must have
+ * <code>null</code> as their parent identity.</p>
+ *  <P>A cache should be used. This is provided by the {@link BasicAclEntryCache}. <code>BasicAclProvider</code> by
+ * default is setup to use the {@link NullAclEntryCache}, which performs no caching.</p>
+ *  <P>To implement the {@link #getAcls(Object, Authentication)} method, <code>BasicAclProvider</code> requires a
+ * {@link EffectiveAclsResolver} to be configured against it. By default the {@link
+ * GrantedAuthorityEffectiveAclsResolver} is used.</p>
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public class BasicAclProvider implements AclProvider, InitializingBean {
 public class BasicAclProvider implements AclProvider, InitializingBean {
-    //~ Static fields/initializers =============================================
+    //~ Static fields/initializers =====================================================================================
 
 
     private static final Log logger = LogFactory.getLog(BasicAclProvider.class);
     private static final Log logger = LogFactory.getLog(BasicAclProvider.class);
 
 
-    /**
-     * Marker added to the cache to indicate an AclObjectIdentity has no
-     * corresponding BasicAclEntry[]s
-     */
+    /** Marker added to the cache to indicate an AclObjectIdentity has no corresponding BasicAclEntry[]s */
     private static String RECIPIENT_FOR_CACHE_EMPTY = "RESERVED_RECIPIENT_NOBODY";
     private static String RECIPIENT_FOR_CACHE_EMPTY = "RESERVED_RECIPIENT_NOBODY";
 
 
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
-    /**
-     * Must be set to an appropriate data access object. Defaults to
-     * <code>null</code>.
-     */
+    /** Must be set to an appropriate data access object. Defaults to <code>null</code>. */
     private BasicAclDao basicAclDao;
     private BasicAclDao basicAclDao;
     private BasicAclEntryCache basicAclEntryCache = new NullAclEntryCache();
     private BasicAclEntryCache basicAclEntryCache = new NullAclEntryCache();
     private Class defaultAclObjectIdentityClass = NamedEntityObjectIdentity.class;
     private Class defaultAclObjectIdentityClass = NamedEntityObjectIdentity.class;
     private Class restrictSupportToClass = null;
     private Class restrictSupportToClass = null;
     private EffectiveAclsResolver effectiveAclsResolver = new GrantedAuthorityEffectiveAclsResolver();
     private EffectiveAclsResolver effectiveAclsResolver = new GrantedAuthorityEffectiveAclsResolver();
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
+
+    public void afterPropertiesSet() {
+        Assert.notNull(basicAclDao, "basicAclDao required");
+        Assert.notNull(basicAclEntryCache, "basicAclEntryCache required");
+        Assert.notNull(basicAclEntryCache, "basicAclEntryCache required");
+        Assert.notNull(effectiveAclsResolver, "effectiveAclsResolver required");
+        Assert.notNull(defaultAclObjectIdentityClass, "defaultAclObjectIdentityClass required");
+        Assert.isTrue(AclObjectIdentity.class.isAssignableFrom(this.defaultAclObjectIdentityClass),
+            "defaultAclObjectIdentityClass must implement AclObjectIdentity");
+
+        try {
+            Constructor constructor = defaultAclObjectIdentityClass.getConstructor(new Class[] {Object.class});
+        } catch (NoSuchMethodException nsme) {
+            throw new IllegalArgumentException(
+                "defaultAclObjectIdentityClass must provide a constructor that accepts the domain object instance!");
+        }
+    }
 
 
     public AclEntry[] getAcls(Object domainInstance) {
     public AclEntry[] getAcls(Object domainInstance) {
         Map map = new HashMap();
         Map map = new HashMap();
@@ -120,15 +111,13 @@ public class BasicAclProvider implements AclProvider, InitializingBean {
         // Add the leaf objects to the Map, keyed on recipient
         // Add the leaf objects to the Map, keyed on recipient
         for (int i = 0; i < instanceAclEntries.length; i++) {
         for (int i = 0; i < instanceAclEntries.length; i++) {
             if (logger.isDebugEnabled()) {
             if (logger.isDebugEnabled()) {
-                logger.debug("Explicit add: "
-                        + instanceAclEntries[i].toString());
+                logger.debug("Explicit add: " + instanceAclEntries[i].toString());
             }
             }
 
 
             map.put(instanceAclEntries[i].getRecipient(), instanceAclEntries[i]);
             map.put(instanceAclEntries[i].getRecipient(), instanceAclEntries[i]);
         }
         }
 
 
-        AclObjectIdentity parent = instanceAclEntries[0]
-                .getAclObjectParentIdentity();
+        AclObjectIdentity parent = instanceAclEntries[0].getAclObjectParentIdentity();
 
 
         while (parent != null) {
         while (parent != null) {
             BasicAclEntry[] parentAclEntries = lookup(parent);
             BasicAclEntry[] parentAclEntries = lookup(parent);
@@ -150,16 +139,13 @@ public class BasicAclProvider implements AclProvider, InitializingBean {
             for (int i = 0; i < parentAclEntries.length; i++) {
             for (int i = 0; i < parentAclEntries.length; i++) {
                 if (!map.containsKey(parentAclEntries[i].getRecipient())) {
                 if (!map.containsKey(parentAclEntries[i].getRecipient())) {
                     if (logger.isDebugEnabled()) {
                     if (logger.isDebugEnabled()) {
-                        logger.debug("Added parent to map: "
-                                + parentAclEntries[i].toString());
+                        logger.debug("Added parent to map: " + parentAclEntries[i].toString());
                     }
                     }
 
 
-                    map.put(parentAclEntries[i].getRecipient(),
-                            parentAclEntries[i]);
+                    map.put(parentAclEntries[i].getRecipient(), parentAclEntries[i]);
                 } else {
                 } else {
                     if (logger.isDebugEnabled()) {
                     if (logger.isDebugEnabled()) {
-                        logger.debug("Did NOT add parent to map: "
-                                + parentAclEntries[i].toString());
+                        logger.debug("Did NOT add parent to map: " + parentAclEntries[i].toString());
                     }
                     }
                 }
                 }
             }
             }
@@ -170,204 +156,98 @@ public class BasicAclProvider implements AclProvider, InitializingBean {
 
 
         Collection collection = map.values();
         Collection collection = map.values();
 
 
-        return (AclEntry[]) collection.toArray(new AclEntry[]{});
+        return (AclEntry[]) collection.toArray(new AclEntry[] {});
     }
     }
 
 
-    public AclEntry[] getAcls(Object domainInstance,
-        Authentication authentication) {
+    public AclEntry[] getAcls(Object domainInstance, Authentication authentication) {
         AclEntry[] allAcls = (AclEntry[]) this.getAcls(domainInstance);
         AclEntry[] allAcls = (AclEntry[]) this.getAcls(domainInstance);
 
 
-        return this.effectiveAclsResolver.resolveEffectiveAcls(allAcls,
-            authentication);
-    }
-
-    public void setBasicAclDao(BasicAclDao basicAclDao) {
-        this.basicAclDao = basicAclDao;
+        return this.effectiveAclsResolver.resolveEffectiveAcls(allAcls, authentication);
     }
     }
 
 
     public BasicAclDao getBasicAclDao() {
     public BasicAclDao getBasicAclDao() {
         return basicAclDao;
         return basicAclDao;
     }
     }
 
 
-    public void setBasicAclEntryCache(BasicAclEntryCache basicAclEntryCache) {
-        this.basicAclEntryCache = basicAclEntryCache;
-    }
-
     public BasicAclEntryCache getBasicAclEntryCache() {
     public BasicAclEntryCache getBasicAclEntryCache() {
         return basicAclEntryCache;
         return basicAclEntryCache;
     }
     }
 
 
-    /**
-     * Allows selection of the <code>AclObjectIdentity</code> class that an
-     * attempt should be made to construct if the passed object does not
-     * implement <code>AclObjectIdentityAware</code>.
-     * 
-     * <P>
-     * NB: Any <code>defaultAclObjectIdentityClass</code><b>must</b> provide a
-     * public constructor that accepts an <code>Object</code>. Otherwise it is
-     * not possible for the <code>BasicAclProvider</code> to try to create the
-     * <code>AclObjectIdentity</code> instance at runtime.
-     * </p>
-     *
-     * @param defaultAclObjectIdentityClass
-     */
-    public void setDefaultAclObjectIdentityClass(
-        Class defaultAclObjectIdentityClass) {
-        this.defaultAclObjectIdentityClass = defaultAclObjectIdentityClass;
-    }
-
     public Class getDefaultAclObjectIdentityClass() {
     public Class getDefaultAclObjectIdentityClass() {
         return defaultAclObjectIdentityClass;
         return defaultAclObjectIdentityClass;
     }
     }
 
 
-    public void setEffectiveAclsResolver(
-        EffectiveAclsResolver effectiveAclsResolver) {
-        this.effectiveAclsResolver = effectiveAclsResolver;
-    }
-
     public EffectiveAclsResolver getEffectiveAclsResolver() {
     public EffectiveAclsResolver getEffectiveAclsResolver() {
         return effectiveAclsResolver;
         return effectiveAclsResolver;
     }
     }
 
 
-    /**
-     * If set to a value other than <code>null</code>, the {@link
-     * #supports(Object)} method will <b>only</b> support the indicates class.
-     * This is useful if you wish to wire multiple
-     * <code>BasicAclProvider</code>s in a list of
-     * <code>AclProviderManager.providers</code> but only have particular
-     * instances respond to particular domain object types.
-     *
-     * @param restrictSupportToClass the class to restrict this
-     *        <code>BasicAclProvider</code> to service request for, or
-     *        <code>null</code> (the default) if the
-     *        <code>BasicAclProvider</code> should respond to every class
-     *        presented
-     */
-    public void setRestrictSupportToClass(Class restrictSupportToClass) {
-        this.restrictSupportToClass = restrictSupportToClass;
-    }
-
     public Class getRestrictSupportToClass() {
     public Class getRestrictSupportToClass() {
         return restrictSupportToClass;
         return restrictSupportToClass;
     }
     }
 
 
-    public void afterPropertiesSet() {
-        Assert.notNull(basicAclDao, "basicAclDao required");
-        Assert.notNull(basicAclEntryCache, "basicAclEntryCache required");
-        Assert.notNull(basicAclEntryCache, "basicAclEntryCache required");
-        Assert.notNull(effectiveAclsResolver, "effectiveAclsResolver required");
-        Assert.notNull(defaultAclObjectIdentityClass, "defaultAclObjectIdentityClass required");
-        Assert.isTrue(AclObjectIdentity.class.isAssignableFrom(this.defaultAclObjectIdentityClass),
-                "defaultAclObjectIdentityClass must implement AclObjectIdentity");
-
-        try {
-            Constructor constructor = defaultAclObjectIdentityClass
-                    .getConstructor(new Class[]{Object.class});
-        } catch (NoSuchMethodException nsme) {
-            throw new IllegalArgumentException("defaultAclObjectIdentityClass must provide a constructor that accepts the domain object instance!");
-        }
-    }
+    private BasicAclEntry[] lookup(AclObjectIdentity aclObjectIdentity) {
+        BasicAclEntry[] result = basicAclEntryCache.getEntriesFromCache(aclObjectIdentity);
 
 
-    /**
-     * Indicates support for the passed object.
-     * 
-     * <p>
-     * An object will only be supported if it (i) is allowed to be supported as
-     * defined by the {@link #setRestrictSupportToClass(Class)} method,
-     * <b>and</b> (ii) if an <code>AclObjectIdentity</code> is returned by
-     * {@link #obtainIdentity(Object)} for that object.
-     * </p>
-     *
-     * @param domainInstance the instance to check
-     *
-     * @return <code>true</code> if this provider supports the passed object,
-     *         <code>false</code> otherwise
-     */
-    public boolean supports(Object domainInstance) {
-        if (domainInstance == null) {
-            if (logger.isDebugEnabled()) {
-                logger.debug("domainInstance is null");
+        if (result != null) {
+            if (result[0].getRecipient().equals(RECIPIENT_FOR_CACHE_EMPTY)) {
+                return null;
+            } else {
+                return result;
             }
             }
-
-            return false;
         }
         }
 
 
-        if ((restrictSupportToClass != null)
-            && !restrictSupportToClass.isAssignableFrom(
-                domainInstance.getClass())) {
-            if (logger.isDebugEnabled()) {
-                logger.debug("domainInstance not instance of "
-                    + restrictSupportToClass);
-            }
+        result = basicAclDao.getAcls(aclObjectIdentity);
 
 
-            return false;
-        }
+        if (result == null) {
+            SimpleAclEntry[] emptyAclEntries = {
+                    new SimpleAclEntry(RECIPIENT_FOR_CACHE_EMPTY, aclObjectIdentity, null, 0)
+                };
+            basicAclEntryCache.putEntriesInCache(emptyAclEntries);
 
 
-        if (obtainIdentity(domainInstance) == null) {
-            if (logger.isDebugEnabled()) {
-                logger.debug("obtainIdentity returned null");
-            }
+            return null;
+        }
 
 
-            return false;
-        } else {
-            if (logger.isDebugEnabled()) {
-                logger.debug("obtainIdentity returned "
-                    + obtainIdentity(domainInstance));
-            }
+        basicAclEntryCache.putEntriesInCache(result);
 
 
-            return true;
-        }
+        return result;
     }
     }
 
 
     /**
     /**
-     * This method looks up the <code>AclObjectIdentity</code> of a passed
-     * domain object instance.
-     * 
-     * <P>
-     * This implementation attempts to obtain the
-     * <code>AclObjectIdentity</code> via reflection inspection of the class
-     * for the {@link AclObjectIdentityAware} interface. If this fails, an
-     * attempt is made to construct a {@link
-     * #getDefaultAclObjectIdentityClass()} object by passing the domain
-     * instance object into its constructor.
-     * </p>
+     * This method looks up the <code>AclObjectIdentity</code> of a passed domain object instance.<P>This
+     * implementation attempts to obtain the <code>AclObjectIdentity</code> via reflection inspection of the class for
+     * the {@link AclObjectIdentityAware} interface. If this fails, an attempt is made to construct a {@link
+     * #getDefaultAclObjectIdentityClass()} object by passing the domain instance object into its constructor.</p>
      *
      *
-     * @param domainInstance the domain object instance (never
-     *        <code>null</code>)
+     * @param domainInstance the domain object instance (never <code>null</code>)
      *
      *
-     * @return an ACL object identity, or <code>null</code> if one could not be
-     *         obtained
+     * @return an ACL object identity, or <code>null</code> if one could not be obtained
      */
      */
     protected AclObjectIdentity obtainIdentity(Object domainInstance) {
     protected AclObjectIdentity obtainIdentity(Object domainInstance) {
         if (domainInstance instanceof AclObjectIdentityAware) {
         if (domainInstance instanceof AclObjectIdentityAware) {
             AclObjectIdentityAware aclObjectIdentityAware = (AclObjectIdentityAware) domainInstance;
             AclObjectIdentityAware aclObjectIdentityAware = (AclObjectIdentityAware) domainInstance;
 
 
             if (logger.isDebugEnabled()) {
             if (logger.isDebugEnabled()) {
-                logger.debug("domainInstance: " + domainInstance
-                    + " cast to AclObjectIdentityAware");
+                logger.debug("domainInstance: " + domainInstance + " cast to AclObjectIdentityAware");
             }
             }
 
 
             return aclObjectIdentityAware.getAclObjectIdentity();
             return aclObjectIdentityAware.getAclObjectIdentity();
         }
         }
 
 
         try {
         try {
-            Constructor constructor = defaultAclObjectIdentityClass
-                .getConstructor(new Class[] {Object.class});
+            Constructor constructor = defaultAclObjectIdentityClass.getConstructor(new Class[] {Object.class});
 
 
             if (logger.isDebugEnabled()) {
             if (logger.isDebugEnabled()) {
-                logger.debug("domainInstance: " + domainInstance
-                    + " attempting to pass to constructor: " + constructor);
+                logger.debug("domainInstance: " + domainInstance + " attempting to pass to constructor: " + constructor);
             }
             }
 
 
             return (AclObjectIdentity) constructor.newInstance(new Object[] {domainInstance});
             return (AclObjectIdentity) constructor.newInstance(new Object[] {domainInstance});
         } catch (Exception ex) {
         } catch (Exception ex) {
             if (logger.isDebugEnabled()) {
             if (logger.isDebugEnabled()) {
-                logger.debug("Error attempting construction of "
-                    + defaultAclObjectIdentityClass + ": " + ex.getMessage(), ex);
+                logger.debug("Error attempting construction of " + defaultAclObjectIdentityClass + ": "
+                    + ex.getMessage(), ex);
 
 
                 if (ex.getCause() != null) {
                 if (ex.getCause() != null) {
-                    logger.debug("Cause: " + ex.getCause().getMessage(),
-                        ex.getCause());
+                    logger.debug("Cause: " + ex.getCause().getMessage(), ex.getCause());
                 }
                 }
             }
             }
 
 
@@ -375,29 +255,83 @@ public class BasicAclProvider implements AclProvider, InitializingBean {
         }
         }
     }
     }
 
 
-    private BasicAclEntry[] lookup(AclObjectIdentity aclObjectIdentity) {
-        BasicAclEntry[] result = basicAclEntryCache.getEntriesFromCache(aclObjectIdentity);
+    public void setBasicAclDao(BasicAclDao basicAclDao) {
+        this.basicAclDao = basicAclDao;
+    }
 
 
-        if (result != null) {
-            if (result[0].getRecipient().equals(RECIPIENT_FOR_CACHE_EMPTY)) {
-                return null;
-            } else {
-                return result;
+    public void setBasicAclEntryCache(BasicAclEntryCache basicAclEntryCache) {
+        this.basicAclEntryCache = basicAclEntryCache;
+    }
+
+    /**
+     * Allows selection of the <code>AclObjectIdentity</code> class that an attempt should be made to construct
+     * if the passed object does not implement <code>AclObjectIdentityAware</code>.<P>NB: Any
+     * <code>defaultAclObjectIdentityClass</code><b>must</b> provide a public constructor that accepts an
+     * <code>Object</code>. Otherwise it is not possible for the <code>BasicAclProvider</code> to try to create the
+     * <code>AclObjectIdentity</code> instance at runtime.</p>
+     *
+     * @param defaultAclObjectIdentityClass
+     */
+    public void setDefaultAclObjectIdentityClass(Class defaultAclObjectIdentityClass) {
+        this.defaultAclObjectIdentityClass = defaultAclObjectIdentityClass;
+    }
+
+    public void setEffectiveAclsResolver(EffectiveAclsResolver effectiveAclsResolver) {
+        this.effectiveAclsResolver = effectiveAclsResolver;
+    }
+
+    /**
+     * If set to a value other than <code>null</code>, the {@link #supports(Object)} method will <b>only</b>
+     * support the indicates class. This is useful if you wish to wire multiple <code>BasicAclProvider</code>s in a
+     * list of <code>AclProviderManager.providers</code> but only have particular instances respond to particular
+     * domain object types.
+     *
+     * @param restrictSupportToClass the class to restrict this <code>BasicAclProvider</code> to service request for,
+     *        or <code>null</code> (the default) if the <code>BasicAclProvider</code> should respond to every class
+     *        presented
+     */
+    public void setRestrictSupportToClass(Class restrictSupportToClass) {
+        this.restrictSupportToClass = restrictSupportToClass;
+    }
+
+    /**
+     * Indicates support for the passed object.<p>An object will only be supported if it (i) is allowed to be
+     * supported as defined by the {@link #setRestrictSupportToClass(Class)} method, <b>and</b> (ii) if an
+     * <code>AclObjectIdentity</code> is returned by {@link #obtainIdentity(Object)} for that object.</p>
+     *
+     * @param domainInstance the instance to check
+     *
+     * @return <code>true</code> if this provider supports the passed object, <code>false</code> otherwise
+     */
+    public boolean supports(Object domainInstance) {
+        if (domainInstance == null) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("domainInstance is null");
             }
             }
-        }
 
 
-        result = basicAclDao.getAcls(aclObjectIdentity);
+            return false;
+        }
 
 
-        if (result == null) {
-            SimpleAclEntry[] emptyAclEntries = {new SimpleAclEntry(RECIPIENT_FOR_CACHE_EMPTY,
-                        aclObjectIdentity, null, 0)};
-            basicAclEntryCache.putEntriesInCache(emptyAclEntries);
+        if ((restrictSupportToClass != null) && !restrictSupportToClass.isAssignableFrom(domainInstance.getClass())) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("domainInstance not instance of " + restrictSupportToClass);
+            }
 
 
-            return null;
+            return false;
         }
         }
 
 
-        basicAclEntryCache.putEntriesInCache(result);
+        if (obtainIdentity(domainInstance) == null) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("obtainIdentity returned null");
+            }
 
 
-        return result;
+            return false;
+        } else {
+            if (logger.isDebugEnabled()) {
+                logger.debug("obtainIdentity returned " + obtainIdentity(domainInstance));
+            }
+
+            return true;
+        }
     }
     }
 }
 }

+ 8 - 12
core/src/main/java/org/acegisecurity/acl/basic/EffectiveAclsResolver.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
 package org.acegisecurity.acl.basic;
 package org.acegisecurity.acl.basic;
 
 
 import org.acegisecurity.Authentication;
 import org.acegisecurity.Authentication;
+
 import org.acegisecurity.acl.AclEntry;
 import org.acegisecurity.acl.AclEntry;
 
 
 
 
@@ -45,21 +46,16 @@ import org.acegisecurity.acl.AclEntry;
  * @version $Id$
  * @version $Id$
  */
  */
 public interface EffectiveAclsResolver {
 public interface EffectiveAclsResolver {
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
-     * Determines the ACLs that apply to the presented
-     * <code>Authentication</code> object.
+     * Determines the ACLs that apply to the presented <code>Authentication</code> object.
      *
      *
      * @param allAcls every ACL assigned to a domain object instance
      * @param allAcls every ACL assigned to a domain object instance
-     * @param filteredBy the principal (populated with
-     *        <code>GrantedAuthority</code>s along with any other members that
-     *        relate to role or group membership) that effective ACLs should
-     *        be returned for
+     * @param filteredBy the principal (populated with <code>GrantedAuthority</code>s along with any other members that
+     *        relate to role or group membership) that effective ACLs should be returned for
      *
      *
-     * @return the ACLs that apply to the presented principal, or
-     *         <code>null</code> if there are none after filtering
+     * @return the ACLs that apply to the presented principal, or <code>null</code> if there are none after filtering
      */
      */
-    public AclEntry[] resolveEffectiveAcls(AclEntry[] allAcls,
-        Authentication filteredBy);
+    public AclEntry[] resolveEffectiveAcls(AclEntry[] allAcls, Authentication filteredBy);
 }
 }

+ 26 - 49
core/src/main/java/org/acegisecurity/acl/basic/GrantedAuthorityEffectiveAclsResolver.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -17,7 +17,9 @@ package org.acegisecurity.acl.basic;
 
 
 import org.acegisecurity.Authentication;
 import org.acegisecurity.Authentication;
 import org.acegisecurity.GrantedAuthority;
 import org.acegisecurity.GrantedAuthority;
+
 import org.acegisecurity.acl.AclEntry;
 import org.acegisecurity.acl.AclEntry;
+
 import org.acegisecurity.userdetails.UserDetails;
 import org.acegisecurity.userdetails.UserDetails;
 
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.Log;
@@ -28,45 +30,29 @@ import java.util.Vector;
 
 
 
 
 /**
 /**
- * Simple implementation of {@link EffectiveAclsResolver}.
- * 
- * <P>
- * This implementation does not need to understand the "recipient" types
- * presented in a <code>BasicAclEntry</code> because it merely delegates to
- * the detected {@link Authentication#getPrincipal()} or {@link
- * Authentication#getAuthorities()}. The principal object or granted
- * authorities object has its <code>Object.equals(recipient)</code> method
- * called to make the decision as to whether the recipient in the
- * <code>BasicAclEntry</code> is the same as the principal or granted
- * authority.
- * </p>
- * 
- * <P>
- * This class should prove an adequate ACLs resolver if you're using standard
- * Acegi Security classes. This is because the typical
- * <code>Authentication</code> token is
- * <code>UsernamePasswordAuthenticationToken</code>, which for its
- * <code>principal</code> is usually a <code>String</code>. The
- * <code>GrantedAuthorityImpl</code> is typically used for granted
- * authorities, which tests for equality based on a <code>String</code>. This
- * means <code>BasicAclDao</code>s simply need to return a <code>String</code>
- * to represent the recipient. If you use non-<code>String</code> objects, you
- * will probably require an alternative <code>EffectiveAclsResolver</code>.
- * </p>
+ * Simple implementation of {@link EffectiveAclsResolver}.<P>This implementation does not need to understand the
+ * "recipient" types presented in a <code>BasicAclEntry</code> because it merely delegates to the detected {@link
+ * Authentication#getPrincipal()} or {@link Authentication#getAuthorities()}. The principal object or granted
+ * authorities object has its <code>Object.equals(recipient)</code> method called to make the decision as to whether
+ * the recipient in the <code>BasicAclEntry</code> is the same as the principal or granted authority.</p>
+ *  <P>This class should prove an adequate ACLs resolver if you're using standard Acegi Security classes. This is
+ * because the typical <code>Authentication</code> token is <code>UsernamePasswordAuthenticationToken</code>, which
+ * for its <code>principal</code> is usually a <code>String</code>. The <code>GrantedAuthorityImpl</code> is typically
+ * used for granted authorities, which tests for equality based on a <code>String</code>. This means
+ * <code>BasicAclDao</code>s simply need to return a <code>String</code> to represent the recipient. If you use
+ * non-<code>String</code> objects, you will probably require an alternative <code>EffectiveAclsResolver</code>.</p>
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
-public class GrantedAuthorityEffectiveAclsResolver
-    implements EffectiveAclsResolver {
-    //~ Static fields/initializers =============================================
+public class GrantedAuthorityEffectiveAclsResolver implements EffectiveAclsResolver {
+    //~ Static fields/initializers =====================================================================================
 
 
     private static final Log logger = LogFactory.getLog(GrantedAuthorityEffectiveAclsResolver.class);
     private static final Log logger = LogFactory.getLog(GrantedAuthorityEffectiveAclsResolver.class);
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
-    public AclEntry[] resolveEffectiveAcls(AclEntry[] allAcls,
-        Authentication filteredBy) {
+    public AclEntry[] resolveEffectiveAcls(AclEntry[] allAcls, Authentication filteredBy) {
         if ((allAcls == null) || (allAcls.length == 0)) {
         if ((allAcls == null) || (allAcls.length == 0)) {
             return null;
             return null;
         }
         }
@@ -74,8 +60,7 @@ public class GrantedAuthorityEffectiveAclsResolver
         List list = new Vector();
         List list = new Vector();
 
 
         if (logger.isDebugEnabled()) {
         if (logger.isDebugEnabled()) {
-            logger.debug("Locating AclEntry[]s (from set of "
-                + ((allAcls == null) ? 0 : allAcls.length)
+            logger.debug("Locating AclEntry[]s (from set of " + ((allAcls == null) ? 0 : allAcls.length)
                 + ") that apply to Authentication: " + filteredBy);
                 + ") that apply to Authentication: " + filteredBy);
         }
         }
 
 
@@ -84,26 +69,21 @@ public class GrantedAuthorityEffectiveAclsResolver
                 continue;
                 continue;
             }
             }
 
 
-            Object recipient = ((BasicAclEntry) allAcls[i])
-                .getRecipient();
+            Object recipient = ((BasicAclEntry) allAcls[i]).getRecipient();
 
 
             // Allow the Authentication's getPrincipal to decide whether
             // Allow the Authentication's getPrincipal to decide whether
             // the presented recipient is "equal" (allows BasicAclDaos to
             // the presented recipient is "equal" (allows BasicAclDaos to
             // return Strings rather than proper objects in simple cases)
             // return Strings rather than proper objects in simple cases)
             if (filteredBy.getPrincipal().equals(recipient)) {
             if (filteredBy.getPrincipal().equals(recipient)) {
                 if (logger.isDebugEnabled()) {
                 if (logger.isDebugEnabled()) {
-                    logger.debug("Principal matches AclEntry recipient: "
-                        + recipient);
+                    logger.debug("Principal matches AclEntry recipient: " + recipient);
                 }
                 }
 
 
                 list.add(allAcls[i]);
                 list.add(allAcls[i]);
             } else if (filteredBy.getPrincipal() instanceof UserDetails
             } else if (filteredBy.getPrincipal() instanceof UserDetails
-                && ((UserDetails) filteredBy.getPrincipal()).getUsername()
-                    .equals(recipient)) {
+                && ((UserDetails) filteredBy.getPrincipal()).getUsername().equals(recipient)) {
                 if (logger.isDebugEnabled()) {
                 if (logger.isDebugEnabled()) {
-                    logger.debug(
-                        "Principal (from UserDetails) matches AclEntry recipient: "
-                        + recipient);
+                    logger.debug("Principal (from UserDetails) matches AclEntry recipient: " + recipient);
                 }
                 }
 
 
                 list.add(allAcls[i]);
                 list.add(allAcls[i]);
@@ -127,8 +107,7 @@ public class GrantedAuthorityEffectiveAclsResolver
                 for (int k = 0; k < authorities.length; k++) {
                 for (int k = 0; k < authorities.length; k++) {
                     if (authorities[k].equals(recipient)) {
                     if (authorities[k].equals(recipient)) {
                         if (logger.isDebugEnabled()) {
                         if (logger.isDebugEnabled()) {
-                            logger.debug("GrantedAuthority: " + authorities[k]
-                                + " matches recipient: " + recipient);
+                            logger.debug("GrantedAuthority: " + authorities[k] + " matches recipient: " + recipient);
                         }
                         }
 
 
                         list.add(allAcls[i]);
                         list.add(allAcls[i]);
@@ -140,15 +119,13 @@ public class GrantedAuthorityEffectiveAclsResolver
         // return null if appropriate (as per interface contract)
         // return null if appropriate (as per interface contract)
         if (list.size() > 0) {
         if (list.size() > 0) {
             if (logger.isDebugEnabled()) {
             if (logger.isDebugEnabled()) {
-                logger.debug("Returning effective AclEntry array with "
-                    + list.size() + " elements");
+                logger.debug("Returning effective AclEntry array with " + list.size() + " elements");
             }
             }
 
 
             return (BasicAclEntry[]) list.toArray(new BasicAclEntry[] {});
             return (BasicAclEntry[]) list.toArray(new BasicAclEntry[] {});
         } else {
         } else {
             if (logger.isDebugEnabled()) {
             if (logger.isDebugEnabled()) {
-                logger.debug(
-                    "Returning null AclEntry array as zero effective AclEntrys found");
+                logger.debug("Returning null AclEntry array as zero effective AclEntrys found");
             }
             }
 
 
             return null;
             return null;

+ 13 - 25
core/src/main/java/org/acegisecurity/acl/basic/NamedEntityObjectIdentity.java

@@ -23,21 +23,16 @@ import java.lang.reflect.Method;
 
 
 
 
 /**
 /**
- * Simple implementation of {@link AclObjectIdentity}.
- * 
- * <P>
- * Uses <code>String</code>s to store the identity of the domain object
- * instance. Also offers a constructor that uses reflection to build the
- * identity information.
- * </p>
+ * Simple implementation of {@link AclObjectIdentity}.<P>Uses <code>String</code>s to store the identity of the
+ * domain object instance. Also offers a constructor that uses reflection to build the identity information.</p>
  */
  */
 public class NamedEntityObjectIdentity implements AclObjectIdentity {
 public class NamedEntityObjectIdentity implements AclObjectIdentity {
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private String classname;
     private String classname;
     private String id;
     private String id;
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
     public NamedEntityObjectIdentity(String classname, String id) {
     public NamedEntityObjectIdentity(String classname, String id) {
         Assert.hasText(classname, "classname required");
         Assert.hasText(classname, "classname required");
@@ -46,7 +41,7 @@ public class NamedEntityObjectIdentity implements AclObjectIdentity {
         this.id = id;
         this.id = id;
     }
     }
 
 
-    /**
+/**
      * Creates the <code>NamedEntityObjectIdentity</code> based on the passed
      * Creates the <code>NamedEntityObjectIdentity</code> based on the passed
      * object instance. The passed object must provide a <code>getId()</code>
      * object instance. The passed object must provide a <code>getId()</code>
      * method, otherwise an exception will be thrown.
      * method, otherwise an exception will be thrown.
@@ -57,15 +52,13 @@ public class NamedEntityObjectIdentity implements AclObjectIdentity {
      * @throws InvocationTargetException
      * @throws InvocationTargetException
      * @throws IllegalArgumentException
      * @throws IllegalArgumentException
      */
      */
-    public NamedEntityObjectIdentity(Object object)
-        throws IllegalAccessException, InvocationTargetException {
+    public NamedEntityObjectIdentity(Object object) throws IllegalAccessException, InvocationTargetException {
         Assert.notNull(object, "object cannot be null");
         Assert.notNull(object, "object cannot be null");
 
 
         this.classname = (getPackageName(object.getClass().getName()) == null)
         this.classname = (getPackageName(object.getClass().getName()) == null)
-	        ? ClassUtils.getShortName(object.getClass())
-	        : getPackageName(object.getClass().getName()) + "."
-	            + ClassUtils.getShortName(object.getClass());
-        
+            ? ClassUtils.getShortName(object.getClass())
+            : (getPackageName(object.getClass().getName()) + "." + ClassUtils.getShortName(object.getClass()));
+
         Class clazz = object.getClass();
         Class clazz = object.getClass();
 
 
         try {
         try {
@@ -78,15 +71,11 @@ public class NamedEntityObjectIdentity implements AclObjectIdentity {
         }
         }
     }
     }
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
-     * Important so caching operates properly.
-     * 
-     * <P>
-     * Considers an object of the same class equal if it has the same
-     * <code>classname</code> and <code>id</code> properties.
-     * </p>
+     * Important so caching operates properly.<P>Considers an object of the same class equal if it has the same
+     * <code>classname</code> and <code>id</code> properties.</p>
      *
      *
      * @param arg0 object to compare
      * @param arg0 object to compare
      *
      *
@@ -103,8 +92,7 @@ public class NamedEntityObjectIdentity implements AclObjectIdentity {
 
 
         NamedEntityObjectIdentity other = (NamedEntityObjectIdentity) arg0;
         NamedEntityObjectIdentity other = (NamedEntityObjectIdentity) arg0;
 
 
-        if (this.getId().equals(other.getId())
-            && this.getClassname().equals(other.getClassname())) {
+        if (this.getId().equals(other.getId()) && this.getClassname().equals(other.getClassname())) {
             return true;
             return true;
         }
         }
 
 

+ 11 - 10
core/src/main/java/org/acegisecurity/acl/basic/SimpleAclEntry.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -26,7 +26,7 @@ import org.apache.commons.logging.LogFactory;
  * @version $Id$
  * @version $Id$
  */
  */
 public class SimpleAclEntry extends AbstractBasicAclEntry {
 public class SimpleAclEntry extends AbstractBasicAclEntry {
-    //~ Static fields/initializers =============================================
+    //~ Static fields/initializers =====================================================================================
 
 
     private static final Log logger = LogFactory.getLog(SimpleAclEntry.class);
     private static final Log logger = LogFactory.getLog(SimpleAclEntry.class);
 
 
@@ -39,18 +39,20 @@ public class SimpleAclEntry extends AbstractBasicAclEntry {
     public static final int DELETE = (int) Math.pow(2, 4);
     public static final int DELETE = (int) Math.pow(2, 4);
 
 
     // Combinations of base permissions we permit
     // Combinations of base permissions we permit
-    public static final int READ_WRITE_CREATE_DELETE = READ | WRITE | CREATE
-        | DELETE;
+    public static final int READ_WRITE_CREATE_DELETE = READ | WRITE | CREATE | DELETE;
     public static final int READ_WRITE_CREATE = READ | WRITE | CREATE;
     public static final int READ_WRITE_CREATE = READ | WRITE | CREATE;
     public static final int READ_WRITE = READ | WRITE;
     public static final int READ_WRITE = READ | WRITE;
     public static final int READ_WRITE_DELETE = READ | WRITE | DELETE;
     public static final int READ_WRITE_DELETE = READ | WRITE | DELETE;
 
 
     // Array required by the abstract superclass via getValidPermissions()
     // Array required by the abstract superclass via getValidPermissions()
-    private static final int[] validPermissions = {NOTHING, ADMINISTRATION, READ, WRITE, CREATE, DELETE, READ_WRITE_CREATE_DELETE, READ_WRITE_CREATE, READ_WRITE, READ_WRITE_DELETE};
+    private static final int[] validPermissions = {
+            NOTHING, ADMINISTRATION, READ, WRITE, CREATE, DELETE, READ_WRITE_CREATE_DELETE, READ_WRITE_CREATE,
+            READ_WRITE, READ_WRITE_DELETE
+        };
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
-    /**
+/**
      * Allows {@link BasicAclDao} implementations to construct this object
      * Allows {@link BasicAclDao} implementations to construct this object
      * using <code>newInstance()</code>.
      * using <code>newInstance()</code>.
      * 
      * 
@@ -62,13 +64,12 @@ public class SimpleAclEntry extends AbstractBasicAclEntry {
         super();
         super();
     }
     }
 
 
-    public SimpleAclEntry(Object recipient,
-        AclObjectIdentity aclObjectIdentity,
+    public SimpleAclEntry(Object recipient, AclObjectIdentity aclObjectIdentity,
         AclObjectIdentity aclObjectParentIdentity, int mask) {
         AclObjectIdentity aclObjectParentIdentity, int mask) {
         super(recipient, aclObjectIdentity, aclObjectParentIdentity, mask);
         super(recipient, aclObjectIdentity, aclObjectParentIdentity, mask);
     }
     }
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     public int[] getValidPermissions() {
     public int[] getValidPermissions() {
         return validPermissions;
         return validPermissions;

+ 11 - 19
core/src/main/java/org/acegisecurity/acl/basic/cache/BasicAclEntryHolder.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -17,36 +17,28 @@ package org.acegisecurity.acl.basic.cache;
 
 
 import org.acegisecurity.acl.basic.BasicAclEntry;
 import org.acegisecurity.acl.basic.BasicAclEntry;
 
 
-import java.io.Serializable;
-
 import org.springframework.util.Assert;
 import org.springframework.util.Assert;
 
 
+import java.io.Serializable;
+
 
 
 /**
 /**
- * Used by {@link EhCacheBasedAclEntryCache} to store the array of
- * <code>BasicAclEntry</code>s in the cache.
- * 
- * <P>
- * This is necessary because caches store a single object per key, not an
- * array.
- * </p>
- * 
- * <P>
- * This class uses value object semantics. ie: construction-based
- * initialisation without any setters for the properties.
- * </p>
+ * Used by {@link EhCacheBasedAclEntryCache} to store the array of <code>BasicAclEntry</code>s in the cache.<P>This
+ * is necessary because caches store a single object per key, not an array.</p>
+ *  <P>This class uses value object semantics. ie: construction-based initialisation without any setters for the
+ * properties.</p>
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public class BasicAclEntryHolder implements Serializable {
 public class BasicAclEntryHolder implements Serializable {
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private BasicAclEntry[] basicAclEntries;
     private BasicAclEntry[] basicAclEntries;
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
-    /**
+/**
      * Constructs the <code>BasicAclEntryHolder</code>.
      * Constructs the <code>BasicAclEntryHolder</code>.
      *
      *
      * @param aclEntries to cache (any <code>null</code>s will cause an
      * @param aclEntries to cache (any <code>null</code>s will cause an
@@ -68,7 +60,7 @@ public class BasicAclEntryHolder implements Serializable {
         this.basicAclEntries = aclEntries;
         this.basicAclEntries = aclEntries;
     }
     }
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     public BasicAclEntry[] getBasicAclEntries() {
     public BasicAclEntry[] getBasicAclEntries() {
         return basicAclEntries;
         return basicAclEntries;

+ 8 - 13
core/src/main/java/org/acegisecurity/acl/basic/cache/EhCacheBasedAclEntryCache.java

@@ -40,17 +40,16 @@ import org.springframework.util.Assert;
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
-public class EhCacheBasedAclEntryCache implements BasicAclEntryCache,
-    InitializingBean {
-    //~ Static fields/initializers =============================================
+public class EhCacheBasedAclEntryCache implements BasicAclEntryCache, InitializingBean {
+    //~ Static fields/initializers =====================================================================================
 
 
     private static final Log logger = LogFactory.getLog(EhCacheBasedAclEntryCache.class);
     private static final Log logger = LogFactory.getLog(EhCacheBasedAclEntryCache.class);
 
 
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private Cache cache;
     private Cache cache;
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     public void afterPropertiesSet() throws Exception {
     public void afterPropertiesSet() throws Exception {
         Assert.notNull(cache, "cache mandatory");
         Assert.notNull(cache, "cache mandatory");
@@ -60,15 +59,13 @@ public class EhCacheBasedAclEntryCache implements BasicAclEntryCache,
         return cache;
         return cache;
     }
     }
 
 
-    public BasicAclEntry[] getEntriesFromCache(
-        AclObjectIdentity aclObjectIdentity) {
+    public BasicAclEntry[] getEntriesFromCache(AclObjectIdentity aclObjectIdentity) {
         Element element = null;
         Element element = null;
 
 
         try {
         try {
             element = cache.get(aclObjectIdentity);
             element = cache.get(aclObjectIdentity);
         } catch (CacheException cacheException) {
         } catch (CacheException cacheException) {
-            throw new DataRetrievalFailureException("Cache failure: "
-                + cacheException.getMessage());
+            throw new DataRetrievalFailureException("Cache failure: " + cacheException.getMessage());
         }
         }
 
 
         // Return null if cache element has expired or not found
         // Return null if cache element has expired or not found
@@ -81,8 +78,7 @@ public class EhCacheBasedAclEntryCache implements BasicAclEntryCache,
         }
         }
 
 
         if (logger.isDebugEnabled()) {
         if (logger.isDebugEnabled()) {
-            logger.debug("Cache hit: " + (element != null) + "; object: "
-                + aclObjectIdentity);
+            logger.debug("Cache hit: " + (element != null) + "; object: " + aclObjectIdentity);
         }
         }
 
 
         BasicAclEntryHolder holder = (BasicAclEntryHolder) element.getValue();
         BasicAclEntryHolder holder = (BasicAclEntryHolder) element.getValue();
@@ -92,8 +88,7 @@ public class EhCacheBasedAclEntryCache implements BasicAclEntryCache,
 
 
     public void putEntriesInCache(BasicAclEntry[] basicAclEntry) {
     public void putEntriesInCache(BasicAclEntry[] basicAclEntry) {
         BasicAclEntryHolder holder = new BasicAclEntryHolder(basicAclEntry);
         BasicAclEntryHolder holder = new BasicAclEntryHolder(basicAclEntry);
-        Element element = new Element(basicAclEntry[0].getAclObjectIdentity(),
-                holder);
+        Element element = new Element(basicAclEntry[0].getAclObjectIdentity(), holder);
 
 
         if (logger.isDebugEnabled()) {
         if (logger.isDebugEnabled()) {
             logger.debug("Cache put: " + element.getKey());
             logger.debug("Cache put: " + element.getKey());

+ 5 - 11
core/src/main/java/org/acegisecurity/acl/basic/cache/NullAclEntryCache.java

@@ -21,29 +21,23 @@ import org.acegisecurity.acl.basic.BasicAclEntryCache;
 
 
 
 
 /**
 /**
- * Does not perform any caching.
- * 
- * <P>
- * <B>Do not use in production settings</B>, as ACL queries are likely to be
- * extensive.
- * </p>
+ * Does not perform any caching.<P><B>Do not use in production settings</B>, as ACL queries are likely to be
+ * extensive.</p>
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public class NullAclEntryCache implements BasicAclEntryCache {
 public class NullAclEntryCache implements BasicAclEntryCache {
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
-     * As nothing ever stored in the cache, will always return
-     * <code>null</code>.
+     * As nothing ever stored in the cache, will always return <code>null</code>.
      *
      *
      * @param aclObjectIdentity ignored
      * @param aclObjectIdentity ignored
      *
      *
      * @return always <code>null</code>
      * @return always <code>null</code>
      */
      */
-    public BasicAclEntry[] getEntriesFromCache(
-        AclObjectIdentity aclObjectIdentity) {
+    public BasicAclEntry[] getEntriesFromCache(AclObjectIdentity aclObjectIdentity) {
         return null;
         return null;
     }
     }
 
 

+ 66 - 136
core/src/main/java/org/acegisecurity/acl/basic/jdbc/JdbcDaoImpl.java

@@ -42,56 +42,48 @@ import javax.sql.DataSource;
 
 
 
 
 /**
 /**
- * <p>
- * Retrieves ACL details from a JDBC location.
- * </p>
- * 
- * <p>
- * A default database structure is assumed. This may be overridden by setting
- * the default query strings to use. If this does not provide enough
- * flexibility, another strategy would be to subclass this class and override
- * the {@link MappingSqlQuery} instance used, via the {@link
- * #initMappingSqlQueries()} extension point.
- * </p>
+ * <p>Retrieves ACL details from a JDBC location.</p>
+ *  <p>A default database structure is assumed. This may be overridden by setting the default query strings to use.
+ * If this does not provide enough flexibility, another strategy would be to subclass this class and override the
+ * {@link MappingSqlQuery} instance used, via the {@link #initMappingSqlQueries()} extension point.</p>
  */
  */
 public class JdbcDaoImpl extends JdbcDaoSupport implements BasicAclDao {
 public class JdbcDaoImpl extends JdbcDaoSupport implements BasicAclDao {
-    //~ Static fields/initializers =============================================
+    //~ Static fields/initializers =====================================================================================
 
 
     public static final String RECIPIENT_USED_FOR_INHERITENCE_MARKER = "___INHERITENCE_MARKER_ONLY___";
     public static final String RECIPIENT_USED_FOR_INHERITENCE_MARKER = "___INHERITENCE_MARKER_ONLY___";
     public static final String DEF_ACLS_BY_OBJECT_IDENTITY_QUERY = "SELECT RECIPIENT, MASK FROM acl_permission WHERE acl_object_identity = ?";
     public static final String DEF_ACLS_BY_OBJECT_IDENTITY_QUERY = "SELECT RECIPIENT, MASK FROM acl_permission WHERE acl_object_identity = ?";
     public static final String DEF_OBJECT_PROPERTIES_QUERY = "SELECT CHILD.ID, CHILD.OBJECT_IDENTITY, CHILD.ACL_CLASS, PARENT.OBJECT_IDENTITY as PARENT_OBJECT_IDENTITY FROM acl_object_identity as CHILD LEFT OUTER JOIN acl_object_identity as PARENT ON CHILD.parent_object=PARENT.id WHERE CHILD.object_identity = ?";
     public static final String DEF_OBJECT_PROPERTIES_QUERY = "SELECT CHILD.ID, CHILD.OBJECT_IDENTITY, CHILD.ACL_CLASS, PARENT.OBJECT_IDENTITY as PARENT_OBJECT_IDENTITY FROM acl_object_identity as CHILD LEFT OUTER JOIN acl_object_identity as PARENT ON CHILD.parent_object=PARENT.id WHERE CHILD.object_identity = ?";
     private static final Log logger = LogFactory.getLog(JdbcDaoImpl.class);
     private static final Log logger = LogFactory.getLog(JdbcDaoImpl.class);
 
 
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     protected MappingSqlQuery aclsByObjectIdentity;
     protected MappingSqlQuery aclsByObjectIdentity;
     protected MappingSqlQuery objectProperties;
     protected MappingSqlQuery objectProperties;
     private String aclsByObjectIdentityQuery;
     private String aclsByObjectIdentityQuery;
     private String objectPropertiesQuery;
     private String objectPropertiesQuery;
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
     public JdbcDaoImpl() {
     public JdbcDaoImpl() {
         aclsByObjectIdentityQuery = DEF_ACLS_BY_OBJECT_IDENTITY_QUERY;
         aclsByObjectIdentityQuery = DEF_ACLS_BY_OBJECT_IDENTITY_QUERY;
         objectPropertiesQuery = DEF_OBJECT_PROPERTIES_QUERY;
         objectPropertiesQuery = DEF_OBJECT_PROPERTIES_QUERY;
     }
     }
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
-     * Responsible for covering a <code>AclObjectIdentity</code> to a
-     * <code>String</code> that can be located in the RDBMS.
+     * Responsible for covering a <code>AclObjectIdentity</code> to a <code>String</code> that can be located
+     * in the RDBMS.
      *
      *
      * @param aclObjectIdentity to locate
      * @param aclObjectIdentity to locate
      *
      *
      * @return the object identity as a <code>String</code>
      * @return the object identity as a <code>String</code>
      */
      */
-    protected String convertAclObjectIdentityToString(
-        AclObjectIdentity aclObjectIdentity) {
+    protected String convertAclObjectIdentityToString(AclObjectIdentity aclObjectIdentity) {
         // Ensure we can process this type of AclObjectIdentity
         // Ensure we can process this type of AclObjectIdentity
         Assert.isInstanceOf(NamedEntityObjectIdentity.class, aclObjectIdentity,
         Assert.isInstanceOf(NamedEntityObjectIdentity.class, aclObjectIdentity,
-            "Only aclObjectIdentity of type NamedEntityObjectIdentity supported (was passed: "
-            + aclObjectIdentity + ")");
+            "Only aclObjectIdentity of type NamedEntityObjectIdentity supported (was passed: " + aclObjectIdentity
+            + ")");
 
 
         NamedEntityObjectIdentity neoi = (NamedEntityObjectIdentity) aclObjectIdentity;
         NamedEntityObjectIdentity neoi = (NamedEntityObjectIdentity) aclObjectIdentity;
 
 
@@ -100,37 +92,26 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements BasicAclDao {
     }
     }
 
 
     /**
     /**
-     * Constructs an individual <code>BasicAclEntry</code> from the passed
-     * <code>AclDetailsHolder</code>s.
-     * 
-     * <P>
-     * Guarantees to never return <code>null</code> (exceptions are thrown in
-     * the event of any issues).
-     * </p>
+     * Constructs an individual <code>BasicAclEntry</code> from the passed <code>AclDetailsHolder</code>s.<P>Guarantees
+     * to never return <code>null</code> (exceptions are thrown in the event of any issues).</p>
      *
      *
-     * @param propertiesInformation mandatory information about which instance
-     *        to create, the object identity, and the parent object identity
-     *        (<code>null</code> or empty <code>String</code>s prohibited for
+     * @param propertiesInformation mandatory information about which instance to create, the object identity, and the
+     *        parent object identity (<code>null</code> or empty <code>String</code>s prohibited for
      *        <code>aclClass</code> and <code>aclObjectIdentity</code>
      *        <code>aclClass</code> and <code>aclObjectIdentity</code>
-     * @param aclInformation optional information about the individual ACL
-     *        record (if <code>null</code> only an "inheritence marker"
-     *        instance is returned which will include a recipient of {@link
-     *        #RECIPIENT_USED_FOR_INHERITENCE_MARKER} ; if not
-     *        <code>null</code>, it is prohibited to present <code>null</code>
-     *        or an empty <code>String</code> for <code>recipient</code>)
+     * @param aclInformation optional information about the individual ACL record (if <code>null</code> only an
+     *        "inheritence marker" instance is returned which will include a recipient of {@link
+     *        #RECIPIENT_USED_FOR_INHERITENCE_MARKER} ; if not <code>null</code>, it is prohibited to present
+     *        <code>null</code> or an empty <code>String</code> for <code>recipient</code>)
      *
      *
      * @return a fully populated instance suitable for use by external objects
      * @return a fully populated instance suitable for use by external objects
      *
      *
-     * @throws IllegalArgumentException if the indicated ACL class could not be
-     *         created
+     * @throws IllegalArgumentException if the indicated ACL class could not be created
      */
      */
-    private BasicAclEntry createBasicAclEntry(
-        AclDetailsHolder propertiesInformation, AclDetailsHolder aclInformation) {
+    private BasicAclEntry createBasicAclEntry(AclDetailsHolder propertiesInformation, AclDetailsHolder aclInformation) {
         BasicAclEntry entry;
         BasicAclEntry entry;
 
 
         try {
         try {
-            entry = (BasicAclEntry) propertiesInformation.getAclClass()
-                                                         .newInstance();
+            entry = (BasicAclEntry) propertiesInformation.getAclClass().newInstance();
         } catch (InstantiationException ie) {
         } catch (InstantiationException ie) {
             throw new IllegalArgumentException(ie.getMessage());
             throw new IllegalArgumentException(ie.getMessage());
         } catch (IllegalAccessException iae) {
         } catch (IllegalAccessException iae) {
@@ -138,8 +119,7 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements BasicAclDao {
         }
         }
 
 
         entry.setAclObjectIdentity(propertiesInformation.getAclObjectIdentity());
         entry.setAclObjectIdentity(propertiesInformation.getAclObjectIdentity());
-        entry.setAclObjectParentIdentity(propertiesInformation
-            .getAclObjectParentIdentity());
+        entry.setAclObjectParentIdentity(propertiesInformation.getAclObjectParentIdentity());
 
 
         if (aclInformation == null) {
         if (aclInformation == null) {
             // this is an inheritence marker instance only
             // this is an inheritence marker instance only
@@ -155,30 +135,19 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements BasicAclDao {
     }
     }
 
 
     /**
     /**
-     * Returns the ACLs associated with the requested
-     * <code>AclObjectIdentity</code>.
-     * 
-     * <P>
-     * The {@link BasicAclEntry}s returned by this method will have
-     * <code>String</code>-based recipients. This will not be a problem if you
-     * are using the <code>GrantedAuthorityEffectiveAclsResolver</code>, which
-     * is the default configured against <code>BasicAclProvider</code>.
-     * </p>
-     * 
-     * <P>
-     * This method will only return ACLs for requests where the
-     * <code>AclObjectIdentity</code> is of type {@link
-     * NamedEntityObjectIdentity}. Of course, you can subclass or replace this
-     * class and support your own custom <code>AclObjectIdentity</code> types.
-     * </p>
+     * Returns the ACLs associated with the requested <code>AclObjectIdentity</code>.<P>The {@link
+     * BasicAclEntry}s returned by this method will have <code>String</code>-based recipients. This will not be a
+     * problem if you are using the <code>GrantedAuthorityEffectiveAclsResolver</code>, which is the default
+     * configured against <code>BasicAclProvider</code>.</p>
+     *  <P>This method will only return ACLs for requests where the <code>AclObjectIdentity</code> is of type
+     * {@link NamedEntityObjectIdentity}. Of course, you can subclass or replace this class and support your own
+     * custom <code>AclObjectIdentity</code> types.</p>
      *
      *
-     * @param aclObjectIdentity for which ACL information is required (cannot
-     *        be <code>null</code> and must be an instance of
-     *        <code>NamedEntityObjectIdentity</code>)
+     * @param aclObjectIdentity for which ACL information is required (cannot be <code>null</code> and must be an
+     *        instance of <code>NamedEntityObjectIdentity</code>)
      *
      *
-     * @return the ACLs that apply (without any <code>null</code>s inside the
-     *         array), or <code>null</code> if not found or if an incompatible
-     *         <code>AclObjectIdentity</code> was requested
+     * @return the ACLs that apply (without any <code>null</code>s inside the array), or <code>null</code> if not found
+     *         or if an incompatible <code>AclObjectIdentity</code> was requested
      */
      */
     public BasicAclEntry[] getAcls(AclObjectIdentity aclObjectIdentity) {
     public BasicAclEntry[] getAcls(AclObjectIdentity aclObjectIdentity) {
         String aclObjectIdentityString;
         String aclObjectIdentityString;
@@ -201,21 +170,18 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements BasicAclDao {
         AclDetailsHolder propertiesInformation = (AclDetailsHolder) objects.get(0);
         AclDetailsHolder propertiesInformation = (AclDetailsHolder) objects.get(0);
 
 
         // Lookup the object's ACLs from RDBMS (guaranteed no nulls)
         // Lookup the object's ACLs from RDBMS (guaranteed no nulls)
-        List acls = aclsByObjectIdentity.execute(propertiesInformation
-                .getForeignKeyId());
+        List acls = aclsByObjectIdentity.execute(propertiesInformation.getForeignKeyId());
 
 
         if (acls.size() == 0) {
         if (acls.size() == 0) {
             // return merely an inheritence marker (as we know about the object but it has no related ACLs)
             // return merely an inheritence marker (as we know about the object but it has no related ACLs)
-            return new BasicAclEntry[] {createBasicAclEntry(propertiesInformation,
-                    null)};
+            return new BasicAclEntry[] {createBasicAclEntry(propertiesInformation, null)};
         } else {
         } else {
             // return the individual ACL instances
             // return the individual ACL instances
             AclDetailsHolder[] aclHolders = (AclDetailsHolder[]) acls.toArray(new AclDetailsHolder[] {});
             AclDetailsHolder[] aclHolders = (AclDetailsHolder[]) acls.toArray(new AclDetailsHolder[] {});
             List toReturnAcls = new Vector();
             List toReturnAcls = new Vector();
 
 
             for (int i = 0; i < aclHolders.length; i++) {
             for (int i = 0; i < aclHolders.length; i++) {
-                toReturnAcls.add(createBasicAclEntry(propertiesInformation,
-                        aclHolders[i]));
+                toReturnAcls.add(createBasicAclEntry(propertiesInformation, aclHolders[i]));
             }
             }
 
 
             return (BasicAclEntry[]) toReturnAcls.toArray(new BasicAclEntry[] {});
             return (BasicAclEntry[]) toReturnAcls.toArray(new BasicAclEntry[] {});
@@ -239,26 +205,22 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements BasicAclDao {
     }
     }
 
 
     /**
     /**
-     * Extension point to allow other MappingSqlQuery objects to be substituted
-     * in a subclass
+     * Extension point to allow other MappingSqlQuery objects to be substituted in a subclass
      */
      */
     protected void initMappingSqlQueries() {
     protected void initMappingSqlQueries() {
         setAclsByObjectIdentity(new AclsByObjectIdentityMapping(getDataSource()));
         setAclsByObjectIdentity(new AclsByObjectIdentityMapping(getDataSource()));
         setObjectProperties(new ObjectPropertiesMapping(getDataSource()));
         setObjectProperties(new ObjectPropertiesMapping(getDataSource()));
     }
     }
 
 
-    public void setAclsByObjectIdentity(
-        MappingSqlQuery aclsByObjectIdentityQuery) {
+    public void setAclsByObjectIdentity(MappingSqlQuery aclsByObjectIdentityQuery) {
         this.aclsByObjectIdentity = aclsByObjectIdentityQuery;
         this.aclsByObjectIdentity = aclsByObjectIdentityQuery;
     }
     }
 
 
     /**
     /**
-     * Allows the default query string used to retrieve ACLs based on object
-     * identity to be overriden, if default table or column names need to be
-     * changed. The default query is {@link
-     * #DEF_ACLS_BY_OBJECT_IDENTITY_QUERY}; when modifying this query, ensure
-     * that all returned columns are mapped back to the same column names as
-     * in the default query.
+     * Allows the default query string used to retrieve ACLs based on object identity to be overriden, if
+     * default table or column names need to be changed. The default query is {@link
+     * #DEF_ACLS_BY_OBJECT_IDENTITY_QUERY}; when modifying this query, ensure that all returned columns are mapped
+     * back to the same column names as in the default query.
      *
      *
      * @param queryString The query string to set
      * @param queryString The query string to set
      */
      */
@@ -274,22 +236,14 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements BasicAclDao {
         objectPropertiesQuery = queryString;
         objectPropertiesQuery = queryString;
     }
     }
 
 
-    //~ Inner Classes ==========================================================
+    //~ Inner Classes ==================================================================================================
 
 
     /**
     /**
-     * Used to hold details of a domain object instance's properties, or an
-     * individual ACL entry.
-     * 
-     * <P>
-     * Not all properties will be set. The actual properties set will depend on
-     * which <code>MappingSqlQuery</code> creates the object.
-     * </p>
-     * 
-     * <P>
-     * Does not enforce <code>null</code>s or empty <code>String</code>s as
-     * this is performed by the <code>MappingSqlQuery</code> objects (or
-     * preferably the backend RDBMS via schema constraints).
-     * </p>
+     * Used to hold details of a domain object instance's properties, or an individual ACL entry.<P>Not all
+     * properties will be set. The actual properties set will depend on which <code>MappingSqlQuery</code> creates the
+     * object.</p>
+     *  <P>Does not enforce <code>null</code>s or empty <code>String</code>s as this is performed by the
+     * <code>MappingSqlQuery</code> objects (or preferably the backend RDBMS via schema constraints).</p>
      */
      */
     protected final class AclDetailsHolder {
     protected final class AclDetailsHolder {
         private AclObjectIdentity aclObjectIdentity;
         private AclObjectIdentity aclObjectIdentity;
@@ -299,7 +253,7 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements BasicAclDao {
         private int mask;
         private int mask;
         private long foreignKeyId;
         private long foreignKeyId;
 
 
-        /**
+/**
          * Record details of an individual ACL entry (usually from the
          * Record details of an individual ACL entry (usually from the
          * ACL_PERMISSION table)
          * ACL_PERMISSION table)
          *
          *
@@ -311,7 +265,7 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements BasicAclDao {
             this.mask = mask;
             this.mask = mask;
         }
         }
 
 
-        /**
+/**
          * Record details of a domain object instance's properties (usually
          * Record details of a domain object instance's properties (usually
          * from the ACL_OBJECT_IDENTITY table)
          * from the ACL_OBJECT_IDENTITY table)
          *
          *
@@ -326,8 +280,7 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements BasicAclDao {
          *        created for each individual ACL entry (or an inheritence
          *        created for each individual ACL entry (or an inheritence
          *        "holder" class if there are no ACL entries)
          *        "holder" class if there are no ACL entries)
          */
          */
-        public AclDetailsHolder(long foreignKeyId,
-            AclObjectIdentity aclObjectIdentity,
+        public AclDetailsHolder(long foreignKeyId, AclObjectIdentity aclObjectIdentity,
             AclObjectIdentity aclObjectParentIdentity, Class aclClass) {
             AclObjectIdentity aclObjectParentIdentity, Class aclClass) {
             this.foreignKeyId = foreignKeyId;
             this.foreignKeyId = foreignKeyId;
             this.aclObjectIdentity = aclObjectIdentity;
             this.aclObjectIdentity = aclObjectIdentity;
@@ -361,21 +314,11 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements BasicAclDao {
     }
     }
 
 
     /**
     /**
-     * Query object to look up individual ACL entries.
-     * 
-     * <P>
-     * Returns the generic <code>AclDetailsHolder</code> object.
-     * </p>
-     * 
-     * <P>
-     * Guarantees to never return <code>null</code> (exceptions are thrown in
-     * the event of any issues).
-     * </p>
-     * 
-     * <P>
-     * The executed SQL requires the following information be made available
-     * from the indicated placeholders: 1. RECIPIENT, 2. MASK.
-     * </p>
+     * Query object to look up individual ACL entries.<P>Returns the generic <code>AclDetailsHolder</code>
+     * object.</p>
+     *  <P>Guarantees to never return <code>null</code> (exceptions are thrown in the event of any issues).</p>
+     *  <P>The executed SQL requires the following information be made available from the indicated
+     * placeholders: 1. RECIPIENT, 2. MASK.</p>
      */
      */
     protected class AclsByObjectIdentityMapping extends MappingSqlQuery {
     protected class AclsByObjectIdentityMapping extends MappingSqlQuery {
         protected AclsByObjectIdentityMapping(DataSource ds) {
         protected AclsByObjectIdentityMapping(DataSource ds) {
@@ -395,22 +338,11 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements BasicAclDao {
     }
     }
 
 
     /**
     /**
-     * Query object to look up properties for an object identity.
-     * 
-     * <P>
-     * Returns the generic <code>AclDetailsHolder</code> object.
-     * </p>
-     * 
-     * <P>
-     * Guarantees to never return <code>null</code> (exceptions are thrown in
-     * the event of any issues).
-     * </p>
-     * 
-     * <P>
-     * The executed SQL requires the following information be made available
-     * from the indicated placeholders: 1. ID, 2. OBJECT_IDENTITY, 3.
-     * ACL_CLASS and 4. PARENT_OBJECT_IDENTITY.
-     * </p>
+     * Query object to look up properties for an object identity.<P>Returns the generic
+     * <code>AclDetailsHolder</code> object.</p>
+     *  <P>Guarantees to never return <code>null</code> (exceptions are thrown in the event of any issues).</p>
+     *  <P>The executed SQL requires the following information be made available from the indicated
+     * placeholders: 1. ID, 2. OBJECT_IDENTITY, 3. ACL_CLASS and 4. PARENT_OBJECT_IDENTITY.</p>
      */
      */
     protected class ObjectPropertiesMapping extends MappingSqlQuery {
     protected class ObjectPropertiesMapping extends MappingSqlQuery {
         protected ObjectPropertiesMapping(DataSource ds) {
         protected ObjectPropertiesMapping(DataSource ds) {
@@ -440,8 +372,7 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements BasicAclDao {
             String parentObjectIdentity = rs.getString(4); // optional
             String parentObjectIdentity = rs.getString(4); // optional
             Assert.hasText(objectIdentity,
             Assert.hasText(objectIdentity,
                 "required DEF_OBJECT_PROPERTIES_QUERY value (objectIdentity) returned null or empty");
                 "required DEF_OBJECT_PROPERTIES_QUERY value (objectIdentity) returned null or empty");
-            Assert.hasText(aclClass,
-                "required DEF_OBJECT_PROPERTIES_QUERY value (aclClass) returned null or empty");
+            Assert.hasText(aclClass, "required DEF_OBJECT_PROPERTIES_QUERY value (aclClass) returned null or empty");
 
 
             Class aclClazz;
             Class aclClazz;
 
 
@@ -451,8 +382,7 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements BasicAclDao {
                 throw new IllegalArgumentException(cnf.getMessage());
                 throw new IllegalArgumentException(cnf.getMessage());
             }
             }
 
 
-            return new AclDetailsHolder(id, buildIdentity(objectIdentity),
-                buildIdentity(parentObjectIdentity), aclClazz);
+            return new AclDetailsHolder(id, buildIdentity(objectIdentity), buildIdentity(parentObjectIdentity), aclClazz);
         }
         }
     }
     }
 }
 }

+ 51 - 96
core/src/main/java/org/acegisecurity/acl/basic/jdbc/JdbcExtendedDaoImpl.java

@@ -47,36 +47,20 @@ import javax.sql.DataSource;
 
 
 
 
 /**
 /**
- * <p>
- * Extension of the base {@link JdbcDaoImpl}, which implements {@link
- * BasicAclExtendedDao}.
- * </p>
- * 
- * <p>
- * A default database structure is assumed. This may be overridden by setting
- * the default query strings to use.
- * </p>
- * 
- * <p>
- * If you are using a cache with <code>BasicAclProvider</code>, you should
- * specify that cache via {@link #setBasicAclEntryCache(BasicAclEntryCache)}.
- * This will cause cache evictions (removals) to take place whenever a DAO
- * mutator method is called.
- * </p>
- * 
- * <p>
- * This implementation works with <code>String</code> based recipients and
- * {@link org.acegisecurity.acl.basic.NamedEntityObjectIdentity} only. The
- * latter can be changed by overriding {@link
- * #convertAclObjectIdentityToString(AclObjectIdentity)}.
- * </p>
+ * <p>Extension of the base {@link JdbcDaoImpl}, which implements {@link BasicAclExtendedDao}.</p>
+ *  <p>A default database structure is assumed. This may be overridden by setting the default query strings to use.</p>
+ *  <p>If you are using a cache with <code>BasicAclProvider</code>, you should specify that cache via {@link
+ * #setBasicAclEntryCache(BasicAclEntryCache)}. This will cause cache evictions (removals) to take place whenever a
+ * DAO mutator method is called.</p>
+ *  <p>This implementation works with <code>String</code> based recipients and {@link
+ * org.acegisecurity.acl.basic.NamedEntityObjectIdentity} only. The latter can be changed by overriding {@link
+ * #convertAclObjectIdentityToString(AclObjectIdentity)}.</p>
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
-public class JdbcExtendedDaoImpl extends JdbcDaoImpl
-    implements BasicAclExtendedDao {
-    //~ Static fields/initializers =============================================
+public class JdbcExtendedDaoImpl extends JdbcDaoImpl implements BasicAclExtendedDao {
+    //~ Static fields/initializers =====================================================================================
 
 
     private static final Log logger = LogFactory.getLog(JdbcExtendedDaoImpl.class);
     private static final Log logger = LogFactory.getLog(JdbcExtendedDaoImpl.class);
     public static final String DEF_ACL_OBJECT_IDENTITY_DELETE_STATEMENT = "DELETE FROM acl_object_identity WHERE id = ?";
     public static final String DEF_ACL_OBJECT_IDENTITY_DELETE_STATEMENT = "DELETE FROM acl_object_identity WHERE id = ?";
@@ -86,7 +70,7 @@ public class JdbcExtendedDaoImpl extends JdbcDaoImpl
     public static final String DEF_ACL_PERMISSION_UPDATE_STATEMENT = "UPDATE acl_permission SET mask = ? WHERE id = ?";
     public static final String DEF_ACL_PERMISSION_UPDATE_STATEMENT = "UPDATE acl_permission SET mask = ? WHERE id = ?";
     public static final String DEF_LOOKUP_PERMISSION_ID_QUERY = "SELECT id FROM acl_permission WHERE acl_object_identity = ? AND recipient = ?";
     public static final String DEF_LOOKUP_PERMISSION_ID_QUERY = "SELECT id FROM acl_permission WHERE acl_object_identity = ? AND recipient = ?";
 
 
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private AclObjectIdentityDelete aclObjectIdentityDelete;
     private AclObjectIdentityDelete aclObjectIdentityDelete;
     private AclObjectIdentityInsert aclObjectIdentityInsert;
     private AclObjectIdentityInsert aclObjectIdentityInsert;
@@ -102,7 +86,7 @@ public class JdbcExtendedDaoImpl extends JdbcDaoImpl
     private String aclPermissionUpdateStatement;
     private String aclPermissionUpdateStatement;
     private String lookupPermissionIdQuery;
     private String lookupPermissionIdQuery;
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
     public JdbcExtendedDaoImpl() {
     public JdbcExtendedDaoImpl() {
         aclObjectIdentityDeleteStatement = DEF_ACL_OBJECT_IDENTITY_DELETE_STATEMENT;
         aclObjectIdentityDeleteStatement = DEF_ACL_OBJECT_IDENTITY_DELETE_STATEMENT;
@@ -113,22 +97,20 @@ public class JdbcExtendedDaoImpl extends JdbcDaoImpl
         lookupPermissionIdQuery = DEF_LOOKUP_PERMISSION_ID_QUERY;
         lookupPermissionIdQuery = DEF_LOOKUP_PERMISSION_ID_QUERY;
     }
     }
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
-    public void changeMask(AclObjectIdentity aclObjectIdentity,
-        Object recipient, Integer newMask) throws DataAccessException {
+    public void changeMask(AclObjectIdentity aclObjectIdentity, Object recipient, Integer newMask)
+        throws DataAccessException {
         basicAclEntryCache.removeEntriesFromCache(aclObjectIdentity);
         basicAclEntryCache.removeEntriesFromCache(aclObjectIdentity);
 
 
         // Retrieve acl_object_identity record details
         // Retrieve acl_object_identity record details
         AclDetailsHolder aclDetailsHolder = lookupAclDetailsHolder(aclObjectIdentity);
         AclDetailsHolder aclDetailsHolder = lookupAclDetailsHolder(aclObjectIdentity);
 
 
         // Retrieve applicable acl_permission.id
         // Retrieve applicable acl_permission.id
-        long permissionId = lookupPermissionId(aclDetailsHolder.getForeignKeyId(),
-                recipient.toString());
+        long permissionId = lookupPermissionId(aclDetailsHolder.getForeignKeyId(), recipient.toString());
 
 
         if (permissionId == -1) {
         if (permissionId == -1) {
-            throw new DataRetrievalFailureException(
-                "Could not locate existing acl_permission for aclObjectIdentity: "
+            throw new DataRetrievalFailureException("Could not locate existing acl_permission for aclObjectIdentity: "
                 + aclObjectIdentity + ", recipient: " + recipient.toString());
                 + aclObjectIdentity + ", recipient: " + recipient.toString());
         }
         }
 
 
@@ -147,59 +129,48 @@ public class JdbcExtendedDaoImpl extends JdbcDaoImpl
         }
         }
 
 
         // Retrieve acl_object_identity record details
         // Retrieve acl_object_identity record details
-        AclDetailsHolder aclDetailsHolder = lookupAclDetailsHolder(basicAclEntry
-                .getAclObjectIdentity());
+        AclDetailsHolder aclDetailsHolder = lookupAclDetailsHolder(basicAclEntry.getAclObjectIdentity());
 
 
         // Ensure there isn't an existing record for this recipient
         // Ensure there isn't an existing record for this recipient
-        long permissionId = lookupPermissionId(aclDetailsHolder.getForeignKeyId(),
-                basicAclEntry.getRecipient());
+        long permissionId = lookupPermissionId(aclDetailsHolder.getForeignKeyId(), basicAclEntry.getRecipient());
 
 
         if (permissionId != -1) {
         if (permissionId != -1) {
-            throw new DataIntegrityViolationException("Recipient '"
-                + basicAclEntry.getRecipient()
-                + "' already exists for aclObjectIdentity ID "
-                + aclDetailsHolder.getForeignKeyId() + " (permission ID " + ")");
+            throw new DataIntegrityViolationException("Recipient '" + basicAclEntry.getRecipient()
+                + "' already exists for aclObjectIdentity ID " + aclDetailsHolder.getForeignKeyId()
+                + " (permission ID " + ")");
         }
         }
 
 
         // Create acl_permission
         // Create acl_permission
         aclPermissionInsert.insert(new Long(aclDetailsHolder.getForeignKeyId()),
         aclPermissionInsert.insert(new Long(aclDetailsHolder.getForeignKeyId()),
-            basicAclEntry.getRecipient().toString(),
-            new Integer(basicAclEntry.getMask()));
+            basicAclEntry.getRecipient().toString(), new Integer(basicAclEntry.getMask()));
     }
     }
 
 
     /**
     /**
-     * Convenience method that creates an acl_object_identity record if
-     * required.
+     * Convenience method that creates an acl_object_identity record if required.
      *
      *
-     * @param basicAclEntry containing the <code>AclObjectIdentity</code> to
-     *        create
+     * @param basicAclEntry containing the <code>AclObjectIdentity</code> to create
      *
      *
      * @throws DataAccessException
      * @throws DataAccessException
      */
      */
     private void createAclObjectIdentityIfRequired(BasicAclEntry basicAclEntry)
     private void createAclObjectIdentityIfRequired(BasicAclEntry basicAclEntry)
         throws DataAccessException {
         throws DataAccessException {
-        basicAclEntryCache.removeEntriesFromCache(basicAclEntry
-            .getAclObjectIdentity());
+        basicAclEntryCache.removeEntriesFromCache(basicAclEntry.getAclObjectIdentity());
 
 
-        String aclObjectIdentityString = convertAclObjectIdentityToString(basicAclEntry
-                .getAclObjectIdentity());
+        String aclObjectIdentityString = convertAclObjectIdentityToString(basicAclEntry.getAclObjectIdentity());
 
 
         // Lookup the object's main properties from the RDBMS (guaranteed no nulls)
         // Lookup the object's main properties from the RDBMS (guaranteed no nulls)
         List objects = objectProperties.execute(aclObjectIdentityString);
         List objects = objectProperties.execute(aclObjectIdentityString);
 
 
         if (objects.size() == 0) {
         if (objects.size() == 0) {
             if (basicAclEntry.getAclObjectParentIdentity() != null) {
             if (basicAclEntry.getAclObjectParentIdentity() != null) {
-                AclDetailsHolder parentDetails = lookupAclDetailsHolder(basicAclEntry
-                        .getAclObjectParentIdentity());
+                AclDetailsHolder parentDetails = lookupAclDetailsHolder(basicAclEntry.getAclObjectParentIdentity());
 
 
                 // Must create the acl_object_identity record
                 // Must create the acl_object_identity record
-                aclObjectIdentityInsert.insert(aclObjectIdentityString,
-                    new Long(parentDetails.getForeignKeyId()),
+                aclObjectIdentityInsert.insert(aclObjectIdentityString, new Long(parentDetails.getForeignKeyId()),
                     basicAclEntry.getClass().getName());
                     basicAclEntry.getClass().getName());
             } else {
             } else {
                 // Must create the acl_object_identity record
                 // Must create the acl_object_identity record
-                aclObjectIdentityInsert.insert(aclObjectIdentityString, null,
-                    basicAclEntry.getClass().getName());
+                aclObjectIdentityInsert.insert(aclObjectIdentityString, null, basicAclEntry.getClass().getName());
             }
             }
         }
         }
     }
     }
@@ -212,8 +183,7 @@ public class JdbcExtendedDaoImpl extends JdbcDaoImpl
         AclDetailsHolder aclDetailsHolder = lookupAclDetailsHolder(aclObjectIdentity);
         AclDetailsHolder aclDetailsHolder = lookupAclDetailsHolder(aclObjectIdentity);
 
 
         // Retrieve all acl_permissions applying to this acl_object_identity
         // Retrieve all acl_permissions applying to this acl_object_identity
-        Iterator acls = aclsByObjectIdentity.execute(aclDetailsHolder
-                .getForeignKeyId()).iterator();
+        Iterator acls = aclsByObjectIdentity.execute(aclDetailsHolder.getForeignKeyId()).iterator();
 
 
         // Delete all existing acl_permissions applying to this acl_object_identity
         // Delete all existing acl_permissions applying to this acl_object_identity
         while (acls.hasNext()) {
         while (acls.hasNext()) {
@@ -222,8 +192,7 @@ public class JdbcExtendedDaoImpl extends JdbcDaoImpl
         }
         }
 
 
         // Delete acl_object_identity
         // Delete acl_object_identity
-        aclObjectIdentityDelete.delete(new Long(
-                aclDetailsHolder.getForeignKeyId()));
+        aclObjectIdentityDelete.delete(new Long(aclDetailsHolder.getForeignKeyId()));
     }
     }
 
 
     public void delete(AclObjectIdentity aclObjectIdentity, Object recipient)
     public void delete(AclObjectIdentity aclObjectIdentity, Object recipient)
@@ -234,8 +203,7 @@ public class JdbcExtendedDaoImpl extends JdbcDaoImpl
         AclDetailsHolder aclDetailsHolder = lookupAclDetailsHolder(aclObjectIdentity);
         AclDetailsHolder aclDetailsHolder = lookupAclDetailsHolder(aclObjectIdentity);
 
 
         // Delete acl_permission
         // Delete acl_permission
-        aclPermissionDelete.delete(new Long(aclDetailsHolder.getForeignKeyId()),
-            recipient.toString());
+        aclPermissionDelete.delete(new Long(aclDetailsHolder.getForeignKeyId()), recipient.toString());
     }
     }
 
 
     public AclObjectIdentityDelete getAclObjectIdentityDelete() {
     public AclObjectIdentityDelete getAclObjectIdentityDelete() {
@@ -309,8 +277,7 @@ public class JdbcExtendedDaoImpl extends JdbcDaoImpl
      *
      *
      * @throws DataRetrievalFailureException if record could not be found
      * @throws DataRetrievalFailureException if record could not be found
      */
      */
-    private AclDetailsHolder lookupAclDetailsHolder(
-        AclObjectIdentity aclObjectIdentity)
+    private AclDetailsHolder lookupAclDetailsHolder(AclObjectIdentity aclObjectIdentity)
         throws DataRetrievalFailureException {
         throws DataRetrievalFailureException {
         String aclObjectIdentityString = convertAclObjectIdentityToString(aclObjectIdentity);
         String aclObjectIdentityString = convertAclObjectIdentityToString(aclObjectIdentity);
 
 
@@ -318,8 +285,7 @@ public class JdbcExtendedDaoImpl extends JdbcDaoImpl
         List objects = objectProperties.execute(aclObjectIdentityString);
         List objects = objectProperties.execute(aclObjectIdentityString);
 
 
         if (objects.size() == 0) {
         if (objects.size() == 0) {
-            throw new DataRetrievalFailureException(
-                "aclObjectIdentity not found: " + aclObjectIdentityString);
+            throw new DataRetrievalFailureException("aclObjectIdentity not found: " + aclObjectIdentityString);
         }
         }
 
 
         // Should only be one record
         // Should only be one record
@@ -327,8 +293,8 @@ public class JdbcExtendedDaoImpl extends JdbcDaoImpl
     }
     }
 
 
     /**
     /**
-     * Convenience method to lookup the acl_permission applying to a given
-     * acl_object_identity.id and acl_permission.recipient.
+     * Convenience method to lookup the acl_permission applying to a given acl_object_identity.id and
+     * acl_permission.recipient.
      *
      *
      * @param aclObjectIdentityId to locate
      * @param aclObjectIdentityId to locate
      * @param recipient to locate
      * @param recipient to locate
@@ -339,8 +305,7 @@ public class JdbcExtendedDaoImpl extends JdbcDaoImpl
      */
      */
     private long lookupPermissionId(long aclObjectIdentityId, Object recipient)
     private long lookupPermissionId(long aclObjectIdentityId, Object recipient)
         throws DataAccessException {
         throws DataAccessException {
-        List list = lookupPermissionIdMapping.execute(new Object[] {new Long(
-                        aclObjectIdentityId), recipient});
+        List list = lookupPermissionIdMapping.execute(new Object[] {new Long(aclObjectIdentityId), recipient});
 
 
         if (list.size() == 0) {
         if (list.size() == 0) {
             return -1;
             return -1;
@@ -349,23 +314,19 @@ public class JdbcExtendedDaoImpl extends JdbcDaoImpl
         return ((Long) list.get(0)).longValue();
         return ((Long) list.get(0)).longValue();
     }
     }
 
 
-    public void setAclObjectIdentityDelete(
-        AclObjectIdentityDelete aclObjectIdentityDelete) {
+    public void setAclObjectIdentityDelete(AclObjectIdentityDelete aclObjectIdentityDelete) {
         this.aclObjectIdentityDelete = aclObjectIdentityDelete;
         this.aclObjectIdentityDelete = aclObjectIdentityDelete;
     }
     }
 
 
-    public void setAclObjectIdentityDeleteStatement(
-        String aclObjectIdentityDeleteStatement) {
+    public void setAclObjectIdentityDeleteStatement(String aclObjectIdentityDeleteStatement) {
         this.aclObjectIdentityDeleteStatement = aclObjectIdentityDeleteStatement;
         this.aclObjectIdentityDeleteStatement = aclObjectIdentityDeleteStatement;
     }
     }
 
 
-    public void setAclObjectIdentityInsert(
-        AclObjectIdentityInsert aclObjectIdentityInsert) {
+    public void setAclObjectIdentityInsert(AclObjectIdentityInsert aclObjectIdentityInsert) {
         this.aclObjectIdentityInsert = aclObjectIdentityInsert;
         this.aclObjectIdentityInsert = aclObjectIdentityInsert;
     }
     }
 
 
-    public void setAclObjectIdentityInsertStatement(
-        String aclObjectIdentityInsertStatement) {
+    public void setAclObjectIdentityInsertStatement(String aclObjectIdentityInsertStatement) {
         this.aclObjectIdentityInsertStatement = aclObjectIdentityInsertStatement;
         this.aclObjectIdentityInsertStatement = aclObjectIdentityInsertStatement;
     }
     }
 
 
@@ -373,8 +334,7 @@ public class JdbcExtendedDaoImpl extends JdbcDaoImpl
         this.aclPermissionDelete = aclPermissionDelete;
         this.aclPermissionDelete = aclPermissionDelete;
     }
     }
 
 
-    public void setAclPermissionDeleteStatement(
-        String aclPermissionDeleteStatement) {
+    public void setAclPermissionDeleteStatement(String aclPermissionDeleteStatement) {
         this.aclPermissionDeleteStatement = aclPermissionDeleteStatement;
         this.aclPermissionDeleteStatement = aclPermissionDeleteStatement;
     }
     }
 
 
@@ -382,8 +342,7 @@ public class JdbcExtendedDaoImpl extends JdbcDaoImpl
         this.aclPermissionInsert = aclPermissionInsert;
         this.aclPermissionInsert = aclPermissionInsert;
     }
     }
 
 
-    public void setAclPermissionInsertStatement(
-        String aclPermissionInsertStatement) {
+    public void setAclPermissionInsertStatement(String aclPermissionInsertStatement) {
         this.aclPermissionInsertStatement = aclPermissionInsertStatement;
         this.aclPermissionInsertStatement = aclPermissionInsertStatement;
     }
     }
 
 
@@ -391,8 +350,7 @@ public class JdbcExtendedDaoImpl extends JdbcDaoImpl
         this.aclPermissionUpdate = aclPermissionUpdate;
         this.aclPermissionUpdate = aclPermissionUpdate;
     }
     }
 
 
-    public void setAclPermissionUpdateStatement(
-        String aclPermissionUpdateStatement) {
+    public void setAclPermissionUpdateStatement(String aclPermissionUpdateStatement) {
         this.aclPermissionUpdateStatement = aclPermissionUpdateStatement;
         this.aclPermissionUpdateStatement = aclPermissionUpdateStatement;
     }
     }
 
 
@@ -401,8 +359,7 @@ public class JdbcExtendedDaoImpl extends JdbcDaoImpl
         this.basicAclEntryCache = basicAclEntryCache;
         this.basicAclEntryCache = basicAclEntryCache;
     }
     }
 
 
-    public void setLookupPermissionIdMapping(
-        MappingSqlQuery lookupPermissionIdMapping) {
+    public void setLookupPermissionIdMapping(MappingSqlQuery lookupPermissionIdMapping) {
         this.lookupPermissionIdMapping = lookupPermissionIdMapping;
         this.lookupPermissionIdMapping = lookupPermissionIdMapping;
     }
     }
 
 
@@ -410,7 +367,7 @@ public class JdbcExtendedDaoImpl extends JdbcDaoImpl
         this.lookupPermissionIdQuery = lookupPermissionIdQuery;
         this.lookupPermissionIdQuery = lookupPermissionIdQuery;
     }
     }
 
 
-    //~ Inner Classes ==========================================================
+    //~ Inner Classes ==================================================================================================
 
 
     protected class AclObjectIdentityDelete extends SqlUpdate {
     protected class AclObjectIdentityDelete extends SqlUpdate {
         protected AclObjectIdentityDelete(DataSource ds) {
         protected AclObjectIdentityDelete(DataSource ds) {
@@ -419,8 +376,7 @@ public class JdbcExtendedDaoImpl extends JdbcDaoImpl
             compile();
             compile();
         }
         }
 
 
-        protected void delete(Long aclObjectIdentity)
-            throws DataAccessException {
+        protected void delete(Long aclObjectIdentity) throws DataAccessException {
             super.update(aclObjectIdentity.intValue());
             super.update(aclObjectIdentity.intValue());
         }
         }
     }
     }
@@ -434,8 +390,7 @@ public class JdbcExtendedDaoImpl extends JdbcDaoImpl
             compile();
             compile();
         }
         }
 
 
-        protected void insert(String objectIdentity,
-            Long parentAclObjectIdentity, String aclClass)
+        protected void insert(String objectIdentity, Long parentAclObjectIdentity, String aclClass)
             throws DataAccessException {
             throws DataAccessException {
             Object[] objs = new Object[] {objectIdentity, parentAclObjectIdentity, aclClass};
             Object[] objs = new Object[] {objectIdentity, parentAclObjectIdentity, aclClass};
             super.update(objs);
             super.update(objs);
@@ -465,8 +420,8 @@ public class JdbcExtendedDaoImpl extends JdbcDaoImpl
             compile();
             compile();
         }
         }
 
 
-        protected void insert(Long aclObjectIdentity, String recipient,
-            Integer mask) throws DataAccessException {
+        protected void insert(Long aclObjectIdentity, String recipient, Integer mask)
+            throws DataAccessException {
             Object[] objs = new Object[] {aclObjectIdentity, recipient, mask};
             Object[] objs = new Object[] {aclObjectIdentity, recipient, mask};
             super.update(objs);
             super.update(objs);
         }
         }

+ 35 - 43
core/src/main/java/org/acegisecurity/adapters/AbstractAdapterAuthenticationToken.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
 package org.acegisecurity.adapters;
 package org.acegisecurity.adapters;
 
 
 import org.acegisecurity.GrantedAuthority;
 import org.acegisecurity.GrantedAuthority;
+
 import org.acegisecurity.providers.AbstractAuthenticationToken;
 import org.acegisecurity.providers.AbstractAuthenticationToken;
 
 
 
 
@@ -25,19 +26,18 @@ import org.acegisecurity.providers.AbstractAuthenticationToken;
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
-public abstract class AbstractAdapterAuthenticationToken
-    extends AbstractAuthenticationToken implements AuthByAdapter {
-    //~ Instance fields ========================================================
+public abstract class AbstractAdapterAuthenticationToken extends AbstractAuthenticationToken implements AuthByAdapter {
+    //~ Instance fields ================================================================================================
 
 
     private int keyHash;
     private int keyHash;
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
     protected AbstractAdapterAuthenticationToken() {
     protected AbstractAdapterAuthenticationToken() {
         super(null);
         super(null);
     }
     }
 
 
-    /**
+/**
      * The only way an <code>AbstractAdapterAuthentication</code> should be
      * The only way an <code>AbstractAdapterAuthentication</code> should be
      * constructed.
      * constructed.
      *
      *
@@ -45,21 +45,29 @@ public abstract class AbstractAdapterAuthenticationToken
      *        #getKeyHash()}
      *        #getKeyHash()}
      * @param authorities the authorities granted to this principal
      * @param authorities the authorities granted to this principal
      */
      */
-    protected AbstractAdapterAuthenticationToken(String key,
-        GrantedAuthority[] authorities) {
+    protected AbstractAdapterAuthenticationToken(String key, GrantedAuthority[] authorities) {
         super(authorities);
         super(authorities);
         this.keyHash = key.hashCode();
         this.keyHash = key.hashCode();
     }
     }
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
-    /**
-     * Setting is ignored. Always considered authenticated.
-     *
-     * @param ignored DOCUMENT ME!
-     */
-    public void setAuthenticated(boolean ignored) {
-        // ignored
+    public boolean equals(Object obj) {
+        if (obj instanceof AbstractAdapterAuthenticationToken) {
+            if (!super.equals(obj)) {
+                return false;
+            }
+
+            AbstractAdapterAuthenticationToken test = (AbstractAdapterAuthenticationToken) obj;
+
+            return (this.getKeyHash() == test.getKeyHash());
+        }
+
+        return false;
+    }
+
+    public int getKeyHash() {
+        return this.keyHash;
     }
     }
 
 
     /**
     /**
@@ -71,24 +79,13 @@ public abstract class AbstractAdapterAuthenticationToken
         return true;
         return true;
     }
     }
 
 
-    public int getKeyHash() {
-        return this.keyHash;
-    }
-
     /**
     /**
-     * Iterates the granted authorities and indicates whether or not the
-     * specified role is held.
-     * 
-     * <p>
-     * Comparison is based on the <code>String</code> returned by {@link
-     * GrantedAuthority#getAuthority}.
-     * </p>
+     * Iterates the granted authorities and indicates whether or not the specified role is held.<p>Comparison
+     * is based on the <code>String</code> returned by {@link GrantedAuthority#getAuthority}.</p>
      *
      *
-     * @param role the role being searched for in this object's granted
-     *        authorities list
+     * @param role the role being searched for in this object's granted authorities list
      *
      *
-     * @return <code>true</code> if the granted authority is held, or
-     *         <code>false</code> otherwise
+     * @return <code>true</code> if the granted authority is held, or <code>false</code> otherwise
      */
      */
     public boolean isUserInRole(String role) {
     public boolean isUserInRole(String role) {
         GrantedAuthority[] authorities = super.getAuthorities();
         GrantedAuthority[] authorities = super.getAuthorities();
@@ -102,17 +99,12 @@ public abstract class AbstractAdapterAuthenticationToken
         return false;
         return false;
     }
     }
 
 
-    public boolean equals(Object obj) {
-        if (obj instanceof AbstractAdapterAuthenticationToken) {
-            if (!super.equals(obj)) {
-                return false;
-            }
-
-            AbstractAdapterAuthenticationToken test = (AbstractAdapterAuthenticationToken) obj;
-
-            return (this.getKeyHash() == test.getKeyHash());
-        }
-
-        return false;
+    /**
+     * Setting is ignored. Always considered authenticated.
+     *
+     * @param ignored DOCUMENT ME!
+     */
+    public void setAuthenticated(boolean ignored) {
+        // ignored
     }
     }
 }
 }

+ 5 - 6
core/src/main/java/org/acegisecurity/adapters/AuthByAdapter.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -32,13 +32,12 @@ import org.acegisecurity.Authentication;
  * @version $Id$
  * @version $Id$
  */
  */
 public interface AuthByAdapter extends Authentication {
 public interface AuthByAdapter extends Authentication {
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
-     * Returns the hash code of the key that was passed to the constructor of
-     * the <code>AuthByAdapter</code> implementation. The implementation
-     * should convert the value to a hash code at construction time, rather
-     * than storing the key itself.
+     * Returns the hash code of the key that was passed to the constructor of the <code>AuthByAdapter</code>
+     * implementation. The implementation should convert the value to a hash code at construction time, rather than
+     * storing the key itself.
      *
      *
      * @return the hash code of the key used when the object was created.
      * @return the hash code of the key used when the object was created.
      */
      */

+ 11 - 22
core/src/main/java/org/acegisecurity/adapters/AuthByAdapterProvider.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -32,32 +32,22 @@ import org.springframework.util.Assert;
 
 
 
 
 /**
 /**
- * An {@link AuthenticationProvider} implementation that can authenticate an
- * {@link AuthByAdapter}.
- * 
- * <P>
- * Configured in the bean context with a key that should match the key used by
- * adapters to generate <code>AuthByAdapter</code> instances. It treats as
- * valid any such instance presenting a hash code that matches the
- * <code>AuthByAdapterProvider</code>-configured key.
- * </p>
- * 
- * <P>
- * If the key does not match, a <code>BadCredentialsException</code> is thrown.
- * </p>
+ * An {@link AuthenticationProvider} implementation that can authenticate an {@link AuthByAdapter}.<P>Configured in
+ * the bean context with a key that should match the key used by adapters to generate <code>AuthByAdapter</code>
+ * instances. It treats as valid any such instance presenting a hash code that matches the
+ * <code>AuthByAdapterProvider</code>-configured key.</p>
+ *  <P>If the key does not match, a <code>BadCredentialsException</code> is thrown.</p>
  */
  */
-public class AuthByAdapterProvider implements InitializingBean,
-    AuthenticationProvider, MessageSourceAware {
-    //~ Instance fields ========================================================
+public class AuthByAdapterProvider implements InitializingBean, AuthenticationProvider, MessageSourceAware {
+    //~ Instance fields ================================================================================================
 
 
     protected MessageSourceAccessor messages = AcegiMessageSource.getAccessor();
     protected MessageSourceAccessor messages = AcegiMessageSource.getAccessor();
     private String key;
     private String key;
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     public void afterPropertiesSet() throws Exception {
     public void afterPropertiesSet() throws Exception {
-        Assert.notNull(key,
-            "A Key is required and should match that configured for the adapters");
+        Assert.notNull(key, "A Key is required and should match that configured for the adapters");
         Assert.notNull(messages, "A message source must be set");
         Assert.notNull(messages, "A message source must be set");
     }
     }
 
 
@@ -68,8 +58,7 @@ public class AuthByAdapterProvider implements InitializingBean,
         if (token.getKeyHash() == key.hashCode()) {
         if (token.getKeyHash() == key.hashCode()) {
             return authentication;
             return authentication;
         } else {
         } else {
-            throw new BadCredentialsException(messages.getMessage(
-                    "AuthByAdapterProvider.incorrectKey",
+            throw new BadCredentialsException(messages.getMessage("AuthByAdapterProvider.incorrectKey",
                     "The presented AuthByAdapter implementation does not contain the expected key"));
                     "The presented AuthByAdapter implementation does not contain the expected key"));
         }
         }
     }
     }

+ 16 - 31
core/src/main/java/org/acegisecurity/adapters/HttpRequestIntegrationFilter.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
 package org.acegisecurity.adapters;
 package org.acegisecurity.adapters;
 
 
 import org.acegisecurity.Authentication;
 import org.acegisecurity.Authentication;
+
 import org.acegisecurity.context.SecurityContextHolder;
 import org.acegisecurity.context.SecurityContextHolder;
 
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.Log;
@@ -35,63 +36,47 @@ import javax.servlet.http.HttpServletRequest;
 
 
 
 
 /**
 /**
- * Populates <code>SecurityContext</code> with the <code>Authentication</code>
- * obtained from the container's
- * <code>HttpServletRequest.getUserPrincipal()</code>.
- * 
- * <p>
- * Use this filter with container adapters only.
- * </p>
- * 
- * <p>
- * This filter <b>never</b> preserves the <code>Authentication</code> on the
- * <code>SecurityContext</code> - it is replaced every request.
- * </p>
- * 
- * <p>
- * See {@link org.acegisecurity.context.HttpSessionContextIntegrationFilter}
- * for further information.
- * </p>
+ * Populates <code>SecurityContext</code> with the <code>Authentication</code> obtained from the container's
+ * <code>HttpServletRequest.getUserPrincipal()</code>.<p>Use this filter with container adapters only.</p>
+ *  <p>This filter <b>never</b> preserves the <code>Authentication</code> on the <code>SecurityContext</code> - it
+ * is replaced every request.</p>
+ *  <p>See {@link org.acegisecurity.context.HttpSessionContextIntegrationFilter} for further information.</p>
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
 public class HttpRequestIntegrationFilter implements Filter {
 public class HttpRequestIntegrationFilter implements Filter {
-    //~ Static fields/initializers =============================================
+    //~ Static fields/initializers =====================================================================================
 
 
     private static final Log logger = LogFactory.getLog(HttpRequestIntegrationFilter.class);
     private static final Log logger = LogFactory.getLog(HttpRequestIntegrationFilter.class);
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
      * Does nothing. We use IoC container lifecycle services instead.
      * Does nothing. We use IoC container lifecycle services instead.
      */
      */
     public void destroy() {}
     public void destroy() {}
 
 
-    public void doFilter(ServletRequest request, ServletResponse response,
-        FilterChain chain) throws IOException, ServletException {
+    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+        throws IOException, ServletException {
         if (request instanceof HttpServletRequest) {
         if (request instanceof HttpServletRequest) {
-            Principal principal = ((HttpServletRequest) request)
-                .getUserPrincipal();
+            Principal principal = ((HttpServletRequest) request).getUserPrincipal();
 
 
             if ((principal != null) && principal instanceof Authentication) {
             if ((principal != null) && principal instanceof Authentication) {
                 SecurityContextHolder.getContext().setAuthentication((Authentication) principal);
                 SecurityContextHolder.getContext().setAuthentication((Authentication) principal);
 
 
                 if (logger.isDebugEnabled()) {
                 if (logger.isDebugEnabled()) {
-                    logger.debug(
-                        "SecurityContextHolder updated with Authentication from container: '"
-                        + principal + "'");
+                    logger.debug("SecurityContextHolder updated with Authentication from container: '" + principal
+                        + "'");
                 }
                 }
             } else {
             } else {
                 if (logger.isDebugEnabled()) {
                 if (logger.isDebugEnabled()) {
-                    logger.debug(
-                        "SecurityContextHolder not set with new Authentication as Principal was: '"
+                    logger.debug("SecurityContextHolder not set with new Authentication as Principal was: '"
                         + principal + "'");
                         + principal + "'");
                 }
                 }
             }
             }
         } else {
         } else {
-            throw new IllegalArgumentException(
-                "Only HttpServletRequest is acceptable");
+            throw new IllegalArgumentException("Only HttpServletRequest is acceptable");
         }
         }
 
 
         chain.doFilter(request, response);
         chain.doFilter(request, response);

+ 8 - 10
core/src/main/java/org/acegisecurity/adapters/PrincipalAcegiUserToken.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -21,31 +21,29 @@ import java.security.Principal;
 
 
 
 
 /**
 /**
- * A {@link Principal} compatible  {@link org.acegisecurity.Authentication}
- * object.
+ * A {@link Principal} compatible  {@link org.acegisecurity.Authentication} object.
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
-public class PrincipalAcegiUserToken extends AbstractAdapterAuthenticationToken
-    implements Principal {
-    //~ Instance fields ========================================================
+public class PrincipalAcegiUserToken extends AbstractAdapterAuthenticationToken implements Principal {
+    //~ Instance fields ================================================================================================
 
 
     private Object principal;
     private Object principal;
     private String password;
     private String password;
     private String username;
     private String username;
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
-    public PrincipalAcegiUserToken(String key, String username,
-        String password, GrantedAuthority[] authorities, Object principal) {
+    public PrincipalAcegiUserToken(String key, String username, String password, GrantedAuthority[] authorities,
+        Object principal) {
         super(key, authorities);
         super(key, authorities);
         this.username = username;
         this.username = username;
         this.password = password;
         this.password = password;
         this.principal = principal;
         this.principal = principal;
     }
     }
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     public Object getCredentials() {
     public Object getCredentials() {
         return this.password;
         return this.password;

+ 14 - 22
core/src/main/java/org/acegisecurity/afterinvocation/AfterInvocationProvider.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -29,36 +29,28 @@ import org.acegisecurity.ConfigAttributeDefinition;
  * @version $Id$
  * @version $Id$
  */
  */
 public interface AfterInvocationProvider {
 public interface AfterInvocationProvider {
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
-    public Object decide(Authentication authentication, Object object,
-        ConfigAttributeDefinition config, Object returnedObject)
-        throws AccessDeniedException;
+    public Object decide(Authentication authentication, Object object, ConfigAttributeDefinition config,
+        Object returnedObject) throws AccessDeniedException;
 
 
     /**
     /**
-     * Indicates whether this <code>AfterInvocationProvider</code> is able to
-     * participate in a decision involving the passed
-     * <code>ConfigAttribute</code>.
-     * 
-     * <p>
-     * This allows the <code>AbstractSecurityInterceptor</code> to check every
-     * configuration attribute can be consumed by the configured
-     * <code>AccessDecisionManager</code> and/or <code>RunAsManager</code>
-     * and/or <code>AccessDecisionManager</code>.
-     * </p>
+     * Indicates whether this <code>AfterInvocationProvider</code> is able to participate in a decision
+     * involving the passed <code>ConfigAttribute</code>.<p>This allows the
+     * <code>AbstractSecurityInterceptor</code> to check every configuration attribute can be consumed by the
+     * configured <code>AccessDecisionManager</code> and/or <code>RunAsManager</code> and/or
+     * <code>AccessDecisionManager</code>.</p>
      *
      *
-     * @param attribute a configuration attribute that has been configured
-     *        against the <code>AbstractSecurityInterceptor</code>
+     * @param attribute a configuration attribute that has been configured against the
+     *        <code>AbstractSecurityInterceptor</code>
      *
      *
-     * @return true if this <code>AfterInvocationProvider</code> can support
-     *         the passed configuration attribute
+     * @return true if this <code>AfterInvocationProvider</code> can support the passed configuration attribute
      */
      */
     public boolean supports(ConfigAttribute attribute);
     public boolean supports(ConfigAttribute attribute);
 
 
     /**
     /**
-     * Indicates whether the <code>AfterInvocationProvider</code> is able to
-     * provide "after invocation" processing for the indicated secured object
-     * type.
+     * Indicates whether the <code>AfterInvocationProvider</code> is able to provide "after invocation"
+     * processing for the indicated secured object type.
      *
      *
      * @param clazz the class of secure object that is being queried
      * @param clazz the class of secure object that is being queried
      *
      *

+ 47 - 71
core/src/main/java/org/acegisecurity/afterinvocation/AfterInvocationProviderManager.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -31,38 +31,55 @@ import java.util.List;
 
 
 
 
 /**
 /**
- * Provider-based implementation of {@link AfterInvocationManager}.
- * 
- * <p>
- * Handles configuration of a bean context defined list of  {@link
- * AfterInvocationProvider}s.
- * </p>
- * 
- * <p>
- * Every <code>AfterInvocationProvider</code> will be polled when the {@link
- * #decide(Authentication, Object, ConfigAttributeDefinition, Object)} method
- * is called. The <code>Object</code> returned from each provider will be
- * presented to the successive provider for processing. This means each
- * provider <b>must</b> ensure they return the <code>Object</code>, even if
- * they are not interested in the "after invocation" decision (perhaps as the
- * secure object invocation did not include a configuration attribute a given
- * provider is configured to respond to).
- * </p>
+ * Provider-based implementation of {@link AfterInvocationManager}.<p>Handles configuration of a bean context
+ * defined list of  {@link AfterInvocationProvider}s.</p>
+ *  <p>Every <code>AfterInvocationProvider</code> will be polled when the {@link #decide(Authentication, Object,
+ * ConfigAttributeDefinition, Object)} method is called. The <code>Object</code> returned from each provider will be
+ * presented to the successive provider for processing. This means each provider <b>must</b> ensure they return the
+ * <code>Object</code>, even if they are not interested in the "after invocation" decision (perhaps as the secure
+ * object invocation did not include a configuration attribute a given provider is configured to respond to).</p>
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @version $Id$
  * @version $Id$
  */
  */
-public class AfterInvocationProviderManager implements AfterInvocationManager,
-    InitializingBean {
-    //~ Static fields/initializers =============================================
+public class AfterInvocationProviderManager implements AfterInvocationManager, InitializingBean {
+    //~ Static fields/initializers =====================================================================================
 
 
     protected static final Log logger = LogFactory.getLog(AfterInvocationProviderManager.class);
     protected static final Log logger = LogFactory.getLog(AfterInvocationProviderManager.class);
 
 
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private List providers;
     private List providers;
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
+
+    public void afterPropertiesSet() throws Exception {
+        checkIfValidList(this.providers);
+    }
+
+    private void checkIfValidList(List listToCheck) {
+        if ((listToCheck == null) || (listToCheck.size() == 0)) {
+            throw new IllegalArgumentException("A list of AfterInvocationProviders is required");
+        }
+    }
+
+    public Object decide(Authentication authentication, Object object, ConfigAttributeDefinition config,
+        Object returnedObject) throws AccessDeniedException {
+        Iterator iter = this.providers.iterator();
+
+        Object result = returnedObject;
+
+        while (iter.hasNext()) {
+            AfterInvocationProvider provider = (AfterInvocationProvider) iter.next();
+            result = provider.decide(authentication, object, config, result);
+        }
+
+        return result;
+    }
+
+    public List getProviders() {
+        return this.providers;
+    }
 
 
     public void setProviders(List newList) {
     public void setProviders(List newList) {
         checkIfValidList(newList);
         checkIfValidList(newList);
@@ -77,8 +94,7 @@ public class AfterInvocationProviderManager implements AfterInvocationManager,
 
 
                 AfterInvocationProvider attemptToCast = (AfterInvocationProvider) currentObject;
                 AfterInvocationProvider attemptToCast = (AfterInvocationProvider) currentObject;
             } catch (ClassCastException cce) {
             } catch (ClassCastException cce) {
-                throw new IllegalArgumentException("AfterInvocationProvider "
-                    + currentObject.getClass().getName()
+                throw new IllegalArgumentException("AfterInvocationProvider " + currentObject.getClass().getName()
                     + " must implement AfterInvocationProvider");
                     + " must implement AfterInvocationProvider");
             }
             }
         }
         }
@@ -86,36 +102,11 @@ public class AfterInvocationProviderManager implements AfterInvocationManager,
         this.providers = newList;
         this.providers = newList;
     }
     }
 
 
-    public List getProviders() {
-        return this.providers;
-    }
-
-    public void afterPropertiesSet() throws Exception {
-        checkIfValidList(this.providers);
-    }
-
-    public Object decide(Authentication authentication, Object object,
-        ConfigAttributeDefinition config, Object returnedObject)
-        throws AccessDeniedException {
-        Iterator iter = this.providers.iterator();
-
-        Object result = returnedObject;
-
-        while (iter.hasNext()) {
-            AfterInvocationProvider provider = (AfterInvocationProvider) iter
-                .next();
-            result = provider.decide(authentication, object, config, result);
-        }
-
-        return result;
-    }
-
     public boolean supports(ConfigAttribute attribute) {
     public boolean supports(ConfigAttribute attribute) {
         Iterator iter = this.providers.iterator();
         Iterator iter = this.providers.iterator();
 
 
         while (iter.hasNext()) {
         while (iter.hasNext()) {
-            AfterInvocationProvider provider = (AfterInvocationProvider) iter
-                .next();
+            AfterInvocationProvider provider = (AfterInvocationProvider) iter.next();
 
 
             if (logger.isDebugEnabled()) {
             if (logger.isDebugEnabled()) {
                 logger.debug("Evaluating " + attribute + " against " + provider);
                 logger.debug("Evaluating " + attribute + " against " + provider);
@@ -130,27 +121,19 @@ public class AfterInvocationProviderManager implements AfterInvocationManager,
     }
     }
 
 
     /**
     /**
-     * Iterates through all <code>AfterInvocationProvider</code>s and ensures
-     * each can support the presented class.
-     * 
-     * <p>
-     * If one or more providers cannot support the presented class,
-     * <code>false</code> is returned.
-     * </p>
+     * Iterates through all <code>AfterInvocationProvider</code>s and ensures each can support the presented
+     * class.<p>If one or more providers cannot support the presented class, <code>false</code> is returned.</p>
      *
      *
      * @param clazz the secure object class being queries
      * @param clazz the secure object class being queries
      *
      *
-     * @return if the <code>AfterInvocationProviderManager</code> can support
-     *         the secure object class, which requires every one of its
-     *         <code>AfterInvocationProvider</code>s to support the secure
-     *         object class
+     * @return if the <code>AfterInvocationProviderManager</code> can support the secure object class, which requires
+     *         every one of its <code>AfterInvocationProvider</code>s to support the secure object class
      */
      */
     public boolean supports(Class clazz) {
     public boolean supports(Class clazz) {
         Iterator iter = this.providers.iterator();
         Iterator iter = this.providers.iterator();
 
 
         while (iter.hasNext()) {
         while (iter.hasNext()) {
-            AfterInvocationProvider provider = (AfterInvocationProvider) iter
-                .next();
+            AfterInvocationProvider provider = (AfterInvocationProvider) iter.next();
 
 
             if (!provider.supports(clazz)) {
             if (!provider.supports(clazz)) {
                 return false;
                 return false;
@@ -159,11 +142,4 @@ public class AfterInvocationProviderManager implements AfterInvocationManager,
 
 
         return true;
         return true;
     }
     }
-
-    private void checkIfValidList(List listToCheck) {
-        if ((listToCheck == null) || (listToCheck.size() == 0)) {
-            throw new IllegalArgumentException(
-                "A list of AfterInvocationProviders is required");
-        }
-    }
 }
 }

+ 93 - 133
core/src/main/java/org/acegisecurity/afterinvocation/BasicAclEntryAfterInvocationCollectionFilteringProvider.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ import org.acegisecurity.Authentication;
 import org.acegisecurity.AuthorizationServiceException;
 import org.acegisecurity.AuthorizationServiceException;
 import org.acegisecurity.ConfigAttribute;
 import org.acegisecurity.ConfigAttribute;
 import org.acegisecurity.ConfigAttributeDefinition;
 import org.acegisecurity.ConfigAttributeDefinition;
+
 import org.acegisecurity.acl.AclEntry;
 import org.acegisecurity.acl.AclEntry;
 import org.acegisecurity.acl.AclManager;
 import org.acegisecurity.acl.AclManager;
 import org.acegisecurity.acl.basic.BasicAclEntry;
 import org.acegisecurity.acl.basic.BasicAclEntry;
@@ -42,125 +43,61 @@ import java.util.Set;
 
 
 
 
 /**
 /**
- * <p>
- * Given a <code>Collection</code> of domain object instances returned from a
- * secure object invocation, remove any <code>Collection</code> elements the
- * principal does not have appropriate permission to access as defined by the
- * {@link AclManager}.
- * </p>
- * 
- * <p>
- * The <code>AclManager</code> is used to retrieve the access control list
- * (ACL) permissions associated with each <code>Collection</code>  domain
- * object instance element for the current <code>Authentication</code> object.
- * This class is designed to process {@link AclEntry}s that are subclasses of
- * {@link org.acegisecurity.acl.basic.BasicAclEntry} only.
- * Generally these are obtained by using the {@link
- * org.acegisecurity.acl.basic.BasicAclProvider}.
- * </p>
- * 
- * <p>
- * This after invocation provider will fire if any {@link
- * ConfigAttribute#getAttribute()} matches the {@link
- * #processConfigAttribute}. The provider will then lookup the ACLs from the
- * <code>AclManager</code> and ensure the principal is {@link
- * org.acegisecurity.acl.basic.BasicAclEntry#isPermitted(int)} for
- * at least one of the {@link #requirePermission}s for each
- * <code>Collection</code> element. If the principal does not have at least
- * one of the permissions, that element will not be included in the returned
- * <code>Collection</code>.
- * </p>
- * 
- * <p>
- * Often users will setup a <code>BasicAclEntryAfterInvocationProvider</code>
- * with a {@link #processConfigAttribute} of
- * <code>AFTER_ACL_COLLECTION_READ</code> and a {@link #requirePermission} of
- * <code>SimpleAclEntry.READ</code>. These are also the defaults.
- * </p>
- * 
- * <p>
- * The <code>AclManager</code> is allowed to return any implementations of
- * <code>AclEntry</code> it wishes. However, this provider will only be able
- * to validate against <code>BasicAclEntry</code>s, and thus a
- * <code>Collection</code> element will be filtered from the resulting
- * <code>Collection</code> if no <code>AclEntry</code> is of type
- * <code>BasicAclEntry</code>.
- * </p>
- * 
- * <p>
- * If the provided <code>returnObject</code> is <code>null</code>, a
- * <code>null</code><code>Collection</code> will be returned. If the provided
- * <code>returnObject</code> is not a <code>Collection</code>, an {@link
- * AuthorizationServiceException} will be thrown.
- * </p>
- * 
- * <p>
- * All comparisons and prefixes are case sensitive.
- * </p>
+ * <p>Given a <code>Collection</code> of domain object instances returned from a secure object invocation, remove
+ * any <code>Collection</code> elements the principal does not have appropriate permission to access as defined by the
+ * {@link AclManager}.</p>
+ *  <p>The <code>AclManager</code> is used to retrieve the access control list (ACL) permissions associated with
+ * each <code>Collection</code>  domain object instance element for the current <code>Authentication</code> object.
+ * This class is designed to process {@link AclEntry}s that are subclasses of {@link
+ * org.acegisecurity.acl.basic.BasicAclEntry} only. Generally these are obtained by using the {@link
+ * org.acegisecurity.acl.basic.BasicAclProvider}.</p>
+ *  <p>This after invocation provider will fire if any {@link ConfigAttribute#getAttribute()} matches the {@link
+ * #processConfigAttribute}. The provider will then lookup the ACLs from the <code>AclManager</code> and ensure the
+ * principal is {@link org.acegisecurity.acl.basic.BasicAclEntry#isPermitted(int)} for at least one of the {@link
+ * #requirePermission}s for each <code>Collection</code> element. If the principal does not have at least one of the
+ * permissions, that element will not be included in the returned <code>Collection</code>.</p>
+ *  <p>Often users will setup a <code>BasicAclEntryAfterInvocationProvider</code> with a {@link
+ * #processConfigAttribute} of <code>AFTER_ACL_COLLECTION_READ</code> and a {@link #requirePermission} of
+ * <code>SimpleAclEntry.READ</code>. These are also the defaults.</p>
+ *  <p>The <code>AclManager</code> is allowed to return any implementations of <code>AclEntry</code> it wishes.
+ * However, this provider will only be able to validate against <code>BasicAclEntry</code>s, and thus a
+ * <code>Collection</code> element will be filtered from the resulting <code>Collection</code> if no
+ * <code>AclEntry</code> is of type <code>BasicAclEntry</code>.</p>
+ *  <p>If the provided <code>returnObject</code> is <code>null</code>, a <code>null</code><code>Collection</code>
+ * will be returned. If the provided <code>returnObject</code> is not a <code>Collection</code>, an {@link
+ * AuthorizationServiceException} will be thrown.</p>
+ *  <p>All comparisons and prefixes are case sensitive.</p>
  *
  *
  * @author Ben Alex
  * @author Ben Alex
  * @author Paulo Neves
  * @author Paulo Neves
  * @version $Id$
  * @version $Id$
  */
  */
-public class BasicAclEntryAfterInvocationCollectionFilteringProvider
-    implements AfterInvocationProvider, InitializingBean {
-    //~ Static fields/initializers =============================================
+public class BasicAclEntryAfterInvocationCollectionFilteringProvider implements AfterInvocationProvider,
+    InitializingBean {
+    //~ Static fields/initializers =====================================================================================
 
 
     protected static final Log logger = LogFactory.getLog(BasicAclEntryAfterInvocationCollectionFilteringProvider.class);
     protected static final Log logger = LogFactory.getLog(BasicAclEntryAfterInvocationCollectionFilteringProvider.class);
 
 
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private AclManager aclManager;
     private AclManager aclManager;
+    private Class processDomainObjectClass = Object.class;
     private String processConfigAttribute = "AFTER_ACL_COLLECTION_READ";
     private String processConfigAttribute = "AFTER_ACL_COLLECTION_READ";
     private int[] requirePermission = {SimpleAclEntry.READ};
     private int[] requirePermission = {SimpleAclEntry.READ};
-    private Class processDomainObjectClass = Object.class;
-
-    //~ Methods ================================================================
-
-    public void setProcessDomainObjectClass(Class processDomainObjectClass) {
-        Assert.notNull(processDomainObjectClass,
-        "processDomainObjectClass cannot be set to null");
-        this.processDomainObjectClass = processDomainObjectClass;
-	}
-
-    public void setAclManager(AclManager aclManager) {
-        this.aclManager = aclManager;
-    }
-
-    public AclManager getAclManager() {
-        return aclManager;
-    }
 
 
-    public void setProcessConfigAttribute(String processConfigAttribute) {
-        this.processConfigAttribute = processConfigAttribute;
-    }
-
-    public String getProcessConfigAttribute() {
-        return processConfigAttribute;
-    }
-
-    public void setRequirePermission(int[] requirePermission) {
-        this.requirePermission = requirePermission;
-    }
-
-    public int[] getRequirePermission() {
-        return requirePermission;
-    }
+    //~ Methods ========================================================================================================
 
 
     public void afterPropertiesSet() throws Exception {
     public void afterPropertiesSet() throws Exception {
-        Assert.notNull(processConfigAttribute,
-            "A processConfigAttribute is mandatory");
+        Assert.notNull(processConfigAttribute, "A processConfigAttribute is mandatory");
         Assert.notNull(aclManager, "An aclManager is mandatory");
         Assert.notNull(aclManager, "An aclManager is mandatory");
 
 
         if ((requirePermission == null) || (requirePermission.length == 0)) {
         if ((requirePermission == null) || (requirePermission.length == 0)) {
-            throw new IllegalArgumentException(
-                "One or more requirePermission entries is mandatory");
+            throw new IllegalArgumentException("One or more requirePermission entries is mandatory");
         }
         }
     }
     }
 
 
-    public Object decide(Authentication authentication, Object object,
-        ConfigAttributeDefinition config, Object returnedObject)
-        throws AccessDeniedException {
+    public Object decide(Authentication authentication, Object object, ConfigAttributeDefinition config,
+        Object returnedObject) throws AccessDeniedException {
         Iterator iter = config.getConfigAttributes();
         Iterator iter = config.getConfigAttributes();
 
 
         while (iter.hasNext()) {
         while (iter.hasNext()) {
@@ -203,7 +140,7 @@ public class BasicAclEntryAfterInvocationCollectionFilteringProvider
                     if (domainObject == null) {
                     if (domainObject == null) {
                         hasPermission = true;
                         hasPermission = true;
                     } else if (!processDomainObjectClass.isAssignableFrom(domainObject.getClass())) {
                     } else if (!processDomainObjectClass.isAssignableFrom(domainObject.getClass())) {
-                    	hasPermission = true;
+                        hasPermission = true;
                     } else {
                     } else {
                         acls = aclManager.getAcls(domainObject, authentication);
                         acls = aclManager.getAcls(domainObject, authentication);
                     }
                     }
@@ -212,21 +149,16 @@ public class BasicAclEntryAfterInvocationCollectionFilteringProvider
                         for (int i = 0; i < acls.length; i++) {
                         for (int i = 0; i < acls.length; i++) {
                             // Locate processable AclEntrys
                             // Locate processable AclEntrys
                             if (acls[i] instanceof BasicAclEntry) {
                             if (acls[i] instanceof BasicAclEntry) {
-                            	BasicAclEntry processableAcl = (BasicAclEntry) acls[i];
+                                BasicAclEntry processableAcl = (BasicAclEntry) acls[i];
 
 
                                 // See if principal has any of the required permissions
                                 // See if principal has any of the required permissions
-                                for (int y = 0; y < requirePermission.length;
-                                    y++) {
-                                    if (processableAcl.isPermitted(
-                                            requirePermission[y])) {
+                                for (int y = 0; y < requirePermission.length; y++) {
+                                    if (processableAcl.isPermitted(requirePermission[y])) {
                                         hasPermission = true;
                                         hasPermission = true;
 
 
                                         if (logger.isDebugEnabled()) {
                                         if (logger.isDebugEnabled()) {
-                                            logger.debug(
-                                                "Principal is authorised for element: "
-                                                + domainObject
-                                                + " due to ACL: "
-                                                + processableAcl.toString());
+                                            logger.debug("Principal is authorised for element: " + domainObject
+                                                + " due to ACL: " + processableAcl.toString());
                                         }
                                         }
                                     }
                                     }
                                 }
                                 }
@@ -238,9 +170,7 @@ public class BasicAclEntryAfterInvocationCollectionFilteringProvider
                         filterer.remove(domainObject);
                         filterer.remove(domainObject);
 
 
                         if (logger.isDebugEnabled()) {
                         if (logger.isDebugEnabled()) {
-                            logger.debug(
-                                "Principal is NOT authorised for element: "
-                                + domainObject);
+                            logger.debug("Principal is NOT authorised for element: " + domainObject);
                         }
                         }
                     }
                     }
                 }
                 }
@@ -252,9 +182,37 @@ public class BasicAclEntryAfterInvocationCollectionFilteringProvider
         return returnedObject;
         return returnedObject;
     }
     }
 
 
+    public AclManager getAclManager() {
+        return aclManager;
+    }
+
+    public String getProcessConfigAttribute() {
+        return processConfigAttribute;
+    }
+
+    public int[] getRequirePermission() {
+        return requirePermission;
+    }
+
+    public void setAclManager(AclManager aclManager) {
+        this.aclManager = aclManager;
+    }
+
+    public void setProcessConfigAttribute(String processConfigAttribute) {
+        this.processConfigAttribute = processConfigAttribute;
+    }
+
+    public void setProcessDomainObjectClass(Class processDomainObjectClass) {
+        Assert.notNull(processDomainObjectClass, "processDomainObjectClass cannot be set to null");
+        this.processDomainObjectClass = processDomainObjectClass;
+    }
+
+    public void setRequirePermission(int[] requirePermission) {
+        this.requirePermission = requirePermission;
+    }
+
     public boolean supports(ConfigAttribute attribute) {
     public boolean supports(ConfigAttribute attribute) {
-        if ((attribute.getAttribute() != null)
-            && attribute.getAttribute().equals(getProcessConfigAttribute())) {
+        if ((attribute.getAttribute() != null) && attribute.getAttribute().equals(getProcessConfigAttribute())) {
             return true;
             return true;
         } else {
         } else {
             return false;
             return false;
@@ -262,8 +220,7 @@ public class BasicAclEntryAfterInvocationCollectionFilteringProvider
     }
     }
 
 
     /**
     /**
-     * This implementation supports any type of class, because it does not
-     * query the presented secure object.
+     * This implementation supports any type of class, because it does not query the presented secure object.
      *
      *
      * @param clazz the secure object
      * @param clazz the secure object
      *
      *
@@ -279,7 +236,7 @@ public class BasicAclEntryAfterInvocationCollectionFilteringProvider
  * Filter strategy interface.
  * Filter strategy interface.
  */
  */
 interface Filterer {
 interface Filterer {
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
      * Gets the filtered collection or array.
      * Gets the filtered collection or array.
@@ -308,11 +265,11 @@ interface Filterer {
  * A filter used to filter Collections.
  * A filter used to filter Collections.
  */
  */
 class CollectionFilterer implements Filterer {
 class CollectionFilterer implements Filterer {
-    //~ Static fields/initializers =============================================
+    //~ Static fields/initializers =====================================================================================
 
 
     protected static final Log logger = LogFactory.getLog(BasicAclEntryAfterInvocationCollectionFilteringProvider.class);
     protected static final Log logger = LogFactory.getLog(BasicAclEntryAfterInvocationCollectionFilteringProvider.class);
 
 
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private Collection collection;
     private Collection collection;
 
 
@@ -321,7 +278,7 @@ class CollectionFilterer implements Filterer {
     private Iterator collectionIter;
     private Iterator collectionIter;
     private Set removeList;
     private Set removeList;
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
     CollectionFilterer(Collection collection) {
     CollectionFilterer(Collection collection) {
         this.collection = collection;
         this.collection = collection;
@@ -336,9 +293,10 @@ class CollectionFilterer implements Filterer {
         removeList = new HashSet();
         removeList = new HashSet();
     }
     }
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
+     * 
      * @see org.acegisecurity.afterinvocation.Filterer#getFilteredObject()
      * @see org.acegisecurity.afterinvocation.Filterer#getFilteredObject()
      */
      */
     public Object getFilteredObject() {
     public Object getFilteredObject() {
@@ -352,14 +310,15 @@ class CollectionFilterer implements Filterer {
         }
         }
 
 
         if (logger.isDebugEnabled()) {
         if (logger.isDebugEnabled()) {
-            logger.debug("Original collection contained " + originalSize
-                + " elements; now contains " + collection.size() + " elements");
+            logger.debug("Original collection contained " + originalSize + " elements; now contains "
+                + collection.size() + " elements");
         }
         }
 
 
         return collection;
         return collection;
     }
     }
 
 
     /**
     /**
+     * 
      * @see org.acegisecurity.afterinvocation.Filterer#iterator()
      * @see org.acegisecurity.afterinvocation.Filterer#iterator()
      */
      */
     public Iterator iterator() {
     public Iterator iterator() {
@@ -369,6 +328,7 @@ class CollectionFilterer implements Filterer {
     }
     }
 
 
     /**
     /**
+     * 
      * @see org.acegisecurity.afterinvocation.Filterer#remove(java.lang.Object)
      * @see org.acegisecurity.afterinvocation.Filterer#remove(java.lang.Object)
      */
      */
     public void remove(Object object) {
     public void remove(Object object) {
@@ -381,16 +341,16 @@ class CollectionFilterer implements Filterer {
  * A filter used to filter arrays.
  * A filter used to filter arrays.
  */
  */
 class ArrayFilterer implements Filterer {
 class ArrayFilterer implements Filterer {
-    //~ Static fields/initializers =============================================
+    //~ Static fields/initializers =====================================================================================
 
 
     protected static final Log logger = LogFactory.getLog(BasicAclEntryAfterInvocationCollectionFilteringProvider.class);
     protected static final Log logger = LogFactory.getLog(BasicAclEntryAfterInvocationCollectionFilteringProvider.class);
 
 
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private Set removeList;
     private Set removeList;
     private Object[] list;
     private Object[] list;
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
     ArrayFilterer(Object[] list) {
     ArrayFilterer(Object[] list) {
         this.list = list;
         this.list = list;
@@ -401,18 +361,17 @@ class ArrayFilterer implements Filterer {
         removeList = new HashSet();
         removeList = new HashSet();
     }
     }
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
+     * 
      * @see org.acegisecurity.afterinvocation.Filterer#getFilteredObject()
      * @see org.acegisecurity.afterinvocation.Filterer#getFilteredObject()
      */
      */
     public Object getFilteredObject() {
     public Object getFilteredObject() {
         // Recreate an array of same type and filter the removed objects.
         // Recreate an array of same type and filter the removed objects.
         int originalSize = list.length;
         int originalSize = list.length;
         int sizeOfResultingList = originalSize - removeList.size();
         int sizeOfResultingList = originalSize - removeList.size();
-        Object[] filtered = (Object[]) Array.newInstance(list.getClass()
-                                                             .getComponentType(),
-                sizeOfResultingList);
+        Object[] filtered = (Object[]) Array.newInstance(list.getClass().getComponentType(), sizeOfResultingList);
 
 
         for (int i = 0, j = 0; i < list.length; i++) {
         for (int i = 0, j = 0; i < list.length; i++) {
             Object object = list[i];
             Object object = list[i];
@@ -424,8 +383,7 @@ class ArrayFilterer implements Filterer {
         }
         }
 
 
         if (logger.isDebugEnabled()) {
         if (logger.isDebugEnabled()) {
-            logger.debug("Original array contained " + originalSize
-                + " elements; now contains " + sizeOfResultingList
+            logger.debug("Original array contained " + originalSize + " elements; now contains " + sizeOfResultingList
                 + " elements");
                 + " elements");
         }
         }
 
 
@@ -433,6 +391,7 @@ class ArrayFilterer implements Filterer {
     }
     }
 
 
     /**
     /**
+     * 
      * @see org.acegisecurity.afterinvocation.Filterer#iterator()
      * @see org.acegisecurity.afterinvocation.Filterer#iterator()
      */
      */
     public Iterator iterator() {
     public Iterator iterator() {
@@ -440,6 +399,7 @@ class ArrayFilterer implements Filterer {
     }
     }
 
 
     /**
     /**
+     * 
      * @see org.acegisecurity.afterinvocation.Filterer#remove(java.lang.Object)
      * @see org.acegisecurity.afterinvocation.Filterer#remove(java.lang.Object)
      */
      */
     public void remove(Object object) {
     public void remove(Object object) {

+ 50 - 85
core/src/main/java/org/acegisecurity/afterinvocation/BasicAclEntryAfterInvocationProvider.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -15,116 +15,81 @@
 
 
 package org.acegisecurity.afterinvocation;
 package org.acegisecurity.afterinvocation;
 
 
-import java.util.Iterator;
-
 import org.acegisecurity.AccessDeniedException;
 import org.acegisecurity.AccessDeniedException;
 import org.acegisecurity.AcegiMessageSource;
 import org.acegisecurity.AcegiMessageSource;
 import org.acegisecurity.Authentication;
 import org.acegisecurity.Authentication;
 import org.acegisecurity.ConfigAttribute;
 import org.acegisecurity.ConfigAttribute;
 import org.acegisecurity.ConfigAttributeDefinition;
 import org.acegisecurity.ConfigAttributeDefinition;
+
 import org.acegisecurity.acl.AclEntry;
 import org.acegisecurity.acl.AclEntry;
 import org.acegisecurity.acl.AclManager;
 import org.acegisecurity.acl.AclManager;
 import org.acegisecurity.acl.basic.BasicAclEntry;
 import org.acegisecurity.acl.basic.BasicAclEntry;
 import org.acegisecurity.acl.basic.SimpleAclEntry;
 import org.acegisecurity.acl.basic.SimpleAclEntry;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.logging.LogFactory;
+
 import org.springframework.beans.factory.InitializingBean;
 import org.springframework.beans.factory.InitializingBean;
+
 import org.springframework.context.MessageSource;
 import org.springframework.context.MessageSource;
 import org.springframework.context.MessageSourceAware;
 import org.springframework.context.MessageSourceAware;
 import org.springframework.context.support.MessageSourceAccessor;
 import org.springframework.context.support.MessageSourceAccessor;
+
 import org.springframework.util.Assert;
 import org.springframework.util.Assert;
 
 
+import java.util.Iterator;
+
 
 
 /**
 /**
- * <p>
- * Given a domain object instance returned from a secure object invocation,
- * ensures the principal has appropriate permission as defined by the {@link
- * AclManager}.
- * </p>
- * 
- * <p>
- * The <code>AclManager</code> is used to retrieve the access control list
- * (ACL) permissions associated with a domain object instance for the current
- * <code>Authentication</code> object. This class is designed to process
- * {@link AclEntry}s that are subclasses of {@link
- * org.acegisecurity.acl.basic.BasicAclEntry} only. Generally these are
- * obtained by using the {@link org.acegisecurity.acl.basic.BasicAclProvider}.
- * </p>
- * 
- * <p>
- * This after invocation provider will fire if any  {@link
- * ConfigAttribute#getAttribute()} matches the {@link
- * #processConfigAttribute}. The provider will then lookup the ACLs from the
- * <code>AclManager</code> and ensure the principal is {@link
- * org.acegisecurity.acl.basic.BasicAclEntry#isPermitted(int)} for at least
- * one of the {@link #requirePermission}s.
- * </p>
- * 
- * <p>
- * Often users will setup a <code>BasicAclEntryAfterInvocationProvider</code>
- * with a {@link #processConfigAttribute} of <code>AFTER_ACL_READ</code> and a
- * {@link #requirePermission} of  <code>SimpleAclEntry.READ</code>. These are
- * also the defaults.
- * </p>
- * 
- * <p>
- * If the principal does not have sufficient permissions, an
- * <code>AccessDeniedException</code> will be thrown.
- * </p>
- * 
- * <p>
- * The <code>AclManager</code> is allowed to return any implementations of
- * <code>AclEntry</code> it wishes. However, this provider will only be able
- * to validate against <code>BasicAclEntry</code>s, and thus access will be
- * denied if no <code>AclEntry</code> is of type <code>BasicAclEntry</code>.
- * </p>
- * 
- * <p>
- * If the provided <code>returnObject</code> is <code>null</code>, permission
- * will always be granted and <code>null</code> will be returned.
- * </p>
- * 
- * <p>
- * All comparisons and prefixes are case sensitive.
- * </p>
+ * <p>Given a domain object instance returned from a secure object invocation, ensures the principal has
+ * appropriate permission as defined by the {@link AclManager}.</p>
+ *  <p>The <code>AclManager</code> is used to retrieve the access control list (ACL) permissions associated with a
+ * domain object instance for the current <code>Authentication</code> object. This class is designed to process {@link
+ * AclEntry}s that are subclasses of {@link org.acegisecurity.acl.basic.BasicAclEntry} only. Generally these are
+ * obtained by using the {@link org.acegisecurity.acl.basic.BasicAclProvider}.</p>
+ *  <p>This after invocation provider will fire if any  {@link ConfigAttribute#getAttribute()} matches the {@link
+ * #processConfigAttribute}. The provider will then lookup the ACLs from the <code>AclManager</code> and ensure the
+ * principal is {@link org.acegisecurity.acl.basic.BasicAclEntry#isPermitted(int)} for at least one of the {@link
+ * #requirePermission}s.</p>
+ *  <p>Often users will setup a <code>BasicAclEntryAfterInvocationProvider</code> with a {@link
+ * #processConfigAttribute} of <code>AFTER_ACL_READ</code> and a {@link #requirePermission} of
+ * <code>SimpleAclEntry.READ</code>. These are also the defaults.</p>
+ *  <p>If the principal does not have sufficient permissions, an <code>AccessDeniedException</code> will be thrown.</p>
+ *  <p>The <code>AclManager</code> is allowed to return any implementations of <code>AclEntry</code> it wishes.
+ * However, this provider will only be able to validate against <code>BasicAclEntry</code>s, and thus access will be
+ * denied if no <code>AclEntry</code> is of type <code>BasicAclEntry</code>.</p>
+ *  <p>If the provided <code>returnObject</code> is <code>null</code>, permission will always be granted and
+ * <code>null</code> will be returned.</p>
+ *  <p>All comparisons and prefixes are case sensitive.</p>
  */
  */
-public class BasicAclEntryAfterInvocationProvider
-    implements AfterInvocationProvider, InitializingBean, MessageSourceAware {
-    //~ Static fields/initializers =============================================
+public class BasicAclEntryAfterInvocationProvider implements AfterInvocationProvider, InitializingBean,
+    MessageSourceAware {
+    //~ Static fields/initializers =====================================================================================
 
 
     protected static final Log logger = LogFactory.getLog(BasicAclEntryAfterInvocationProvider.class);
     protected static final Log logger = LogFactory.getLog(BasicAclEntryAfterInvocationProvider.class);
 
 
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     private AclManager aclManager;
     private AclManager aclManager;
+    private Class processDomainObjectClass = Object.class;
     protected MessageSourceAccessor messages = AcegiMessageSource.getAccessor();
     protected MessageSourceAccessor messages = AcegiMessageSource.getAccessor();
     private String processConfigAttribute = "AFTER_ACL_READ";
     private String processConfigAttribute = "AFTER_ACL_READ";
     private int[] requirePermission = {SimpleAclEntry.READ};
     private int[] requirePermission = {SimpleAclEntry.READ};
-    private Class processDomainObjectClass = Object.class;
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
-    public void setProcessDomainObjectClass(Class processDomainObjectClass) {
-        Assert.notNull(processDomainObjectClass,
-        "processDomainObjectClass cannot be set to null");
-        this.processDomainObjectClass = processDomainObjectClass;
-	}
-
-	public void afterPropertiesSet() throws Exception {
-        Assert.notNull(processConfigAttribute,
-            "A processConfigAttribute is mandatory");
+    public void afterPropertiesSet() throws Exception {
+        Assert.notNull(processConfigAttribute, "A processConfigAttribute is mandatory");
         Assert.notNull(aclManager, "An aclManager is mandatory");
         Assert.notNull(aclManager, "An aclManager is mandatory");
         Assert.notNull(messages, "A message source must be set");
         Assert.notNull(messages, "A message source must be set");
 
 
         if ((requirePermission == null) || (requirePermission.length == 0)) {
         if ((requirePermission == null) || (requirePermission.length == 0)) {
-            throw new IllegalArgumentException(
-                "One or more requirePermission entries is mandatory");
+            throw new IllegalArgumentException("One or more requirePermission entries is mandatory");
         }
         }
     }
     }
 
 
-    public Object decide(Authentication authentication, Object object,
-        ConfigAttributeDefinition config, Object returnedObject)
-        throws AccessDeniedException {
+    public Object decide(Authentication authentication, Object object, ConfigAttributeDefinition config,
+        Object returnedObject) throws AccessDeniedException {
         Iterator iter = config.getConfigAttributes();
         Iterator iter = config.getConfigAttributes();
 
 
         while (iter.hasNext()) {
         while (iter.hasNext()) {
@@ -141,7 +106,7 @@ public class BasicAclEntryAfterInvocationProvider
 
 
                     return null;
                     return null;
                 }
                 }
-                
+
                 if (!processDomainObjectClass.isAssignableFrom(returnedObject.getClass())) {
                 if (!processDomainObjectClass.isAssignableFrom(returnedObject.getClass())) {
                     if (logger.isDebugEnabled()) {
                     if (logger.isDebugEnabled()) {
                         logger.debug("Return object is not applicable for this provider, skipping");
                         logger.debug("Return object is not applicable for this provider, skipping");
@@ -150,8 +115,7 @@ public class BasicAclEntryAfterInvocationProvider
                     return null;
                     return null;
                 }
                 }
 
 
-                AclEntry[] acls = aclManager.getAcls(returnedObject,
-                        authentication);
+                AclEntry[] acls = aclManager.getAcls(returnedObject, authentication);
 
 
                 if ((acls == null) || (acls.length == 0)) {
                 if ((acls == null) || (acls.length == 0)) {
                     throw new AccessDeniedException(messages.getMessage(
                     throw new AccessDeniedException(messages.getMessage(
@@ -169,10 +133,8 @@ public class BasicAclEntryAfterInvocationProvider
                         for (int y = 0; y < requirePermission.length; y++) {
                         for (int y = 0; y < requirePermission.length; y++) {
                             if (processableAcl.isPermitted(requirePermission[y])) {
                             if (processableAcl.isPermitted(requirePermission[y])) {
                                 if (logger.isDebugEnabled()) {
                                 if (logger.isDebugEnabled()) {
-                                    logger.debug(
-                                        "Principal DOES have permission to return object: "
-                                        + returnedObject + " due to ACL: "
-                                        + processableAcl.toString());
+                                    logger.debug("Principal DOES have permission to return object: " + returnedObject
+                                        + " due to ACL: " + processableAcl.toString());
                                 }
                                 }
 
 
                                 return returnedObject;
                                 return returnedObject;
@@ -216,13 +178,17 @@ public class BasicAclEntryAfterInvocationProvider
         this.processConfigAttribute = processConfigAttribute;
         this.processConfigAttribute = processConfigAttribute;
     }
     }
 
 
+    public void setProcessDomainObjectClass(Class processDomainObjectClass) {
+        Assert.notNull(processDomainObjectClass, "processDomainObjectClass cannot be set to null");
+        this.processDomainObjectClass = processDomainObjectClass;
+    }
+
     public void setRequirePermission(int[] requirePermission) {
     public void setRequirePermission(int[] requirePermission) {
         this.requirePermission = requirePermission;
         this.requirePermission = requirePermission;
     }
     }
 
 
     public boolean supports(ConfigAttribute attribute) {
     public boolean supports(ConfigAttribute attribute) {
-        if ((attribute.getAttribute() != null)
-            && attribute.getAttribute().equals(getProcessConfigAttribute())) {
+        if ((attribute.getAttribute() != null) && attribute.getAttribute().equals(getProcessConfigAttribute())) {
             return true;
             return true;
         } else {
         } else {
             return false;
             return false;
@@ -230,8 +196,7 @@ public class BasicAclEntryAfterInvocationProvider
     }
     }
 
 
     /**
     /**
-     * This implementation supports any type of class, because it does not
-     * query the presented secure object.
+     * This implementation supports any type of class, because it does not query the presented secure object.
      *
      *
      * @param clazz the secure object
      * @param clazz the secure object
      *
      *

+ 8 - 12
core/src/main/java/org/acegisecurity/captcha/AlwaysTestAfterMaxRequestsCaptchaChannelProcessor.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -19,25 +19,21 @@
 package org.acegisecurity.captcha;
 package org.acegisecurity.captcha;
 
 
 /**
 /**
- * <p>
- * return false if ny CaptchaChannelProcessorTemplate of mapped urls has been
- * requested more than thresold; <br>
- * Default keyword : REQUIRES_CAPTCHA_ABOVE_THRESOLD_REQUESTS
- * </p>
+ * <p>return false if ny CaptchaChannelProcessorTemplate of mapped urls has been requested more than thresold; <br>
+ * Default keyword : REQUIRES_CAPTCHA_ABOVE_THRESOLD_REQUESTS</p>
  *
  *
  * @author Marc-Antoine Garrigue
  * @author Marc-Antoine Garrigue
  * @version $Id$
  * @version $Id$
  */
  */
-public class AlwaysTestAfterMaxRequestsCaptchaChannelProcessor
-    extends CaptchaChannelProcessorTemplate {
-    //~ Static fields/initializers =============================================
+public class AlwaysTestAfterMaxRequestsCaptchaChannelProcessor extends CaptchaChannelProcessorTemplate {
+    //~ Static fields/initializers =====================================================================================
 
 
     /** Keyword for this channelProcessor */
     /** Keyword for this channelProcessor */
     public static final String DEFAULT_KEYWORD = "REQUIRES_CAPTCHA_ABOVE_THRESOLD_REQUESTS";
     public static final String DEFAULT_KEYWORD = "REQUIRES_CAPTCHA_ABOVE_THRESOLD_REQUESTS";
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
-    /**
+/**
      * Constructor
      * Constructor
      */
      */
     public AlwaysTestAfterMaxRequestsCaptchaChannelProcessor() {
     public AlwaysTestAfterMaxRequestsCaptchaChannelProcessor() {
@@ -45,7 +41,7 @@ public class AlwaysTestAfterMaxRequestsCaptchaChannelProcessor
         this.setKeyword(DEFAULT_KEYWORD);
         this.setKeyword(DEFAULT_KEYWORD);
     }
     }
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
      * Verify wheter the context is valid concerning humanity
      * Verify wheter the context is valid concerning humanity

+ 12 - 17
core/src/main/java/org/acegisecurity/captcha/AlwaysTestAfterTimeInMillisCaptchaChannelProcessor.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -12,27 +12,25 @@
  * See the License for the specific language governing permissions and
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * limitations under the License.
  */
  */
+
 package org.acegisecurity.captcha;
 package org.acegisecurity.captcha;
 
 
 /**
 /**
- * <p>
- * return false if thresold is greater than millis since last captcha test has occured;<br>
- * Default keyword : REQUIRES_CAPTCHA_AFTER_THRESOLD_IN_MILLIS
- * </p>
+ * <p>return false if thresold is greater than millis since last captcha test has occured;<br>
+ * Default keyword : REQUIRES_CAPTCHA_AFTER_THRESOLD_IN_MILLIS</p>
  *
  *
  * @author Marc-Antoine Garrigue
  * @author Marc-Antoine Garrigue
  * @version $Id$
  * @version $Id$
  */
  */
-public class AlwaysTestAfterTimeInMillisCaptchaChannelProcessor
-    extends CaptchaChannelProcessorTemplate {
-    //~ Static fields/initializers =============================================
+public class AlwaysTestAfterTimeInMillisCaptchaChannelProcessor extends CaptchaChannelProcessorTemplate {
+    //~ Static fields/initializers =====================================================================================
 
 
     /** Keyword for this channelProcessor */
     /** Keyword for this channelProcessor */
     public static final String DEFAULT_KEYWORD = "REQUIRES_CAPTCHA_AFTER_THRESOLD_IN_MILLIS";
     public static final String DEFAULT_KEYWORD = "REQUIRES_CAPTCHA_AFTER_THRESOLD_IN_MILLIS";
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
-    /**
+/**
      * Constructor
      * Constructor
      */
      */
     public AlwaysTestAfterTimeInMillisCaptchaChannelProcessor() {
     public AlwaysTestAfterTimeInMillisCaptchaChannelProcessor() {
@@ -40,7 +38,7 @@ public class AlwaysTestAfterTimeInMillisCaptchaChannelProcessor
         this.setKeyword(DEFAULT_KEYWORD);
         this.setKeyword(DEFAULT_KEYWORD);
     }
     }
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
      * Verify wheter the context is valid concerning humanity
      * Verify wheter the context is valid concerning humanity
@@ -50,15 +48,12 @@ public class AlwaysTestAfterTimeInMillisCaptchaChannelProcessor
      * @return true if valid, false otherwise
      * @return true if valid, false otherwise
      */
      */
     boolean isContextValidConcerningHumanity(CaptchaSecurityContext context) {
     boolean isContextValidConcerningHumanity(CaptchaSecurityContext context) {
-        if ((System.currentTimeMillis()
-            - context.getLastPassedCaptchaDateInMillis()) < getThresold()) {
-            logger.debug(
-                "context is valid : last passed captcha date - current time < thresold");
+        if ((System.currentTimeMillis() - context.getLastPassedCaptchaDateInMillis()) < getThresold()) {
+            logger.debug("context is valid : last passed captcha date - current time < thresold");
 
 
             return true;
             return true;
         } else {
         } else {
-            logger.debug(
-                "context is not valid : last passed captcha date - current time > thresold");
+            logger.debug("context is not valid : last passed captcha date - current time > thresold");
 
 
             return false;
             return false;
         }
         }

+ 12 - 18
core/src/main/java/org/acegisecurity/captcha/AlwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -19,26 +19,23 @@ import org.springframework.util.Assert;
 
 
 
 
 /**
 /**
- * <p>
- * return false if thresold is lower than average time millis between any
- * CaptchaChannelProcessorTemplate mapped urls requests and is human;<br>
+ * <p>return false if thresold is lower than average time millis between any CaptchaChannelProcessorTemplate mapped
+ * urls requests and is human;<br>
  * Default keyword : REQUIRES_CAPTCHA_BELOW_AVERAGE_TIME_IN_MILLIS_REQUESTS <br>
  * Default keyword : REQUIRES_CAPTCHA_BELOW_AVERAGE_TIME_IN_MILLIS_REQUESTS <br>
- * Note : before first humanity check
- * </p>
+ * Note : before first humanity check</p>
  *
  *
  * @author Marc-Antoine Garrigue
  * @author Marc-Antoine Garrigue
  * @version $Id$
  * @version $Id$
  */
  */
-public class AlwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor
-    extends CaptchaChannelProcessorTemplate {
-    //~ Static fields/initializers =============================================
+public class AlwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor extends CaptchaChannelProcessorTemplate {
+    //~ Static fields/initializers =====================================================================================
 
 
     /** Keyword for this channelProcessor */
     /** Keyword for this channelProcessor */
     public static final String DEFAULT_KEYWORD = "REQUIRES_CAPTCHA_BELOW_AVERAGE_TIME_IN_MILLIS_REQUESTS";
     public static final String DEFAULT_KEYWORD = "REQUIRES_CAPTCHA_BELOW_AVERAGE_TIME_IN_MILLIS_REQUESTS";
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
-    /**
+/**
      * Constructor
      * Constructor
      */
      */
     public AlwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor() {
     public AlwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor() {
@@ -46,7 +43,7 @@ public class AlwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor
         this.setKeyword(DEFAULT_KEYWORD);
         this.setKeyword(DEFAULT_KEYWORD);
     }
     }
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
      * Verify if thresold is &gt; 0
      * Verify if thresold is &gt; 0
@@ -68,8 +65,7 @@ public class AlwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor
     boolean isContextValidConcerningHumanity(CaptchaSecurityContext context) {
     boolean isContextValidConcerningHumanity(CaptchaSecurityContext context) {
         int req = context.getHumanRestrictedResourcesRequestsCount();
         int req = context.getHumanRestrictedResourcesRequestsCount();
         float thresold = getThresold();
         float thresold = getThresold();
-        float duration = System.currentTimeMillis()
-            - context.getLastPassedCaptchaDateInMillis();
+        float duration = System.currentTimeMillis() - context.getLastPassedCaptchaDateInMillis();
         float average;
         float average;
 
 
         if (req == 0) {
         if (req == 0) {
@@ -79,13 +75,11 @@ public class AlwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor
         }
         }
 
 
         if (context.isHuman() && (average > thresold)) {
         if (context.isHuman() && (average > thresold)) {
-            logger.debug(
-                "context is valid : average time between requests < thresold && is human");
+            logger.debug("context is valid : average time between requests < thresold && is human");
 
 
             return true;
             return true;
         } else {
         } else {
-            logger.debug(
-                "context is not valid : request count > thresold or is not human");
+            logger.debug("context is not valid : request count > thresold or is not human");
 
 
             return false;
             return false;
         }
         }

+ 56 - 67
core/src/main/java/org/acegisecurity/captcha/CaptchaChannelProcessorTemplate.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -17,8 +17,11 @@ package org.acegisecurity.captcha;
 
 
 import org.acegisecurity.ConfigAttribute;
 import org.acegisecurity.ConfigAttribute;
 import org.acegisecurity.ConfigAttributeDefinition;
 import org.acegisecurity.ConfigAttributeDefinition;
+
 import org.acegisecurity.context.SecurityContextHolder;
 import org.acegisecurity.context.SecurityContextHolder;
+
 import org.acegisecurity.intercept.web.FilterInvocation;
 import org.acegisecurity.intercept.web.FilterInvocation;
+
 import org.acegisecurity.securechannel.ChannelEntryPoint;
 import org.acegisecurity.securechannel.ChannelEntryPoint;
 import org.acegisecurity.securechannel.ChannelProcessor;
 import org.acegisecurity.securechannel.ChannelProcessor;
 
 
@@ -37,67 +40,32 @@ import javax.servlet.ServletException;
 
 
 
 
 /**
 /**
- * <p>
- * CaptchaChannel template : Ensures the user has enough human privileges by
- * review of the {@link CaptchaSecurityContext} and using an abstract routine
- * {@link #isContextValidConcerningHumanity(CaptchaSecurityContext)}
- * (implemented by sub classes)
- * </p>
- * 
- * <P>
- * The component uses 2 main parameters for its configuration :
- * 
- * <ul>
- * <li>
- * a keyword to be mapped to urls in the {@link
- * org.acegisecurity.securechannel.ChannelProcessingFilter} configuration<br>
- * default value provided by sub classes.
- * </li>
- * <li>
- * and a thresold : used by the routine {@link
- * #isContextValidConcerningHumanity(CaptchaSecurityContext)} to evaluate
- * whether the {@link CaptchaSecurityContext} is valid default value = 0
- * </li>
- * </ul>
- * </p>
+ * <p>CaptchaChannel template : Ensures the user has enough human privileges by review of the {@link
+ * CaptchaSecurityContext} and using an abstract routine {@link
+ * #isContextValidConcerningHumanity(CaptchaSecurityContext)} (implemented by sub classes)</p>
+ *  <P>The component uses 2 main parameters for its configuration :
+ *  <ul>
+ *      <li>a keyword to be mapped to urls in the {@link
+ *      org.acegisecurity.securechannel.ChannelProcessingFilter} configuration<br>
+ *      default value provided by sub classes.</li>
+ *      <li>and a thresold : used by the routine {@link
+ *      #isContextValidConcerningHumanity(CaptchaSecurityContext)} to evaluate whether the {@link
+ *      CaptchaSecurityContext} is valid default value = 0</li>
+ *  </ul>
+ *  </p>
  *
  *
  * @author marc antoine Garrigue
  * @author marc antoine Garrigue
  * @version $Id$
  * @version $Id$
  */
  */
-public abstract class CaptchaChannelProcessorTemplate
-    implements ChannelProcessor, InitializingBean {
-    //~ Instance fields ========================================================
+public abstract class CaptchaChannelProcessorTemplate implements ChannelProcessor, InitializingBean {
+    //~ Instance fields ================================================================================================
 
 
-    protected Log logger = LogFactory.getLog(this.getClass());
     private ChannelEntryPoint entryPoint;
     private ChannelEntryPoint entryPoint;
+    protected Log logger = LogFactory.getLog(this.getClass());
     private String keyword = null;
     private String keyword = null;
     private int thresold = 0;
     private int thresold = 0;
 
 
-    //~ Methods ================================================================
-
-    public void setEntryPoint(ChannelEntryPoint entryPoint) {
-        this.entryPoint = entryPoint;
-    }
-
-    public ChannelEntryPoint getEntryPoint() {
-        return entryPoint;
-    }
-
-    public void setKeyword(String keyword) {
-        this.keyword = keyword;
-    }
-
-    public String getKeyword() {
-        return keyword;
-    }
-
-    public void setThresold(int thresold) {
-        this.thresold = thresold;
-    }
-
-    public int getThresold() {
-        return thresold;
-    }
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
      * Verify if entryPoint and keyword are ok
      * Verify if entryPoint and keyword are ok
@@ -109,8 +77,8 @@ public abstract class CaptchaChannelProcessorTemplate
         Assert.hasLength(keyword, "keyword required");
         Assert.hasLength(keyword, "keyword required");
     }
     }
 
 
-    public void decide(FilterInvocation invocation,
-        ConfigAttributeDefinition config) throws IOException, ServletException {
+    public void decide(FilterInvocation invocation, ConfigAttributeDefinition config)
+        throws IOException, ServletException {
         if ((invocation == null) || (config == null)) {
         if ((invocation == null) || (config == null)) {
             throw new IllegalArgumentException("Nulls cannot be provided");
             throw new IllegalArgumentException("Nulls cannot be provided");
         }
         }
@@ -127,12 +95,10 @@ public abstract class CaptchaChannelProcessorTemplate
                 logger.debug("supports this attribute : " + attribute);
                 logger.debug("supports this attribute : " + attribute);
 
 
                 if (!isContextValidConcerningHumanity(context)) {
                 if (!isContextValidConcerningHumanity(context)) {
-                    logger.debug(
-                        "context is not allowed to access ressource, redirect to captcha entry point");
+                    logger.debug("context is not allowed to access ressource, redirect to captcha entry point");
                     redirectToEntryPoint(invocation);
                     redirectToEntryPoint(invocation);
                 } else {
                 } else {
-                    logger.debug(
-                        "has been successfully checked this keyword, increment request count");
+                    logger.debug("has been successfully checked this keyword, increment request count");
                     context.incrementHumanRestrictedRessoucesRequestsCount();
                     context.incrementHumanRestrictedRessoucesRequestsCount();
                 }
                 }
             } else {
             } else {
@@ -141,16 +107,19 @@ public abstract class CaptchaChannelProcessorTemplate
         }
         }
     }
     }
 
 
-    public boolean supports(ConfigAttribute attribute) {
-        if ((attribute != null) && (keyword.equals(attribute.getAttribute()))) {
-            return true;
-        } else {
-            return false;
-        }
+    public ChannelEntryPoint getEntryPoint() {
+        return entryPoint;
     }
     }
 
 
-    abstract boolean isContextValidConcerningHumanity(
-        CaptchaSecurityContext context);
+    public String getKeyword() {
+        return keyword;
+    }
+
+    public int getThresold() {
+        return thresold;
+    }
+
+    abstract boolean isContextValidConcerningHumanity(CaptchaSecurityContext context);
 
 
     private void redirectToEntryPoint(FilterInvocation invocation)
     private void redirectToEntryPoint(FilterInvocation invocation)
         throws IOException, ServletException {
         throws IOException, ServletException {
@@ -160,4 +129,24 @@ public abstract class CaptchaChannelProcessorTemplate
 
 
         entryPoint.commence(invocation.getRequest(), invocation.getResponse());
         entryPoint.commence(invocation.getRequest(), invocation.getResponse());
     }
     }
+
+    public void setEntryPoint(ChannelEntryPoint entryPoint) {
+        this.entryPoint = entryPoint;
+    }
+
+    public void setKeyword(String keyword) {
+        this.keyword = keyword;
+    }
+
+    public void setThresold(int thresold) {
+        this.thresold = thresold;
+    }
+
+    public boolean supports(ConfigAttribute attribute) {
+        if ((attribute != null) && (keyword.equals(attribute.getAttribute()))) {
+            return true;
+        } else {
+            return false;
+        }
+    }
 }
 }

+ 191 - 229
core/src/main/java/org/acegisecurity/captcha/CaptchaEntryPoint.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
 package org.acegisecurity.captcha;
 package org.acegisecurity.captcha;
 
 
 import org.acegisecurity.securechannel.ChannelEntryPoint;
 import org.acegisecurity.securechannel.ChannelEntryPoint;
+
 import org.acegisecurity.util.PortMapper;
 import org.acegisecurity.util.PortMapper;
 import org.acegisecurity.util.PortMapperImpl;
 import org.acegisecurity.util.PortMapperImpl;
 import org.acegisecurity.util.PortResolver;
 import org.acegisecurity.util.PortResolver;
@@ -43,47 +44,25 @@ import javax.servlet.http.HttpServletResponse;
 
 
 
 
 /**
 /**
- * The captcha entry point : redirect to the captcha test page. <br>
- * 
- * <p>
- * This entry point can force the use of SSL : see {@link #getForceHttps()}<br>
- * </p>
- * This entry point allows internal OR external redirect : see {@link #setOutsideWebApp(boolean)}<br>
- * / Original request can be added to the redirect path using a custom
- * translation : see {@link #setIncludeOriginalRequest(boolean)}<br>
- * Original request is translated using URLEncoding and the following
- * translation mapping in the redirect url :
- * 
- * <ul>
- * <li>
- * original url => {@link #getOriginalRequestUrlParameterName()}
- * </li>
- * <li>
- * If {@link #isIncludeOriginalParameters()}
- * </li>
- * <li>
- * original method => {@link #getOriginalRequestMethodParameterName()}
- * </li>
- * <li>
- * original parameters => {@link #getOriginalRequestParametersParameterName()}
- * </li>
- * <li>
- * The original parameters string is contructed using :
- * 
- * <ul>
- * <li>
- * a parameter separator {@link #getOriginalRequestParametersSeparator()}
- * </li>
- * <li>
- * a parameter name value pair separator for each parameter {@link
- * #getOriginalRequestParametersNameValueSeparator()}
- * </li>
- * </ul>
- * 
- * </li>
- * </ul>
- * 
- * <br><br>
+ * The captcha entry point : redirect to the captcha test page. <br><p>This entry point can force the use of SSL :
+ * see {@link #getForceHttps()}<br></p>
+ *  This entry point allows internal OR external redirect : see {@link #setOutsideWebApp(boolean)}<br>
+ * / Original request can be added to the redirect path using a custom translation : see {@link #setIncludeOriginalRequest(boolean)}<br>
+ * Original request is translated using URLEncoding and the following translation mapping in the redirect url :
+ *  <ul>
+ *      <li>original url => {@link #getOriginalRequestUrlParameterName()}</li>
+ *      <li>If {@link #isIncludeOriginalParameters()}</li>
+ *      <li>original method => {@link #getOriginalRequestMethodParameterName()}</li>
+ *      <li>original parameters => {@link #getOriginalRequestParametersParameterName()}</li>
+ *      <li>The original parameters string is contructed using :
+ *      <ul>
+ *          <li>a parameter separator {@link #getOriginalRequestParametersSeparator()}</li>
+ *          <li>a parameter name value pair separator for each parameter {@link
+ *          #getOriginalRequestParametersNameValueSeparator()}</li>
+ *      </ul>
+ *      </li>
+ *  </ul>
+ *  <br><br>
  * Default values :<br>
  * Default values :<br>
  * forceHttps = false<br>
  * forceHttps = false<br>
  * includesOriginalRequest = true<br>
  * includesOriginalRequest = true<br>
@@ -100,13 +79,13 @@ import javax.servlet.http.HttpServletResponse;
  * @version $Id$
  * @version $Id$
  */
  */
 public class CaptchaEntryPoint implements ChannelEntryPoint, InitializingBean {
 public class CaptchaEntryPoint implements ChannelEntryPoint, InitializingBean {
-    //~ Static fields/initializers =============================================
+    //~ Static fields/initializers =====================================================================================
 
 
     // ~ Static fields/initializers
     // ~ Static fields/initializers
     // =============================================
     // =============================================
     private static final Log logger = LogFactory.getLog(CaptchaEntryPoint.class);
     private static final Log logger = LogFactory.getLog(CaptchaEntryPoint.class);
 
 
-    //~ Instance fields ========================================================
+    //~ Instance fields ================================================================================================
 
 
     // ~ Instance fields
     // ~ Instance fields
     // ========================================================
     // ========================================================
@@ -124,197 +103,24 @@ public class CaptchaEntryPoint implements ChannelEntryPoint, InitializingBean {
     private boolean includeOriginalRequest = true;
     private boolean includeOriginalRequest = true;
     private boolean isOutsideWebApp = false;
     private boolean isOutsideWebApp = false;
 
 
-    //~ Methods ================================================================
-
-    /**
-     * The URL where the <code>CaptchaProcessingFilter</code> login page can be
-     * found. Should be relative to the web-app context path, and include a
-     * leading <code>/</code>
-     *
-     * @param captchaFormUrl
-     */
-    public void setCaptchaFormUrl(String captchaFormUrl) {
-        this.captchaFormUrl = captchaFormUrl;
-    }
-
-    /**
-     * DOCUMENT ME!
-     *
-     * @return the captcha test page to redirect to.
-     */
-    public String getCaptchaFormUrl() {
-        return captchaFormUrl;
-    }
-
-    // ~ Methods
-    // ================================================================
-
-    /**
-     * Set to true to force captcha form access to be via https. If this value
-     * is ture (the default is false), and the incoming request for the
-     * protected resource which triggered the interceptor was not already
-     * <code>https</code>, then
-     *
-     * @param forceHttps
-     */
-    public void setForceHttps(boolean forceHttps) {
-        this.forceHttps = forceHttps;
-    }
-
-    public boolean getForceHttps() {
-        return forceHttps;
-    }
-
-    public void setIncludeOriginalParameters(boolean includeOriginalParameters) {
-        this.includeOriginalParameters = includeOriginalParameters;
-    }
-
-    public boolean isIncludeOriginalParameters() {
-        return includeOriginalParameters;
-    }
-
-    /**
-     * If set to true, the original request url will be appended to the
-     * redirect url using the {@link #getOriginalRequestUrlParameterName()}.
-     *
-     * @param includeOriginalRequest
-     */
-    public void setIncludeOriginalRequest(boolean includeOriginalRequest) {
-        this.includeOriginalRequest = includeOriginalRequest;
-    }
-
-    public boolean isIncludeOriginalRequest() {
-        return includeOriginalRequest;
-    }
-
-    public void setOriginalRequestMethodParameterName(
-        String originalRequestMethodParameterName) {
-        this.originalRequestMethodParameterName = originalRequestMethodParameterName;
-    }
-
-    public String getOriginalRequestMethodParameterName() {
-        return originalRequestMethodParameterName;
-    }
-
-    public void setOriginalRequestParametersNameValueSeparator(
-        String originalRequestParametersNameValueSeparator) {
-        this.originalRequestParametersNameValueSeparator = originalRequestParametersNameValueSeparator;
-    }
-
-    public String getOriginalRequestParametersNameValueSeparator() {
-        return originalRequestParametersNameValueSeparator;
-    }
-
-    public void setOriginalRequestParametersParameterName(
-        String originalRequestParametersParameterName) {
-        this.originalRequestParametersParameterName = originalRequestParametersParameterName;
-    }
-
-    public String getOriginalRequestParametersParameterName() {
-        return originalRequestParametersParameterName;
-    }
-
-    public void setOriginalRequestParametersSeparator(
-        String originalRequestParametersSeparator) {
-        this.originalRequestParametersSeparator = originalRequestParametersSeparator;
-    }
-
-    public String getOriginalRequestParametersSeparator() {
-        return originalRequestParametersSeparator;
-    }
-
-    public void setOriginalRequestUrlParameterName(
-        String originalRequestUrlParameterName) {
-        this.originalRequestUrlParameterName = originalRequestUrlParameterName;
-    }
-
-    public String getOriginalRequestUrlParameterName() {
-        return originalRequestUrlParameterName;
-    }
-
-    /**
-     * if set to true, the {@link #commence(ServletRequest, ServletResponse)}
-     * method uses the {@link #getCaptchaFormUrl()} as a complete URL, else it
-     * as a 'inside WebApp' path.
-     *
-     * @param isOutsideWebApp
-     */
-    public void setOutsideWebApp(boolean isOutsideWebApp) {
-        this.isOutsideWebApp = isOutsideWebApp;
-    }
-
-    public boolean isOutsideWebApp() {
-        return isOutsideWebApp;
-    }
-
-    public void setPortMapper(PortMapper portMapper) {
-        this.portMapper = portMapper;
-    }
-
-    public PortMapper getPortMapper() {
-        return portMapper;
-    }
-
-    public void setPortResolver(PortResolver portResolver) {
-        this.portResolver = portResolver;
-    }
-
-    public PortResolver getPortResolver() {
-        return portResolver;
-    }
-
-    public void setUrlEncodingCharset(String urlEncodingCharset) {
-        this.urlEncodingCharset = urlEncodingCharset;
-    }
-
-    public String getUrlEncodingCharset() {
-        return urlEncodingCharset;
-    }
+    //~ Methods ========================================================================================================
 
 
     public void afterPropertiesSet() throws Exception {
     public void afterPropertiesSet() throws Exception {
         Assert.hasLength(captchaFormUrl, "captchaFormUrl must be specified");
         Assert.hasLength(captchaFormUrl, "captchaFormUrl must be specified");
-        Assert.hasLength(originalRequestMethodParameterName,
-            "originalRequestMethodParameterName must be specified");
+        Assert.hasLength(originalRequestMethodParameterName, "originalRequestMethodParameterName must be specified");
         Assert.hasLength(originalRequestParametersNameValueSeparator,
         Assert.hasLength(originalRequestParametersNameValueSeparator,
             "originalRequestParametersNameValueSeparator must be specified");
             "originalRequestParametersNameValueSeparator must be specified");
         Assert.hasLength(originalRequestParametersParameterName,
         Assert.hasLength(originalRequestParametersParameterName,
             "originalRequestParametersParameterName must be specified");
             "originalRequestParametersParameterName must be specified");
-        Assert.hasLength(originalRequestParametersSeparator,
-            "originalRequestParametersSeparator must be specified");
-        Assert.hasLength(originalRequestUrlParameterName,
-            "originalRequestUrlParameterName must be specified");
-        Assert.hasLength(urlEncodingCharset,
-            "urlEncodingCharset must be specified");
+        Assert.hasLength(originalRequestParametersSeparator, "originalRequestParametersSeparator must be specified");
+        Assert.hasLength(originalRequestUrlParameterName, "originalRequestUrlParameterName must be specified");
+        Assert.hasLength(urlEncodingCharset, "urlEncodingCharset must be specified");
         Assert.notNull(portMapper, "portMapper must be specified");
         Assert.notNull(portMapper, "portMapper must be specified");
         Assert.notNull(portResolver, "portResolver must be specified");
         Assert.notNull(portResolver, "portResolver must be specified");
         URLEncoder.encode("   fzaef é& à ", urlEncodingCharset);
         URLEncoder.encode("   fzaef é& à ", urlEncodingCharset);
     }
     }
 
 
-    public void commence(ServletRequest request, ServletResponse response)
-        throws IOException, ServletException {
-        StringBuffer redirectUrl = new StringBuffer();
-        HttpServletRequest req = (HttpServletRequest) request;
-
-        if (isOutsideWebApp) {
-            redirectUrl = redirectUrl.append(captchaFormUrl);
-        } else {
-            buildInternalRedirect(redirectUrl, req);
-        }
-
-        if (includeOriginalRequest) {
-            includeOriginalRequest(redirectUrl, req);
-        }
-
-        // add post parameter? DONE!
-        if (logger.isDebugEnabled()) {
-            logger.debug("Redirecting to: " + redirectUrl);
-        }
-
-        ((HttpServletResponse) response).sendRedirect(redirectUrl.toString());
-    }
-
-    private void buildInternalRedirect(StringBuffer redirectUrl,
-        HttpServletRequest req) {
+    private void buildInternalRedirect(StringBuffer redirectUrl, HttpServletRequest req) {
         // construct it
         // construct it
         StringBuffer simpleRedirect = new StringBuffer();
         StringBuffer simpleRedirect = new StringBuffer();
 
 
@@ -373,8 +179,75 @@ public class CaptchaEntryPoint implements ChannelEntryPoint, InitializingBean {
         }
         }
     }
     }
 
 
-    private void includeOriginalRequest(StringBuffer redirectUrl,
-        HttpServletRequest req) {
+    public void commence(ServletRequest request, ServletResponse response)
+        throws IOException, ServletException {
+        StringBuffer redirectUrl = new StringBuffer();
+        HttpServletRequest req = (HttpServletRequest) request;
+
+        if (isOutsideWebApp) {
+            redirectUrl = redirectUrl.append(captchaFormUrl);
+        } else {
+            buildInternalRedirect(redirectUrl, req);
+        }
+
+        if (includeOriginalRequest) {
+            includeOriginalRequest(redirectUrl, req);
+        }
+
+        // add post parameter? DONE!
+        if (logger.isDebugEnabled()) {
+            logger.debug("Redirecting to: " + redirectUrl);
+        }
+
+        ((HttpServletResponse) response).sendRedirect(redirectUrl.toString());
+    }
+
+    /**
+     * DOCUMENT ME!
+     *
+     * @return the captcha test page to redirect to.
+     */
+    public String getCaptchaFormUrl() {
+        return captchaFormUrl;
+    }
+
+    public boolean getForceHttps() {
+        return forceHttps;
+    }
+
+    public String getOriginalRequestMethodParameterName() {
+        return originalRequestMethodParameterName;
+    }
+
+    public String getOriginalRequestParametersNameValueSeparator() {
+        return originalRequestParametersNameValueSeparator;
+    }
+
+    public String getOriginalRequestParametersParameterName() {
+        return originalRequestParametersParameterName;
+    }
+
+    public String getOriginalRequestParametersSeparator() {
+        return originalRequestParametersSeparator;
+    }
+
+    public String getOriginalRequestUrlParameterName() {
+        return originalRequestUrlParameterName;
+    }
+
+    public PortMapper getPortMapper() {
+        return portMapper;
+    }
+
+    public PortResolver getPortResolver() {
+        return portResolver;
+    }
+
+    public String getUrlEncodingCharset() {
+        return urlEncodingCharset;
+    }
+
+    private void includeOriginalRequest(StringBuffer redirectUrl, HttpServletRequest req) {
         // add original request to the url
         // add original request to the url
         if (redirectUrl.indexOf("?") >= 0) {
         if (redirectUrl.indexOf("?") >= 0) {
             redirectUrl.append("&");
             redirectUrl.append("&");
@@ -386,8 +259,7 @@ public class CaptchaEntryPoint implements ChannelEntryPoint, InitializingBean {
         redirectUrl.append("=");
         redirectUrl.append("=");
 
 
         try {
         try {
-            redirectUrl.append(URLEncoder.encode(req.getRequestURL().toString(),
-                    urlEncodingCharset));
+            redirectUrl.append(URLEncoder.encode(req.getRequestURL().toString(), urlEncodingCharset));
         } catch (UnsupportedEncodingException e) {
         } catch (UnsupportedEncodingException e) {
             logger.warn(e);
             logger.warn(e);
         }
         }
@@ -423,11 +295,101 @@ public class CaptchaEntryPoint implements ChannelEntryPoint, InitializingBean {
             }
             }
 
 
             try {
             try {
-                redirectUrl.append(URLEncoder.encode(qp.toString(),
-                        urlEncodingCharset));
+                redirectUrl.append(URLEncoder.encode(qp.toString(), urlEncodingCharset));
             } catch (Exception e) {
             } catch (Exception e) {
                 logger.warn(e);
                 logger.warn(e);
             }
             }
         }
         }
     }
     }
+
+    public boolean isIncludeOriginalParameters() {
+        return includeOriginalParameters;
+    }
+
+    public boolean isIncludeOriginalRequest() {
+        return includeOriginalRequest;
+    }
+
+    public boolean isOutsideWebApp() {
+        return isOutsideWebApp;
+    }
+
+    /**
+     * The URL where the <code>CaptchaProcessingFilter</code> login page can be found. Should be relative to
+     * the web-app context path, and include a leading <code>/</code>
+     *
+     * @param captchaFormUrl
+     */
+    public void setCaptchaFormUrl(String captchaFormUrl) {
+        this.captchaFormUrl = captchaFormUrl;
+    }
+
+    // ~ Methods
+    // ================================================================
+    /**
+     * Set to true to force captcha form access to be via https. If this value is ture (the default is false),
+     * and the incoming request for the protected resource which triggered the interceptor was not already
+     * <code>https</code>, then
+     *
+     * @param forceHttps
+     */
+    public void setForceHttps(boolean forceHttps) {
+        this.forceHttps = forceHttps;
+    }
+
+    public void setIncludeOriginalParameters(boolean includeOriginalParameters) {
+        this.includeOriginalParameters = includeOriginalParameters;
+    }
+
+    /**
+     * If set to true, the original request url will be appended to the redirect url using the {@link
+     * #getOriginalRequestUrlParameterName()}.
+     *
+     * @param includeOriginalRequest
+     */
+    public void setIncludeOriginalRequest(boolean includeOriginalRequest) {
+        this.includeOriginalRequest = includeOriginalRequest;
+    }
+
+    public void setOriginalRequestMethodParameterName(String originalRequestMethodParameterName) {
+        this.originalRequestMethodParameterName = originalRequestMethodParameterName;
+    }
+
+    public void setOriginalRequestParametersNameValueSeparator(String originalRequestParametersNameValueSeparator) {
+        this.originalRequestParametersNameValueSeparator = originalRequestParametersNameValueSeparator;
+    }
+
+    public void setOriginalRequestParametersParameterName(String originalRequestParametersParameterName) {
+        this.originalRequestParametersParameterName = originalRequestParametersParameterName;
+    }
+
+    public void setOriginalRequestParametersSeparator(String originalRequestParametersSeparator) {
+        this.originalRequestParametersSeparator = originalRequestParametersSeparator;
+    }
+
+    public void setOriginalRequestUrlParameterName(String originalRequestUrlParameterName) {
+        this.originalRequestUrlParameterName = originalRequestUrlParameterName;
+    }
+
+    /**
+     * if set to true, the {@link #commence(ServletRequest, ServletResponse)} method uses the {@link
+     * #getCaptchaFormUrl()} as a complete URL, else it as a 'inside WebApp' path.
+     *
+     * @param isOutsideWebApp
+     */
+    public void setOutsideWebApp(boolean isOutsideWebApp) {
+        this.isOutsideWebApp = isOutsideWebApp;
+    }
+
+    public void setPortMapper(PortMapper portMapper) {
+        this.portMapper = portMapper;
+    }
+
+    public void setPortResolver(PortResolver portResolver) {
+        this.portResolver = portResolver;
+    }
+
+    public void setUrlEncodingCharset(String urlEncodingCharset) {
+        this.urlEncodingCharset = urlEncodingCharset;
+    }
 }
 }

+ 14 - 16
core/src/main/java/org/acegisecurity/captcha/CaptchaSecurityContext.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -24,38 +24,36 @@ import org.acegisecurity.context.SecurityContext;
  * @author marc antoine garrigue
  * @author marc antoine garrigue
  */
  */
 public interface CaptchaSecurityContext extends SecurityContext {
 public interface CaptchaSecurityContext extends SecurityContext {
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
-     * set human attribute, should called after captcha validation.
+     * DOCUMENT ME!
+     *
+     * @return number of human restricted resources requests since the last passed captcha.
      */
      */
-    void setHuman();
+    int getHumanRestrictedResourcesRequestsCount();
 
 
     /**
     /**
      * DOCUMENT ME!
      * DOCUMENT ME!
      *
      *
-     * @return true if the current user has already passed a captcha.
+     * @return the date of the last passed Captcha in millis, 0 if the user never passed captcha.
      */
      */
-    boolean isHuman();
+    long getLastPassedCaptchaDateInMillis();
 
 
     /**
     /**
-     * DOCUMENT ME!
-     *
-     * @return number of human restricted resources requests since the last
-     *         passed captcha.
+     * Method to increment the human Restricted Resrouces Requests Count;
      */
      */
-    int getHumanRestrictedResourcesRequestsCount();
+    void incrementHumanRestrictedRessoucesRequestsCount();
 
 
     /**
     /**
      * DOCUMENT ME!
      * DOCUMENT ME!
      *
      *
-     * @return the date of the last passed Captcha in millis, 0 if the user
-     *         never passed captcha.
+     * @return true if the current user has already passed a captcha.
      */
      */
-    long getLastPassedCaptchaDateInMillis();
+    boolean isHuman();
 
 
     /**
     /**
-     * Method to increment the human Restricted Resrouces Requests Count;
+     * set human attribute, should called after captcha validation.
      */
      */
-    void incrementHumanRestrictedRessoucesRequestsCount();
+    void setHuman();
 }
 }

+ 48 - 42
core/src/main/java/org/acegisecurity/captcha/CaptchaSecurityContextImpl.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -23,15 +23,14 @@ import org.acegisecurity.context.SecurityContextImpl;
  *
  *
  * @author mag
  * @author mag
  */
  */
-public class CaptchaSecurityContextImpl extends SecurityContextImpl
-    implements CaptchaSecurityContext {
-    //~ Instance fields ========================================================
+public class CaptchaSecurityContextImpl extends SecurityContextImpl implements CaptchaSecurityContext {
+    //~ Instance fields ================================================================================================
 
 
     private boolean human;
     private boolean human;
     private int humanRestrictedResourcesRequestsCount;
     private int humanRestrictedResourcesRequestsCount;
     private long lastPassedCaptchaDate;
     private long lastPassedCaptchaDate;
 
 
-    //~ Constructors ===========================================================
+    //~ Constructors ===================================================================================================
 
 
     public CaptchaSecurityContextImpl() {
     public CaptchaSecurityContextImpl() {
         super();
         super();
@@ -40,19 +39,28 @@ public class CaptchaSecurityContextImpl extends SecurityContextImpl
         humanRestrictedResourcesRequestsCount = 0;
         humanRestrictedResourcesRequestsCount = 0;
     }
     }
 
 
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
-    /**
-     * Reset the lastPassedCaptchaDate and count.
-     */
-    public void setHuman() {
-        this.human = true;
-        this.lastPassedCaptchaDate = System.currentTimeMillis();
-        this.humanRestrictedResourcesRequestsCount = 0;
-    }
+    public boolean equals(Object obj) {
+        if (obj instanceof CaptchaSecurityContextImpl) {
+            CaptchaSecurityContextImpl rhs = (CaptchaSecurityContextImpl) obj;
 
 
-    public boolean isHuman() {
-        return human;
+            if (this.isHuman() != rhs.isHuman()) {
+                return false;
+            }
+
+            if (this.getHumanRestrictedResourcesRequestsCount() != rhs.getHumanRestrictedResourcesRequestsCount()) {
+                return false;
+            }
+
+            if (this.getLastPassedCaptchaDateInMillis() != rhs.getLastPassedCaptchaDateInMillis()) {
+                return false;
+            }
+
+            return super.equals(obj);
+        }
+
+        return false;
     }
     }
 
 
     public int getHumanRestrictedResourcesRequestsCount() {
     public int getHumanRestrictedResourcesRequestsCount() {
@@ -63,6 +71,18 @@ public class CaptchaSecurityContextImpl extends SecurityContextImpl
         return lastPassedCaptchaDate;
         return lastPassedCaptchaDate;
     }
     }
 
 
+    public int hashCode() {
+        int code = super.hashCode();
+        code ^= this.humanRestrictedResourcesRequestsCount;
+        code ^= this.lastPassedCaptchaDate;
+
+        if (this.isHuman()) {
+            code ^= -37;
+        }
+
+        return code;
+    }
+
     /**
     /**
      * Method to increment the human Restricted Resrouces Requests Count;
      * Method to increment the human Restricted Resrouces Requests Count;
      */
      */
@@ -70,30 +90,16 @@ public class CaptchaSecurityContextImpl extends SecurityContextImpl
         humanRestrictedResourcesRequestsCount++;
         humanRestrictedResourcesRequestsCount++;
     }
     }
 
 
-	public boolean equals(Object obj) {
-		if (obj instanceof CaptchaSecurityContextImpl) {
-			CaptchaSecurityContextImpl rhs = (CaptchaSecurityContextImpl) obj;
-			if (this.isHuman() != rhs.isHuman()) {
-				return false;
-			}
-			if (this.getHumanRestrictedResourcesRequestsCount() != rhs.getHumanRestrictedResourcesRequestsCount()) {
-				return false;
-			}
-			if (this.getLastPassedCaptchaDateInMillis() != rhs.getLastPassedCaptchaDateInMillis()) {
-				return false;
-			}
-			return super.equals(obj);
-		}
-		return false;
-	}
-
-	public int hashCode() {
-		int code = super.hashCode();
-		code ^= this.humanRestrictedResourcesRequestsCount;
-		code ^= this.lastPassedCaptchaDate;
-		if (this.isHuman()) {
-			code ^= -37;
-		}
-		return code;
-	}
+    public boolean isHuman() {
+        return human;
+    }
+
+    /**
+     * Reset the lastPassedCaptchaDate and count.
+     */
+    public void setHuman() {
+        this.human = true;
+        this.lastPassedCaptchaDate = System.currentTimeMillis();
+        this.humanRestrictedResourcesRequestsCount = 0;
+    }
 }
 }

+ 3 - 6
core/src/main/java/org/acegisecurity/captcha/CaptchaServiceProxy.java

@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -15,8 +15,6 @@
 
 
 package org.acegisecurity.captcha;
 package org.acegisecurity.captcha;
 
 
-
-
 /**
 /**
  * Provide a common interface for captcha validation.
  * Provide a common interface for captcha validation.
  *
  *
@@ -24,7 +22,7 @@ package org.acegisecurity.captcha;
  * @version $Id$
  * @version $Id$
  */
  */
 public interface CaptchaServiceProxy {
 public interface CaptchaServiceProxy {
-    //~ Methods ================================================================
+    //~ Methods ========================================================================================================
 
 
     /**
     /**
      * DOCUMENT ME!
      * DOCUMENT ME!
@@ -32,8 +30,7 @@ public interface CaptchaServiceProxy {
      * @param id the id token
      * @param id the id token
      * @param captchaResponse the user response
      * @param captchaResponse the user response
      *
      *
-     * @return true if the response is validated by the back end captcha
-     *         service.
+     * @return true if the response is validated by the back end captcha service.
      */
      */
     boolean validateReponseForId(String id, Object captchaResponse);
     boolean validateReponseForId(String id, Object captchaResponse);
 }
 }

Some files were not shown because too many files changed in this diff