Hi Jamie!

Thanks for the patch :)

In order for me to evaluate could you please explain what you did in the patch and why? What exactly was broken and what did you fix?

For future contributions could you please create the diffs using -u instead of -c?

Thanks again,

Oliver

Jamie Mortimore wrote:

In version 2.0rc1 of slide the auto-create-users functionality is not
working.

The attached patch fixes the problem. With the new functionality enabled
users authenticated by the servlet container are added as users within
slide.

It is configured with the following properties in Domain.xml:

auto-create-users and
auto-create-users-role

These properties do not have the same definition as they did previously.

auto-create-users specifies the user to use to create new users, so it
must be a root user and auto-create-users-role specifies the role to add
the new user to. If this property is not specified the user will not be
added to any roles.

A typical configuration would be:

<configuration>
        ...
        <auto-create-users>root</auto-create-users>
        <auto-create-users-role>user</auto-create-users-role>
        ...
</configuration>

The root user will be used to create new users. New users will be added
to the user role.

To apply the patch download the source for slide version 2.0rc1 and
extract it from the archive. Apply the patch from within the
jakarta-slide directory. On *n*x you would do something like:

$ tar -xzf jakarta-slide-server-2.0rc1-src.tar.gz
$ cd jakarta-slide
$ patch -p0 < <path-to-patch>/jakarta-slide-server-2.0rc1-src.patch

You can now build the distribution following the normal instructions.

Jamie.


------------------------------------------------------------------------


diff -rc ./src/share/org/apache/slide/common/NamespaceConfig.java ../../jakarta-slide/src/share/org/apache/slide/common/NamespaceConfig.java
*** ./src/share/org/apache/slide/common/NamespaceConfig.java 2004-02-05 16:05:04.000000000 +0000
--- ../../jakarta-slide/src/share/org/apache/slide/common/NamespaceConfig.java 2004-04-24 16:33:04.000000000 +0100
***************
*** 266,278 ****
/**
* Automatically create users.
*/
! protected boolean autoCreateUsers = false;
/**
* Roles implementation to be used for automatically created users.
*/
! protected String autoCreateUsersRole = "slideroles.basic.UserRoleImpl";
// ------------------------------------------------------------- Properties
--- 266,278 ----
/**
* Automatically create users.
*/
! protected String autoCreateUsers = null;
/**
* Roles implementation to be used for automatically created users.
*/
! protected String autoCreateUsersRole = null;
// ------------------------------------------------------------- Properties
***************
*** 595,601 ****
/**
* Is automcatic user creation active ?
*/
! public boolean isAutoCreateUsers() {
return autoCreateUsers;
}
--- 595,601 ----
/**
* Is automcatic user creation active ?
*/
! public String getAutoCreateUsers() {
return autoCreateUsers;
}
***************
*** 850,866 ****
}
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) {
}
}
--- 850,865 ----
}
try {
! autoCreateUsers = config.getConfiguration("auto-create-users").getValue();
} catch (ConfigurationException e) {
! autoCreateUsers = null;
}
try {
autoCreateUsersRole =
config.getConfiguration("auto-create-users-role").getValue();
} catch (ConfigurationException e) {
+ autoCreateUsersRole = null;
}
}
diff -rc ./src/share/org/apache/slide/content/ContentImpl.java ../../jakarta-slide/src/share/org/apache/slide/content/ContentImpl.java
*** ./src/share/org/apache/slide/content/ContentImpl.java 2004-02-26 11:31:01.000000000 +0000
--- ../../jakarta-slide/src/share/org/apache/slide/content/ContentImpl.java 2004-04-24 18:07:29.000000000 +0100
***************
*** 41,46 ****
--- 41,47 ----
import org.apache.slide.security.Security;
import org.apache.slide.structure.ActionNode;
import org.apache.slide.structure.LinkedObjectNotFoundException;
+ import org.apache.slide.structure.ObjectAlreadyExistsException;
import org.apache.slide.structure.ObjectNode;
import org.apache.slide.structure.ObjectNotFoundException;
import org.apache.slide.structure.Structure;
***************
*** 359,364 ****
--- 360,405 ----
return revisionContent;
}
+ /**
+ * Create a new user.
+ * + * @param root The token to use to create the user.
+ * @param user The name of the user to create.
+ * @param role The role to add the user to, null for no roles.
+ */
+ public void createUser(SlideToken root, String user, String role)
+ throws AccessDeniedException,
+ LinkedObjectNotFoundException, ServiceAccessException,
+ ObjectLockedException, ObjectNotFoundException,
+ ObjectAlreadyExistsException, RevisionAlreadyExistException,
+ RevisionDescriptorNotFoundException, RevisionNotFoundException {
+ Uri subjectUri = namespace.getUri(root, namespaceConfig.getUsersPath()+"/"+user);
+ SubjectNode object = new SubjectNode();
+ NodeRevisionDescriptor revisionDescriptor = new NodeRevisionDescriptor(0);
+ + structureHelper.create(root, object, subjectUri.toString());
+ revisionDescriptor.setProperty("password", "http://jakarta.apache.org/slide/";, "");
+ create(root, object.getUri(), revisionDescriptor, null);
+ + if (role != null) {
+ String userRole = namespaceConfig.getRolesPath()+"/"+role;
+ NodeRevisionDescriptors revisions = retrieve(root, userRole);
+ NodeRevisionNumber number = revisions.getLatestRevision(); + NodeRevisionDescriptor descriptor = retrieve(root, revisions, number);
+ NodeProperty prop = descriptor.getProperty("group-member-set");
+ + NodeProperty newNodeProp = new NodeProperty(prop.getName(),
+ new StringBuffer(prop.getValue().toString()).
+ append("<D:href xmlns:D='DAV:'>").
+ append(subjectUri.toString()).
+ append("</D:href>").toString(), prop.getNamespace(),
+ prop.getType(), prop.isProtected());
+ + descriptor.setProperty(newNodeProp);
+ + store(root, userRole, descriptor, null);
+ }
+ }
/**
* Create new revision descriptors.
diff -rc ./src/share/org/apache/slide/content/Content.java ../../jakarta-slide/src/share/org/apache/slide/content/Content.java
*** ./src/share/org/apache/slide/content/Content.java 2004-02-05 16:05:07.000000000 +0000
--- ../../jakarta-slide/src/share/org/apache/slide/content/Content.java 2004-04-24 18:07:12.000000000 +0100
***************
*** 28,33 ****
--- 28,34 ----
import org.apache.slide.lock.ObjectLockedException;
import org.apache.slide.security.AccessDeniedException;
import org.apache.slide.structure.LinkedObjectNotFoundException;
+ import org.apache.slide.structure.ObjectAlreadyExistsException;
import org.apache.slide.structure.ObjectNotFoundException;
/**
***************
*** 125,130 ****
--- 126,144 ----
ServiceAccessException, RevisionContentNotFoundException, ObjectLockedException;
+ /**
+ * Create a new user.
+ * + * @param root The token to use to create the user.
+ * @param user The name of the user to create.
+ * @param role The role to add the user to, null for no roles.
+ */
+ public void createUser(SlideToken root, String user, String role)
+ throws AccessDeniedException,
+ LinkedObjectNotFoundException, ServiceAccessException,
+ ObjectLockedException, ObjectNotFoundException,
+ ObjectAlreadyExistsException, RevisionAlreadyExistException,
+ RevisionDescriptorNotFoundException, RevisionNotFoundException;
/**
* Create new revision descriptors.
diff -rc ./src/share/org/apache/slide/security/SecurityImpl.java ../../jakarta-slide/src/share/org/apache/slide/security/SecurityImpl.java
*** ./src/share/org/apache/slide/security/SecurityImpl.java 2004-02-05 16:05:12.000000000 +0000
--- ../../jakarta-slide/src/share/org/apache/slide/security/SecurityImpl.java 2004-04-24 16:07:01.000000000 +0100
***************
*** 973,1041 ****
Uri subjectUri = namespace.getUri
(token, namespaceConfig.getUsersPath()+"/"+user);
! 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);
! }
! }
}
private void loadActionsCache(Namespace namespace, NamespaceConfig namespaceConfig) {
--- 973,979 ----
Uri subjectUri = namespace.getUri
(token, namespaceConfig.getUsersPath()+"/"+user);
! return subjectUri.getStore().retrieveObject(subjectUri);
}
private void loadActionsCache(Namespace namespace, NamespaceConfig namespaceConfig) {
diff -rc ./src/webdav/server/org/apache/slide/webdav/method/AbstractWebdavMethod.java ../../jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/AbstractWebdavMethod.java
*** ./src/webdav/server/org/apache/slide/webdav/method/AbstractWebdavMethod.java 2004-04-01 14:46:39.000000000 +0100
--- ../../jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/AbstractWebdavMethod.java 2004-04-24 16:26:39.000000000 +0100
***************
*** 36,47 ****
--- 36,49 ----
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+ import org.apache.slide.authenticate.CredentialsToken;
import org.apache.slide.common.Domain;
import org.apache.slide.common.NamespaceAccessToken;
import org.apache.slide.common.NestedSlideException;
import org.apache.slide.common.ServiceAccessException;
import org.apache.slide.common.SlideException;
import org.apache.slide.common.SlideToken;
+ import org.apache.slide.common.SlideTokenImpl;
import org.apache.slide.common.SlideTokenWrapper;
import org.apache.slide.content.Content;
import org.apache.slide.content.NodeProperty;
***************
*** 294,299 ****
--- 296,327 ----
this.resp = resp;
this.slideToken = WebdavUtils.getSlideToken(req);
this.requestUri = WebdavUtils.getRelativePath(req, config);
+ + String rootUserName = token.getNamespaceConfig().getAutoCreateUsers();
+ + if (rootUserName != null) { + try {
+ security.getPrincipal(slideToken);
+ } catch (ObjectNotFoundException e) {
+ SlideToken root = new SlideTokenImpl(new CredentialsToken(rootUserName));
+
+ try {
+ token.begin();
+ content.createUser(root,
+ slideToken.getCredentialsToken().getPublicCredentials(),
+ token.getNamespaceConfig().getAutoCreateUsersRole());
+ token.commit();
+ } catch (Exception ex) {
+ token.getLogger().log(ex,LOG_CHANNEL,Logger.ERROR);
+ int statusCode = WebdavStatus.SC_INTERNAL_SERVER_ERROR;
+ sendError( statusCode, ex );
+ throw new WebdavException( statusCode );
+ }
+ } catch (ServiceAccessException e) {
+ // ignore
+ }
+ }
+ parseRequestHeaders();
boolean transactionIsStarted = false;




------------------------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to