You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by re...@apache.org on 2001/03/23 08:40:55 UTC
cvs commit: jakarta-slide/src/share/org/apache/slide/security SecurityImpl.java
remm 01/03/22 23:40:55
Modified: src/share/org/apache/slide/common NamespaceConfig.java
src/share/org/apache/slide/security SecurityImpl.java
Log:
- Adds automatic creation of principals. You can see by looking at the updated
getPrincipal method why it's not recommended to try directly manipulating the
objects :)
- That feature is disabled by default, but the default configuration enables
it, as it will ease the pain of first time users :)
- You can specify the types of the objects created.
- Security notice : DO NOT use the current SlideRealm with automatic creation
of users.
Revision Changes Path
1.14 +46 -4 jakarta-slide/src/share/org/apache/slide/common/NamespaceConfig.java
Index: NamespaceConfig.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/NamespaceConfig.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- NamespaceConfig.java 2001/02/26 00:57:42 1.13
+++ NamespaceConfig.java 2001/03/23 07:40:53 1.14
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/NamespaceConfig.java,v 1.13 2001/02/26 00:57:42 remm Exp $
- * $Revision: 1.13 $
- * $Date: 2001/02/26 00:57:42 $
+ * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/NamespaceConfig.java,v 1.14 2001/03/23 07:40:53 remm Exp $
+ * $Revision: 1.14 $
+ * $Date: 2001/03/23 07:40:53 $
*
* ====================================================================
*
@@ -81,7 +81,7 @@
* Configuration of the Namespace.
*
* @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
- * @version $Revision: 1.13 $
+ * @version $Revision: 1.14 $
*/
public final class NamespaceConfig {
@@ -268,6 +268,17 @@
protected ContentInterceptor[] contentInterceptors
= new ContentInterceptor[0];
+ /**
+ * Automatically create users.
+ */
+ protected boolean autoCreateUsers = false;
+
+
+ /**
+ * Roles implementation to be used for automatically created users.
+ */
+ protected String autoCreateUsersRole = "slideroles.basic.UserRoleImpl";
+
// ------------------------------------------------------------- Properties
@@ -540,6 +551,23 @@
}
+ /**
+ * Is automcatic user creation active ?
+ */
+ public boolean isAutoCreateUsers() {
+ return autoCreateUsers;
+ }
+
+
+ /**
+ * Get the class name of the role which will be used to create nodes which
+ * are automatically created when isAutoCreateUsers() returns true.
+ */
+ public String getAutoCreateUsersRole() {
+ return autoCreateUsersRole;
+ }
+
+
// -------------------------------------------------------- Package Methods
@@ -717,6 +745,20 @@
filesPath = config.getConfiguration("filepath").getValue();
} catch (ConfigurationException e) {
filesPath = "";
+ }
+
+ try {
+ autoCreateUsers = Boolean.valueOf
+ (config.getConfiguration("auto-create-users").getValue())
+ .booleanValue();
+ } catch (ConfigurationException e) {
+ autoCreateUsers = false;
+ }
+
+ try {
+ autoCreateUsersRole =
+ config.getConfiguration("auto-create-users-role").getValue();
+ } catch (ConfigurationException e) {
}
parameters = new Hashtable();
1.22 +74 -7 jakarta-slide/src/share/org/apache/slide/security/SecurityImpl.java
Index: SecurityImpl.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/security/SecurityImpl.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- SecurityImpl.java 2001/02/27 07:29:25 1.21
+++ SecurityImpl.java 2001/03/23 07:40:54 1.22
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/security/SecurityImpl.java,v 1.21 2001/02/27 07:29:25 remm Exp $
- * $Revision: 1.21 $
- * $Date: 2001/02/27 07:29:25 $
+ * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/security/SecurityImpl.java,v 1.22 2001/03/23 07:40:54 remm Exp $
+ * $Revision: 1.22 $
+ * $Date: 2001/03/23 07:40:54 $
*
* ====================================================================
*
@@ -66,6 +66,8 @@
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import org.apache.slide.common.*;
import org.apache.slide.structure.*;
import org.apache.slide.authenticate.CredentialsToken;
@@ -75,7 +77,7 @@
* Security helper.
*
* @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
- * @version $Revision: 1.21 $
+ * @version $Revision: 1.22 $
*/
public final class SecurityImpl implements Security {
@@ -313,7 +315,8 @@
Uri objectUri = namespace.getUri(permission.getObjectUri());
ObjectNode object = objectUri.getStore().retrieveObject(objectUri);
- checkCredentials(token, object, namespaceConfig.getRevokePermissionAction());
+ checkCredentials(token, object,
+ namespaceConfig.getRevokePermissionAction());
objectUri.getStore().revokePermission(objectUri, permission);
}
@@ -720,11 +723,75 @@
if ((principalPath == null) || (principalPath.equals(""))) {
principalPath = namespaceConfig.getGuestPath();
}
+
Uri subjectUri = namespace.getUri
(namespaceConfig.getUsersPath() + "/" + principalPath);
- return subjectUri.getStore().retrieveObject(subjectUri);
+ try {
+ return subjectUri.getStore().retrieveObject(subjectUri);
+ } catch (ObjectNotFoundException e) {
+ if (!namespaceConfig.isAutoCreateUsers()) {
+ throw e;
+ } else {
+ try {
+
+ Uri parentUri = subjectUri.getParentUri();
+ ObjectNode parent =
+ subjectUri.getStore().retrieveObject(parentUri);
+ Enumeration childrenEnum = parent.enumerateChildren();
+ Enumeration linksEnum = parent.enumerateLinks();
+ Vector children = new Vector();
+ while (childrenEnum.hasMoreElements()) {
+ children.addElement(childrenEnum.nextElement());
+ }
+ children.addElement(subjectUri.toString());
+ Vector links = new Vector();
+ while (linksEnum.hasMoreElements()) {
+ links.addElement(linksEnum.nextElement());
+ }
+
+ // First, load the object's class
+ Class objectClass = Class.forName
+ (namespaceConfig.getAutoCreateUsersRole());
+ Class[] types = { String.class };
+ Object[] args = { subjectUri.toString() };
+ Constructor constructor =
+ objectClass.getConstructor(types);
+ ObjectNode object =
+ (ObjectNode) constructor.newInstance(args);
+ subjectUri.getStore().createObject(subjectUri, object);
+
+ Class[] types2 =
+ { String.class, Vector.class, Vector.class };
+ Object[] args2 = { parentUri.toString(), children, links };
+ constructor = parent.getClass().getConstructor(types2);
+ object = (ObjectNode) constructor.newInstance(args2);
+ parentUri.getStore().storeObject(parentUri, object);
+ } catch (ClassNotFoundException ex) {
+ // Can't find role implementing class
+ throw new ObjectNotFoundException(subjectUri);
+ } catch (NoSuchMethodException ex) {
+ // Can't find appropriate constructor
+ throw new ObjectNotFoundException(subjectUri);
+ } catch (InstantiationException ex) {
+ // Can't instatiate object
+ throw new ObjectNotFoundException(subjectUri);
+ } catch (InvocationTargetException ex) {
+ // Can't invoke constructor
+ throw new ObjectNotFoundException(subjectUri);
+ } catch (IllegalAccessException ex) {
+ // Constructor is not public
+ throw new ObjectNotFoundException(subjectUri);
+ } catch (ObjectAlreadyExistsException ex) {
+ // Should never happen
+ e.printStackTrace();
+ throw new ObjectNotFoundException(subjectUri);
+ }
+ return subjectUri.getStore().retrieveObject(subjectUri);
+ }
+ }
}
-
+
+
}