Advertisement
Gigi95

User Service

Apr 21st, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.49 KB | None | 0 0
  1. import org.alfresco.model.ContentModel;
  2. import org.alfresco.service.ServiceRegistry;
  3. import org.alfresco.service.cmr.repository.NodeRef;
  4. import org.alfresco.service.cmr.security.AuthenticationService;
  5. import org.alfresco.service.cmr.security.PermissionService;
  6. import org.alfresco.service.cmr.security.PersonService;
  7. import org.alfresco.util.ApplicationContextHelper;
  8. import org.springframework.context.ApplicationContext;
  9.  
  10. import java.util.HashMap;
  11. import java.util.Map;
  12.  
  13. public class UserService {
  14.  
  15.     private static ServiceRegistry serviceRegistry;
  16.  
  17.     private static AuthenticationService authService;
  18.  
  19.     private static PersonService personService;
  20.  
  21.     private static PermissionService permissionService;
  22.  
  23.     public static void init(ApplicationContext ctx) {
  24.         ctx = ApplicationContextHelper.getApplicationContext();
  25.         if(ctx!=null && ctx.containsBean(ServiceRegistry.SERVICE_REGISTRY)){
  26.             serviceRegistry = (ServiceRegistry)ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
  27.             if(serviceRegistry!=null){
  28.                 authService = serviceRegistry.getAuthenticationService();
  29.             }
  30.             if(serviceRegistry!=null){
  31.                 personService = serviceRegistry.getPersonService();
  32.             }
  33.         }
  34.     }
  35.  
  36.     private void getAuthentication(String userName, String passwd){
  37.         NodeRef person = personService.getPerson(authService.getCurrentUserName());
  38.     }
  39.  
  40.     private void createUser(String userName, String passwd){
  41.  
  42.         if(!personService.personExists(userName)){
  43.             Map user = new HashMap();
  44.             user.put(ContentModel.PROP_USERNAME, userName);
  45.             user.put(ContentModel.PROP_FIRSTNAME, "firstName");
  46.             user.put(ContentModel.PROP_LASTNAME, "lastName");
  47.             user.put(ContentModel.PROP_EMAIL, userName+"@example.com");
  48.             user.put(ContentModel.PROP_TITLE, "jobTitle");
  49.  
  50.             personService.createPerson(user);
  51.  
  52.         }
  53.  
  54.     }
  55.  
  56.     public static void main(String[] args) {
  57.         String connectionName = "http://127.0.0.1:8080/alfresco/";
  58.         String userName = "admin";
  59.         String passwd = "rockstar";
  60.  
  61.         if (serviceRegistry!=null) {
  62.             System.out.println("User Created!");
  63.             if (serviceRegistry != null) {
  64.                 System.out.println("Folder Created with Name: \t" + personService.getPerson(userName));
  65.             } else {
  66.                 System.out.println("Nope!");
  67.             }
  68.  
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement