1 17 package org.alfresco.util; 18 19 import java.io.Serializable ; 20 import java.util.HashMap ; 21 22 import org.alfresco.model.ContentModel; 23 import org.alfresco.service.cmr.repository.NodeRef; 24 import org.alfresco.service.cmr.repository.NodeService; 25 import org.alfresco.service.cmr.security.AuthenticationService; 26 import org.alfresco.service.namespace.NamespaceService; 27 import org.alfresco.service.namespace.QName; 28 29 34 public abstract class TestWithUserUtils extends BaseSpringTest 35 { 36 45 public static void createUser( 46 String userName, 47 String password, 48 NodeRef rootNodeRef, 49 NodeService nodeService, 50 AuthenticationService authenticationService) 51 { 52 QName children = ContentModel.ASSOC_CHILDREN; 53 QName system = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "system"); 54 QName container = ContentModel.TYPE_CONTAINER; 55 QName types = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "people"); 56 57 NodeRef systemNodeRef = nodeService.createNode(rootNodeRef, children, system, container).getChildRef(); 58 NodeRef typesNodeRef = nodeService.createNode(systemNodeRef, children, types, container).getChildRef(); 59 60 HashMap <QName, Serializable > properties = new HashMap <QName, Serializable >(); 61 properties.put(ContentModel.PROP_USERNAME, userName); 62 NodeRef goodUserPerson = nodeService.createNode(typesNodeRef, children, ContentModel.TYPE_PERSON, container, properties).getChildRef(); 63 64 66 authenticationService.createAuthentication(userName, password.toCharArray()); 67 } 68 69 77 public static void authenticateUser( 78 String userName, 79 String password, 80 NodeRef rootNodeRef, 81 AuthenticationService authenticationService) 82 { 83 authenticationService.authenticate(userName, password.toCharArray()); 84 } 85 86 92 public static String getCurrentUser(AuthenticationService authenticationService) 93 { 94 String un = authenticationService.getCurrentUserName(); 95 if (un != null) 96 { 97 return un; 98 } 99 else 100 { 101 throw new RuntimeException ("The current user could not be retrieved."); 102 } 103 104 } 105 106 public static void deleteUser(String user_name, String pwd, NodeRef ref, NodeService service, AuthenticationService service2) 107 { 108 service2.deleteAuthentication(user_name); 109 } 110 111 } 112 | Popular Tags |