[jboss-cvs] jboss-seam/src/main/org/jboss/seam/security/management ...

Shane Bryzak sbryzak at redhat.com
Thu Jan 3 02:52:29 EST 2008


  User: sbryzak2
  Date: 08/01/03 02:52:29

  Modified:    src/main/org/jboss/seam/security/management  
                        JpaIdentityStore.java
  Added:       src/main/org/jboss/seam/security/management  
                        NoSuchUserException.java
  Log:
  added NoSuchUserException, improved exception handling, other minor changes
  
  Revision  Changes    Path
  1.7       +81 -10    jboss-seam/src/main/org/jboss/seam/security/management/JpaIdentityStore.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: JpaIdentityStore.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/security/management/JpaIdentityStore.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- JpaIdentityStore.java	3 Jan 2008 07:03:19 -0000	1.6
  +++ JpaIdentityStore.java	3 Jan 2008 07:52:29 -0000	1.7
  @@ -101,14 +101,32 @@
      
      public boolean deleteAccount(String name)
      {
  -      UserAccount account = validateUser(name);
  +      UserAccount account;
  +      try
  +      {
  +         account = validateUser(name);
  +      } 
  +      catch (NoSuchUserException e)
  +      {
  +         return false;
  +      }
         getEntityManager().remove(account);
         return true;
      }
      
      public boolean grantRole(String name, String role)
      {
  -      UserAccount account = validateUser(name);      
  +      UserAccount account;
  +      
  +      try
  +      {
  +         account = validateUser(name);         
  +      }
  +      catch (NoSuchUserException ex)
  +      {
  +         return false;
  +      }
  +            
         UserAccount roleToGrant = validateRole(role);
         
         if (account.getMemberships() == null)
  @@ -128,7 +146,16 @@
      
      public boolean revokeRole(String name, String role)
      {
  -      UserAccount account = validateUser(name);      
  +      UserAccount account;
  +      try
  +      {
  +         account = validateUser(name);
  +      } 
  +      catch (NoSuchUserException e)
  +      {
  +         return false;
  +      }
  +      
         UserAccount roleToRevoke = validateRole(role);      
         boolean success = account.getMemberships().remove(roleToRevoke);
         mergeAccount(account);
  @@ -137,7 +164,15 @@
      
      public boolean enableAccount(String name)
      {
  -      UserAccount account = validateUser(name);        
  +      UserAccount account;
  +      try
  +      {
  +         account = validateUser(name);
  +      } 
  +      catch (NoSuchUserException e)
  +      {
  +         return false;
  +      }        
         
         // If it's already enabled return false
         if (account.isEnabled())
  @@ -153,7 +188,15 @@
      
      public boolean disableAccount(String name)
      {
  -      UserAccount account = validateUser(name);       
  +      UserAccount account;
  +      try
  +      {
  +         account = validateUser(name);
  +      } 
  +      catch (NoSuchUserException e)
  +      {
  +         return false;
  +      }       
         
         // If it's already enabled return false
         if (!account.isEnabled())
  @@ -169,7 +212,15 @@
      
      public List<String> getGrantedRoles(String name)
      {
  -      UserAccount account = validateUser(name);
  +      UserAccount account;
  +      try
  +      {
  +         account = validateUser(name);
  +      } 
  +      catch (NoSuchUserException e)
  +      {
  +         return null;
  +      }
   
         List<String> roles = new ArrayList<String>();
         
  @@ -186,7 +237,15 @@
      
      public List<String> getImpliedRoles(String name)
      {
  -      UserAccount account = validateUser(name);
  +      UserAccount account;
  +      try
  +      {
  +         account = validateUser(name);
  +      } 
  +      catch (NoSuchUserException e)
  +      {
  +         return null;
  +      }
   
         Set<String> roles = new HashSet<String>();
   
  @@ -217,7 +276,16 @@
      
      public boolean authenticate(String username, String password)
      {
  -      UserAccount account = validateUser(username);
  +      UserAccount account = null;
  +      
  +      try
  +      {
  +         account = validateUser(username);
  +      }         
  +      catch (NoSuchUserException ex)
  +      {
  +         return false;  
  +      }
         
         if (account == null || !account.getAccountType().equals(AccountType.user)
               || !account.isEnabled())
  @@ -242,7 +310,7 @@
       * @param name The user's username
       * @return The UserAccount for the specified user
       */
  -   protected UserAccount validateUser(String name)
  +   protected UserAccount validateUser(String name) throws NoSuchUserException
      {      
         try
         {
  @@ -255,7 +323,7 @@
         }
         catch (NoResultException ex)
         {
  -         throw new IdentityManagementException("No such user: " + name);         
  +         throw new NoSuchUserException("No such user: " + name);         
         }
      }
      
  @@ -287,6 +355,9 @@
               .setParameter("accountType", AccountType.role)
               .getSingleResult();
            
  +         // Force load memberships
  +         role.getMemberships().size();
  +         
            roleCache.add(role);
            
            return role;
  
  
  
  1.1      date: 2008/01/03 07:52:29;  author: sbryzak2;  state: Exp;jboss-seam/src/main/org/jboss/seam/security/management/NoSuchUserException.java
  
  Index: NoSuchUserException.java
  ===================================================================
  package org.jboss.seam.security.management;
  
  /**
   * Thrown when an operation is attempted on a non-existant user.  
   * 
   * @author Shane Bryzak
   */
  public class NoSuchUserException extends Exception
  {
     public NoSuchUserException(String message)
     {
        super(message);
     }
     
     public NoSuchUserException(String message, Throwable cause)
     {
        super(message, cause);
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list