You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2003/06/25 16:38:31 UTC
cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/ac2/file FileAccessController.java FilePolicyManager.java
andreas 2003/06/25 07:38:31
Modified: src/java/org/apache/lenya/cms/ac FileGroup.java
FileUser.java User.java FileRole.java Group.java
LDAPUser.java Role.java
Added: src/java/org/apache/lenya/cms/ac2 PolicyManager.java
Accreditable.java PolicyAuthorizer.java
AccessController.java Machine.java
Identifiable.java Identity.java World.java
URLPolicy.java Policy.java DefaultPolicy.java
Credential.java Authorizer.java
src/java/org/apache/lenya/cms/ac2/workflow
WorkflowAuthorizer.java
src/java/org/apache/lenya/cms/ac2/file
FileAccessController.java FilePolicyManager.java
Log:
initial checkin of new access control implementation
Revision Changes Path
1.6 +45 -34 cocoon-lenya/src/java/org/apache/lenya/cms/ac/FileGroup.java
Index: FileGroup.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ac/FileGroup.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FileGroup.java 25 Jun 2003 08:56:32 -0000 1.5
+++ FileGroup.java 25 Jun 2003 14:38:29 -0000 1.6
@@ -50,13 +50,11 @@
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.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.configuration.DefaultConfigurationSerializer;
-import org.apache.lenya.cms.publication.Publication;
import org.apache.log4j.Category;
/**
@@ -64,7 +62,7 @@
*
*
*/
-public class FileGroup extends Group {
+public class FileGroup extends Group implements Item {
private static Category log = Category.getInstance(FileGroup.class);
public static final String GROUP = "group";
@@ -72,31 +70,32 @@
public static final String ROLE = "role";
public static final String NAME_ATTRIBUTE = "name";
public static final String CLASS_ATTRIBUTE = "class";
-
- private Publication publication;
-
- /**
- * Create a new instance of <code>FileGroup</code>
- *
- * @param publication to which the group will be attached to
- * @param name the name of the group
+
+ /**
+ * Creates a new FileGroup object.
+ */
+ public FileGroup() {
+ }
+
+ /**
+ * Create a new instance of <code>FileGroup</code>
+ * @param configurationDirectory to which the group will be attached to
+ * @param name the name of the group
*/
- public FileGroup(Publication publication, String name) {
+ public FileGroup(File configurationDirectory, String name) {
super(name);
- this.publication = publication;
+ setConfigurationDirectory(configurationDirectory);
}
- /**
- * Create a new instance of <code>FileGroup</code>
- *
- * @param publication to which the group will be attached to
- * @param config containing the group details
- * @throws ConfigurationException if the instantiation fails
- */
- public FileGroup(Publication publication, Configuration config)
+ /**
+ * Configures this file group.
+ * @param config The configuration.
+ * @throws ConfigurationException when something went wrong.
+ */
+ public void configure(Configuration config)
throws ConfigurationException {
- super(config.getAttribute(NAME_ATTRIBUTE));
- this.publication = publication;
+
+ setName(config.getAttribute(NAME_ATTRIBUTE));
Configuration[] rolesConfig = config.getChildren(ROLES);
if (rolesConfig.length == 1) {
@@ -105,14 +104,13 @@
String roleName = roles[i].getValue();
RoleManager manager = null;
try {
- manager = RoleManager.instance(publication);
+ manager = RoleManager.instance(getConfigurationDirectory());
} catch (AccessControlException e) {
throw new ConfigurationException(
"Exception when trying to fetch RoleManager for publication: "
- + publication,
+ + getConfigurationDirectory(),
e);
}
- addRole(manager.getRole(roleName));
}
} else {
@@ -133,7 +131,7 @@
DefaultConfigurationSerializer serializer =
new DefaultConfigurationSerializer();
Configuration config = createConfiguration();
- File xmlPath = GroupManager.instance(publication).getPath();
+ File xmlPath = getConfigurationDirectory();
File xmlfile = new File(xmlPath, getName() + GroupManager.SUFFIX);
try {
serializer.serializeToFile(xmlfile, config);
@@ -157,13 +155,26 @@
child = new DefaultConfiguration(ROLES);
config.addChild(child);
- Iterator groupsIter = getRoles();
- while (groupsIter.hasNext()) {
- DefaultConfiguration groupNode = new DefaultConfiguration(ROLE);
- groupNode.setValue(((Role) groupsIter.next()).getName());
- child.addChild(groupNode);
- }
return config;
}
+
+ private File configurationDirectory;
+
+ /**
+ * Returns the configuration directory.
+ * @return A file object.
+ */
+ protected File getConfigurationDirectory() {
+ return configurationDirectory;
+ }
+
+ /**
+ * @see org.apache.lenya.cms.ac.Item#setConfigurationDirectory(java.io.File)
+ */
+ public void setConfigurationDirectory(File configurationDirectory) {
+ assert configurationDirectory != null
+ && configurationDirectory.isDirectory();
+ this.configurationDirectory = configurationDirectory;
+ }
}
1.18 +52 -42 cocoon-lenya/src/java/org/apache/lenya/cms/ac/FileUser.java
Index: FileUser.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ac/FileUser.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- FileUser.java 25 Jun 2003 08:56:32 -0000 1.17
+++ FileUser.java 25 Jun 2003 14:38:29 -0000 1.18
@@ -50,13 +50,11 @@
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.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.configuration.DefaultConfigurationSerializer;
-import org.apache.lenya.cms.publication.Publication;
import org.apache.log4j.Category;
/**
@@ -64,7 +62,7 @@
*
*
*/
-public class FileUser extends User {
+public class FileUser extends User implements Item {
private Category log = Category.getInstance(FileUser.class);
public static final String ID = "identity";
@@ -77,64 +75,68 @@
public static final String ID_ATTRIBUTE = "id";
public static final String CLASS_ATTRIBUTE = "class";
- private Publication publication;
+ private File configurationDirectory;
+
+ /**
+ * Creates a new FileUser object.
+ */
+ public FileUser() {
+ }
/**
* Create a FileUser
*
- * @param publication where the user will be attached to
+ * @param configurationDirectory where the user will be attached to
* @param id the user id
* @param fullName the full name of the user
* @param email the users email address
* @param password the users password
*/
public FileUser(
- Publication publication,
+ File configurationDirectory,
String id,
String fullName,
String email,
String password) {
super(id, fullName, email, password);
- this.publication = publication;
+ setConfigurationDirectory(configurationDirectory);
}
- /**
- * Create a FileUser.
- *
- * @param publication where the user will be attached to
- * @param config where the user details are specified
- * @throws ConfigurationException if the necessary details aren't specified in the config
- */
- public FileUser(Publication publication, Configuration config)
+ /**
+ * Configure this FileUser.
+ *
+ * @param config where the user details are specified
+ * @throws ConfigurationException if the necessary details aren't specified in the config
+ */
+ public void configure(Configuration config)
throws ConfigurationException {
- super(
- config.getAttribute(ID_ATTRIBUTE),
- config.getChild(FULL_NAME).getValue(null),
- config.getChild(EMAIL).getValue(),
- config.getChild(PASSWORD).getValue(null));
- this.publication = publication;
+ setId(config.getAttribute(ID_ATTRIBUTE));
+ setFullName(config.getChild(FULL_NAME).getValue(null));
+ setEmail(config.getChild(EMAIL).getValue());
setEncryptedPassword(config.getChild(PASSWORD).getValue(null));
+
Configuration[] groups = config.getChildren(GROUPS);
if (groups.length == 1) {
groups = groups[0].getChildren(GROUP);
GroupManager manager = null;
try {
- manager = GroupManager.instance(publication);
+ manager = GroupManager.instance(configurationDirectory);
} catch (AccessControlException e) {
throw new ConfigurationException(
- "Exception when trying to fetch GroupManager for publication: "
- + publication,
+ "Exception when trying to fetch GroupManager for directory: ["
+ + configurationDirectory + "]",
e);
}
for (int i = 0; i < groups.length; i++) {
String groupName = groups[i].getValue();
Group group = manager.getGroup(groupName);
- if (group != null) {
- addGroup(group);
- } else {
- log.error(
- "Couldn't find Group for group name: " + groupName);
+ if (!group.contains(this)) {
+ group.add(this);
+ }
+ if (group == null) {
+ log.error(
+ "Couldn't find Group for group name [" + groupName + "]");
}
}
} else {
@@ -176,10 +178,10 @@
child = new DefaultConfiguration(GROUPS);
config.addChild(child);
- Iterator groupsIter = getGroups();
- while (groupsIter.hasNext()) {
+ Group groups[] = getGroups();
+ for (int i = 0; i < groups.length; i++) {
DefaultConfiguration groupNode = new DefaultConfiguration(GROUP);
- groupNode.setValue(((Group) groupsIter.next()).getName());
+ groupNode.setValue(groups[i].getName());
child.addChild(groupNode);
}
return config;
@@ -192,10 +194,10 @@
DefaultConfigurationSerializer serializer =
new DefaultConfigurationSerializer();
Configuration config = createConfiguration();
- UserManager manager = UserManager.instance(publication);
+ UserManager manager = UserManager.instance(configurationDirectory);
manager.add(this);
- File xmlPath = manager.getPath();
+ File xmlPath = manager.getConfigurationDirectory();
File xmlfile = new File(xmlPath, getId() + UserManager.SUFFIX);
try {
serializer.serializeToFile(xmlfile, config);
@@ -209,20 +211,28 @@
*/
public void delete() throws AccessControlException {
super.delete();
- UserManager manager = UserManager.instance(publication);
+ UserManager manager = UserManager.instance(configurationDirectory);
manager.remove(this);
- File xmlPath = manager.getPath();
+ File xmlPath = manager.getConfigurationDirectory();
File xmlfile = new File(xmlPath, getId() + UserManager.SUFFIX);
xmlfile.delete();
}
/**
- * Get the publication where this FileUser is attached to.
- *
- * @return the <code>Publication</code>
+ * Returns the configuration directory.
+ * @return A file object.
+ */
+ protected File getConfigurationDirectory() {
+ return configurationDirectory;
+ }
+
+ /**
+ * @see org.apache.lenya.cms.ac.Item#setConfigurationDirectory(java.io.File)
*/
- protected Publication getPublication() {
- return publication;
+ public void setConfigurationDirectory(File configurationDirectory) {
+ assert configurationDirectory != null
+ && configurationDirectory.isDirectory();
+ this.configurationDirectory = configurationDirectory;
}
}
1.16 +50 -53 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.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- User.java 25 Jun 2003 08:56:32 -0000 1.15
+++ User.java 25 Jun 2003 14:38:29 -0000 1.16
@@ -49,24 +49,31 @@
package org.apache.lenya.cms.ac;
+import java.util.Arrays;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Set;
+import org.apache.lenya.cms.ac2.*;
import org.apache.log4j.Category;
/**
*
* @author nobby
*/
-public abstract class User {
- private Category log = Category.getInstance(User.class);
+public abstract class User extends AbstractGroupable implements Identifiable {
+ private static Category log = Category.getInstance(User.class);
private String id;
- private String fullName;
- private String email;
- private String encryptedPassword;
- private Set groups = new HashSet();
+ private String fullName;
+ private String email;
+ private String encryptedPassword;
+ private Set groups = new HashSet();
+
+ /**
+ * Creates a new User.
+ */
+ public User() {
+ }
/**
* Create a User instance
@@ -102,15 +109,6 @@
}
/**
- * Get all groups
- *
- * @return an <code>Iterator</code>
- */
- public Iterator getGroups() {
- return groups.iterator();
- }
-
- /**
* Get the user id
*
* @return the user id
@@ -138,41 +136,8 @@
}
/**
- * Remove all groups
- */
- public void removeAllGroups() {
- for (Iterator iter = groups.iterator(); iter.hasNext();) {
- Group group = (Group) iter.next();
- group.removeUser(this);
- }
- groups.clear();
- }
-
- /**
- * Add the specified group to this user
- *
- * @param group which is to be added
- */
- public void addGroup(Group group) {
- assert group != null;
- groups.add(group);
- group.addUser(this);
- }
-
- /**
- * Remove the specified group from this user
- *
- * @param group which is to be removed
- */
- public void removeGroup(Group group) {
- groups.remove(group);
- group.removeUser(this);
- }
-
- /**
- * Set the password
- *
- * @param plainTextPassword the password in plain text
+ * Sets the password.
+ * @param plainTextPassword The plain text passwrod.
*/
public void setPassword(String plainTextPassword) {
encryptedPassword = Password.encrypt(plainTextPassword);
@@ -211,7 +176,7 @@
* @throws AccessControlException if the delete failed
*/
public void delete() throws AccessControlException {
- removeAllGroups();
+ removeFromAllGroups();
}
/** (non-Javadoc)
@@ -246,4 +211,36 @@
return this.encryptedPassword.equals(Password.encrypt(password));
}
+
+
+ /**
+ * Sets the ID of this user.
+ * @param string The ID.
+ */
+ public void setId(String string) {
+ assert string != null && !"".equals(string);
+ id = string;
+ }
+
+ /**
+ * @see org.apache.lenya.cms.ac.Accreditable#getAccreditables()
+ */
+ public Accreditable[] getAccreditables() {
+ Set accreditables = new HashSet();
+ accreditables.add(this);
+ Group groups[] = getGroups();
+ for (int i = 0; i < groups.length; i++) {
+ Accreditable groupAccreditables[] = groups[i].getAccreditables();
+ accreditables.addAll(Arrays.asList(groupAccreditables));
+ }
+ return (Accreditable[]) accreditables.toArray(new Accreditable[accreditables.size()]);
+ }
+
+ /**
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ return "[user " + getId() + "]";
+ }
+
}
1.5 +42 -23 cocoon-lenya/src/java/org/apache/lenya/cms/ac/FileRole.java
Index: FileRole.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ac/FileRole.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FileRole.java 25 Jun 2003 08:56:32 -0000 1.4
+++ FileRole.java 25 Jun 2003 14:38:29 -0000 1.5
@@ -55,42 +55,42 @@
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.configuration.DefaultConfigurationSerializer;
-import org.apache.lenya.cms.publication.Publication;
/**
* @author egli
*
*
*/
-public class FileRole extends Role {
+public class FileRole extends Role implements Item {
- public static final String GROUP = "role";
+ /**
+ * Creates a new file role.
+ * @param configurationDirectory The configuration directory.
+ * @param roleName The role name.
+ */
+ public FileRole(File configurationDirectory, String roleName) {
+ setName(roleName);
+ setConfigurationDirectory(configurationDirectory);
+ }
+
+ public static final String GROUP = "role";
public static final String NAME_ATTRIBUTE = "name";
public static final String CLASS_ATTRIBUTE = "class";
- private Publication publication;
-
- /**
- * Create a new instance of <code>FileRole</code>
- *
- * @param publication to which the role is to be attached
- * @param name name of the role
- */
- public FileRole(Publication publication, String name) {
- super(name);
- this.publication = publication;
- }
+ /**
+ * Creates a new FileRole object.
+ */
+ public FileRole() {
+ }
/**
- * Create a new instance of <code>FileRole</code>
+ * Configure this instance of <code>FileRole</code>
*
- * @param publication to which the role is to be attached
* @param config containing the role details
- * @throws ConfigurationException if the <code>FileRole</code> could not be instantiated
+ * @throws ConfigurationException if the <code>FileRole</code> could not be configured
*/
- public FileRole(Publication publication, Configuration config) throws ConfigurationException {
- super(config.getAttribute(NAME_ATTRIBUTE));
- this.publication = publication;
+ public void configure(Configuration config) throws ConfigurationException {
+ setName(config.getAttribute(NAME_ATTRIBUTE));
}
/**
@@ -102,7 +102,7 @@
DefaultConfigurationSerializer serializer =
new DefaultConfigurationSerializer();
Configuration config = createConfiguration();
- File xmlPath = RoleManager.instance(publication).getPath();
+ File xmlPath = getConfigurationDirectory();
File xmlfile = new File(xmlPath, getName() + RoleManager.SUFFIX);
try {
serializer.serializeToFile(xmlfile, config);
@@ -123,5 +123,24 @@
config.setAttribute(CLASS_ATTRIBUTE, this.getClass().getName());
return config;
}
+
+ private File configurationDirectory;
+
+
+
+ /**
+ * Returns the configuration directory.
+ * @return A file object.
+ */
+ public File getConfigurationDirectory() {
+ return configurationDirectory;
+ }
+
+ /**
+ * @see org.apache.lenya.cms.ac.Item#setConfigurationDirectory(java.io.File)
+ */
+ public void setConfigurationDirectory(File file) {
+ configurationDirectory = file;
+ }
}
1.6 +76 -86 cocoon-lenya/src/java/org/apache/lenya/cms/ac/Group.java
Index: Group.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ac/Group.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Group.java 24 Jun 2003 17:44:26 -0000 1.5
+++ Group.java 25 Jun 2003 14:38:29 -0000 1.6
@@ -49,123 +49,113 @@
package org.apache.lenya.cms.ac;
+import java.util.Collections;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Set;
+import org.apache.lenya.cms.ac2.*;
+
/**
+ * A group is a set of {@link Groupable}s.
* @author egli
- *
- *
+ * @author <a href="mailto:andreas@apache.org">Andreas Hartmann</a>
*/
-public class Group {
+public class Group implements Accreditable {
private String name;
- private Set roles = new HashSet();
- private Set users = new HashSet();
+
+ /**
+ * Creates a new group.
+ */
+ public Group() {
+ }
- /**
- * Create a group
- *
- * @param name the name for this group
- */
+ /**
+ * Creates a new group.
+ * @param name The group name.
+ */
public Group(String name) {
this.name = name;
}
/**
* Get the name of this group
- *
- * @return the name
+ * @return The name.
*/
public String getName() {
return name;
}
- /**
- * Get all roles of this group
- *
- * @return an <code>Iterator</code>
- */
- public Iterator getRoles() {
- return roles.iterator();
- }
+ /**
+ * Set the name of this group
+ * @param string The name.
+ */
+ public void setName(String string) {
+ name = string;
+ }
+
+ private Set members = new HashSet();
+
+ /**
+ * Returns the members of this group.
+ * @return An array of {@link Groupable}s.
+ */
+ public Groupable[] getMembers() {
+ return (Groupable[]) members.toArray(new Groupable[members.size()]);
+ }
/**
- * Get all users
- *
- * @return an <code>Iterator</code>
- */
- public Iterator getUsers() {
- return users.iterator();
- }
-
- /**
- * Set the name of this group
- *
- * @param string whith which the name is replaced
- */
- public void setName(String string) {
- name = string;
- }
-
- /**
- * Add a role to this group
- *
- * @param role the role that is to be added
- */
- public void addRole(Role role) {
- assert role != null;
- roles.add(role);
- role.addGroup(this);
- }
-
- /**
- * Remove a role from this group
- *
- * @param role the role that is to be removed
- */
- public void removeRole(Role role) {
- roles.remove(role);
- role.removeGroup(this);
- }
-
- /**
- * Add a user to this group
- *
- * @param user the user that is to be added
+ * Adds a member to this group.
+ * @param member The member to add.
*/
- public void addUser(User user) {
- users.add(user);
+ public void add(Groupable member) {
+ assert member != null && !members.contains(member);
+ members.add(member);
+ member.addedToGroup(this);
}
- /**
- * Remove the given user from the group.
- *
- * @param user the user that is to be removed
- */
- public void removeUser(User user) {
- users.remove(user);
+ /**
+ * Removes a member from this group.
+ * @param member The member to remove.
+ */
+ public void remove(Groupable member) {
+ assert member != null && members.contains(member);
+ members.remove(member);
+ member.removedFromGroup(this);
}
/**
- * Is this group equal to an object
- *
- * @param obj the object that the Group is compared to
- * @return true if the object is also of type Group and has the same name.
+ * @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
+ boolean equals = false;
if (obj instanceof Group) {
- return getName().equals(((Group) obj).getName());
+ equals = getName().equals(((Group) obj).getName());
}
- return false;
+ return equals;
}
- /** (non-Javadoc)
+ /**
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return getName().hashCode();
}
+
+ /**
+ * Returns if this group contains this member.
+ * @param member The member to check.
+ * @return A boolean value.
+ */
+ boolean contains(Groupable member) {
+ return members.contains(member);
+ }
+
+ /**
+ * @see org.apache.lenya.cms.ac.Accreditable#getAccreditables()
+ */
+ public Accreditable[] getAccreditables() {
+ return (Accreditable[]) Collections.singleton(this).toArray(new Accreditable[1]);
+ }
}
1.8 +15 -14 cocoon-lenya/src/java/org/apache/lenya/cms/ac/LDAPUser.java
Index: LDAPUser.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ac/LDAPUser.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- LDAPUser.java 25 Jun 2003 09:16:53 -0000 1.7
+++ LDAPUser.java 25 Jun 2003 14:38:29 -0000 1.8
@@ -66,7 +66,6 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.lenya.cms.publication.Publication;
import org.apache.log4j.Category;
/**
@@ -93,23 +92,28 @@
private static String SECURITY_AUTHENTICATION = "security-authentication";
private String ldapId;
+
+ /**
+ * Creates a new LDAPUser object.
+ */
+ public LDAPUser() {
+ }
/**
* Create an LDAPUser
*
- * @param publication where the user will be attached to
+ * @param configurationDirectory where the user will be attached to
* @param id user id of LDAPUser
* @param email of LDAPUser
* @param ldapId of LDAPUser
* @throws ConfigurationException if the properties could not be read
*/
public LDAPUser(
- Publication publication,
+ File configurationDirectory,
String id,
String email,
- String ldapId)
- throws ConfigurationException {
- super(publication, id, null, email, null);
+ String ldapId) throws ConfigurationException {
+ super(configurationDirectory, id, null, email, null);
this.ldapId = ldapId;
try {
readProperties();
@@ -121,13 +125,12 @@
/**
* Create a new LDAPUser from a configuration
*
- * @param publication where the user will be attached to
* @param config the <code>Configuration</code> specifying the user details
* @throws ConfigurationException if the user could not be instantiated
*/
- public LDAPUser(Publication publication, Configuration config)
+ public void configure(Configuration config)
throws ConfigurationException {
- super(publication, config);
+ super.configure(config);
ldapId = config.getChild(LDAP_ID).getValue();
try {
readProperties();
@@ -272,8 +275,7 @@
System.setProperty(
"javax.net.ssl.trustStore",
- getPublication().getDirectory().getAbsolutePath()
- + CONFIG_PATH
+ getConfigurationDirectory().getAbsolutePath() + File.separator
+ defaultProperties.getProperty(KEY_STORE));
env.put(
@@ -314,8 +316,7 @@
// create and load default properties
File propertiesFile =
new File(
- getPublication().getDirectory(),
- CONFIG_PATH + "ldap.properties");
+ getConfigurationDirectory(), "ldap.properties");
if (defaultProperties == null) {
defaultProperties = new Properties();
FileInputStream in;
1.9 +25 -45 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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Role.java 25 Jun 2003 08:56:32 -0000 1.8
+++ Role.java 25 Jun 2003 14:38:29 -0000 1.9
@@ -6,21 +6,22 @@
package org.apache.lenya.cms.ac;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
/**
- *
- * @author nobby
+ * A Role embodies the privilege to do certain things.
+ * @author <a href="mailto:andreas@apache.org">Andreas Hartmann</a>
*/
public class Role {
-
- /**
- * Create a new instance of <code>Role</code>
- *
- * @param name the name of the role
- */
+
+ /**
+ * Creates a new instance of Role.
+ */
+ public Role() {
+ }
+
+ /**
+ * Creates a new instance of Role.
+ * @param name The role name.
+ */
public Role(String name) {
assert name != null;
this.name = name;
@@ -28,47 +29,26 @@
private String name;
- private Set groups = new HashSet();
-
- /**
- * Get the name
- *
- * @return a <code>String</code>
- */
+ /**
+ * Returns the name of this role.
+ * @return A string.
+ */
public String getName() {
return name;
}
/**
- * Add a group
- *
- * @param group the group to add
+ * Sets the name of this role.
+ * @param name The name.
*/
- public void addGroup(Group group) {
- assert group != null;
- groups.add(group);
+ public void setName(String name) {
+ assert name != null && !"".equals(name);
+ this.name = name;
}
- /**
- * Remove a specific group
- *
- * @param group the group to remove
- */
- public void removeGroup(Group group) {
- groups.remove(group);
- }
/**
- * Get all groups
- *
- * @return an <code>Iterator</code>
- */
- public Iterator getGroups() {
- return groups.iterator();
- }
-
- /** (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
+ * @see java.lang.Object#equals(Object)
*/
public boolean equals(Object otherObject) {
boolean equals = false;
@@ -81,14 +61,14 @@
return equals;
}
- /** (non-Javadoc)
+ /**
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return getName().hashCode();
}
- /** (non-Javadoc)
+ /**
* @see java.lang.Object#toString()
*/
public String toString() {
1.1 cocoon-lenya/src/java/org/apache/lenya/cms/ac2/PolicyManager.java
Index: PolicyManager.java
===================================================================
/*
* $Id
* <License>
* 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 MERCHANTI-
* BILITY 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.
* </License>
*/
package org.apache.lenya.cms.ac2;
import org.apache.lenya.cms.ac.AccessControlException;
/**
* @author andreas
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public interface PolicyManager {
/**
* Builds the URL policy for a URL.
* @param url The URL.
* @return A policy.
* @throws AccessControlException when something went wrong.
*/
DefaultPolicy buildURLPolicy(String url) throws AccessControlException;
/**
* Builds the subtree policy for a URL.
* @param url The URL.
* @return A policy.
* @throws AccessControlException when something went wrong.
*/
DefaultPolicy buildSubtreePolicy(String url) throws AccessControlException;
/**
* Saves a URL policy.
* @param url The URL to save the policy for.
* @param policy The policy to save.
* @throws AccessControlException when something went wrong.
*/
void saveURLPolicy(String url, DefaultPolicy policy) throws AccessControlException;
/**
* Saves a Subtree policy.
* @param url The url to save the policy for.
* @param policy The policy to save.
* @throws AccessControlException when something went wrong.
*/
void saveSubtreePolicy(String url, DefaultPolicy policy) throws AccessControlException;
}
1.1 cocoon-lenya/src/java/org/apache/lenya/cms/ac2/Accreditable.java
Index: Accreditable.java
===================================================================
/*
* $Id
* <License>
* 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 MERCHANTI-
* BILITY 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.
* </License>
*/
package org.apache.lenya.cms.ac2;
/**
* An Accreditable can be accredited with roles on a certain URI
* using a {@link Credential}.
* @author <a href="mailto:andreas@apache.org">Andreas Hartmann</a>
*/
public interface Accreditable {
/**
* Returns the set of accreditables of this accreditable.
* The set contains the accreditable itself and all collections it belongs to.
* @return An array of accreditables.
*/
Accreditable[] getAccreditables();
}
1.1 cocoon-lenya/src/java/org/apache/lenya/cms/ac2/PolicyAuthorizer.java
Index: PolicyAuthorizer.java
===================================================================
/*
* $Id
* <License>
* 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 MERCHANTI-
* BILITY 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.
* </License>
*/
package org.apache.lenya.cms.ac2;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.cocoon.environment.Request;
import org.apache.lenya.cms.ac.AccessControlException;
import org.apache.lenya.cms.ac.Role;
import org.apache.lenya.cms.publication.PageEnvelope;
/**
* @author andreas
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class PolicyAuthorizer implements Authorizer {
/**
* Creates a new policy authorizer.
*/
public PolicyAuthorizer() {
}
/**
* Template method, override {@link #setup(Map)} to setup your authorizer.
* @see org.apache.lenya.cms.ac2.Authorizer#authorize(org.apache.lenya.cms.ac2.Identity, java.lang.String, java.util.Map)
*/
public boolean authorize(Identity identity, PageEnvelope envelope, Request request)
throws AccessControlException {
Policy policy = getAccessController().getPolicy(envelope);
Role roles[] = policy.getRoles(identity);
return roles.length > 0;
}
/**
* Factory method to build the access controller.
* @return An access controller.
*/
protected AccessController getAccessController() {
return controller;
}
protected static final String ACCESS_CONTROLLER_ELEMENT = "access-controller";
protected static final String CLASSNAME_ATTRIBUTE = "src";
private AccessController controller;
/**
* @see org.apache.lenya.cms.ac2.Authorizer#configure(org.apache.avalon.framework.configuration.Configuration)
*/
public void configure(Configuration configuration) throws ConfigurationException {
Configuration accessControllerConfiguration =
configuration.getChild(ACCESS_CONTROLLER_ELEMENT);
String className = accessControllerConfiguration.getAttribute(CLASSNAME_ATTRIBUTE);
AccessController controller;
try {
controller = (AccessController) Class.forName(className).newInstance();
} catch (Exception e) {
throw new ConfigurationException("Configuration failed: ", e);
}
controller.configure(accessControllerConfiguration);
this.controller = controller;
}
}
1.1 cocoon-lenya/src/java/org/apache/lenya/cms/ac2/AccessController.java
Index: AccessController.java
===================================================================
/*
* $Id
* <License>
* 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 MERCHANTI-
* BILITY 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.
* </License>
*/
package org.apache.lenya.cms.ac2;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.lenya.cms.ac.AccessControlException;
import org.apache.lenya.cms.ac.GroupManager;
import org.apache.lenya.cms.ac.RoleManager;
import org.apache.lenya.cms.ac.UserManager;
import org.apache.lenya.cms.publication.PageEnvelope;
/**
* @author andreas
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public interface AccessController {
/**
* Returns the user manager of this access controller.
* @return A user manager.
* @throws AccessControlException when something went wrong.
*/
UserManager getUserManager() throws AccessControlException;
/**
* Returns the group manager of this access controller.
* @return A group manager.
* @throws AccessControlException when something went wrong.
*/
GroupManager getGroupManager() throws AccessControlException;
/**
* Returns the role manager of this access controller.
* @return A role manager.
* @throws AccessControlException when something went wrong.
*/
RoleManager getRoleManager() throws AccessControlException;
/**
* Returns the policy manager of this access controller.
* @return A policy manager.
* @throws AccessControlException when something went wrong.
*/
PolicyManager getPolicyManager() throws AccessControlException;
/**
* Returns the policy for a given page.
* @param envelope The envelope of the page.
* @return The policy.
* @throws AccessControlException when something went wrong.
*/
Policy getPolicy(PageEnvelope envelope) throws AccessControlException;
/**
* Configures this access controller.
* @param configuration The configuration.
* @throws ConfigurationException if something went wrong.
*/
void configure(Configuration configuration) throws ConfigurationException;
}
1.1 cocoon-lenya/src/java/org/apache/lenya/cms/ac2/Machine.java
Index: Machine.java
===================================================================
/*
* $Id
* <License>
* 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 MERCHANTI-
* BILITY 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.
* </License>
*/
package org.apache.lenya.cms.ac2;
import java.util.Collections;
/**
* @author andreas
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class Machine implements Identifiable {
/**
* Creates a new machine object.
* @param ip The IP address.
*/
public Machine(String ip) {
assert ip != null && !"".equals(ip);
this.ip = ip;
}
private String ip;
/**
* @see java.lang.Object#equals(Object)
*/
public boolean equals(Object otherObject) {
boolean equals = false;
if (otherObject instanceof Machine) {
Machine otherRole = (Machine) otherObject;
equals = getIp().equals(otherRole.getIp());
}
return equals;
}
/**
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return getIp().hashCode();
}
/**
* @see org.apache.lenya.cms.ac2.Accreditable#getAccreditables()
*/
public Accreditable[] getAccreditables() {
return (Accreditable[]) Collections.singleton(this).toArray(new Accreditable[1]);
}
/**
* Returns the IP address.
* @return The IP address.
*/
public String getIp() {
return ip;
}
}
1.1 cocoon-lenya/src/java/org/apache/lenya/cms/ac2/Identifiable.java
Index: Identifiable.java
===================================================================
/*
* $Id
* <License>
* 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 MERCHANTI-
* BILITY 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.
* </License>
*/
package org.apache.lenya.cms.ac2;
/**
* A marker interface to mark an {@link Accreditable} as identifiable.
*
* @author andreas
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public interface Identifiable extends Accreditable {
}
1.1 cocoon-lenya/src/java/org/apache/lenya/cms/ac2/Identity.java
Index: Identity.java
===================================================================
/*
* $Id
* <License>
* 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 MERCHANTI-
* BILITY 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.
* </License>
*/
package org.apache.lenya.cms.ac2;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
/**
* @author andreas
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class Identity implements Identifiable {
private Set identifiables = new HashSet();
/**
* Returns the identifiables of this identity.
* @return An array of identifiables.
*/
public Identifiable[] getIdentifiables() {
return (Identifiable[]) identifiables.toArray(new Identifiable[identifiables.size()]);
}
/**
* Adds a new identifiable to this identity.
* @param identifiable The identifiable to add.
*/
public void addIdentifiable(Identifiable identifiable) {
assert identifiable != null;
assert identifiable != this;
assert !identifiables.contains(identifiable);
identifiables.add(identifiable);
}
/**
* @see org.apache.lenya.cms.ac.Accreditable#getAccreditables()
*/
public Accreditable[] getAccreditables() {
Set accreditables = new HashSet();
Identifiable identifiables[] = getIdentifiables();
for (int i = 0; i < identifiables.length; i++) {
Accreditable groupAccreditables[] = identifiables[i].getAccreditables();
accreditables.addAll(Arrays.asList(groupAccreditables));
}
return (Accreditable[]) accreditables.toArray(new Accreditable[accreditables.size()]);
}
/**
* @see java.lang.Object#toString()
*/
public String toString() {
String accrString = "";
Accreditable accreditables[] = getAccreditables();
for (int i = 0; i < accreditables.length; i++) {
accrString += " " + accreditables[i];
}
String string = "[identity:" + accrString + "]";
return string;
}
}
1.1 cocoon-lenya/src/java/org/apache/lenya/cms/ac2/World.java
Index: World.java
===================================================================
/*
* $Id
* <License>
* 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 MERCHANTI-
* BILITY 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.
* </License>
*/
package org.apache.lenya.cms.ac2;
import java.util.Collections;
/**
* @author andreas
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public final class World implements Identifiable {
/**
* Creates a new World object.
*/
private World() {
}
private static World instance;
/**
* Returns the singleton world object.
* @return A world object.
*/
public static World getInstance() {
if (instance == null) {
instance = new World();
}
return instance;
}
/**
* @see org.apache.lenya.cms.ac2.Accreditable#getAccreditables()
*/
public Accreditable[] getAccreditables() {
return (Accreditable[]) Collections.singleton(this).toArray(new Accreditable[1]);
}
}
1.1 cocoon-lenya/src/java/org/apache/lenya/cms/ac2/URLPolicy.java
Index: URLPolicy.java
===================================================================
/*
* $Id
* <License>
* 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 MERCHANTI-
* BILITY 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.
* </License>
*/
package org.apache.lenya.cms.ac2;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.apache.lenya.cms.ac.AccessControlException;
import org.apache.lenya.cms.ac.Role;
/**
* A policy at a certain URL.
* @author andreas
*/
public class URLPolicy implements Policy {
/**
* Returns the resulting policy for a certain URL.
* @param url The URL.
* @param manager The policy manager.
*/
public URLPolicy(String url, PolicyManager manager) {
assert url != null;
this.url = url;
assert manager != null;
policyManager = manager;
}
private String url;
private PolicyManager policyManager;
/**
* @see org.apache.lenya.cms.ac2.Policy#getRoles(org.apache.lenya.cms.ac2.Identity)
*/
public Role[] getRoles(Identity identity) throws AccessControlException {
Set roles = new HashSet();
Policy urlPolicy = getPolicyManager().buildURLPolicy(getUrl());
addRoles(urlPolicy, identity, roles);
String url = "";
String[] directories = url.split("/");
for (int i = 0; i < directories.length; i++) {
}
addRoles(identity, url, roles);
return (Role[]) roles.toArray(new Role[roles.size()]);
}
/**
* Adds roles of a certain URL to a set.
* @param identity The identity.
* @param url The URL.
* @param roles The roles set.
* @throws AccessControlException when something went wrong.
*/
protected void addRoles(Identity identity, String url, Set roles) throws AccessControlException {
addRoles(getPolicyManager().buildSubtreePolicy(url), identity, roles);
}
/**
* Adds the roles of an identity of a policy to a role set.
* @param policy The policy.
* @param identity The identity.
* @param roles The role set.
* @throws AccessControlException when something went wrong.
*/
protected void addRoles(Policy policy, Identity identity, Set roles) throws AccessControlException {
roles.addAll(Arrays.asList(policy.getRoles(identity)));
}
/**
* Returns the URL of this policy.
* @return The URL of this policy.
*/
public String getUrl() {
return url;
}
/**
* Returns the policy builder.
* @return A policy builder.
*/
public PolicyManager getPolicyManager() {
return policyManager;
}
}
1.1 cocoon-lenya/src/java/org/apache/lenya/cms/ac2/Policy.java
Index: Policy.java
===================================================================
/*
* $Id
* <License>
* 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 MERCHANTI-
* BILITY 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.
* </License>
*/
package org.apache.lenya.cms.ac2;
import org.apache.lenya.cms.ac.AccessControlException;
import org.apache.lenya.cms.ac.Role;
/**
* @author andreas
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public interface Policy {
/**
* Returns all roles of a certain identity.
* @param identity The identity.
* @return An array of roles.
* @throws AccessControlException when something went wrong.
*/
Role[] getRoles(Identity identity) throws AccessControlException;
}
1.1 cocoon-lenya/src/java/org/apache/lenya/cms/ac2/DefaultPolicy.java
Index: DefaultPolicy.java
===================================================================
/*
* $Id
* <License>
* 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 MERCHANTI-
* BILITY 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.
* </License>
*/
package org.apache.lenya.cms.ac2;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.apache.lenya.cms.ac.Role;
/**
* A DefaultPolicy is the own policy of a certain URL (not merged).
*
* @author andreas
*/
public class DefaultPolicy implements Policy {
private Set credentials = new HashSet();
/**
* Adds a credential to this policy.
* @param credential A credential.
*/
public void addCredential(Credential credential) {
assert credential != null;
assert !credentials.contains(credential);
credentials.add(credential);
}
/**
* Returns the credentials of this policy.
* @return An array of credentials.
*/
public Credential[] getCredentials() {
return (Credential[]) credentials.toArray(new Credential[credentials.size()]);
}
/**
* @see org.apache.lenya.cms.ac2.Policy#getRoles(org.apache.lenya.cms.ac2.Identity)
*/
public Role[] getRoles(Identity identity) {
Accreditable accreditables[] = identity.getAccreditables();
Credential credentials[] = getCredentials();
Set roles = new HashSet();
for (int credIndex = 0; credIndex < credentials.length; credIndex++) {
for (int accrIndex = 0; accrIndex < accreditables.length; accrIndex++) {
Credential credential = credentials[credIndex];
Accreditable accreditable = accreditables[accrIndex];
if (credential.getAccreditable().equals(accreditable)) {
roles.addAll(Arrays.asList(credential.getRoles()));
}
}
}
return (Role[]) roles.toArray(new Role[roles.size()]);
}
}
1.1 cocoon-lenya/src/java/org/apache/lenya/cms/ac2/Credential.java
Index: Credential.java
===================================================================
/*
* $Id
* <License>
* 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 MERCHANTI-
* BILITY 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.
* </License>
*/
package org.apache.lenya.cms.ac2;
import java.util.HashSet;
import java.util.Set;
import org.apache.lenya.cms.ac.Role;
/**
* A credential assigns a set of {@link Role}s to an {@link Accreditable}.
*
* @author <a href="mailto:andreas@apache.org">Andreas Hartmann</a>
*/
public class Credential {
private Accreditable accreditable;
private Set roles = new HashSet();
/**
* Creates a new credential object.
* @param accreditable The accreditable.
*/
public Credential(Accreditable accreditable) {
setAccreditable(accreditable);
}
/**
* Sets the accreditable for this credential.
* @param accreditable The accreditable.
*/
protected void setAccreditable(Accreditable accreditable) {
assert accreditable != null;
this.accreditable = accreditable;
}
/**
* Returns all roles of this credential.
*
* @return An array of roles.
*/
public Role[] getRoles() {
return (Role[]) roles.toArray(new Role[roles.size()]);
}
/**
* Adds a role to this credential.
* @param role The role to add.
*/
public void addRole(Role role) {
assert role != null && !roles.contains(role);
roles.add(role);
}
/**
* Removes a role from this credential.
* @param role The role to remove.
*/
public void removeRole(Role role) {
assert role != null && roles.contains(role);
roles.remove(role);
}
/**
* Returns the accreditable of this credential.
* @return An accreditable.
*/
public Accreditable getAccreditable() {
return accreditable;
}
/**
* @see java.lang.Object#toString()
*/
public String toString() {
return "[credential of: " + getAccreditable() + "]";
}
}
1.1 cocoon-lenya/src/java/org/apache/lenya/cms/ac2/Authorizer.java
Index: Authorizer.java
===================================================================
/*
* $Id
* <License>
* 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 MERCHANTI-
* BILITY 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.
* </License>
*/
package org.apache.lenya.cms.ac2;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.cocoon.environment.Request;
import org.apache.lenya.cms.ac.AccessControlException;
import org.apache.lenya.cms.publication.PageEnvelope;
/**
* @author andreas
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public interface Authorizer {
/**
* Authorizes an identity at a URL.
* @param identity The identity.
* @param envelope The envelope of the page to be accessed.
* @param request The request.
* @return <code>true</code> if the identity is authorized, <code>false</code> otherwise.
* @throws AccessControlException when something went wrong.
*/
boolean authorize(Identity identity, PageEnvelope envelope, Request request) throws AccessControlException;
/**
* Configures this authorizer.
* @param configuration The configuration.
* @throws ConfigurationException if something went wrong.
*/
void configure(Configuration configuration) throws ConfigurationException;
}
1.1 cocoon-lenya/src/java/org/apache/lenya/cms/ac2/workflow/WorkflowAuthorizer.java
Index: WorkflowAuthorizer.java
===================================================================
/*
* $Id
* <License>
* 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 MERCHANTI-
* BILITY 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.
* </License>
*/
package org.apache.lenya.cms.ac2.workflow;
import org.apache.cocoon.environment.Request;
import org.apache.lenya.cms.ac.AccessControlException;
import org.apache.lenya.cms.ac.Role;
import org.apache.lenya.cms.ac2.Identity;
import org.apache.lenya.cms.ac2.Policy;
import org.apache.lenya.cms.ac2.PolicyAuthorizer;
import org.apache.lenya.cms.publication.DefaultDocument;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.PageEnvelope;
import org.apache.lenya.cms.workflow.WorkflowFactory;
import org.apache.lenya.workflow.Event;
import org.apache.lenya.workflow.Situation;
import org.apache.lenya.workflow.WorkflowException;
import org.apache.lenya.workflow.WorkflowInstance;
/**
* If the client requested invoking a workflow event, this authorizer checks if
* the current document state and identity roles allow this transition.
*
* @author andreas
*/
public class WorkflowAuthorizer extends PolicyAuthorizer {
protected static final String EVENT_PARAMETER = "lenya.event";
/**
* @see org.apache.lenya.cms.ac2.Authorizer#authorize(org.apache.lenya.cms.ac2.Identity, org.apache.lenya.cms.publication.PageEnvelope, org.apache.cocoon.environment.Request)
*/
public boolean authorize(Identity identity, PageEnvelope envelope, Request request)
throws AccessControlException {
boolean authorized = true;
String event = request.getParameter(EVENT_PARAMETER);
if (event != null) {
WorkflowFactory factory = WorkflowFactory.newInstance();
Document document =
new DefaultDocument(envelope.getPublication(), envelope.getDocumentId());
WorkflowInstance instance;
Situation situation;
try {
instance = factory.buildInstance(document);
Policy policy = getAccessController().getPolicy(envelope);
Role roles[] = policy.getRoles(identity);
situation = factory.buildSituation(roles);
} catch (WorkflowException e) {
throw new AccessControlException(e);
}
authorized = false;
Event[] events = instance.getExecutableEvents(situation);
int i = 0;
while (!authorized && i < events.length) {
if (events[i].getName().equals(event)) {
authorized = true;
}
i++;
}
}
return authorized;
}
}
1.1 cocoon-lenya/src/java/org/apache/lenya/cms/ac2/file/FileAccessController.java
Index: FileAccessController.java
===================================================================
/*
* $Id
* <License>
* 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 MERCHANTI-
* BILITY 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.
* </License>
*/
package org.apache.lenya.cms.ac2.file;
import java.io.File;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.lenya.cms.ac.AccessControlException;
import org.apache.lenya.cms.ac.GroupManager;
import org.apache.lenya.cms.ac.RoleManager;
import org.apache.lenya.cms.ac.UserManager;
import org.apache.lenya.cms.ac2.AccessController;
import org.apache.lenya.cms.ac2.PolicyManager;
import org.apache.lenya.cms.ac2.URLPolicy;
import org.apache.lenya.cms.ac2.Policy;
import org.apache.lenya.cms.publication.PageEnvelope;
/**
* @author andreas
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class FileAccessController implements AccessController {
/**
* Creates a new FileAccessController.
* If you use this constructor, you have to set the configuration directory either
* by calling {@link #setConfigurationDirectory(File)} or by calling
* {@link #configure(Configuration)}.
*/
public FileAccessController() {
}
/**
* Creates a new FileAccessController based on a configuration directory.
* @param configurationDirectory The configuration directory.
*/
public FileAccessController(File configurationDirectory) {
assert configurationDirectory != null;
assert configurationDirectory.exists();
assert configurationDirectory.isDirectory();
this.configurationDirectory = configurationDirectory;
}
private File configurationDirectory;
protected static final String POLICY_PATH = "policies";
protected static final String ACCREDITABLE_PATH = "passwd";
/**
* Returns the configuration directory.
* @return The configuration directory.
*/
public File getConfigurationDirectory() {
return configurationDirectory;
}
/**
* Returns the directory where accreditables are configured.
* @return A file.
*/
protected File getAccreditableConfigurationDirectory() {
return new File(getConfigurationDirectory(), ACCREDITABLE_PATH);
}
/**
* @see org.apache.lenya.cms.ac2.AccessController#getUserManager()
*/
public UserManager getUserManager() throws AccessControlException {
return UserManager.instance(getAccreditableConfigurationDirectory());
}
/**
* @see org.apache.lenya.cms.ac2.AccessController#getGroupManager()
*/
public GroupManager getGroupManager() throws AccessControlException {
return GroupManager.instance(getAccreditableConfigurationDirectory());
}
/**
* @see org.apache.lenya.cms.ac2.AccessController#getRoleManager()
*/
public RoleManager getRoleManager() throws AccessControlException {
return RoleManager.instance(getAccreditableConfigurationDirectory());
}
/**
* @see org.apache.lenya.cms.ac2.AccessController#getPolicy(java.lang.String)
*/
public Policy getPolicy(PageEnvelope envelope) throws AccessControlException {
assert envelope != null;
if (getConfigurationDirectory() == null) {
if (configurationDirectoryPath == null) {
throw new AccessControlException("Configuration directory not set!");
}
File directory =
new File(envelope.getPublication().getDirectory(), configurationDirectoryPath);
setConfigurationDirectory(directory);
}
return getPolicy(envelope.getDocumentURL());
}
/**
* Returns the policy for a given URL.
* @param url The URL.
* @return A policy.
* @throws AccessControlException when something went wrong.
*/
protected Policy getPolicy(String url) throws AccessControlException {
URLPolicy policy = new URLPolicy(url, getPolicyManager());
return policy;
}
private PolicyManager policyManager;
/**
* @see org.apache.lenya.cms.ac2.AccessController#getPolicyManager()
*/
public PolicyManager getPolicyManager() throws AccessControlException {
if (policyManager == null) {
policyManager =
new FilePolicyManager(
new File(getConfigurationDirectory(), POLICY_PATH),
getUserManager(),
getGroupManager(),
getRoleManager());
}
return policyManager;
}
protected static final String DIRECTORY_ELEMENT = "directory";
protected static final String SRC_ATTRIBUTE = "src";
/**
* @see org.apache.lenya.cms.ac2.AccessController#configure(File, org.apache.avalon.framework.configuration.Configuration)
*/
public void configure(Configuration configuration) throws ConfigurationException {
Configuration directoryConfiguration = configuration.getChild(DIRECTORY_ELEMENT);
configurationDirectoryPath = directoryConfiguration.getAttribute(SRC_ATTRIBUTE);
}
private String configurationDirectoryPath;
/**
* Sets the configuration directory.
* @param file The configuration directory.
*/
public void setConfigurationDirectory(File file) {
assert file != null && file.isDirectory();
configurationDirectory = file;
}
}
1.1 cocoon-lenya/src/java/org/apache/lenya/cms/ac2/file/FilePolicyManager.java
Index: FilePolicyManager.java
===================================================================
/*
* $Id
* <License>
* 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 MERCHANTI-
* BILITY 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.
* </License>
*/
package org.apache.lenya.cms.ac2.file;
import java.io.File;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.lenya.cms.ac.AccessControlException;
import org.apache.lenya.cms.ac.Group;
import org.apache.lenya.cms.ac.GroupManager;
import org.apache.lenya.cms.ac.Role;
import org.apache.lenya.cms.ac.RoleManager;
import org.apache.lenya.cms.ac.User;
import org.apache.lenya.cms.ac.UserManager;
import org.apache.lenya.cms.ac2.Accreditable;
import org.apache.lenya.cms.ac2.Credential;
import org.apache.lenya.cms.ac2.DefaultPolicy;
import org.apache.lenya.cms.ac2.Machine;
import org.apache.lenya.cms.ac2.PolicyManager;
import org.apache.lenya.cms.ac2.World;
import org.apache.lenya.xml.DocumentHelper;
import org.apache.lenya.xml.NamespaceHelper;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* A PolicyBuilder is used to build policies.
* @author andreas
*/
public class FilePolicyManager implements PolicyManager {
/**
* Creates a new PolicyBuilder.
* @param policyDirectory The directory where policies are stored.
* @param userManager The user manager.
* @param groupManager The group manager.
* @param roleManager The role manager.
*/
protected FilePolicyManager(
File policyDirectory,
UserManager userManager,
GroupManager groupManager,
RoleManager roleManager) {
assert policyDirectory != null && policyDirectory.isDirectory();
this.policyDirectory = policyDirectory;
assert userManager != null;
this.userManager = userManager;
assert groupManager != null;
this.groupManager = groupManager;
assert roleManager != null;
this.roleManager = roleManager;
}
private UserManager userManager;
private GroupManager groupManager;
private RoleManager roleManager;
private File policyDirectory;
/**
* Builds a policy from a file.
* @param file The file.
* @return A policy.
* @throws AccessControlException when something went wrong.
*/
protected DefaultPolicy buildPolicy(File file) throws AccessControlException {
assert null != file && file.isFile();
DefaultPolicy policy = new DefaultPolicy();
Document document;
try {
document = DocumentHelper.readDocument(file);
} catch (Exception e) {
throw new AccessControlException(e);
}
Element policyElement = document.getDocumentElement();
assert policyElement.getLocalName().equals(POLICY_ELEMENT);
NamespaceHelper helper = new NamespaceHelper(NAMESPACE, DEFAULT_PREFIX, document);
Element credentialElements[] = helper.getChildren(policyElement);
for (int i = 0; i < credentialElements.length; i++) {
Accreditable accreditable = null;
String id = credentialElements[i].getAttribute(ID_ATTRIBUTE);
accreditable = getAccreditable(credentialElements[i].getLocalName(), id);
Credential credential = new Credential(accreditable);
Element roleElements[] = helper.getChildren(credentialElements[i], ROLE_ELEMENT);
for (int j = 0; j < roleElements.length; j++) {
String roleId = roleElements[j].getAttribute(ID_ATTRIBUTE);
Role role = roleManager.getRole(roleId);
credential.addRole(role);
}
policy.addCredential(credential);
}
return policy;
}
/**
* Creates an accredtiable for an element.
* @param elementName The elment name.
* @param id The ID of the accreditable.
* @return An accreditable.
* @throws AccessControlException when something went wrong.
*/
protected Accreditable getAccreditable(String elementName, String id) throws AccessControlException {
Accreditable accreditable = null;
if (elementName.equals(USER_ELEMENT)) {
accreditable = userManager.getUser(id);
} else if (elementName.equals(GROUP_ELEMENT)) {
accreditable = groupManager.getGroup(id);
} else if (elementName.equals(WORLD_ELEMENT)) {
accreditable = World.getInstance();
} else if (elementName.equals(MACHINE_ELEMENT)) {
accreditable = new Machine(id);
}
if (accreditable == null) {
throw new AccessControlException("Unknown accreditable [" + elementName + "]");
}
return accreditable;
}
protected static final String NAMESPACE = "http://apache.org/cocoon/lenya/ac/1.0";
protected static final String DEFAULT_PREFIX = "ac";
protected static final String POLICY_ELEMENT = "policy";
protected static final String GROUP_ELEMENT = "group";
protected static final String USER_ELEMENT = "user";
protected static final String ROLE_ELEMENT = "role";
protected static final String WORLD_ELEMENT = "world";
protected static final String MACHINE_ELEMENT = "machine";
protected static final String ID_ATTRIBUTE = "id";
protected static final String URL_FILENAME = "url-policy.acml";
protected static final String SUBTREE_FILENAME = "subtree-policy.acml";
/**
* @see org.apache.lenya.cms.ac2.PolicyBuilder#buildURLPolicy(java.lang.String)
*/
public DefaultPolicy buildURLPolicy(String url) throws AccessControlException {
return buildPolicy(url, URL_FILENAME);
}
/**
* @see org.apache.lenya.cms.ac2.PolicyBuilder#buildSubtreePolicy(java.lang.String)
*/
public DefaultPolicy buildSubtreePolicy(String url) throws AccessControlException {
return buildPolicy(url, SUBTREE_FILENAME);
}
/**
* Builds a policy from a file.
* @param url The url.
* @param policyFilename The policy filename.
* @return A policy.
* @throws AccessControlException when something went wrong.
*/
protected DefaultPolicy buildPolicy(String url, String policyFilename)
throws AccessControlException {
DefaultPolicy policy;
File policyFile = getPolicyFile(url, policyFilename);
if (policyFile.exists()) {
policy = buildPolicy(policyFile);
}
else {
policy = new DefaultPolicy();
}
return policy;
}
/**
* Returns the policy file for a URL and a policy filename.
* @param url The url to get the file for.
* @param policyFilename The name of the policy file.
* @return A file object.
*/
protected File getPolicyFile(String url, String policyFilename) {
String path = url.replace('/', File.separatorChar) + File.separator + policyFilename;
File policyFile = new File(getPolicyDirectory(), path);
return policyFile;
}
/**
* Returns the policy directory.
* @return A file object.
*/
public File getPolicyDirectory() {
return policyDirectory;
}
/**
* @see org.apache.lenya.cms.ac2.PolicyManager#saveURLPolicy(org.apache.lenya.cms.ac2.Policy)
*/
public void saveURLPolicy(String url, DefaultPolicy policy) throws AccessControlException {
savePolicy(url, policy, URL_FILENAME);
}
/**
* @see org.apache.lenya.cms.ac2.PolicyManager#saveSubtreePolicy(org.apache.lenya.cms.ac2.Policy)
*/
public void saveSubtreePolicy(String url, DefaultPolicy policy) throws AccessControlException {
savePolicy(url, policy, SUBTREE_FILENAME);
}
/**
* Saves a policy to a file.
* @param url The URL to save the policy for.
* @param policy The policy.
* @param filename The file.
* @throws AccessControlException if something goes wrong.
*/
protected void savePolicy(String url, DefaultPolicy policy, String filename)
throws AccessControlException {
NamespaceHelper helper;
try {
helper = new NamespaceHelper(NAMESPACE, DEFAULT_PREFIX, POLICY_ELEMENT);
} catch (ParserConfigurationException e) {
throw new AccessControlException(e);
}
Credential credentials[] = policy.getCredentials();
for (int i = 0; i < credentials.length; i++) {
Accreditable accreditable = credentials[i].getAccreditable();
Element accreditableElement = save(accreditable, helper);
helper.getDocument().getDocumentElement().appendChild(accreditableElement);
}
File file = getPolicyFile(url, filename);
try {
file.getParentFile().mkdirs();
file.createNewFile();
DocumentHelper.writeDocument(helper.getDocument(), file);
} catch (Exception e) {
throw new AccessControlException("Path: [" + file.getAbsolutePath() + "]", e);
}
}
/**
* Saves an accreditable to an XML element.
* @param accreditable The accreditable.
* @param helper The namespace helper to be used.
* @return An XML element.
* @throws AccessControlException when something went wrong.
*/
protected Element save(Accreditable accreditable, NamespaceHelper helper) throws AccessControlException {
String localName = null;
String id = null;
if (accreditable instanceof User) {
localName = USER_ELEMENT;
id = ((User) accreditable).getId();
}
else if (accreditable instanceof Group) {
localName = GROUP_ELEMENT;
id = ((Group) accreditable).getName();
}
else if (accreditable instanceof World) {
localName = WORLD_ELEMENT;
}
else if (accreditable instanceof Machine) {
localName = MACHINE_ELEMENT;
id = ((Machine) accreditable).getIp();
}
if (localName == null) {
throw new AccessControlException("Could not save accreditable [" + accreditable + "]");
}
Element element = helper.createElement(localName);
if (id != null) {
element.setAttribute(ID_ATTRIBUTE, id);
}
return element;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org