Advertisement
Gigi95

Untitled

Apr 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.67 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.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.  
  14.     private static ServiceRegistry serviceRegistry;
  15.  
  16.     private static AuthenticationService authService;
  17.  
  18.     private static PersonService personService;
  19.  
  20.     public static void init(ApplicationContext ctx) {
  21.         ctx = ApplicationContextHelper.getApplicationContext();
  22.         if(ctx!=null){
  23.             System.out.println("Application Context is not null");
  24.         } else
  25.             {System.out.print("Application Context is null");}
  26.  
  27.         if(ctx!=null && ctx.containsBean(ServiceRegistry.SERVICE_REGISTRY)){
  28.             serviceRegistry = (ServiceRegistry)ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
  29.             if(serviceRegistry!=null){
  30.                 authService = serviceRegistry.getAuthenticationService();
  31.             }
  32.             if(serviceRegistry!=null){
  33.                 personService = serviceRegistry.getPersonService();
  34.             }
  35.         }
  36.     }
  37.  
  38.     private void getAuthentication(String userName, String passwd){
  39.         NodeRef user = personService.getPerson(authService.getCurrentUserName());
  40.         if(user!=null){
  41.             System.out.println("Person is not null");
  42.         } else
  43.         {System.out.println("Person is null");}
  44.     }
  45.  
  46.     private void createUser(String userName, String passwd){
  47.         if(!personService.personExists(userName)){
  48.             Map user = new HashMap();
  49.             user.put(ContentModel.PROP_USERNAME, userName);
  50.             user.put(ContentModel.PROP_FIRSTNAME, "firstName");
  51.             user.put(ContentModel.PROP_LASTNAME, "lastName");
  52.             user.put(ContentModel.PROP_EMAIL, userName+"@example.com");
  53.             user.put(ContentModel.PROP_TITLE, "jobTitle");
  54.  
  55.             personService.createPerson(user);
  56.  
  57.         }
  58.  
  59.     }
  60.  
  61.     public static void main(String[] args) {
  62.         String connectionName = "http://127.0.0.1:8080/alfresco/";
  63.         String userName = "admin";
  64.         String passwd = "rockstar";
  65.  
  66.         if (serviceRegistry!=null) {
  67.             System.out.println("User Created!");
  68.             if (personService!= null) {
  69.                 System.out.println("User Created with Name: \t" + personService.getPerson(userName));
  70.             } else {
  71.                 System.out.println("Nope!");
  72.             }
  73.  
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement