You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by ep...@apache.org on 2004/07/05 21:08:01 UTC

cvs commit: jakarta-turbine-fulcrum/security/memory/src/test/org/apache/fulcrum/security/memory/dynamic MemoryPermissionManagerTest.java

epugh       2004/07/05 12:08:01

  Modified:    security/memory/src/java/org/apache/fulcrum/security/memory
                        MemoryPermissionManagerImpl.java
                        MemoryRoleManagerImpl.java
                        MemoryGroupManagerImpl.java
                        MemoryUserManagerImpl.java
               security/memory/src/test/org/apache/fulcrum/security/memory/dynamic
                        MemoryPermissionManagerTest.java
  Added:       security/memory/src/java/org/apache/fulcrum/security/memory
                        MemoryHelper.java
  Log:
  Mkae name the primary key.
  
  Revision  Changes    Path
  1.3       +8 -22     jakarta-turbine-fulcrum/security/memory/src/java/org/apache/fulcrum/security/memory/MemoryPermissionManagerImpl.java
  
  Index: MemoryPermissionManagerImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/security/memory/src/java/org/apache/fulcrum/security/memory/MemoryPermissionManagerImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MemoryPermissionManagerImpl.java	10 Jan 2004 16:14:21 -0000	1.2
  +++ MemoryPermissionManagerImpl.java	5 Jul 2004 19:08:01 -0000	1.3
  @@ -53,7 +53,6 @@
    * <http://www.apache.org/>.
    */
   import java.util.ArrayList;
  -import java.util.Iterator;
   import java.util.List;
   
   import org.apache.commons.logging.Log;
  @@ -61,6 +60,7 @@
   import org.apache.fulcrum.security.entity.Permission;
   import org.apache.fulcrum.security.spi.AbstractPermissionManager;
   import org.apache.fulcrum.security.util.DataBackendException;
  +import org.apache.fulcrum.security.util.EntityExistsException;
   import org.apache.fulcrum.security.util.PermissionSet;
   import org.apache.fulcrum.security.util.UnknownEntityException;
   
  @@ -128,29 +128,20 @@
           throw new UnknownEntityException(
               "Unknown permission '" + permission + "'");
       }
  +    
       /**
        * Determines if the <code>Permission</code> exists in the security system.
        * 
  -     * @param permission a <code>Permission</code> value
  +     * @param permission a <code>String</code> value
        * @return true if the permission exists in the system, false otherwise
        * @throws DataBackendException when more than one Permission with the same name exists.
        * @throws Exception A generic exception.
        */
  -    public boolean checkExists(Permission permission)
  +    public boolean checkExists(String permissionName)
           throws DataBackendException
       {
  -        boolean exists = false;
  -        for (Iterator i = permissions.iterator(); i.hasNext();)
  -        {
  -            Permission p = (Permission) i.next();
  -            if (p.getName().equalsIgnoreCase(permission.getName()) | p.getId()
  -                == permission.getId())
  -            {
  -                exists = true;
  -            }
  -        }
  -        return exists;
  -    }
  +       return MemoryHelper.checkExists(permissions,permissionName);
  +    }    
   
       /**
        * Removes a Permission from the system.
  @@ -196,15 +187,10 @@
           throws DataBackendException
       {
   
  -        permission.setId(getUniqueId());
  +        permission.setId(MemoryHelper.getUniqueId());
           permissions.add(permission);
           return permission;
   
       }
  -   
   
  -    private Integer getUniqueId()
  -    {
  -        return new Integer(++uniqueId);
  -    }
   }
  
  
  
  1.2       +14 -28    jakarta-turbine-fulcrum/security/memory/src/java/org/apache/fulcrum/security/memory/MemoryRoleManagerImpl.java
  
  Index: MemoryRoleManagerImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/security/memory/src/java/org/apache/fulcrum/security/memory/MemoryRoleManagerImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MemoryRoleManagerImpl.java	5 Dec 2003 23:21:55 -0000	1.1
  +++ MemoryRoleManagerImpl.java	5 Jul 2004 19:08:01 -0000	1.2
  @@ -53,7 +53,6 @@
    * <http://www.apache.org/>.
    */
   import java.util.ArrayList;
  -import java.util.Iterator;
   import java.util.List;
   
   import org.apache.commons.logging.Log;
  @@ -61,6 +60,7 @@
   import org.apache.fulcrum.security.entity.Role;
   import org.apache.fulcrum.security.spi.AbstractRoleManager;
   import org.apache.fulcrum.security.util.DataBackendException;
  +import org.apache.fulcrum.security.util.EntityExistsException;
   import org.apache.fulcrum.security.util.RoleSet;
   import org.apache.fulcrum.security.util.UnknownEntityException;
   
  @@ -114,29 +114,19 @@
           }
           throw new UnknownEntityException("Unknown role '" + role + "'");
       }
  +    
       /**
  -      * Determines if the <code>Role</code> exists in the security system.
  -      *
  -      * @param role a <code>Role</code> value
  -      * @return true if the role exists in the system, false otherwise
  -      * @throws DataBackendException when more than one Role with
  -      *         the same name exists.
  -      * @throws Exception A generic exception.
  -      */
  -    public boolean checkExists(Role role) throws DataBackendException
  +     * Determines if the <code>Role</code> exists in the security system.
  +     * 
  +     * @param permission a <code>String</code> value
  +     * @return true if the role exists in the system, false otherwise
  +     * @throws DataBackendException when more than one Role with the same name exists.
  +     * @throws Exception A generic exception.
  +     */
  +    public boolean checkExists(String roleName)
       {
  -        boolean exists = false;
  -        for (Iterator i = roles.iterator(); i.hasNext();)
  -        {
  -            Role r = (Role) i.next();
  -            if (r.getName().equalsIgnoreCase(role.getName()) | r.getId()
  -                == role.getId())
  -            {
  -                exists = true;
  -            }
  -        }
  -        return exists;
  -    }
  +        return MemoryHelper.checkExists(roles,roleName); 
  +    }      
       /**
       		 * Retrieves all roles defined in the system.
       		 *
  @@ -162,7 +152,7 @@
           throws DataBackendException
       {
   
  -        role.setId(getUniqueId());
  +        role.setId(MemoryHelper.getUniqueId());
           roles.add(role);
           // add the role to system-wide cache
           getAllRoles().add(role);
  @@ -203,8 +193,4 @@
           throw new UnknownEntityException("Unknown role '" + role + "'");
       }
      
  -    private Object getUniqueId()
  -    {
  -        return new Integer(++uniqueId);
  -    }
   }
  
  
  
  1.2       +8 -37     jakarta-turbine-fulcrum/security/memory/src/java/org/apache/fulcrum/security/memory/MemoryGroupManagerImpl.java
  
  Index: MemoryGroupManagerImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/security/memory/src/java/org/apache/fulcrum/security/memory/MemoryGroupManagerImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MemoryGroupManagerImpl.java	5 Dec 2003 23:21:55 -0000	1.1
  +++ MemoryGroupManagerImpl.java	5 Jul 2004 19:08:01 -0000	1.2
  @@ -53,7 +53,6 @@
    * <http://www.apache.org/>.
    */
   import java.util.ArrayList;
  -import java.util.Iterator;
   import java.util.List;
   
   import org.apache.commons.logging.Log;
  @@ -62,6 +61,7 @@
   import org.apache.fulcrum.security.entity.Group;
   import org.apache.fulcrum.security.spi.AbstractGroupManager;
   import org.apache.fulcrum.security.util.DataBackendException;
  +import org.apache.fulcrum.security.util.EntityExistsException;
   import org.apache.fulcrum.security.util.GroupSet;
   import org.apache.fulcrum.security.util.UnknownEntityException;
   
  @@ -80,12 +80,9 @@
       private static Log log = LogFactory.getLog(MemoryGroupManagerImpl.class);
       private static List groups = new ArrayList();
   
  -
       /** Our Unique ID counter */
       private static int uniqueId = 0;
   
  -
  -   
       /**
       	 * Retrieves all groups defined in the system.
       	 *
  @@ -169,7 +166,7 @@
           {
           }
       }
  -
  +    
       /**
        * Determines if the <code>Group</code> exists in the security system.
        *
  @@ -179,30 +176,10 @@
        *         the same name exists.
        * @throws Exception A generic exception.
        */
  -    public boolean checkExists(Group group) throws DataBackendException
  -    {
  -        try
  -        {
  -            boolean exists = false;
  -            for (Iterator i = groups.iterator(); i.hasNext();)
  -            {
  -                Group g = (Group) i.next();
  -                if (g.getName().equalsIgnoreCase(group.getName()) | g.getId()
  -                    == group.getId())
  -                {
  -                    exists = true;
  -                }
  -            }
  -            return exists;
  -            //return groups.contains(group);
  -        }
  -        catch (Exception e)
  -        {
  -            throw new DataBackendException(
  -                "Problem checking if groups exists",
  -                e);
  -        }
  -    }
  +    public boolean checkExists(String groupName) throws DataBackendException
  +    {     
  +        return MemoryHelper.checkExists(groups,groupName);      
  +    }    
       /**
       	* Creates a new group with specified attributes.
       	*
  @@ -216,17 +193,11 @@
           throws DataBackendException
       {
           
  -            group.setId(getUniqueId());
  +            group.setId(MemoryHelper.getUniqueId());
               groups.add(group);
               // return the object with correct id
               return group;
          
       }
  -
  -    private Integer getUniqueId()
  -    {
  -        return new Integer(++uniqueId);
  -    }
  -
       
   }
  
  
  
  1.3       +5 -48     jakarta-turbine-fulcrum/security/memory/src/java/org/apache/fulcrum/security/memory/MemoryUserManagerImpl.java
  
  Index: MemoryUserManagerImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/security/memory/src/java/org/apache/fulcrum/security/memory/MemoryUserManagerImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MemoryUserManagerImpl.java	10 Jan 2004 16:15:03 -0000	1.2
  +++ MemoryUserManagerImpl.java	5 Jul 2004 19:08:01 -0000	1.3
  @@ -61,6 +61,7 @@
   import org.apache.fulcrum.security.entity.User;
   import org.apache.fulcrum.security.spi.AbstractUserManager;
   import org.apache.fulcrum.security.util.DataBackendException;
  +import org.apache.fulcrum.security.util.EntityExistsException;
   import org.apache.fulcrum.security.util.UnknownEntityException;
   import org.apache.fulcrum.security.util.UserSet;
   
  @@ -83,31 +84,6 @@
       /** Our Unique ID counter */
       private static int uniqueId = 0;
   
  -
  -    /**
  -     * Check whether a specified user's account exists.
  -     *
  -     * The login name is used for looking up the account.
  -     *
  -     * @param user The user to be checked.
  -     * @return true if the specified account exists
  -     * @throws DataBackendException if there was an error accessing
  -     *         the data backend.
  -     */
  -    public boolean checkExists(User user) throws DataBackendException
  -    {
  -        boolean exists = false;
  -        for (Iterator i = users.iterator(); i.hasNext();)
  -        {
  -            User u = (User) i.next();
  -            if (u.getName().equalsIgnoreCase(user.getName()) | u.getId()
  -                == user.getId())
  -            {
  -                exists = true;
  -            }
  -        }
  -        return exists;
  -    }
       /**
        * Check whether a specified user's account exists.
        *
  @@ -120,21 +96,8 @@
        */
       public boolean checkExists(String userName) throws DataBackendException
       {
  -        List tempUsers = new ArrayList();
  -        for (Iterator i = users.iterator(); i.hasNext();)
  -        {
  -            User user = (User) i.next();
  -            if (user.getName().equalsIgnoreCase(userName))
  -            {
  -                tempUsers.add(user);
  -            }
  -        }
  -        if (tempUsers.size() > 1)
  -        {
  -            throw new DataBackendException(
  -                "Multiple Users with same username '" + userName + "'");
  -        }
  -        return (tempUsers.size() == 1);
  +        return MemoryHelper.checkExists(users,userName); 
  +       
       }
       /**
        * Retrieve a user from persistent storage using username as the
  @@ -209,7 +172,7 @@
       {
          
               users.remove(user);
  -            user.setId(getUniqueId());
  +            user.setId(MemoryHelper.getUniqueId());
               users.add(user);
               return user;
           
  @@ -236,11 +199,5 @@
           {
               throw new UnknownEntityException("Unknown user '" + user + "'");
           }
  -    }
  -
  -  
  -    private Object getUniqueId()
  -    {
  -        return new Integer(++uniqueId);
       }
   }
  
  
  
  1.1                  jakarta-turbine-fulcrum/security/memory/src/java/org/apache/fulcrum/security/memory/MemoryHelper.java
  
  Index: MemoryHelper.java
  ===================================================================
  package org.apache.fulcrum.security.memory;
  
  import java.util.Iterator;
  import java.util.List;
  
  import org.apache.fulcrum.security.entity.SecurityEntity;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  /**
   *
   * This implementation keeps all objects in memory.  This is mostly meant to help
   * with testing and prototyping of ideas.
   *
   * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
   * @version $Id: MemoryHelper.java,v 1.1 2004/07/05 19:08:01 epugh Exp $
   */
  public class MemoryHelper
  {
  
      /** Our Unique ID counter */
      private static int uniqueId = 0;
     
      public static Integer getUniqueId()
      {
          return new Integer(++uniqueId);
      }
      
      public static boolean checkExists(List securityEntities, String name){
          boolean exists = false;
          for (Iterator i = securityEntities.iterator(); i.hasNext();)
          {
              SecurityEntity securityEntity = (SecurityEntity) i.next();
              if (securityEntity.getName().equalsIgnoreCase(name))
              {
                  exists = true;
              }
          }
          return exists;        
      }
  }
  
  
  
  1.2       +1 -0      jakarta-turbine-fulcrum/security/memory/src/test/org/apache/fulcrum/security/memory/dynamic/MemoryPermissionManagerTest.java
  
  Index: MemoryPermissionManagerTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/security/memory/src/test/org/apache/fulcrum/security/memory/dynamic/MemoryPermissionManagerTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MemoryPermissionManagerTest.java	5 Dec 2003 23:21:55 -0000	1.1
  +++ MemoryPermissionManagerTest.java	5 Jul 2004 19:08:01 -0000	1.2
  @@ -67,6 +67,7 @@
       }
       public void setUp()
       {
  +        
           try
           {
               this.setRoleFileName(null);
  
  
  

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