cancel
Showing results for 
Search instead for 
Did you mean: 

custom User Registry groups

kriton
Champ in-the-making
Champ in-the-making
I am trying to implement a custom User Registry. I can succesfully added users in the Registry, but I have troubles adding groups in it. For the time being I am creating a sample User Registry with dummy users and groups (No syncing to my actual user database) as to test how this process works.

This is part of the log of alfresco startup. 3 users and 3 groups are suppsoed to have been added.

2012-05-30 11:38:27,025  ERROR [alfresco.sample.SampleUserRefistry] [main] WFT NO ERROR 5
2012-05-30 11:38:27,026  INFO  [security.sync.ChainingUserRegistrySynchronizer] [main] Synchronizing users and groups with user registry 'lbi2'
2012-05-30 11:38:27,038  INFO  [security.sync.ChainingUserRegistrySynchronizer] [main] Retrieving all groups from user registry 'lbi2'
2012-05-30 11:38:27,040  ERROR [alfresco.sample.SampleUserRefistry] [main] WFT NO ERROR 1
2012-05-30 11:38:27,050  INFO  [security.sync.ChainingUserRegistrySynchronizer] [main] lbi2 Group Analysis: Commencing batch of 3 entries
2012-05-30 11:38:27,128  INFO  [security.sync.ChainingUserRegistrySynchronizer] [main] lbi2 Group Analysis: Processed 3 entries out of 3. 100% complete. Rate: 38 per second. 0 failures detected.
2012-05-30 11:38:27,129  INFO  [security.sync.ChainingUserRegistrySynchronizer] [main] lbi2 Group Analysis: Completed batch of 3 entries
2012-05-30 11:38:27,132  INFO  [security.sync.ChainingUserRegistrySynchronizer] [main] Retrieving all users from user registry 'lbi2'
2012-05-30 11:38:27,137  ERROR [alfresco.sample.SampleUserRefistry] [main] WFT NO ERROR -1
2012-05-30 11:38:27,146  INFO  [security.sync.ChainingUserRegistrySynchronizer] [main] lbi2 User Creation and Association: Commencing batch of 3 entries
2012-05-30 11:38:27,217  INFO  [security.sync.ChainingUserRegistrySynchronizer] [main] lbi2 User Creation and Association: Processed 3 entries out of 3. 100% complete. Rate: 42 per second. 0 failures detected.
2012-05-30 11:38:27,218  INFO  [security.sync.ChainingUserRegistrySynchronizer] [main] lbi2 User Creation and Association: Completed batchof 3 entries
2012-05-30 11:38:27,219  INFO  [security.sync.ChainingUserRegistrySynchronizer] [main] Finished synchronizing users and groups with user registry 'lbi2'
2012-05-30 11:38:27,227  INFO  [security.sync.ChainingUserRegistrySynchronizer] [main] 3 user(s) and 3 group(s) processed

However once in the system I can see no trace of the groups having been created. Users are added normally.

This is my java class:

package mytests.sample;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.Set;
import org.alfresco.repo.management.subsystems.ActivateableBean;
import org.alfresco.repo.security.sync.NodeDescription;
import org.alfresco.repo.security.sync.UserRegistry;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;


public class SampleUserRefistry implements ActivateableBean, UserRegistry, InitializingBean {

   private static Log log = LogFactory.getLog(SampleUserRefistry.class);
   private static final String GROUP_PREFIX = "GROUP_";

   /** Is this bean active? I.e. should this part of the subsystem be used? */
   private boolean active = true;

   /** The namespace service. */
   private NamespaceService namespaceService;

   @Override
   public void afterPropertiesSet() throws Exception {
      log.error("WFT NO ERROR 0");
      StringBuilder errors = new StringBuilder();
      if(namespaceService==null) {
         errors.append("namespaceService is required. ");
      }
      if(errors.length()>0) {
         throw new IllegalArgumentException(errors.toString());
      }
   }

   /**
    * Gets descriptions of all the persons (users) in the user registry or all those changed since a certain date.
    *
    * @param modifiedSince
    *            if non-null, then only descriptions of users modified since this date should be returned; if
    *            null then descriptions of all users should be returned.
    * @return a {@link Collection} of {@link NodeDescription}s of all the persons (users) in the user registry or all
    *         those changed since a certain date. The description properties should correspond to those of an Alfresco
    *         person node.
    */
   @Override
   public Collection<NodeDescription> getPersons(Date modifiedSince) {
      log.error("WFT NO ERROR -1");
      ArrayList<NodeDescription> users = new ArrayList<NodeDescription>();
      users.add(createNodeUser("nuser1"));
      users.add(createNodeUser("nuser2"));
      users.add(createNodeUser("nuser3"));
      
      
      return users;

   }

   private NodeDescription createNodeUser(String username) {
      NodeDescription anode = new NodeDescription(username);
      anode.getProperties().put(QName.createQName("cm:userName", namespaceService), username);
      anode.getProperties().put(QName.createQName("cm:firstName", namespaceService), username);
      anode.getProperties().put(QName.createQName("cm:lastName", namespaceService), username);
      anode.getProperties().put(QName.createQName("cm:email", namespaceService), username+"@sample.com");
      anode.getProperties().put(QName.createQName("cm:organization", namespaceService), "none");
      return anode;
   }

   @Override
   public Collection<NodeDescription> getGroups(Date modifiedSince) {
      log.error("WFT NO ERROR 1");
      ArrayList<NodeDescription> groups = new ArrayList<NodeDescription>();

      groups.add(createNodeGroup("agroup1"));
      groups.add(createNodeGroup("agroup2"));
      groups.add(createNodeGroup("agroup3"));

      
      return groups ;
   }
   
   public NodeDescription createNodeGroup(String name){
      NodeDescription anode = new NodeDescription(GROUP_PREFIX+name);
      anode.getProperties().put(QName.createQName("cm:authorityName", namespaceService), GROUP_PREFIX+name);
      anode.getProperties().put(QName.createQName("cm:authorityDisplayName", namespaceService), name);
      //anode.getProperties().put(QName.createQName("cm:name", namespaceService), GROUP_PREFIX+name);
      
      return anode ;
   }
   

   @Override
   public Collection<String> getPersonNames() {
      log.error("WFT NO ERROR 2");
      ArrayList<String> names = new ArrayList<String>();
      names.add("nuser1");
      names.add("nuser2");
      names.add("nuser3");
      return names;
   }

   @Override
   public Collection<String> getGroupNames() {
      log.error("WFT NO ERROR 3");
      ArrayList<String> groupNames = new ArrayList<String>();
      groupNames.add("agroup1");
      groupNames.add("agroup2");
      groupNames.add("agroup3");
      
      return groupNames ;

   }

   /**
    * Gets the set of property names that are auto-mapped by this user registry. These should remain read-only for this
    * registry's users in the UI.
    *
    * @return the person mapped properties
    */
   @Override
   public Set<QName> getPersonMappedProperties() {
      log.error("WFT NO ERROR 4");
      return Collections.emptySet();
   }


   /**
    * Controls whether this bean is active. I.e. should this part of the subsystem be used?
    *
    * @param active
    *            true if this bean is active
    */
   public void setActive(boolean active)
   {
      this.active = active;
   }

   @Override
   public boolean isActive() {
      log.error("WFT NO ERROR 5");
      return this.active;
   }

   /**
    * Sets the namespace service.
    *
    * @param namespaceService
    *            the namespace service
    */
   public void setNamespaceService(NamespaceService namespaceService)
   {
      this.namespaceService = namespaceService;
   }

   private static boolean hasText(String str) {
      return (str!=null) && (str.trim().length()>0);
   }

   private static boolean hasntText(String str) {
      return !hasText(str);
   }

}


As you can see I create new users and groups and in code and I do no outside syncing, so the class is basically very simple. I think the problem lies in the properties or the name I set for the NodeDescription for the groups.

Any pointers ?

Thanks.
1 REPLY 1

iblanco
Confirmed Champ
Confirmed Champ
It looks good to me.

I've been developping something similar and I had a problem related with Zones. It might not be related but is worth checking.
Once the sync is executed go to the node explorer and go to "workspace/SpaceStore => System => Zones", make sure your external zone is not duplicated.

Check this ticket: https://issues.alfresco.com/jira/browse/ALF-13776

I solved it by "previously creating" the zone, but as you can see in the ticket that's not a very appreciated solution.