Return-Path: Delivered-To: apmail-cocoon-lenya-cvs-archive@cocoon.apache.org Received: (qmail 71979 invoked by uid 500); 28 May 2003 14:45:21 -0000 Mailing-List: contact lenya-cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Post: List-Help: List-Unsubscribe: List-Subscribe: Reply-To: "Lenya CVS Mailing List" Delivered-To: mailing list lenya-cvs@cocoon.apache.org Received: (qmail 71952 invoked from network); 28 May 2003 14:45:20 -0000 Date: 28 May 2003 14:45:19 -0000 Message-ID: <20030528144519.98345.qmail@icarus.apache.org> From: egli@apache.org To: cocoon-lenya-cvs@apache.org Subject: cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/workflow/impl RoleCondition.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N egli 2003/05/28 07:45:19 Modified: src/java/org/apache/lenya/cms/ac User.java Role.java src/java/org/apache/lenya/cms/workflow/impl RoleCondition.java Added: src/java/org/apache/lenya/cms/ac AccessControlException.java FileUser.java Group.java Log: Added the new User framework. This allows for adding and deleting users. There is a class which maps the users to the identity xml files format. Revision Changes Path 1.3 +163 -18 cocoon-lenya/src/java/org/apache/lenya/cms/ac/User.java Index: User.java =================================================================== RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ac/User.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- User.java 24 Apr 2003 13:52:37 -0000 1.2 +++ User.java 28 May 2003 14:45:18 -0000 1.3 @@ -1,37 +1,182 @@ /* - * User.java + * $Id$ + * + * The Apache Software License * - * Created on 9. April 2003, 12:40 + * Copyright (c) 2002 lenya. 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. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: "This product + * includes software developed by lenya (http://www.lenya.org)" + * + * 4. The name "lenya" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact contact@lenya.org + * + * 5. Products derived from this software may not be called "lenya" nor + * may "lenya" appear in their names without prior written permission + * of lenya. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: "This product includes software developed by lenya + * (http://www.lenya.org)" + * + * THIS SOFTWARE IS PROVIDED BY lenya "AS IS" WITHOUT ANY WARRANTY EXPRESS + * OR IMPLIED, INCLUDING THE WARRANTY OF NON-INFRINGEMENT AND THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * lenya WILL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY YOU AS A RESULT + * OF USING THIS SOFTWARE. IN NO EVENT WILL lenya BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR LOST PROFITS EVEN IF lenya HAS BEEN + * ADVISED OF THE POSSIBILITY OF THEIR OCCURRENCE. lenya WILL NOT BE LIABLE + * FOR ANY THIRD PARTY CLAIMS AGAINST YOU. + * + * Lenya includes software developed by the Apache Software Foundation, W3C, + * DOM4J Project, BitfluxEditor and Xopus. + * */ package org.apache.lenya.cms.ac; import java.util.HashSet; +import java.util.Iterator; import java.util.Set; +import org.apache.avalon.framework.configuration.Configuration; + /** * * @author nobby */ -public class User { +public abstract class User { + + protected String id; + protected String fullName; + protected String email; + protected String password; + protected Set groups = new HashSet(); + - /** Creates a new instance of User */ + private Group group; + public User() { + this(null, null, null, null); } - private Set roles = new HashSet(); - - public void addRole(Role role) { - assert role != null; - roles.add(role); - } - - public Role[] getRoles() { - return (Role[]) roles.toArray(new Role[roles.size()]); - } - - public boolean hasRole(Role role) { - return roles.contains(role); + /** + * Create a User instance + * @param id + */ + public User(String id) { + this(id, null, null, null); } - + + /** + * Create a User instance + * @param id + * @param fullName + * @param email + * @param password + */ + public User(String id, String fullName, String email, String password) { + this.id = id; + this.fullName = fullName; + this.email = email; + this.password = password; + } + + /** + * @return + */ + public String getEmail() { + return email; + } + + /** + * @return + */ + public String getFullName() { + return fullName; + } + + /** + * @return + */ + public Iterator getGroups() { + return groups.iterator(); + } + + /** + * @return + */ + public String getId() { + return id; + } + + /** + * @param string + */ + public void setEmail(String string) { + email = string; + } + + /** + * @param string + */ + public void setFullName(String string) { + fullName = string; + } + + /** + * @param set + */ + public void addGroup(Group group) { + groups.add(group); + group.addUser(this); + } + + /** + * @param set + */ + public void removeGroup(Group group) { + groups.remove(group); + group.removeUser(this); + } + + /** + * @param string + */ + public void setPassword(String string) { + password = string; + } + + public abstract void save() throws AccessControlException; + + public abstract void configure(Configuration config); } + + + + + + + + + + + + + + + 1.5 +18 -0 cocoon-lenya/src/java/org/apache/lenya/cms/ac/Role.java Index: Role.java =================================================================== RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ac/Role.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Role.java 24 Apr 2003 13:52:37 -0000 1.4 +++ Role.java 28 May 2003 14:45:18 -0000 1.5 @@ -6,6 +6,10 @@ package org.apache.lenya.cms.ac; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + /** * * @author nobby @@ -20,8 +24,22 @@ private String name; + private Set groups = new HashSet(); + public String getName() { return name; + } + + public void addGroup(Group group) { + groups.add(group); + } + + public void removeGroup(Group group) { + groups.remove(group); + } + + public Iterator getGroups() { + return groups.iterator(); } public boolean equals(Object otherObject) { 1.1 cocoon-lenya/src/java/org/apache/lenya/cms/ac/AccessControlException.java Index: AccessControlException.java =================================================================== package org.apache.lenya.cms.ac; /** * @author egli * * */ public class AccessControlException extends Exception { /** * Create an AccessControlException * */ public AccessControlException() { super(); } /** * Create an AccessControlException * * @param message */ public AccessControlException(String message) { super(message); } /** * Create an AccessControlException * * @param message * @param cause */ public AccessControlException(String message, Throwable cause) { super(message, cause); } /** * Create an AccessControlException * * @param cause */ public AccessControlException(Throwable cause) { super(cause); } } 1.1 cocoon-lenya/src/java/org/apache/lenya/cms/ac/FileUser.java Index: FileUser.java =================================================================== /* * $Id: FileUser.java,v 1.1 2003/05/28 14:45:18 egli Exp $ * * The Apache Software License * * Copyright (c) 2002 lenya. 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. All advertising materials mentioning features or use of this * software must display the following acknowledgment: "This product * includes software developed by lenya (http://www.lenya.org)" * * 4. The name "lenya" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact contact@lenya.org * * 5. Products derived from this software may not be called "lenya" nor * may "lenya" appear in their names without prior written permission * of lenya. * * 6. Redistributions of any form whatsoever must retain the following * acknowledgment: "This product includes software developed by lenya * (http://www.lenya.org)" * * THIS SOFTWARE IS PROVIDED BY lenya "AS IS" WITHOUT ANY WARRANTY EXPRESS * OR IMPLIED, INCLUDING THE WARRANTY OF NON-INFRINGEMENT AND THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * lenya WILL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY YOU AS A RESULT * OF USING THIS SOFTWARE. IN NO EVENT WILL lenya BE LIABLE FOR ANY SPECIAL, * INDIRECT OR CONSEQUENTIAL DAMAGES OR LOST PROFITS EVEN IF lenya HAS BEEN * ADVISED OF THE POSSIBILITY OF THEIR OCCURRENCE. lenya WILL NOT BE LIABLE * FOR ANY THIRD PARTY CLAIMS AGAINST YOU. * * Lenya includes software developed by the Apache Software Foundation, W3C, * DOM4J Project, BitfluxEditor and Xopus. * */ package org.apache.lenya.cms.ac; import java.io.File; import java.util.Iterator; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.DefaultConfiguration; import org.apache.avalon.framework.configuration.DefaultConfigurationSerializer; import org.w3c.dom.Document; /** * @author egli * * */ public class FileUser extends User { public static final String ID = "identity"; public static final String FULL_NAME = "fullname"; public static final String EMAIL = "email"; public static final String PASSWORD = "password"; public static final String GROUPS = "groups"; public static final String GROUP = "group"; public static final String PASSWORD_ATTRIBUTE = "type"; public static final String ID_ATTRIBUTE = "id"; public static final String CLASS_ATTRIBUTE = "class"; public static final String NAMESPACE_URI = ""; protected Document document; protected File xmlfile; protected DefaultConfiguration config; /** * @param id */ public FileUser(String id) { super(id); } /** * @return */ protected Configuration createDocument() { DefaultConfiguration config = new DefaultConfiguration(ID); config.setAttribute(ID_ATTRIBUTE, id); config.setAttribute(CLASS_ATTRIBUTE, this.getClass().getName()); DefaultConfiguration child = null; // add fullname node child = new DefaultConfiguration(FULL_NAME); child.setValue(fullName); config.addChild(child); // add email node child = new DefaultConfiguration(EMAIL); child.setValue(email); config.addChild(child); // add email child = new DefaultConfiguration(PASSWORD); child.setValue(email); child.setAttribute(PASSWORD_ATTRIBUTE, "md5"); config.addChild(child); // add group nodes child = new DefaultConfiguration(GROUP); config.addChild(child); Iterator groupsIter = getGroups(); while (groupsIter.hasNext()) { DefaultConfiguration groupNode = new DefaultConfiguration(GROUPS); groupNode.setValue(((Group) groupsIter.next()).getName()); child.addChild(groupNode); } return config; } /* (non-Javadoc) * @see org.apache.lenya.cms.ac.User#save() */ public void save() throws AccessControlException { DefaultConfigurationSerializer serializer = new DefaultConfigurationSerializer(); try { serializer.serializeToFile(xmlfile, config); } catch (Exception e) { throw new AccessControlException(e); } } /* (non-Javadoc) * @see org.apache.lenya.cms.ac.User#configure(org.apache.avalon.framework.configuration.Configuration) */ public void configure(Configuration config) { this.config.addAll(config); } } 1.1 cocoon-lenya/src/java/org/apache/lenya/cms/ac/Group.java Index: Group.java =================================================================== /* * $Id: Group.java,v 1.1 2003/05/28 14:45:18 egli Exp $ * * The Apache Software License * * Copyright (c) 2002 lenya. 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. All advertising materials mentioning features or use of this * software must display the following acknowledgment: "This product * includes software developed by lenya (http://www.lenya.org)" * * 4. The name "lenya" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact contact@lenya.org * * 5. Products derived from this software may not be called "lenya" nor * may "lenya" appear in their names without prior written permission * of lenya. * * 6. Redistributions of any form whatsoever must retain the following * acknowledgment: "This product includes software developed by lenya * (http://www.lenya.org)" * * THIS SOFTWARE IS PROVIDED BY lenya "AS IS" WITHOUT ANY WARRANTY EXPRESS * OR IMPLIED, INCLUDING THE WARRANTY OF NON-INFRINGEMENT AND THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * lenya WILL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY YOU AS A RESULT * OF USING THIS SOFTWARE. IN NO EVENT WILL lenya BE LIABLE FOR ANY SPECIAL, * INDIRECT OR CONSEQUENTIAL DAMAGES OR LOST PROFITS EVEN IF lenya HAS BEEN * ADVISED OF THE POSSIBILITY OF THEIR OCCURRENCE. lenya WILL NOT BE LIABLE * FOR ANY THIRD PARTY CLAIMS AGAINST YOU. * * Lenya includes software developed by the Apache Software Foundation, W3C, * DOM4J Project, BitfluxEditor and Xopus. * */ package org.apache.lenya.cms.ac; import java.util.HashSet; import java.util.Iterator; import java.util.Set; /** * @author egli * * */ public class Group { protected String name; protected Set roles = new HashSet(); protected Set users = new HashSet(); /** * Get the name of this group * * @return */ public String getName() { return name; } /** * Get all roles of this group * * @return */ public Iterator getRoles() { return roles.iterator(); } public Iterator getUsers() { return users.iterator(); } /** * Set the name of this group * * @param string */ public void setName(String string) { name = string; } /** * Add a role to this group * * @param role */ public void addRole(Role role) { roles.add(role); role.addGroup(this); } /** * Remove a role from this group * * @param role */ public void removeRole(Role role) { roles.remove(role); role.removeGroup(this); } public void addUser(User user) { users.add(user); } public void removeUser(User user) { users.remove(user); } } 1.3 +18 -5 cocoon-lenya/src/java/org/apache/lenya/cms/workflow/impl/RoleCondition.java Index: RoleCondition.java =================================================================== RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/workflow/impl/RoleCondition.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- RoleCondition.java 24 Apr 2003 13:53:00 -0000 1.2 +++ RoleCondition.java 28 May 2003 14:45:19 -0000 1.3 @@ -6,6 +6,10 @@ package org.apache.lenya.cms.workflow.impl; +import java.util.Iterator; +import java.util.Set; + +import org.apache.lenya.cms.ac.Group; import org.apache.lenya.cms.ac.Role; import org.apache.lenya.cms.ac.User; import org.apache.lenya.cms.workflow.Condition; @@ -27,15 +31,24 @@ */ public boolean isComplied(Situation situation) { User user = situation.getUser(); - Role userRoles[] = user.getRoles(); + Iterator userGroups = user.getGroups(); + Set userRoles = null; + + while (userGroups.hasNext()) { + Iterator groupRoles = ((Group)userGroups.next()).getRoles(); + while (groupRoles.hasNext()) { + userRoles.add(groupRoles.next()); + } + } Role conditionRole = new Role(getExpression().trim()); boolean complied = false; - for (int i = 0; i < userRoles.length; i++) { - if (conditionRole.equals(userRoles[i])) { - complied = true; - } + Iterator roles = userRoles.iterator(); + while (!complied && roles.hasNext()) { + if (conditionRole.equals(roles.next())) { + complied = true; + } } return complied; } --------------------------------------------------------------------- To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org