portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject cvs commit: jakarta-jetspeed-2/components/security/src/test/org/apache/jetspeed/security/spi TestInternalPasswordCredentialHistoryHandlingInterceptor.java
Date Mon, 07 Mar 2005 14:05:45 GMT
ate         2005/03/07 06:05:45

  Modified:    components/security/src/java/org/apache/jetspeed/security/spi/impl
                        LdapSecurityMappingHandler.java
                        DefaultSecurityMappingHandler.java
                        SecurityAccessImpl.java
                        LdapUserSecurityHandler.java
                        LdapCredentialHandler.java
                        DefaultCredentialHandler.java
               components/security/src/java/org/apache/jetspeed/security/impl
                        AuthenticationProviderProxyImpl.java
                        UserManagerImpl.java RoleManagerImpl.java
                        PermissionManagerImpl.java GroupManagerImpl.java
               components/security/src/test/org/apache/jetspeed/security/spi
                        TestInternalPasswordCredentialHistoryHandlingInterceptor.java
  Log:
  Implement usage of KeyedMessage SecurityException types instead of using String based type
indications.
  See: http://issues.apache.org/jira/browse/JS2-219
  
  Revision  Changes    Path
  1.2       +2 -4      jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/LdapSecurityMappingHandler.java
  
  Index: LdapSecurityMappingHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/LdapSecurityMappingHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LdapSecurityMappingHandler.java	5 Mar 2005 23:27:13 -0000	1.1
  +++ LdapSecurityMappingHandler.java	7 Mar 2005 14:05:45 -0000	1.2
  @@ -325,8 +325,7 @@
           }
           else
           {
  -            throw new SecurityException("User [" + uid
  -                    + "] does not exist. You must first create him before attempting to
add groups to him.");
  +            throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST.create(uid));
           }
       }
   
  @@ -344,8 +343,7 @@
           }
           else
           {
  -            throw new SecurityException("Group [" + uid
  -                    + "] does not exist. You must first create it before attempting to
add it to a user.");
  +            throw new SecurityException(SecurityException.GROUP_DOES_NOT_EXIST.create(uid));
           }
       }
   
  
  
  
  1.6       +8 -8      jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/DefaultSecurityMappingHandler.java
  
  Index: DefaultSecurityMappingHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/DefaultSecurityMappingHandler.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DefaultSecurityMappingHandler.java	29 Oct 2004 14:08:35 -0000	1.5
  +++ DefaultSecurityMappingHandler.java	7 Mar 2005 14:05:45 -0000	1.6
  @@ -166,7 +166,7 @@
           // Check anyway.
           if (null == internalRole)
           {
  -            throw new SecurityException(SecurityException.ROLE_DOES_NOT_EXIST + " " + roleFullPathName);
  +            throw new SecurityException(SecurityException.ROLE_DOES_NOT_EXIST.create(roleFullPathName));
           }
           internalRoles.add(internalRole);
           internalUser.setRolePrincipals(internalRoles);
  @@ -196,7 +196,7 @@
               // Check anyway.
               if (null == internalRole)
               {
  -                throw new SecurityException(SecurityException.ROLE_DOES_NOT_EXIST + " "
+ roleFullPathName);
  +                throw new SecurityException(SecurityException.ROLE_DOES_NOT_EXIST.create(roleFullPathName));
               }
               internalRoles.remove(internalRole);
               // Remove dead mapping records. I.e. No mapping is associated with the specific
record.
  @@ -213,7 +213,7 @@
           }
           else
           {
  -            throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST + " " + username);
  +            throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST.create(username));
           }
       }
   
  @@ -262,7 +262,7 @@
                   .getFullPathFromPrincipalName(groupFullPathName));
           if (null == internalGroup)
           {
  -            throw new SecurityException(SecurityException.GROUP_DOES_NOT_EXIST + " " +
groupFullPathName);
  +            throw new SecurityException(SecurityException.GROUP_DOES_NOT_EXIST.create(groupFullPathName));
           }
           Collection internalRoles = internalGroup.getRolePrincipals();
           InternalRolePrincipal internalRole = commonQueries.getInternalRolePrincipal(RolePrincipalImpl
  @@ -282,7 +282,7 @@
                   .getFullPathFromPrincipalName(groupFullPathName));
           if (null == internalGroup)
           {
  -            throw new SecurityException(SecurityException.GROUP_DOES_NOT_EXIST + " " +
internalGroup);
  +            throw new SecurityException(SecurityException.GROUP_DOES_NOT_EXIST.create(internalGroup));
           }
           Collection internalRoles = internalGroup.getRolePrincipals();
           InternalRolePrincipal internalRole = commonQueries.getInternalRolePrincipal(RolePrincipalImpl
  @@ -447,7 +447,7 @@
           // Check anyway.
           if (null == internalGroup)
           {
  -            throw new SecurityException(SecurityException.GROUP_DOES_NOT_EXIST + " " +
groupFullPathName);
  +            throw new SecurityException(SecurityException.GROUP_DOES_NOT_EXIST.create(groupFullPathName));
           }
           internalGroups.add(internalGroup);
           internalUser.setGroupPrincipals(internalGroups);
  @@ -477,7 +477,7 @@
               // Check anyway.
               if (null == internalGroup)
               {
  -                throw new SecurityException(SecurityException.GROUP_DOES_NOT_EXIST + "
" + groupFullPathName);
  +                throw new SecurityException(SecurityException.GROUP_DOES_NOT_EXIST.create(groupFullPathName));
               }
               internalGroups.remove(internalGroup);
               // Remove dead mapping records. I.e. No mapping is associated with the specific
record.
  @@ -494,7 +494,7 @@
           }
           else
           {
  -            throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST + " " + username);
  +            throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST.create(username));
           }
       }
       
  
  
  
  1.5       +19 -6     jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/SecurityAccessImpl.java
  
  Index: SecurityAccessImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/SecurityAccessImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SecurityAccessImpl.java	3 Feb 2005 02:54:09 -0000	1.4
  +++ SecurityAccessImpl.java	7 Mar 2005 14:05:45 -0000	1.5
  @@ -19,6 +19,7 @@
   import java.util.Iterator;
   
   import org.apache.jetspeed.components.dao.InitablePersistenceBrokerDaoSupport;
  +import org.apache.jetspeed.i18n.KeyedMessage;
   import org.apache.jetspeed.security.SecurityException;
   import org.apache.jetspeed.security.UserPrincipal;
   import org.apache.jetspeed.security.impl.UserPrincipalImpl;
  @@ -154,7 +155,9 @@
           }
           catch (Exception e)
           {
  -            String msg = "Unable to lock user for update.";
  +            KeyedMessage msg = SecurityException.UNEXPECTED.create("SecurityAccess.setInternalUserPrincipal",
  +                                                                   "store",
  +                                                                   e.getMessage());
               logger.error(msg, e);
               throw new SecurityException(msg, e);
           }
  @@ -182,7 +185,9 @@
           }
           catch (Exception e)
           {
  -            String msg = "Unable to lock User for update.";
  +            KeyedMessage msg = SecurityException.UNEXPECTED.create("SecurityAccess.removeInternalUserPrincipal",
  +                                                                   "store",
  +                                                                   e.getMessage());
               logger.error(msg, e);
               throw new SecurityException(msg, e);
           }
  @@ -226,7 +231,9 @@
           }
           catch (Exception e)
           {
  -            String msg = "Unable to lock role for update.";
  +            KeyedMessage msg = SecurityException.UNEXPECTED.create("SecurityAccess.setInternalRolePrincipal",
  +                                                                   "store",
  +                                                                   e.getMessage());
               logger.error(msg, e);
               throw new SecurityException(msg, e);
           }
  @@ -255,7 +262,9 @@
           }
           catch (Exception e)
           {
  -            String msg = "Unable to lock role for delete.";
  +            KeyedMessage msg = SecurityException.UNEXPECTED.create("SecurityAccess.removeInternalRolePrincipal",
  +                                                                   "store",
  +                                                                   e.getMessage());
               logger.error(msg, e);
               throw new SecurityException(msg, e);
           }
  @@ -301,7 +310,9 @@
           }
           catch (Exception e)
           {
  -            String msg = "Unable to lock group for update.";
  +            KeyedMessage msg = SecurityException.UNEXPECTED.create("SecurityAccess.setInternalGroupPrincipal",
  +                                                                   "store",
  +                                                                   e.getMessage());
               logger.error(msg, e);         
               throw new SecurityException(msg, e);
           }
  @@ -330,7 +341,9 @@
           }
           catch (Exception e)
           {
  -            String msg = "Unable to lock group for delete.";
  +            KeyedMessage msg = SecurityException.UNEXPECTED.create("SecurityAccess.removeInternalGroupPrincipal",
  +                                                                   "store",
  +                                                                   e.getMessage());
               logger.error(msg, e);
               throw new SecurityException(msg, e);
           }
  
  
  
  1.5       +1 -1      jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/LdapUserSecurityHandler.java
  
  Index: LdapUserSecurityHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/LdapUserSecurityHandler.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- LdapUserSecurityHandler.java	5 Mar 2005 23:27:13 -0000	1.4
  +++ LdapUserSecurityHandler.java	7 Mar 2005 14:05:45 -0000	1.5
  @@ -153,7 +153,7 @@
           String uid = userPrincipal.getName();
           if (isUserPrincipal(uid))
           {
  -            throw new SecurityException("The user:" + uid + " already exists.");
  +            throw new SecurityException(SecurityException.USER_ALREADY_EXISTS.create(uid));
           }
           ldap.create(uid);
       }
  
  
  
  1.6       +2 -2      jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/LdapCredentialHandler.java
  
  Index: LdapCredentialHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/LdapCredentialHandler.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- LdapCredentialHandler.java	5 Mar 2005 23:27:13 -0000	1.5
  +++ LdapCredentialHandler.java	7 Mar 2005 14:05:45 -0000	1.6
  @@ -167,12 +167,12 @@
       {
           if (StringUtils.isEmpty(password))
           {
  -            throw new SecurityException("The password cannot be null or empty.");
  +            throw new SecurityException(SecurityException.EMPTY_PARAMETER.create("password"));
           }
   
           if (StringUtils.isEmpty(uid))
           {
  -            throw new SecurityException("The uid cannot be null or empty.");
  +            throw new SecurityException(SecurityException.EMPTY_PARAMETER.create("uid"));
           }
       }
   }
  \ No newline at end of file
  
  
  
  1.14      +4 -4      jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/DefaultCredentialHandler.java
  
  Index: DefaultCredentialHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/DefaultCredentialHandler.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- DefaultCredentialHandler.java	3 Feb 2005 01:26:12 -0000	1.13
  +++ DefaultCredentialHandler.java	7 Mar 2005 14:05:45 -0000	1.14
  @@ -139,7 +139,7 @@
           InternalUserPrincipal internalUser = securityAccess.getInternalUserPrincipal(userName,
false);
           if (null == internalUser)
           {
  -            throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST + " " + userName);
  +            throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST.create(userName));
           }
           
           Collection credentials = internalUser.getCredentials();
  @@ -250,7 +250,7 @@
           }
           else
           {
  -            throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST);
  +            throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST.create(userName));
           }
       }
     
  @@ -284,7 +284,7 @@
           }
           else
           {
  -            throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST);
  +            throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST.create(userName));
           }
       }
       
  @@ -333,7 +333,7 @@
           }
           else
           {
  -            throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST);
  +            throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST.create(userName));
           }
           return authenticated;
       }
  
  
  
  1.5       +13 -13    jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/impl/AuthenticationProviderProxyImpl.java
  
  Index: AuthenticationProviderProxyImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/impl/AuthenticationProviderProxyImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AuthenticationProviderProxyImpl.java	8 Nov 2004 03:23:36 -0000	1.4
  +++ AuthenticationProviderProxyImpl.java	7 Mar 2005 14:05:45 -0000	1.5
  @@ -164,7 +164,7 @@
           }
           else
           {
  -            throw new SecurityException(SecurityException.INVALID_AUTHENTICATION_PROVIDER);
  +            throw new SecurityException(SecurityException.INVALID_AUTHENTICATION_PROVIDER.create(authenticationProvider));
           }
       }
   
  @@ -180,7 +180,7 @@
           }
           else
           {
  -            throw new SecurityException(SecurityException.USER_ALREADY_EXISTS);
  +            throw new SecurityException(SecurityException.USER_ALREADY_EXISTS.create(userPrincipal.getName()));
           }
       }
   
  @@ -197,7 +197,7 @@
           }
           else
           {
  -            throw new SecurityException(SecurityException.INVALID_AUTHENTICATION_PROVIDER);
  +            throw new SecurityException(SecurityException.INVALID_AUTHENTICATION_PROVIDER.create(authenticationProvider));
           }
       }
   
  @@ -213,7 +213,7 @@
           }
           else
           {
  -            throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST);
  +            throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST.create(userPrincipal.getName()));
           }
       }
   
  @@ -230,7 +230,7 @@
           }
           else
           {
  -            throw new SecurityException(SecurityException.INVALID_AUTHENTICATION_PROVIDER);
  +            throw new SecurityException(SecurityException.INVALID_AUTHENTICATION_PROVIDER.create(authenticationProvider));
           }
       }
   
  @@ -274,7 +274,7 @@
           }
           else
           {
  -            throw new SecurityException(SecurityException.INVALID_AUTHENTICATION_PROVIDER);
  +            throw new SecurityException(SecurityException.INVALID_AUTHENTICATION_PROVIDER.create(authenticationProvider));
           }
       }
   
  @@ -290,7 +290,7 @@
           }
           else
           {
  -            throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST);
  +            throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST.create(userName));
           }
       }
   
  @@ -322,7 +322,7 @@
           }
           else
           {
  -            throw new SecurityException(SecurityException.INVALID_AUTHENTICATION_PROVIDER);
  +            throw new SecurityException(SecurityException.INVALID_AUTHENTICATION_PROVIDER.create(authenticationProvider));
           }
       }
   
  @@ -338,7 +338,7 @@
           }
           else
           {
  -            throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST);
  +            throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST.create(userName));
           }
       }
   
  @@ -355,7 +355,7 @@
           }
           else
           {
  -            throw new SecurityException(SecurityException.INVALID_AUTHENTICATION_PROVIDER);
  +            throw new SecurityException(SecurityException.INVALID_AUTHENTICATION_PROVIDER.create(authenticationProvider));
           }
       }
   
  @@ -371,7 +371,7 @@
           }
           else
           {
  -            throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST);
  +            throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST.create(userName));
           }
       }
   
  @@ -387,7 +387,7 @@
           }
           else
           {
  -            throw new SecurityException(SecurityException.INVALID_AUTHENTICATION_PROVIDER);
  +            throw new SecurityException(SecurityException.INVALID_AUTHENTICATION_PROVIDER.create(authenticationProvider));
           }
       }
   
  @@ -403,7 +403,7 @@
           }
           else
           {
  -            throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST);
  +            throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST.create(userName));
           }
       }
   }
  \ No newline at end of file
  
  
  
  1.19      +16 -11    jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/impl/UserManagerImpl.java
  
  Index: UserManagerImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/impl/UserManagerImpl.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- UserManagerImpl.java	22 Dec 2004 17:54:08 -0000	1.18
  +++ UserManagerImpl.java	7 Mar 2005 14:05:45 -0000	1.19
  @@ -29,6 +29,7 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.apache.jetspeed.i18n.KeyedMessage;
   import org.apache.jetspeed.security.AuthenticationProviderProxy;
   import org.apache.jetspeed.security.HierarchyResolver;
   import org.apache.jetspeed.security.SecurityException;
  @@ -210,11 +211,12 @@
                           "addUser(java.lang.String, java.lang.String, java.lang.String)");
   
           if (getAnonymousUser().equals(username)) { throw new SecurityException(
  -                SecurityException.ANONYMOUS_USER_PROTECTED); }
  +                SecurityException.ANONYMOUS_USER_PROTECTED.create(username)); }
   
           // Check if user already exists.
  -        if (userExists(username)) { throw new SecurityException(
  -                SecurityException.USER_ALREADY_EXISTS + " " + username); }
  +        if (userExists(username)) { 
  +            throw new SecurityException(SecurityException.USER_ALREADY_EXISTS.create(username));
  +        }
   
           UserPrincipal userPrincipal = new UserPrincipalImpl(username);
           String fullPath = userPrincipal.getFullPath();
  @@ -244,7 +246,9 @@
               }
           } catch (SecurityException se)
           {
  -            String msg = "Unable to create the user.";
  +            KeyedMessage msg = SecurityException.UNEXPECTED.create("UserManager.addUser",
  +                                                                   "UserSecurityHandler",
  +                                                                   se.getMessage());
               log.error(msg, se);
   
               // Remove the preferences node.
  @@ -271,7 +275,7 @@
           { "username"}, "removeUser(java.lang.String)");
   
           if (getAnonymousUser().equals(username)) { throw new SecurityException(
  -                SecurityException.ANONYMOUS_USER_PROTECTED); }
  +                SecurityException.ANONYMOUS_USER_PROTECTED.create(username)); }
           UserPrincipal userPrincipal = new UserPrincipalImpl(username);
           String fullPath = userPrincipal.getFullPath();
           atnProviderProxy.removeUserPrincipal(userPrincipal);
  @@ -311,8 +315,9 @@
           String fullPath = (new UserPrincipalImpl(username)).getFullPath();
   
           Principal userPrincipal = atnProviderProxy.getUserPrincipal(username);
  -        if (null == userPrincipal) { throw new SecurityException(
  -                SecurityException.USER_DOES_NOT_EXIST + " " + username); }
  +        if (null == userPrincipal) { 
  +            throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST.create(username));
  +        }
   
           principals.add(userPrincipal);
           principals.addAll(securityMappingHandler.getRolePrincipals(username));
  @@ -414,7 +419,7 @@
                           "setPassword(java.lang.String, java.lang.String, java.lang.String)");
   
           if (getAnonymousUser().equals(username)) { throw new SecurityException(
  -                SecurityException.ANONYMOUS_USER_PROTECTED); }
  +                SecurityException.ANONYMOUS_USER_PROTECTED.create(username)); }
           atnProviderProxy.setPassword(username, oldPassword, newPassword);
       }
   
  @@ -430,7 +435,7 @@
           { "userName"}, "setPasswordEnabled(java.lang.String, boolean)");
   
           if (getAnonymousUser().equals(userName)) { throw new SecurityException(
  -                SecurityException.ANONYMOUS_USER_PROTECTED); }
  +                SecurityException.ANONYMOUS_USER_PROTECTED.create(userName)); }
           atnProviderProxy.setPasswordEnabled(userName, enabled);
       }
   
  @@ -446,7 +451,7 @@
           { "userName"}, "setPasswordUpdateRequired(java.lang.String, boolean)");
   
           if (getAnonymousUser().equals(userName)) { throw new SecurityException(
  -                SecurityException.ANONYMOUS_USER_PROTECTED); }
  +                SecurityException.ANONYMOUS_USER_PROTECTED.create(userName)); }
           atnProviderProxy.setPasswordUpdateRequired(userName, updateRequired);
       }
   }
  \ No newline at end of file
  
  
  
  1.13      +19 -10    jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/impl/RoleManagerImpl.java
  
  Index: RoleManagerImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/impl/RoleManagerImpl.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- RoleManagerImpl.java	22 Dec 2004 17:54:08 -0000	1.12
  +++ RoleManagerImpl.java	7 Mar 2005 14:05:45 -0000	1.13
  @@ -26,6 +26,7 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.apache.jetspeed.i18n.KeyedMessage;
   import org.apache.jetspeed.security.AuthenticationProviderProxy;
   import org.apache.jetspeed.security.Role;
   import org.apache.jetspeed.security.RoleManager;
  @@ -89,7 +90,7 @@
           // Check if role already exists.
           if (roleExists(roleFullPathName))
           {
  -            throw new SecurityException(SecurityException.ROLE_ALREADY_EXISTS + " " + roleFullPathName);
  +            throw new SecurityException(SecurityException.ROLE_ALREADY_EXISTS.create(roleFullPathName));
           }
   
           RolePrincipal rolePrincipal = new RolePrincipalImpl(roleFullPathName);
  @@ -114,7 +115,10 @@
           }
           catch (SecurityException se)
           {
  -            String msg = "Unable to create the role.";
  +            KeyedMessage msg = 
  +                SecurityException.UNEXPECTED.create("RoleManager.addRole",
  +                                                    "RoleSecurityHandler.setRolePrincipal("+rolePrincipal.getName()+")",
  +                                                    se.getMessage());
               log.error(msg, se);
   
               // Remove the preferences node.
  @@ -151,8 +155,10 @@
               }
               catch (Exception e)
               {
  -                String msg = "Unable to remove role: "
  -                        + RolePrincipalImpl.getPrincipalNameFromFullPath((String) roles[i]);
  +                KeyedMessage msg = 
  +                    SecurityException.UNEXPECTED.create("RoleManager.removeRole",
  +                                                        "RoleSecurityHandler.removeRolePrincipal("+RolePrincipalImpl.getPrincipalNameFromFullPath((String)
roles[i])+")",
  +                                                        e.getMessage());
                   log.error(msg, e);
                   throw new SecurityException(msg, e);
               }
  @@ -164,7 +170,10 @@
               }
               catch (BackingStoreException bse)
               {
  -                String msg = "Unable to remove role preferences: " + roles[i];
  +                KeyedMessage msg = 
  +                    SecurityException.UNEXPECTED.create("RoleManager.removeRole",
  +                                                        "Preferences.removeNode("+roles[i]+")",
  +                                                        bse.getMessage());
                   log.error(msg, bse);
                   throw new SecurityException(msg, bse);
               }
  @@ -202,7 +211,7 @@
           Principal rolePrincipal = roleSecurityHandler.getRolePrincipal(roleFullPathName);
           if (null == rolePrincipal)
           {
  -            throw new SecurityException(SecurityException.ROLE_DOES_NOT_EXIST + " " + roleFullPathName);
  +            throw new SecurityException(SecurityException.ROLE_DOES_NOT_EXIST.create(roleFullPathName));
           }
           Preferences preferences = Preferences.userRoot().node(fullPath);
           Role role = new RoleImpl(rolePrincipal, preferences);
  @@ -265,13 +274,13 @@
           Principal rolePrincipal = roleSecurityHandler.getRolePrincipal(roleFullPathName);
           if (null == rolePrincipal)
           {
  -            throw new SecurityException(SecurityException.ROLE_DOES_NOT_EXIST + " " + roleFullPathName);
  +            throw new SecurityException(SecurityException.ROLE_DOES_NOT_EXIST.create(roleFullPathName));
           }
           // Check that user exists.
           Principal userPrincipal = atnProviderProxy.getUserPrincipal(username);
           if (null == userPrincipal)
           {
  -            throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST + " " + username);
  +            throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST.create(username));
           }
           // Get the user roles.
           Set rolePrincipals = securityMappingHandler.getRolePrincipals(username);
  @@ -295,7 +304,7 @@
           Principal userPrincipal = atnProviderProxy.getUserPrincipal(username);
           if (null == userPrincipal)
           {
  -            throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST + " " + username);
  +            throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST.create(username));
           }
           // Get the role principal to remove.
           Principal rolePrincipal = roleSecurityHandler.getRolePrincipal(roleFullPathName);
  @@ -338,7 +347,7 @@
           Principal rolePrincipal = roleSecurityHandler.getRolePrincipal(roleFullPathName);
           if (null == rolePrincipal)
           {
  -            throw new SecurityException(SecurityException.ROLE_DOES_NOT_EXIST + " " + roleFullPathName);
  +            throw new SecurityException(SecurityException.ROLE_DOES_NOT_EXIST.create(roleFullPathName));
           }
           securityMappingHandler.setRolePrincipalInGroup(groupFullPathName, roleFullPathName);
       }
  
  
  
  1.10      +25 -8     jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/impl/PermissionManagerImpl.java
  
  Index: PermissionManagerImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/impl/PermissionManagerImpl.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- PermissionManagerImpl.java	29 Oct 2004 14:08:36 -0000	1.9
  +++ PermissionManagerImpl.java	7 Mar 2005 14:05:45 -0000	1.10
  @@ -24,9 +24,12 @@
   import java.util.Collections;
   import java.util.Iterator;
   
  +import org.apache.jetspeed.i18n.KeyedMessage;
   import org.apache.jetspeed.security.PermissionManager;
  +import org.apache.jetspeed.security.RolePrincipal;
   import org.apache.jetspeed.security.SecurityException;
   import org.apache.jetspeed.security.SecurityHelper;
  +import org.apache.jetspeed.security.UserPrincipal;
   import org.apache.jetspeed.security.om.InternalPermission;
   import org.apache.jetspeed.security.om.InternalPrincipal;
   import org.apache.jetspeed.security.om.impl.InternalPermissionImpl;
  @@ -192,7 +195,8 @@
           }
           catch (Exception e)
           {
  -            String msg = "Unable to add permission.";
  +            KeyedMessage msg = SecurityException.UNEXPECTED.create("PermissionManager.addPermission",
  +                                                                   "store", e.getMessage());
               logger.error(msg, e);            
               throw new SecurityException(msg, e);
           }
  @@ -216,8 +220,9 @@
               }
               catch (Exception e)
               {
  -                String msg = "Unable to lock Permission for update.";
  -                logger.error(msg, e);
  +                KeyedMessage msg = SecurityException.UNEXPECTED.create("PermissionManager.removePermission",
  +                                                                       "delete", e.getMessage());
  +                logger.error(msg, e);            
                   throw new SecurityException(msg, e);
               }
           }
  @@ -250,7 +255,8 @@
               }
               catch (Exception e)
               {
  -                String msg = "Unable to lock Principal for update.";
  +                KeyedMessage msg = SecurityException.UNEXPECTED.create("PermissionManager.removePermissions",
  +                                                                       "store", e.getMessage());
                   logger.error(msg, e);                
                   throw new SecurityException(msg, e);
               }
  @@ -273,12 +279,21 @@
           InternalPrincipal internalPrincipal = getInternalPrincipal(fullPath);
           if (null == internalPrincipal)
           {
  -            throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST + ":
" + principal.getName());
  +            if ( principal instanceof UserPrincipal )
  +            {
  +                throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST.create(principal.getName()));
  +            }
  +            else if ( principal instanceof RolePrincipal )
  +            {
  +                throw new SecurityException(SecurityException.ROLE_DOES_NOT_EXIST.create(principal.getName()));
  +            }
  +            // must/should be GroupPrincipal
  +            throw new SecurityException(SecurityException.GROUP_DOES_NOT_EXIST.create(principal.getName()));
           }
           InternalPermission internalPermission = getInternalPermission(permission);
           if (null == internalPermission)
           {
  -            throw new SecurityException(SecurityException.PERMISSION_DOES_NOT_EXIST + ":
" + permission.getName());
  +            throw new SecurityException(SecurityException.PERMISSION_DOES_NOT_EXIST.create(permission.getName()));
           }
   
           if (null != internalPrincipal.getPermissions())
  @@ -298,7 +313,8 @@
           }
           catch (Exception e)
           {
  -            String msg = "Unable to lock Principal for update.";
  +            KeyedMessage msg = SecurityException.UNEXPECTED.create("PermissionManager.grantPermission",
  +                                                                   "store", e.getMessage());
               logger.error(msg, e);            
               throw new SecurityException(msg, e);
           }
  @@ -363,7 +379,8 @@
                       }
                       catch (Exception e)
                       {
  -                        String msg = "Unable to lock principal for update.";
  +                        KeyedMessage msg = SecurityException.UNEXPECTED.create("PermissionManager.revokePermission",
  +                                                                               "store",
e.getMessage());
                           logger.error(msg, e);                      
                           throw new SecurityException(msg, e);
                       }
  
  
  
  1.12      +29 -18    jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/impl/GroupManagerImpl.java
  
  Index: GroupManagerImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/impl/GroupManagerImpl.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- GroupManagerImpl.java	22 Dec 2004 17:54:08 -0000	1.11
  +++ GroupManagerImpl.java	7 Mar 2005 14:05:45 -0000	1.12
  @@ -26,6 +26,7 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.apache.jetspeed.i18n.KeyedMessage;
   import org.apache.jetspeed.security.AuthenticationProviderProxy;
   import org.apache.jetspeed.security.Group;
   import org.apache.jetspeed.security.GroupManager;
  @@ -92,9 +93,9 @@
           { "groupFullPathName"}, "addGroup(java.lang.String)");
   
           // Check if group already exists.
  -        if (groupExists(groupFullPathName)) { throw new SecurityException(
  -                SecurityException.GROUP_ALREADY_EXISTS + " "
  -                        + groupFullPathName); }
  +        if (groupExists(groupFullPathName)) {  
  +            throw new SecurityException(SecurityException.GROUP_ALREADY_EXISTS.create(groupFullPathName));

  +        }
   
           GroupPrincipal groupPrincipal = new GroupPrincipalImpl(
                   groupFullPathName);
  @@ -130,7 +131,7 @@
               {
                   bse.printStackTrace();
               }
  -            throw new SecurityException(msg, se);
  +            throw se;
           }
       }
   
  @@ -157,11 +158,16 @@
                           .removeGroupPrincipal(new GroupPrincipalImpl(
                                   GroupPrincipalImpl
                                           .getPrincipalNameFromFullPath((String) groups[i])));
  +            } catch (SecurityException se)
  +            {
  +                throw se;
               } catch (Exception e)
               {
  -                String msg = "Unable to remove group: "
  -                        + GroupPrincipalImpl
  -                                .getPrincipalNameFromFullPath((String) groups[i]);
  +                KeyedMessage msg = 
  +                    SecurityException.UNEXPECTED.create("GroupManager.removeGroup",
  +                                                        "GroupSecurityHandler.removeGroupPrincipal("+
  +                        GroupPrincipalImpl.getPrincipalNameFromFullPath((String) groups[i])+")",

  +                        e.getMessage());
                   log.error(msg, e);
                   throw new SecurityException(msg, e);
               }
  @@ -173,7 +179,9 @@
                   groupPref.removeNode();
               } catch (BackingStoreException bse)
               {
  -                String msg = "Unable to remove group preferences: " + groups[i];
  +                KeyedMessage msg =
  +                    SecurityException.UNEXPECTED.create("Preferences.removeNode("+groups[i]+")",

  +                                                        bse.getMessage());
                   log.error(msg, bse);
                   throw new SecurityException(msg, bse);
               }
  @@ -214,9 +222,10 @@
   
           Principal groupPrincipal = groupSecurityHandler
                   .getGroupPrincipal(groupFullPathName);
  -        if (null == groupPrincipal) { throw new SecurityException(
  -                SecurityException.GROUP_DOES_NOT_EXIST + " "
  -                        + groupFullPathName); }
  +        if (null == groupPrincipal) { 
  +            throw new SecurityException(
  +                SecurityException.GROUP_DOES_NOT_EXIST.create(groupFullPathName)); 
  +        }
           Preferences preferences = Preferences.userRoot().node(fullPath);
           Group group = new GroupImpl(groupPrincipal, preferences);
           return group;
  @@ -291,13 +300,14 @@
           // Get the group principal to add to user.
           Principal groupPrincipal = groupSecurityHandler
                   .getGroupPrincipal(groupFullPathName);
  -        if (null == groupPrincipal) { throw new SecurityException(
  -                SecurityException.GROUP_DOES_NOT_EXIST + " "
  -                        + groupFullPathName); }
  +        if (null == groupPrincipal) { 
  +            throw new SecurityException(SecurityException.GROUP_DOES_NOT_EXIST.create(groupFullPathName));

  +        }
           // Check that user exists.
           Principal userPrincipal = atnProviderProxy.getUserPrincipal(username);
  -        if (null == userPrincipal) { throw new SecurityException(
  -                SecurityException.USER_DOES_NOT_EXIST + " " + username); }
  +        if (null == userPrincipal) { 
  +            throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST.create(username));
  +        }
           // Get the user groups.
           Set groupPrincipals = securityMappingHandler
                   .getGroupPrincipals(username);
  @@ -323,8 +333,9 @@
   
           // Check that user exists.
           Principal userPrincipal = atnProviderProxy.getUserPrincipal(username);
  -        if (null == userPrincipal) { throw new SecurityException(
  -                SecurityException.USER_DOES_NOT_EXIST + " " + username); }
  +        if (null == userPrincipal) { 
  +            throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST.create(username));
  +        }
           // Get the group principal to remove.
           Principal groupPrincipal = groupSecurityHandler
                   .getGroupPrincipal(groupFullPathName);
  
  
  
  1.2       +2 -2      jakarta-jetspeed-2/components/security/src/test/org/apache/jetspeed/security/spi/TestInternalPasswordCredentialHistoryHandlingInterceptor.java
  
  Index: TestInternalPasswordCredentialHistoryHandlingInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/security/src/test/org/apache/jetspeed/security/spi/TestInternalPasswordCredentialHistoryHandlingInterceptor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestInternalPasswordCredentialHistoryHandlingInterceptor.java	12 Nov 2004 03:17:46 -0000
1.1
  +++ TestInternalPasswordCredentialHistoryHandlingInterceptor.java	7 Mar 2005 14:05:45 -0000
1.2
  @@ -71,7 +71,7 @@
           }
           catch (SecurityException sex)
           {
  -            assertEquals(SecurityException.PASSWORD_ALREADY_USED, sex.getMessage());
  +            assertTrue(SecurityException.PASSWORD_ALREADY_USED.equals(sex.getKeyedMessage()));
           }
           ums.setPassword("testcred","password2","password3");
           ums.setPassword("testcred","password3","password4");
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Mime
View raw message