stephan 2002/07/22 14:26:50 Modified: src/scratchpad/src/org/apache/cocoon/components/repository/impl SlidePrincipalProvider.java Log: Finished the principal provider for the Slide repository. The current implementation works, but should redesigned to use the classes java.security.Principal and java.security.acl.Group. Revision Changes Path 1.5 +197 -22 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/repository/impl/SlidePrincipalProvider.java Index: SlidePrincipalProvider.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/repository/impl/SlidePrincipalProvider.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- SlidePrincipalProvider.java 21 Jul 2002 22:50:55 -0000 1.4 +++ SlidePrincipalProvider.java 22 Jul 2002 21:26:50 -0000 1.5 @@ -91,6 +91,7 @@ import org.apache.slide.macro.MacroParameters; import org.apache.slide.security.Security; import org.apache.slide.structure.GroupNode; +import org.apache.slide.structure.LinkNode; import org.apache.slide.structure.ObjectAlreadyExistsException; import org.apache.slide.structure.ObjectNode; import org.apache.slide.structure.ObjectNotFoundException; @@ -240,10 +241,10 @@ String name = userobject.getUri().substring(userspath.length()+1); // FIXME the CVS code from slide does only implement getRoles - /*Enumeration roles = this.security.getRoles(user); + Enumeration roles = this.security.getRoles(userobject); String role = null; if (roles.hasMoreElements()) - role = (String)children.nextElement();*/ + role = (String)roles.nextElement(); String password = null; try { @@ -254,13 +255,14 @@ NodeRevisionDescriptor revisionDescriptor = this.content.retrieve(slidetoken, revisionDescriptors); - if (revisionDescriptor.getProperty("password")!=null) - password = (String)revisionDescriptor.getProperty("password").getValue(); + if (revisionDescriptor.getProperty("password", NodeProperty.SLIDE_NAMESPACE)!=null) + password = (String)revisionDescriptor.getProperty("password", + NodeProperty.SLIDE_NAMESPACE).getValue(); } catch (RevisionDescriptorNotFoundException rdnfe) { // ignore } - principals.add(new Principal(name, /*role,*/ password)); + principals.add(new Principal(name, role, password)); } } @@ -309,25 +311,25 @@ revision.setProperty(new NodeProperty("source", "", true)); revision.setProperty(new NodeProperty("password", principal.getPassword(), NodeProperty.SLIDE_NAMESPACE)); - content.store(slidetoken, strUri, revision, null); + content.create(slidetoken, strUri, revision, null); nat.commit(); } catch (ObjectAlreadyExistsException e) { - // duplicate username - getLogger().warn("Could not create user", e); + // duplicate principal + getLogger().warn("Could not create principal", e); } catch (ServiceAccessException e) { // low level service access failed - getLogger().warn("Could not create user", e); - throw new ProcessingException("Could not create user", e); + getLogger().warn("Could not create principal", e); + throw new ProcessingException("Could not create principal", e); } catch (Exception e) { // any other errors are unanticipated - getLogger().warn("Could not create user", e); - throw new ProcessingException("Could not create user", e); + getLogger().warn("Could not create principal", e); + throw new ProcessingException("Could not create principal", e); } } catch (Exception e) { // rollback the transaction - getLogger().warn("Could not create user", e); + getLogger().warn("Could not create principal", e); try { nat.rollback(); } catch (Exception e2) { @@ -370,8 +372,8 @@ } catch (MacroException e) { // some aspect of the delete operation failed - getLogger().warn("Could not remove user", e); - throw new ProcessingException("Could not remove user", e); + getLogger().warn("Could not remove principal", e); + throw new ProcessingException("Could not remove principal", e); } } catch (Exception e) { // rollback the transaction @@ -383,7 +385,6 @@ } } } - } /** @@ -435,6 +436,55 @@ * @param group The group, which shoud be add/modified. */ public void addPrincipalGroup(Principal caller, PrincipalGroup group) throws ProcessingException { + // do the actual transaction + try { + try { + nat.begin(); + + SlideToken slidetoken = new SlideTokenImpl(new CredentialsToken(caller)); + + String strUri = config.getUsersPath() + "/" + group.getName(); + + // create the node in the structure + ObjectNode object = new GroupNode(); + structure.create(slidetoken, object, strUri); + + // create a revision with the appropriate properties set + NodeRevisionDescriptor revision = + new NodeRevisionDescriptor(0); + revision.setProperty( + new NodeProperty("resourcetype", "<collection/>", + true)); + revision.setCreationDate(new Date()); + revision.setLastModified(new Date()); + revision.setProperty(new NodeProperty("getcontentlength", "0", true)); + revision.setProperty(new NodeProperty("source", "", true)); + content.create(slidetoken, strUri, revision, null); + + nat.commit(); + + } catch (ObjectAlreadyExistsException e) { + // duplicate group + getLogger().warn("Could not create group", e); + } catch (ServiceAccessException e) { + // low level service access failed + getLogger().warn("Could not create group", e); + throw new ProcessingException("Could not create group", e); + } catch (Exception e) { + // any other errors are unanticipated + getLogger().warn("Could not create group", e); + throw new ProcessingException("Could not create group", e); + } + } catch (Exception e) { + // rollback the transaction + getLogger().warn("Could not create group", e); + try { + nat.rollback(); + } catch (Exception e2) { + // ignore + getLogger().error("Could roll back the operation", e2); + } + } } /** @@ -445,6 +495,44 @@ */ public void removePrincipalGroup(Principal caller, PrincipalGroup group) throws ProcessingException { + + if (group.getName().length() > 0) { + // get the helpers + Macro macro = nat.getMacroHelper(); + + SlideToken slidetoken = new SlideTokenImpl(new CredentialsToken(caller)); + + // get the path of the current authenticated user + String selfUri = config.getUsersPath() + "/" + caller.getName(); + + String strUri = config.getUsersPath() + "/" + group.getName(); + + // do the actual transaction + try { + try { + nat.begin(); + + // the user may not delete herself + if (!selfUri.equals(strUri)) + macro.delete(slidetoken, strUri, new MacroParameters(true, false)); + + nat.commit(); + + } catch (MacroException e) { + // some aspect of the delete operation failed + getLogger().warn("Could not remove group", e); + throw new ProcessingException("Could not remove group", e); + } + } catch (Exception e) { + // rollback the transaction + try { + nat.rollback(); + } catch (Exception e2) { + // ignore + getLogger().error("Could roll back the operation", e2); + } + } + } } /** @@ -452,9 +540,61 @@ * * @param caller The principal, which should do the operation * @param group The given group. - * @param user The principal to add to this group. + * @param principal The principal to add to this group. */ - public void addMember(Principal caller, PrincipalGroup group, Principal user) throws ProcessingException { + public void addMember(Principal caller, PrincipalGroup group, Principal principal) + throws ProcessingException { + // do the actual transaction + try { + try { + nat.begin(); + + SlideToken slidetoken = new SlideTokenImpl(new CredentialsToken(caller)); + + String strUri = config.getUsersPath() + "/" + group.getName() + "/" + principal.getName(); + + // create the node in the structure + LinkNode link = new LinkNode(); + structure.createLink(slidetoken, link, strUri, structure.retrieve(slidetoken, + config.getUsersPath() + "/" + principal.getName())); + + // create a revision with the appropriate properties set + NodeRevisionDescriptor revision = + new NodeRevisionDescriptor(0); + revision.setProperty( + new NodeProperty("resourcetype", "<collection/>", + true)); + revision.setCreationDate(new Date()); + revision.setLastModified(new Date()); + revision.setProperty(new NodeProperty("getcontentlength", "0", true)); + revision.setProperty(new NodeProperty("source", "", true)); + content.create(slidetoken, strUri, revision, null); + + nat.commit(); + + } catch (ObjectAlreadyExistsException e) { + // duplicate member + getLogger().warn("Could not create member", e); + } catch (ServiceAccessException e) { + // low level service access failed + getLogger().warn("Could not create member", e); + throw new ProcessingException("Could not create member", e); + } catch (Exception e) { + // any other errors are unanticipated + getLogger().warn("Could not create member", e); + throw new ProcessingException("Could not create member", e); + } + } catch (Exception e) { + // rollback the transaction + getLogger().warn("Could not create member", e); + try { + nat.rollback(); + } catch (Exception e2) { + // ignore + getLogger().error("Could roll back the operation", e2); + } + } + } /** @@ -515,9 +655,11 @@ NodeRevisionDescriptor revisionDescriptor = this.content.retrieve(slidetoken, revisionDescriptors); String password = null; - if ((revisionDescriptor.getProperty("password")!=null) && - (revisionDescriptor.getProperty("password").getValue()!=null)) - password = revisionDescriptor.getProperty("password").getValue().toString(); + if ((revisionDescriptor.getProperty("password", NodeProperty.SLIDE_NAMESPACE)!=null) && + (revisionDescriptor.getProperty("password", + NodeProperty.SLIDE_NAMESPACE).getValue()!=null)) + password = revisionDescriptor.getProperty("password", + NodeProperty.SLIDE_NAMESPACE).getValue().toString(); principals.add(new Principal(name/*, role*/, password)); } @@ -546,6 +688,39 @@ */ public void removeMember(Principal caller, PrincipalGroup group, Principal principal) throws ProcessingException { + + if ((group.getName().length() > 0) && (principal.getName().length() > 0)) { + // get the helpers + Macro macro = nat.getMacroHelper(); + + SlideToken slidetoken = new SlideTokenImpl(new CredentialsToken(caller)); + + String strUri = config.getUsersPath() + "/" + group.getName() + "/" + principal.getName(); + + // do the actual transaction + try { + try { + nat.begin(); + + macro.delete(slidetoken, strUri, new MacroParameters(true, false)); + + nat.commit(); + + } catch (MacroException e) { + // some aspect of the delete operation failed + getLogger().warn("Could not remove member", e); + throw new ProcessingException("Could not remove member", e); + } + } catch (Exception e) { + // rollback the transaction + try { + nat.rollback(); + } catch (Exception e2) { + // ignore + getLogger().error("Could roll back the operation", e2); + } + } + } } }
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]