Advertisement
Gigi95

User management

Apr 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. import org.alfresco.model.ContentModel;
  2. import org.alfresco.service.ServiceRegistry;
  3. import org.alfresco.service.cmr.security.AuthenticationService;
  4. import org.alfresco.service.cmr.security.PermissionService;
  5. import org.alfresco.service.cmr.security.PersonService;
  6. import org.alfresco.util.ApplicationContextHelper;
  7. import org.springframework.context.ApplicationContext;
  8.  
  9. import java.util.HashMap;
  10. import java.util.Map;
  11.  
  12. public class UserService {
  13.     private static ServiceRegistry serviceRegistry;
  14.  
  15.     private static AuthenticationService authService;
  16.  
  17.     private static PersonService personService;
  18.  
  19.     private static PermissionService permissionService;
  20.  
  21.     public static void init(ApplicationContext ctx) {
  22.         ctx = ApplicationContextHelper.getApplicationContext();
  23.         if(ctx!=null && ctx.containsBean(ServiceRegistry.SERVICE_REGISTRY)){
  24.             serviceRegistry = (ServiceRegistry)ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
  25.             if(serviceRegistry!=null){
  26.                 authService = serviceRegistry.getAuthenticationService();
  27.             }
  28.             if(serviceRegistry!=null){
  29.                 personService = serviceRegistry.getPersonService();
  30.             }
  31.         }
  32.     }
  33.  
  34.     private void createUser(String userName, String passwd){
  35.  
  36.         if(!personService.personExists(userName)){
  37.             Map user = new HashMap();
  38.             user.put(ContentModel.PROP_USERNAME, userName);
  39.             user.put(ContentModel.PROP_FIRSTNAME, "firstName");
  40.             user.put(ContentModel.PROP_LASTNAME, "lastName");
  41.             user.put(ContentModel.PROP_EMAIL, userName+"@example.com");
  42.             user.put(ContentModel.PROP_TITLE, "jobTitle");
  43.  
  44.             personService.createPerson(user);
  45.         }
  46.  
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement