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/10/07 17:11:58 UTC

cvs commit: jakarta-turbine-fulcrum/security/api project.xml

epugh       2004/10/07 08:11:58

  Modified:    security/api/src/java/org/apache/fulcrum/security/model/turbine
                        TurbineModelManager.java
               security/api/src/java/org/apache/fulcrum/security/model/turbine/test
                        AbstractTurbineModelManagerTest.java
               security/api project.xml
  Added:       security/api/src/java/org/apache/fulcrum/security/model/turbine/entity
                        TurbineRole.java TurbineGroup.java TurbineUser.java
                        TurbineRolePermissionoff.java
                        TurbineUserGroupRole.java TurbinePermission.java
               security/api/src/java/org/apache/fulcrum/security/model/turbine
                        AbstractTurbineModelManager.java
  Log:
  Properly flesh out Turbine model.
  
  Revision  Changes    Path
  1.1                  jakarta-turbine-fulcrum/security/api/src/java/org/apache/fulcrum/security/model/turbine/entity/TurbineRole.java
  
  Index: TurbineRole.java
  ===================================================================
  package org.apache.fulcrum.security.model.turbine.entity;
  
  /*
   *  Copyright 2001-2004 The Apache Software Foundation
   *
   *  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 ofs 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.
   */
  
  import java.util.HashSet;
  import java.util.Set;
  
  import org.apache.fulcrum.security.entity.Permission;
  import org.apache.fulcrum.security.entity.Role;
  import org.apache.fulcrum.security.entity.impl.SecurityEntityImpl;
  import org.apache.fulcrum.security.util.PermissionSet;
  
  /**
   * Represents the "turbine" model where permissions are in a many to many
   * relationship to roles, roles are related to groups are related to users, all
   * in many to many relationships.
   * 
   * @author <a href="mailto:epugh@upstate.com">Eric Pugh </a>
   * @version $Id: TurbineRole.java,v 1.1 2004/10/07 15:11:57 epugh Exp $
   */
  public class TurbineRole extends SecurityEntityImpl implements Role {
      private Set permissionSet = new PermissionSet();
  
      private Set userGroupRoleSet = new HashSet();
  
      /**
       * @return
       */
      public PermissionSet getPermissions() {
          if (permissionSet instanceof PermissionSet)
              return (PermissionSet) permissionSet;
          else {
              permissionSet = new PermissionSet(permissionSet);
              return (PermissionSet) permissionSet;
          }
      }
  
      /**
       * @return
       */
      public Set getPermissionsAsSet() {
          return permissionSet;
      }
  
      public void setPermissionsAsSet(Set permissions) {
          this.permissionSet = permissions;
          ;
      }
  
      /**
       * @param permissionSet
       */
      public void setPermissions(PermissionSet permissionSet) {
          if (permissionSet != null)
              this.permissionSet = permissionSet;
          else
              this.permissionSet = new PermissionSet();
      }
  
      /**
       * This method should only be used by a RoleManager. Not directly.
       * 
       * @param permission
       */
      public void addPermission(Permission permission) {
          getPermissions().add(permission);
      }
  
      /**
       * This method should only be used by a RoleManager. Not directly.
       * 
       * @param permission
       */
      public void removePermission(Permission permission) {
          getPermissions().remove(permission);
      }
  
      /**
       * @return
       */
      public Set getUserGroupRoleSet() {
  
          return userGroupRoleSet;
      }
  
      /**
       * @param userGroupRoleSet
       */
      public void setUserGroupRoleSet(Set userGroupRoleSet) {
  
          this.userGroupRoleSet = userGroupRoleSet;
  
      }
  
      /**
       * This method should only be used by a RoleManager. Not directly.
       * 
       * @param group
       */
      public void addUserGroupRole(TurbineUserGroupRole userGroupRole) {
          getUserGroupRoleSet().add(userGroupRole);
      }
  
      /**
       * This method should only be used by a RoleManager. Not directly.
       * 
       * @param group
       */
      public void removeUserGroupRole(TurbineUserGroupRole userGroupRole) {
          getUserGroupRoleSet().remove(userGroupRole);
      }
  
     
  }
  
  
  1.1                  jakarta-turbine-fulcrum/security/api/src/java/org/apache/fulcrum/security/model/turbine/entity/TurbineGroup.java
  
  Index: TurbineGroup.java
  ===================================================================
  package org.apache.fulcrum.security.model.turbine.entity;
  
  /*
   *  Copyright 2001-2004 The Apache Software Foundation
   *
   *  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.
   */
  
  import java.util.HashSet;
  import java.util.Set;
  
  import org.apache.fulcrum.security.entity.Group;
  import org.apache.fulcrum.security.entity.impl.SecurityEntityImpl;
  
  /**
   * Represents the "turbine" model where permissions are in a many to many
   * relationship to roles, roles are related to groups are related to users, all
   * in many to many relationships.
   * 
   * @author <a href="mailto:epugh@upstate.com">Eric Pugh </a>
   * @version $Id: TurbineGroup.java,v 1.1 2004/10/07 15:11:57 epugh Exp $
   */
  public class TurbineGroup extends SecurityEntityImpl implements Group {
      private Set userGroupRoleSet = new HashSet();
  
      /**
       * @return
       */
      public Set getUserGroupRoleSet() {
  
          return userGroupRoleSet;
      }
  
      /**
       * @param userGroupRoleSet
       */
      public void setUserGroupRoleSet(Set userGroupRoleSet) {
          this.userGroupRoleSet = userGroupRoleSet;
  
      }
  
      public void addUserGroupRole(TurbineUserGroupRole userGroupRole) {
          getUserGroupRoleSet().add(userGroupRole);
      }
  
      public void removeUserGroupRole(TurbineUserGroupRole userGroupRole) {
          getUserGroupRoleSet().remove(userGroupRole);
      }
  
  }
  
  
  1.1                  jakarta-turbine-fulcrum/security/api/src/java/org/apache/fulcrum/security/model/turbine/entity/TurbineUser.java
  
  Index: TurbineUser.java
  ===================================================================
  package org.apache.fulcrum.security.model.turbine.entity;
  /*
   *  Copyright 2001-2004 The Apache Software Foundation
   *
   *  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.
   */
  
  import java.util.HashSet;
  import java.util.Set;
  
  import org.apache.fulcrum.security.entity.User;
  import org.apache.fulcrum.security.entity.impl.SecurityEntityImpl;
  
  /**
   * Represents the "turbine" model where permissions are in a many to 
   * many relationship to roles,
   * roles are related to groups are related to users,
   * all in many to many relationships.
   * 
   * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
   * @version $Id: TurbineUser.java,v 1.1 2004/10/07 15:11:57 epugh Exp $
   */
  public class TurbineUser extends SecurityEntityImpl implements User
  {
      private Set userGroupRoleSet = new HashSet();
      private String password;
  
      /**
       * @return
       */
      public Set getUserGroupRoleSet()
      {
  
      		return  userGroupRoleSet;
      }
      /**
       * @param userGroupRoleSet
       */
      public void setUserGroupRoleSet(Set userGroupRoleSet)
      {
      		this.userGroupRoleSet = userGroupRoleSet;
      	
      }
      
      /**
       * @return
       */
      public String getPassword()
      {
          return password;
      }
      /**
       * @param password
       */
      public void setPassword(String password)
      {
          this.password = password;
      }    
      public void addUserGroupRole(TurbineUserGroupRole userGroupRole)
      {
          getUserGroupRoleSet().add(userGroupRole);
      }
      public void removeUserGroupRole(TurbineUserGroupRole userGroupRole)
      {
          getUserGroupRoleSet().remove(userGroupRole);
      }
      
  	
  }
  
  
  
  1.1                  jakarta-turbine-fulcrum/security/api/src/java/org/apache/fulcrum/security/model/turbine/entity/TurbineRolePermissionoff.java
  
  Index: TurbineRolePermissionoff.java
  ===================================================================
  package org.apache.fulcrum.security.model.turbine.entity;
  
  /*
   *  Copyright 2001-2004 The Apache Software Foundation
   *
   *  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.
   */
  
  import org.apache.fulcrum.security.entity.Permission;
  import org.apache.fulcrum.security.entity.Role;
  
  /**
   * Represents the "turbine" model where permissions are in a many to many
   * relationship to roles, roles are related to groups are related to users, all
   * in many to many relationships.
   * 
   * @author <a href="mailto:epugh@upstate.com">Eric Pugh </a>
   * @version $Id: TurbineRolePermissionoff.java,v 1.1 2004/10/07 15:11:57 epugh Exp $
   */
  public class TurbineRolePermissionoff {
      private Role role;
  
      private Permission permission;
  
      /**
       * @return Returns the permission.
       */
      public Permission getPermission() {
          return permission;
      }
  
      /**
       * @return Returns the role.
       */
      public Role getRole() {
          return role;
      }
  
      /**
       * @param permission
       *            The permission to set.
       */
      public void setPermission(Permission permission) {
          this.permission = permission;
      }
  
      /**
       * @param role
       *            The role to set.
       */
      public void setRole(Role role) {
          this.role = role;
      }
  }
  
  
  1.1                  jakarta-turbine-fulcrum/security/api/src/java/org/apache/fulcrum/security/model/turbine/entity/TurbineUserGroupRole.java
  
  Index: TurbineUserGroupRole.java
  ===================================================================
  package org.apache.fulcrum.security.model.turbine.entity;
  
  /*
   *  Copyright 2001-2004 The Apache Software Foundation
   *
   *  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.
   */
  
  import java.io.Serializable;
  
  import org.apache.fulcrum.security.entity.Group;
  import org.apache.fulcrum.security.entity.Role;
  import org.apache.fulcrum.security.entity.User;
  
  
  /**
   * Represents the "turbine" model where permissions are in a many to many
   * relationship to roles, roles are related to groups are related to users, all
   * in many to many relationships.
   * 
   * @author <a href="mailto:epugh@upstate.com">Eric Pugh </a>
   * @version $Id: TurbineUserGroupRole.java,v 1.1 2004/10/07 15:11:57 epugh Exp $
   */
  public class TurbineUserGroupRole implements Serializable {
      private User user;
      private Group group;
      private Role role;
      private int hashCode;
      private boolean hashCodeGenerated=false;
      
      /**
       * @return Returns the group.
       */
      public Group getGroup() {
          return group;
      }
      /**
       * @return Returns the role.
       */
      public Role getRole() {
          return role;
      }
      /**
       * @return Returns the user.
       */
      public User getUser() {
          return user;
      }
      /**
       * @param group The group to set.
       */
      public void setGroup(Group group) {
          this.group = group;
      }
      /**
       * @param role The role to set.
       */
      public void setRole(Role role) {
          this.role = role;
      }
      /**
       * @param user The user to set.
       */
      public void setUser(User user) {
          this.user = user;
      }
      
      public boolean equals(Object obj)
      {
          if (null == obj)
          {
              return false;
          }
          if (!(obj instanceof TurbineUserGroupRole))
          {
              return false;
          }
          else
          {
              TurbineUserGroupRole mObj =(TurbineUserGroupRole) obj;
              if (null != this.getRole() && null != mObj.getRole())
              {
                  if (!this.getRole().equals(mObj.getRole()))
                  {
                      return false;
                  }
              }
              else
              {
                  return false;
              }
              if (null != this.getUser() && null != mObj.getUser())
              {
                  if (!this.getUser().equals(mObj.getUser()))
                  {
                      return false;
                  }
              }
              else
              {
                  return false;
              }
              if (null != this.getGroup() && null != mObj.getGroup())
              {
                  if (!this.getGroup().equals(mObj.getGroup()))
                  {
                      return false;
                  }
              }
              else
              {
                  return false;
              }
              return true;
          }
      }
  
  
      public int hashCode()
      {
          if (!hashCodeGenerated)
          {
              StringBuffer sb = new StringBuffer();
              if (null != this.getRole())
              {
                  sb.append(this.getRole().hashCode());
                  sb.append(":");
              }
              else
              {
                  return super.hashCode();
              }
              if (null != this.getUser())
              {
                  sb.append(this.getUser().hashCode());
                  sb.append(":");
              }
              else
              {
                  return super.hashCode();
              }
              if (null != this.getGroup())
              {
                  sb.append(this.getGroup().hashCode());
                  sb.append(":");
              }
              else
              {
                  return super.hashCode();
              }
              this.hashCode = sb.toString().hashCode();
          }
          return this.hashCode;
      }
  
  
      public String toString()
      {
          return super.toString();
      }    
  }
  
  
  1.1                  jakarta-turbine-fulcrum/security/api/src/java/org/apache/fulcrum/security/model/turbine/entity/TurbinePermission.java
  
  Index: TurbinePermission.java
  ===================================================================
  package org.apache.fulcrum.security.model.turbine.entity;
  
  /*
   *  Copyright 2001-2004 The Apache Software Foundation
   *
   *  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 ofs 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.
   */
  
  import java.util.Set;
  
  import org.apache.fulcrum.security.entity.Permission;
  import org.apache.fulcrum.security.entity.Role;
  import org.apache.fulcrum.security.entity.impl.SecurityEntityImpl;
  import org.apache.fulcrum.security.util.RoleSet;
  
  /**
   * Represents the "turbine" model where permissions are in a many to many
   * relationship to roles, roles are related to groups are related to users, all
   * in many to many relationships.
   * 
   * @author <a href="mailto:epugh@upstate.com">Eric Pugh </a>
   * @version $Id: TurbinePermission.java,v 1.1 2004/10/07 15:11:57 epugh Exp $
   */
  public class TurbinePermission extends SecurityEntityImpl implements Permission {
      private Set roleSet = new RoleSet();
  
      /**
       * @return
       */
      public RoleSet getRoles() {
          if (roleSet instanceof RoleSet)
              return (RoleSet) roleSet;
          else {
              roleSet = new RoleSet(roleSet);
              return (RoleSet) roleSet;
          }
      }
  
      /**
       * @return
       */
      public Set getRolesAsSet() {
          return roleSet;
      }
  
      public void setRolesAsSet(Set roles) {
          this.roleSet = roles;
      }
  
      /**
       * @param roleSet
       */
      public void setRoles(RoleSet roleSet) {
          if (roleSet != null)
              this.roleSet = roleSet;
          else
              this.roleSet = new RoleSet();
      }
  
      /**
       * This method should only be used by a RoleManager. Not directly.
       * 
       * @param permission
       */
      public void addRole(Role role) {
          getRoles().add(role);
      }
  
      /**
       * This method should only be used by a RoleManager. Not directly.
       * 
       * @param permission
       */
      public void removeRole(Role role) {
          getRoles().remove(role);
      }
  
     
  
     
  }
  
  
  1.3       +47 -3     jakarta-turbine-fulcrum/security/api/src/java/org/apache/fulcrum/security/model/turbine/TurbineModelManager.java
  
  Index: TurbineModelManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/security/api/src/java/org/apache/fulcrum/security/model/turbine/TurbineModelManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TurbineModelManager.java	5 Jul 2004 19:28:21 -0000	1.2
  +++ TurbineModelManager.java	7 Oct 2004 15:11:57 -0000	1.3
  @@ -15,10 +15,11 @@
    *  limitations under the License.
    */
   
  +import org.apache.fulcrum.security.ModelManager;
   import org.apache.fulcrum.security.entity.Group;
  +import org.apache.fulcrum.security.entity.Permission;
   import org.apache.fulcrum.security.entity.Role;
   import org.apache.fulcrum.security.entity.User;
  -import org.apache.fulcrum.security.model.dynamic.DynamicModelManager;
   import org.apache.fulcrum.security.util.DataBackendException;
   import org.apache.fulcrum.security.util.UnknownEntityException;
   
  @@ -28,7 +29,7 @@
    * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
    * @version $Id$
    */
  -public interface TurbineModelManager extends DynamicModelManager
  +public interface TurbineModelManager extends ModelManager
   {
   
       /**
  @@ -43,6 +44,49 @@
       	* @return A Group object that represents the global group.
       	*/
       Group getGlobalGroup() throws DataBackendException;
  +    
  +    /**
  +     * Puts a permission in a role
  +     * 
  +     * This method is used when adding a permission to a role
  +     * 
  +     * @param user the User.
  +     * @throws DataBackendException if there was an error accessing the data backend.
  +     * @throws UnknownEntityException if the account is not present.
  +     */
  +    void grant(Role role, Permission permission)
  +        throws DataBackendException, UnknownEntityException;
  +    /**
  +     * Removes a permission from a role
  +     * 
  +     * @param role the Role.
  +     * @throws DataBackendException if there was an error accessing the data backend.
  +     * @throws UnknownEntityException if the user or group is not present.
  +     */
  +    void revoke(Role role, Permission permission)
  +        throws DataBackendException, UnknownEntityException;
  +
  +    /**
  +     * Revokes all roles from an User.
  +     * 
  +     * This method is typically used when deleting an account.
  +     * 
  +     * @param user the User.
  +     * @throws DataBackendException if there was an error accessing the data backend.
  +     * @throws UnknownEntityException if the account is not present.
  +     */
  +    void revokeAll(User user) throws DataBackendException, UnknownEntityException;
  +    /**
  +     * Revokes all permissions from a Role.
  +     * 
  +     * This method is typically used when deleting a Role.
  +     * 
  +     * @param role the Role
  +     * @throws DataBackendException if there was an error accessing the data backend.
  +     * @throws UnknownEntityException if the Role is not present.
  +     */
  +    void revokeAll(Role role) throws DataBackendException, UnknownEntityException;
  +   
   
       /**
        * Grant an User a Role in a Group.
  
  
  
  1.1                  jakarta-turbine-fulcrum/security/api/src/java/org/apache/fulcrum/security/model/turbine/AbstractTurbineModelManager.java
  
  Index: AbstractTurbineModelManager.java
  ===================================================================
  package org.apache.fulcrum.security.model.turbine;
  
  /*
   *  Copyright 2001-2004 The Apache Software Foundation
   *
   *  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.
   */
  
  import org.apache.fulcrum.security.entity.Group;
  import org.apache.fulcrum.security.entity.Permission;
  import org.apache.fulcrum.security.entity.Role;
  import org.apache.fulcrum.security.entity.User;
  import org.apache.fulcrum.security.model.turbine.entity.TurbineRole;
  import org.apache.fulcrum.security.model.turbine.entity.TurbineUser;
  import org.apache.fulcrum.security.model.turbine.entity.TurbineUserGroupRole;
  import org.apache.fulcrum.security.spi.AbstractManager;
  import org.apache.fulcrum.security.util.DataBackendException;
  import org.apache.fulcrum.security.util.EntityExistsException;
  import org.apache.fulcrum.security.util.UnknownEntityException;
  
  /**
   * Holds shared functionality between different implementations of
   * TurbineModelManager's.
   * 
   * @author <a href="mailto:epugh@upstate.com">Eric Pugh </a>
   * @version $Id: AbstractDynamicModelManager.java,v 1.2 2004/07/07 18:18:09
   *          epugh Exp $
   */
  public abstract class AbstractTurbineModelManager extends AbstractManager
  		implements TurbineModelManager {
      /**
       * Provides a reference to the Group object that represents the <a
       * href="#global">global group </a>.
       * 
       * @return A Group object that represents the global group.
       */
      public Group getGlobalGroup() throws DataBackendException {
          Group g = null;
          try {
              g = getGroupManager().getGroupByName(GLOBAL_GROUP_NAME);
          } catch (UnknownEntityException uee) {
              g = getGroupManager().getGroupInstance(GLOBAL_GROUP_NAME);
              try {
                  getGroupManager().addGroup(g);
              } catch (EntityExistsException eee) {
                  throw new DataBackendException(eee.getMessage(), eee);
              }
  
          }
          return g;
      }    
  	/**
  	 * Revokes all permissions and groups from a Role.
  	 * 
  	 * This method is used when deleting a Role.
  	 * 
  	 * @param role
  	 *            the Role
  	 * @throws DataBackendException
  	 *             if there was an error accessing the data backend.
  	 * @throws UnknownEntityException
  	 *             if the Role is not present.
  	 */
  	public synchronized void revokeAll(Role role) throws DataBackendException,
  			UnknownEntityException {
  		boolean roleExists = false;
  		roleExists = getRoleManager().checkExists(role);
  		if (roleExists) {
  
  			Object permissions[] = ((TurbineRole) role).getPermissions()
  					.toArray();
  			for (int i = 0; i < permissions.length; i++) {
  				revoke(role, (Permission) permissions[i]);
  			}
  		} else {
  			throw new UnknownEntityException("Unknown role '" + role.getName()
  					+ "'");
  		}
  
  	}
      
      /**
       * Revokes all roles and groups from a User.
       * 
       * This method is used when deleting a User.
       * 
       * @param user
       *            the User
       * @throws DataBackendException
       *             if there was an error accessing the data backend.
       * @throws UnknownEntityException
       *             if the Role is not present.
       */
      public synchronized void revokeAll(User user) throws DataBackendException,
              UnknownEntityException {
          boolean userExists = false;
          userExists = getUserManager().checkExists(user);
          if (userExists) {
  
              Object userGroupRoles[] = ((TurbineUser) user).getUserGroupRoleSet()
                      .toArray();
              for (int i = 0; i < userGroupRoles.length; i++) {
                  TurbineUserGroupRole ugr =(TurbineUserGroupRole)userGroupRoles[i];
                  revoke(user, ugr.getGroup(),ugr.getRole());
              }
          } else {
              throw new UnknownEntityException("Unknown user '" + user.getName()
                      + "'");
          }
  
      }    
  }
  
  
  1.4       +182 -11   jakarta-turbine-fulcrum/security/api/src/java/org/apache/fulcrum/security/model/turbine/test/AbstractTurbineModelManagerTest.java
  
  Index: AbstractTurbineModelManagerTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/security/api/src/java/org/apache/fulcrum/security/model/turbine/test/AbstractTurbineModelManagerTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractTurbineModelManagerTest.java	21 Sep 2004 12:04:50 -0000	1.3
  +++ AbstractTurbineModelManagerTest.java	7 Oct 2004 15:11:57 -0000	1.4
  @@ -15,9 +15,25 @@
    *  limitations under the License.
    */
   
  +import java.util.Iterator;
  +import java.util.Set;
  +
  +import org.apache.fulcrum.security.GroupManager;
  +import org.apache.fulcrum.security.PermissionManager;
  +import org.apache.fulcrum.security.RoleManager;
  +import org.apache.fulcrum.security.SecurityService;
  +import org.apache.fulcrum.security.UserManager;
   import org.apache.fulcrum.security.entity.Group;
  -import org.apache.fulcrum.security.model.dynamic.test.AbstractDynamicModelManagerTest;
  +import org.apache.fulcrum.security.entity.Permission;
  +import org.apache.fulcrum.security.entity.Role;
  +import org.apache.fulcrum.security.entity.User;
   import org.apache.fulcrum.security.model.turbine.TurbineModelManager;
  +import org.apache.fulcrum.security.model.turbine.entity.TurbineGroup;
  +import org.apache.fulcrum.security.model.turbine.entity.TurbineRole;
  +import org.apache.fulcrum.security.model.turbine.entity.TurbineUser;
  +import org.apache.fulcrum.security.model.turbine.entity.TurbineUserGroupRole;
  +import org.apache.fulcrum.security.util.PermissionSet;
  +import org.apache.fulcrum.testcontainer.BaseUnitTest;
   
   
   /**
  @@ -26,9 +42,38 @@
    * To change the template for this generated type comment go to
    * Window>Preferences>Java>Code Generation>Code and Comments
    */
  -public abstract class AbstractTurbineModelManagerTest extends AbstractDynamicModelManagerTest
  +public abstract class AbstractTurbineModelManagerTest extends BaseUnitTest
   {
  -   
  +    protected Role role;
  +
  +    protected TurbineModelManager modelManager;
  +
  +    protected RoleManager roleManager;
  +
  +    protected GroupManager groupManager;
  +
  +    protected PermissionManager permissionManager;
  +
  +    protected UserManager userManager;
  +
  +    protected SecurityService securityService;
  +
  +    public void setUp() throws Exception {
  +        super.setUp();
  +        roleManager = securityService.getRoleManager();
  +        userManager = securityService.getUserManager();
  +        groupManager = securityService.getGroupManager();
  +        permissionManager = securityService.getPermissionManager();
  +        modelManager = (TurbineModelManager) securityService.getModelManager();
  +    }
  +
  +    public void tearDown() {
  +        this.release(roleManager);
  +        this.release(userManager);
  +        this.release(groupManager);
  +        this.release(permissionManager);
  +        this.release(modelManager);
  +    }   
       /**
        * Constructor for AbstractTurbineModelManagerTest.
        * @param arg0
  @@ -41,17 +86,143 @@
   
   	public void testGetGlobalGroup() throws Exception
   	{
  -		TurbineModelManager tgm = (TurbineModelManager)securityService.getModelManager();
  -		Group global =tgm.getGlobalGroup();
  +		
  +		Group global =modelManager.getGlobalGroup();
   		assertNotNull(global);
   		assertEquals(global.getName(),TurbineModelManager.GLOBAL_GROUP_NAME);
   	}
   	
   	
  -	/**
  -	 * Not needed in Turbine model
  -	 */
  -	public void testAddRemoveDelegate() throws Exception {
  -		//NOOP
  -	}
  +    public void testGrantRolePermission() throws Exception {
  +        Permission permission = permissionManager.getPermissionInstance();
  +        permission.setName("ANSWER_PHONE");
  +        permissionManager.addPermission(permission);
  +        role = roleManager.getRoleInstance("RECEPTIONIST");
  +        roleManager.addRole(role);
  +        modelManager.grant(role, permission);
  +        role = roleManager.getRoleById(role.getId());
  +        PermissionSet permissions = ((TurbineRole) role).getPermissions();
  +        assertEquals(1, permissions.size());
  +        assertTrue(((TurbineRole) role).getPermissions().contains(permission));
  +    }
  +
  +    public void testRevokeRolePermission() throws Exception {
  +        Permission permission = securityService.getPermissionManager()
  +                .getPermissionInstance();
  +        permission.setName("ANSWER_FAX");
  +        securityService.getPermissionManager().addPermission(permission);
  +        role = roleManager.getRoleInstance("SECRETARY");
  +        roleManager.addRole(role);
  +        modelManager.grant(role, permission);
  +        role = roleManager.getRoleById(role.getId());
  +        PermissionSet permissions = ((TurbineRole) role).getPermissions();
  +        assertEquals(1, permissions.size());
  +        modelManager.revoke(role, permission);
  +        role = roleManager.getRoleById(role.getId());
  +        permissions = ((TurbineRole) role).getPermissions();
  +        assertEquals(0, permissions.size());
  +        assertFalse(((TurbineRole) role).getPermissions().contains(permission));
  +    }
  +
  +    public void testRevokeAllRole() throws Exception {
  +        Permission permission = securityService.getPermissionManager()
  +                .getPermissionInstance();
  +        Permission permission2 = securityService.getPermissionManager()
  +                .getPermissionInstance();
  +        permission.setName("SEND_SPAM");
  +        permission2.setName("ANSWER_EMAIL");
  +        securityService.getPermissionManager().addPermission(permission);
  +        securityService.getPermissionManager().addPermission(permission2);
  +        role = roleManager.getRoleInstance("HELPER");
  +        roleManager.addRole(role);
  +        modelManager.grant(role, permission);
  +        modelManager.grant(role, permission2);
  +        role = roleManager.getRoleById(role.getId());
  +        PermissionSet permissions = ((TurbineRole) role).getPermissions();
  +        assertEquals(2, permissions.size());
  +        modelManager.revokeAll(role);
  +        role = roleManager.getRoleById(role.getId());
  +        permissions = ((TurbineRole) role).getPermissions();
  +        assertEquals(0, permissions.size());
  +    }
  +
  +    public void testRevokeAllUser() throws Exception {
  +        Group group = securityService.getGroupManager().getGroupInstance();
  +        group.setName("TEST_REVOKEALLUSER_GROUP");
  +        securityService.getGroupManager().addGroup(group);
  +        Role role = securityService.getRoleManager().getRoleInstance();
  +        role.setName("TEST_REVOKEALLUSER_ROLE");
  +        securityService.getRoleManager().addRole(role);
  +              
  +        User user = userManager.getUserInstance("calvin");
  +        userManager.addUser(user, "calvin");
  +        modelManager.grant(user, group,role);
  +       
  +        group = groupManager.getGroupById(group.getId());
  +        Set userGroupRoleSet = ((TurbineGroup) group).getUserGroupRoleSet();
  +        assertEquals(1, userGroupRoleSet.size());
  +        Set userGroupRoleSet2 = ((TurbineGroup) group).getUserGroupRoleSet();
  +        assertEquals(1, userGroupRoleSet2.size());
  +
  +        modelManager.revokeAll(user);
  +        assertEquals(0, ((TurbineGroup) group).getUserGroupRoleSet().size());
  +        role = securityService.getRoleManager().getRoleByName(
  +                "TEST_REVOKEALLUSER_ROLE");
  +
  +        //assertFalse(((TurbineRole) role).getGroups().contains(group));
  +
  +    }
  +
  +   
  +
  +    public void testGrantUserGroupRole() throws Exception {
  +        Group group = securityService.getGroupManager().getGroupInstance();
  +        group.setName("TEST_GROUP");
  +        securityService.getGroupManager().addGroup(group);
  +        Role role = roleManager.getRoleInstance();
  +        role.setName("TEST_Role");
  +        roleManager.addRole(role);
  +        User user = userManager.getUserInstance("Clint");
  +        userManager.addUser(user, "clint");
  +        modelManager.grant(user, group,role);
  +        boolean ugrFound = false;
  +        TurbineUserGroupRole ugr=null;
  +        for(Iterator i = ((TurbineUser) user).getUserGroupRoleSet().iterator();i.hasNext();){
  +            ugr = (TurbineUserGroupRole)i.next();
  +            if(ugr.getUser().equals(user)&& ugr.getGroup().equals(group) && ugr.getRole().equals(role)){
  +                ugrFound=true;
  +                break;
  +            }
  +        }
  +        assertTrue(ugrFound);;
  +        assertTrue(ugr.getGroup().equals(group));
  +        assertTrue(ugr.getUser().equals(user));
  +
  +    }
  +
  +    public void testRevokeUserGroupRole() throws Exception {
  +        Group group = securityService.getGroupManager().getGroupInstance();
  +        group.setName("TEST_REVOKE");
  +        securityService.getGroupManager().addGroup(group);
  +        User user = userManager.getUserInstance("Lima");
  +        userManager.addUser(user, "pet");
  +        Role role = roleManager.getRoleInstance();
  +        role.setName("TEST_REVOKE_ROLE");
  +        roleManager.addRole(role);     
  +        modelManager.grant(user, group,role);
  +        modelManager.revoke(user, group,role);
  +        boolean ugrFound = false;
  +        TurbineUserGroupRole ugr=null;
  +        for(Iterator i = ((TurbineUser) user).getUserGroupRoleSet().iterator();i.hasNext();){
  +            ugr = (TurbineUserGroupRole)i.next();
  +            if(ugr.getUser().equals(user)&& ugr.getGroup().equals(group) && ugr.getRole().equals(role)){
  +                ugrFound=true;
  +                break;
  +            }
  +        }
  +        assertFalse(ugrFound);;
  +     
  +    }
  +
  +
   }
  
  
  
  1.7       +1 -1      jakarta-turbine-fulcrum/security/api/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/security/api/project.xml,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- project.xml	5 Jul 2004 19:06:43 -0000	1.6
  +++ project.xml	7 Oct 2004 15:11:58 -0000	1.7
  @@ -3,7 +3,7 @@
     <extend>${basedir}/../project.xml</extend>
     <id>fulcrum-security-api</id>
     <name>Fulcrum Security API</name>
  -  <currentVersion>1.0.6</currentVersion>
  +  <currentVersion>1.0.7-dev</currentVersion>
   
     <dependencies>
       <dependency>
  
  
  

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