Java Code Examples for org.alfresco.service.cmr.security.MutableAuthenticationService#createAuthentication()

The following examples show how to use org.alfresco.service.cmr.security.MutableAuthenticationService#createAuthentication() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DownloadServiceIntegrationTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void createUser(String username)
{
    PersonService personService = APP_CONTEXT_INIT.getApplicationContext().getBean("PersonService", PersonService.class);

    MutableAuthenticationService mutableAuthenticationService = APP_CONTEXT_INIT.getApplicationContext()
        .getBean("authenticationService", MutableAuthenticationService.class);
    if (mutableAuthenticationService.authenticationExists(username))
    {
        return;
    }

    mutableAuthenticationService.createAuthentication(username, "password".toCharArray());

    PropertyMap personProperties = new PropertyMap();
    personProperties.put(ContentModel.PROP_USERNAME, username);
    personProperties.put(ContentModel.PROP_AUTHORITY_DISPLAY_NAME, "title" + username);
    personProperties.put(ContentModel.PROP_FIRSTNAME, "firstName");
    personProperties.put(ContentModel.PROP_LASTNAME, "lastName");
    personProperties.put(ContentModel.PROP_EMAIL, username + "@example.com");
    personProperties.put(ContentModel.PROP_JOBTITLE, "jobTitle");
    personService.createPerson(personProperties);
}
 
Example 2
Source File: TestWithUserUtils.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Authenticate as the given user.  If the user does not exist, then authenticate as the system user
 * and create the authentication first.
 */
public static void authenticateUser(
        String userName,
        String password,
        MutableAuthenticationService authenticationService,
        AuthenticationComponent authenticationComponent)
{
    // go system
    try
    {
        authenticationComponent.setSystemUserAsCurrentUser();
        if (!authenticationService.authenticationExists(userName))
        {
            authenticationService.createAuthentication(userName, password.toCharArray());
        }
    }
    finally
    {
        authenticationComponent.clearCurrentSecurityContext();
    }
    authenticationService.authenticate(userName, password.toCharArray());
}
 
Example 3
Source File: OwnableServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void setUp() throws Exception
{
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE)
    {
        throw new AlfrescoRuntimeException(
                "A previous tests did not clean up transaction: " +
                AlfrescoTransactionSupport.getTransactionId());
    }
    
    nodeService = (NodeService) ctx.getBean("nodeService");
    authenticationService = (MutableAuthenticationService) ctx.getBean("authenticationService");
    authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    ownableService = (OwnableService) ctx.getBean("ownableService");
    permissionService = (PermissionService) ctx.getBean("permissionService");

    authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
    authenticationDAO = (MutableAuthenticationDao) ctx.getBean("authenticationDao");
    
    
    TransactionService transactionService = (TransactionService) ctx.getBean(ServiceRegistry.TRANSACTION_SERVICE.getLocalName());
    txn = transactionService.getUserTransaction();
    txn.begin();
    
    StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
    rootNodeRef = nodeService.getRootNode(storeRef);
    permissionService.setPermission(rootNodeRef, PermissionService.ALL_AUTHORITIES, PermissionService.ADD_CHILDREN, true);
    
    if(authenticationDAO.userExists("andy"))
    {
        authenticationService.deleteAuthentication("andy");
    }
    authenticationService.createAuthentication("andy", "andy".toCharArray());
    
    dynamicAuthority = new OwnerDynamicAuthority();
    dynamicAuthority.setOwnableService(ownableService);
   
    authenticationComponent.clearCurrentSecurityContext();
}
 
Example 4
Source File: TestWithUserUtils.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void createUser(
        String userName, 
        String password, 
        String email,
        NodeRef rootNodeRef,
        NodeService nodeService,
        MutableAuthenticationService authenticationService)
{    
    // ignore if the user's authentication already exists
    if (authenticationService.authenticationExists(userName))
    {
        // ignore
        return;
    }
    QName children = ContentModel.ASSOC_CHILDREN;
    QName system = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "system");
    QName container = ContentModel.TYPE_CONTAINER;
    QName types = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "people");
    
    NodeRef systemNodeRef = nodeService.createNode(rootNodeRef, children, system, container).getChildRef();
    NodeRef typesNodeRef = nodeService.createNode(systemNodeRef, children, types, container).getChildRef();
    
    HashMap<QName, Serializable> properties = new HashMap<QName, Serializable>();
    properties.put(ContentModel.PROP_USERNAME, userName);
    if (email != null && email.length() != 0)
    {
        properties.put(ContentModel.PROP_EMAIL, email);
    }
    nodeService.createNode(typesNodeRef, children, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, userName) , container, properties);
    
    // Create the users
    authenticationService.createAuthentication(userName, password.toCharArray()); 
}
 
Example 5
Source File: AclDaoComponentTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setUp() throws Exception
{
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE)
    {
        throw new AlfrescoRuntimeException(
                "A previous tests did not clean up transaction: " +
                AlfrescoTransactionSupport.getTransactionId());
    }
    
    aclDaoComponent = (AclDAO) applicationContext.getBean("aclDAO");
    
    nodeService = (NodeService) applicationContext.getBean("nodeService");
    dictionaryService = (DictionaryService) applicationContext.getBean(ServiceRegistry.DICTIONARY_SERVICE
            .getLocalName());
    permissionService = (PermissionServiceSPI) applicationContext.getBean("permissionService");
    namespacePrefixResolver = (NamespacePrefixResolver) applicationContext
            .getBean(ServiceRegistry.NAMESPACE_SERVICE.getLocalName());
    authenticationService = (MutableAuthenticationService) applicationContext.getBean("authenticationService");
    authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
    serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
    permissionModelDAO = (ModelDAO) applicationContext.getBean("permissionsModelDAO");
    personService = (PersonService) applicationContext.getBean("personService");
    authorityService = (AuthorityService) applicationContext.getBean("authorityService");
    
    authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
    authenticationDAO = (MutableAuthenticationDao) applicationContext.getBean("authenticationDao");
    transactionService = (TransactionService) applicationContext.getBean("transactionComponent");
    
    testTX = transactionService.getUserTransaction();
    testTX.begin();
    this.authenticationComponent.setSystemUserAsCurrentUser();
    
    StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.nanoTime());
    rootNodeRef = nodeService.getRootNode(storeRef);

    QName children = ContentModel.ASSOC_CHILDREN;
    QName system = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "system");
    QName container = ContentModel.TYPE_CONTAINER;
    QName types = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "people");

    systemNodeRef = nodeService.createNode(rootNodeRef, children, system, container).getChildRef();
    NodeRef typesNodeRef = nodeService.createNode(systemNodeRef, children, types, container).getChildRef();
    Map<QName, Serializable> props = createPersonProperties("andy");
    nodeService.createNode(typesNodeRef, children, ContentModel.TYPE_PERSON, container, props).getChildRef();
    props = createPersonProperties("lemur");
    nodeService.createNode(typesNodeRef, children, ContentModel.TYPE_PERSON, container, props).getChildRef();

    // create an authentication object e.g. the user
    if(authenticationDAO.userExists("andy"))
    {
        authenticationService.deleteAuthentication("andy");
    }
    authenticationService.createAuthentication("andy", "andy".toCharArray());

    if(authenticationDAO.userExists("lemur"))
    {
        authenticationService.deleteAuthentication("lemur");
    }
    authenticationService.createAuthentication("lemur", "lemur".toCharArray());
    
    if(authenticationDAO.userExists(AuthenticationUtil.getAdminUserName()))
    {
        authenticationService.deleteAuthentication(AuthenticationUtil.getAdminUserName());
    }
    authenticationService.createAuthentication(AuthenticationUtil.getAdminUserName(), "admin".toCharArray());
    
    authenticationComponent.clearCurrentSecurityContext();
}
 
Example 6
Source File: AbstractPermissionTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setUp() throws Exception
{
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE)
    {
        throw new AlfrescoRuntimeException(
                "A previous tests did not clean up transaction: " +
                AlfrescoTransactionSupport.getTransactionId());
    }
    
    nodeService = (NodeService) applicationContext.getBean("nodeService");
    dictionaryService = (DictionaryService) applicationContext.getBean(ServiceRegistry.DICTIONARY_SERVICE
            .getLocalName());
    permissionService = (PermissionServiceSPI) applicationContext.getBean("permissionService");
    permissionServiceImpl = (PermissionServiceImpl) applicationContext.getBean("permissionServiceImpl");
    namespacePrefixResolver = (NamespacePrefixResolver) applicationContext
            .getBean(ServiceRegistry.NAMESPACE_SERVICE.getLocalName());
    authenticationService = (MutableAuthenticationService) applicationContext.getBean("authenticationService");
    authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
    serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
    permissionModelDAO = (ModelDAO) applicationContext.getBean("permissionsModelDAO");
    personService = (PersonService) applicationContext.getBean("personService");
    authorityService = (AuthorityService) applicationContext.getBean("authorityService");
    authorityDAO = (AuthorityDAO) applicationContext.getBean("authorityDAO");
    siteService = (SiteService) applicationContext.getBean("SiteService"); // Big 'S'
    
    authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
    authenticationDAO = (MutableAuthenticationDao) applicationContext.getBean("authenticationDao");
    nodeDAO = (NodeDAO) applicationContext.getBean("nodeDAO");
    aclDaoComponent = (AclDAO) applicationContext.getBean("aclDAO");
    
    publicServiceAccessService = (PublicServiceAccessService) applicationContext.getBean("publicServiceAccessService");
    policyComponent = (PolicyComponent) applicationContext.getBean("policyComponent");
    
    retryingTransactionHelper = (RetryingTransactionHelper) applicationContext.getBean("retryingTransactionHelper");
    
    transactionService = (TransactionService) applicationContext.getBean("transactionComponent");
    
    testTX = transactionService.getUserTransaction();
    testTX.begin();


    testStoreRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.nanoTime());
    rootNodeRef = nodeService.getRootNode(testStoreRef);

    QName children = ContentModel.ASSOC_CHILDREN;
    QName system = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "system");
    QName container = ContentModel.TYPE_CONTAINER;
    QName types = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "people");

    systemNodeRef = nodeService.createNode(rootNodeRef, children, system, container).getChildRef();
    NodeRef typesNodeRef = nodeService.createNode(systemNodeRef, children, types, container).getChildRef();
    Map<QName, Serializable> props = createPersonProperties(USER1_ANDY);
    nodeService.createNode(typesNodeRef, children, ContentModel.TYPE_PERSON, container, props).getChildRef();
    props = createPersonProperties(USER2_LEMUR);
    nodeService.createNode(typesNodeRef, children, ContentModel.TYPE_PERSON, container, props).getChildRef();

    // create an authentication object e.g. the user
    if(authenticationDAO.userExists(USER1_ANDY))
    {
        authenticationService.deleteAuthentication(USER1_ANDY);
    }
    authenticationService.createAuthentication(USER1_ANDY, USER1_ANDY.toCharArray());

    if(authenticationDAO.userExists(USER2_LEMUR))
    {
        authenticationService.deleteAuthentication(USER2_LEMUR);
    }
    authenticationService.createAuthentication(USER2_LEMUR, USER2_LEMUR.toCharArray());
    
    if(authenticationDAO.userExists(USER3_PAUL))
    {
        authenticationService.deleteAuthentication(USER3_PAUL);
    }
    authenticationService.createAuthentication(USER3_PAUL, USER3_PAUL.toCharArray());
    
    if(authenticationDAO.userExists(AuthenticationUtil.getAdminUserName()))
    {
        authenticationService.deleteAuthentication(AuthenticationUtil.getAdminUserName());
    }
    authenticationService.createAuthentication(AuthenticationUtil.getAdminUserName(), "admin".toCharArray());
    
    authenticationComponent.clearCurrentSecurityContext();
    
    assertTrue(permissionServiceImpl.getAnyDenyDenies());
}
 
Example 7
Source File: LockOwnerDynamicAuthorityTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setUp() throws Exception
{
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE)
    {
        throw new AlfrescoRuntimeException(
                "A previous tests did not clean up transaction: " +
                AlfrescoTransactionSupport.getTransactionId());
    }
    
    nodeService = (NodeService) ctx.getBean("nodeService");
    authenticationService = (MutableAuthenticationService) ctx.getBean("authenticationService");
    authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    lockService = (LockService) ctx.getBean("lockService");
    permissionService = (PermissionService) ctx.getBean("permissionService");
    authenticationDAO = (MutableAuthenticationDao) ctx.getBean("authenticationDao");

    checkOutCheckInService = (CheckOutCheckInService) ctx.getBean("checkOutCheckInService");
    ownableService = (OwnableService) ctx.getBean("ownableService");
    
    authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());

    TransactionService transactionService = (TransactionService) ctx.getBean(ServiceRegistry.TRANSACTION_SERVICE
            .getLocalName());
    userTransaction = transactionService.getUserTransaction();
    userTransaction.begin();

    StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
    rootNodeRef = nodeService.getRootNode(storeRef);
    permissionService.setPermission(rootNodeRef, PermissionService.ALL_AUTHORITIES, PermissionService.ADD_CHILDREN,
            true);

    if (authenticationDAO.userExists("andy"))
    {
        authenticationService.deleteAuthentication("andy");
    }
    authenticationService.createAuthentication("andy", "andy".toCharArray());
    if (authenticationDAO.userExists("lemur"))
    {
        authenticationService.deleteAuthentication("lemur");
    }
    authenticationService.createAuthentication("lemur", "lemur".toCharArray());
    if (authenticationDAO.userExists("frog"))
    {
        authenticationService.deleteAuthentication("frog");
    }
    authenticationService.createAuthentication("frog", "frog".toCharArray());

    dynamicAuthority = new LockOwnerDynamicAuthority();
    dynamicAuthority.setLockService(lockService);

    authenticationComponent.clearCurrentSecurityContext();
}
 
Example 8
Source File: AuthorityServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setUp() throws Exception
{
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE)
    {
        throw new AlfrescoRuntimeException(
                "A previous tests did not clean up transaction: " +
                AlfrescoTransactionSupport.getTransactionId());
    }
    
    authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    authenticationService = (MutableAuthenticationService) ctx.getBean("authenticationService");
    authorityService = (AuthorityService) ctx.getBean("authorityService");
    pubAuthorityService = (AuthorityService) ctx.getBean("AuthorityService");
    personService = (PersonService) ctx.getBean("personService");
    authenticationDAO = (MutableAuthenticationDao) ctx.getBean("authenticationDao");
    aclDaoComponent = (AclDAO) ctx.getBean("aclDAO");
    nodeService = (NodeService) ctx.getBean("nodeService");
    authorityBridgeTableCache = (AuthorityBridgeTableAsynchronouslyRefreshedCache) ctx.getBean("authorityBridgeTableCache");
    nodeArchiveService = (NodeArchiveService) ctx.getBean("nodeArchiveService");
    policyComponent = (PolicyComponent) ctx.getBean("policyComponent");
    transactionService = (TransactionService) ctx.getBean(ServiceRegistry.TRANSACTION_SERVICE.getLocalName());
    authorityDAO = ctx.getBean("authorityDAO", AuthorityDAO.class);
    
    String defaultAdminUser = AuthenticationUtil.getAdminUserName();
    AuthenticationUtil.setFullyAuthenticatedUser(defaultAdminUser);
    
    // cleanup trashcan
    nodeArchiveService.purgeAllArchivedNodes(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
    
    // note: currently depends on any existing (and/or bootstrap) group data - eg. default site "swsdp" (Sample Web Site Design Project)
    SiteService siteService = (SiteService) ctx.getBean("SiteService");
    SITE_CNT = siteService.listSites(defaultAdminUser).size();
    GRP_CNT = DEFAULT_GRP_CNT + (DEFAULT_SITE_GRP_CNT * SITE_CNT);
    ROOT_GRP_CNT = DEFAULT_GRP_CNT + (DEFAULT_SITE_ROOT_GRP_CNT * SITE_CNT);
    
    tx = transactionService.getUserTransaction();
    tx.begin();
    for (String user : getAllAuthorities(AuthorityType.USER))
    {
        if (user.equals(AuthenticationUtil.getGuestUserName()))
        {
            continue;
        }
        else if (user.equals(AuthenticationUtil.getAdminUserName()))
        {
            continue;
        }
        else
        {
            if (personService.personExists(user))
            {
                NodeRef person = personService.getPerson(user);
                NodeRef hf = DefaultTypeConverter.INSTANCE.convert(NodeRef.class, nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER));
                if (hf != null)
                {
                    nodeService.deleteNode(hf);
                }
                aclDaoComponent.deleteAccessControlEntries(user);
                personService.deletePerson(user);
            }
            if (authenticationDAO.userExists(user))
            {
                authenticationDAO.deleteUser(user);
            }
        }

    }
    tx.commit();

    tx = transactionService.getUserTransaction();
    tx.begin();

    if (!authenticationDAO.userExists("andy"))
    {
        authenticationService.createAuthentication("andy", "andy".toCharArray());
    }

    if (!authenticationDAO.userExists(AuthenticationUtil.getAdminUserName()))
    {
        authenticationService.createAuthentication(AuthenticationUtil.getAdminUserName(), "admin".toCharArray());
    }

    if (!authenticationDAO.userExists("administrator"))
    {
        authenticationService.createAuthentication("administrator", "administrator".toCharArray());
    }

}
 
Example 9
Source File: SearchServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    nodeService = (NodeService) ctx.getBean("dbNodeService");
    authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    authenticationService = (MutableAuthenticationService) ctx.getBean("authenticationService");
    authenticationDAO = (MutableAuthenticationDao) ctx.getBean("authenticationDao");
    pubSearchService = (SearchService) ctx.getBean("SearchService");
    pubPermissionService = (PermissionService) ctx.getBean("PermissionService");

    this.authenticationComponent.setSystemUserAsCurrentUser();

    TransactionService transactionService = (TransactionService) ctx.getBean(ServiceRegistry.TRANSACTION_SERVICE
            .getLocalName());
    tx = transactionService.getUserTransaction();
    tx.begin();

    if (!authenticationDAO.userExists("andy"))
    {
        authenticationService.createAuthentication("andy", "andy".toCharArray());
    }

    if (!authenticationDAO.userExists(AuthenticationUtil.getAdminUserName()))
    {
        authenticationService.createAuthentication(AuthenticationUtil.getAdminUserName(), "admin".toCharArray());
    }

    if (!authenticationDAO.userExists("administrator"))
    {
        authenticationService.createAuthentication("administrator", "administrator".toCharArray());
    }

    StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
    rootNodeRef = nodeService.getRootNode(storeRef);

    n1 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}01"),
            ContentModel.TYPE_FOLDER).getChildRef();
    pubPermissionService.setPermission(n1, "andy", "Read", true);
    n2 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}02"),
            ContentModel.TYPE_FOLDER).getChildRef();
    pubPermissionService.setPermission(n2, "andy", "Read", true);
    n3 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}03"),
            ContentModel.TYPE_FOLDER).getChildRef();
    pubPermissionService.setPermission(n3, "andy", "Read", true);
    n4 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}04"),
            ContentModel.TYPE_FOLDER).getChildRef();
    pubPermissionService.setPermission(n4, "andy", "Read", true);
    n5 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}05"),
            ContentModel.TYPE_FOLDER).getChildRef();
    pubPermissionService.setPermission(n5, "andy", "Read", true);
    nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}06"),
            ContentModel.TYPE_FOLDER).getChildRef();
    nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}07"),
            ContentModel.TYPE_FOLDER).getChildRef();
    nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}08"),
            ContentModel.TYPE_FOLDER).getChildRef();
    nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}09"),
            ContentModel.TYPE_FOLDER).getChildRef();
    nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}10"),
            ContentModel.TYPE_FOLDER).getChildRef();
}
 
Example 10
Source File: HiddenAspectTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Before
public void setup() throws SystemException, NotSupportedException
{
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    transactionService = serviceRegistry.getTransactionService();
    nodeService = serviceRegistry.getNodeService();
    fileFolderService = serviceRegistry.getFileFolderService();
    authenticationService = (MutableAuthenticationService) ctx.getBean("AuthenticationService");
    hiddenAspect = (HiddenAspect) ctx.getBean("hiddenAspect");
    interceptor = (FilenameFilteringInterceptor) ctx.getBean("filenameFilteringInterceptor");
    namespacePrefixResolver = (DictionaryNamespaceComponent) ctx.getBean("namespaceService");
    cociService = (CheckOutCheckInService) ctx.getBean("checkOutCheckInService");
    imapService = serviceRegistry.getImapService();
    personService = serviceRegistry.getPersonService();
    permissionService = serviceRegistry.getPermissionService();
    imapEnabled = serviceRegistry.getImapService().getImapServerEnabled();
    
    nodeDAO = (NodeDAO)ctx.getBean("nodeDAO");
    Properties properties = (Properties) ctx.getBean("global-properties");
    cmisDisableHide = Boolean.getBoolean(properties.getProperty("cmis.disable.hidden.leading.period.files"));
    
    // start the transaction
    txn = transactionService.getUserTransaction();
    txn.begin();
    
    username = "user" + System.currentTimeMillis();
    
    PropertyMap testUser = new PropertyMap();
    testUser.put(ContentModel.PROP_USERNAME, username);
    testUser.put(ContentModel.PROP_FIRSTNAME, username);
    testUser.put(ContentModel.PROP_LASTNAME, username);
    testUser.put(ContentModel.PROP_EMAIL, username + "@alfresco.com");
    testUser.put(ContentModel.PROP_JOBTITLE, "jobTitle");

    // authenticate
    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
    
    personService.createPerson(testUser);
    
    // create the ACEGI Authentication instance for the new user
    authenticationService.createAuthentication(username, username.toCharArray());
    
    user = new AlfrescoImapUser(username + "@alfresco.com", username, username);

    // create a test store
    storeRef = nodeService
            .createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + System.currentTimeMillis());
    rootNodeRef = nodeService.getRootNode(storeRef);
    permissionService.setPermission(rootNodeRef, username, PermissionService.CREATE_CHILDREN, true);
    
    AuthenticationUtil.setFullyAuthenticatedUser(username);
    
    topNodeRef = nodeService.createNode(
            rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName(NamespaceService.ALFRESCO_URI, "working root"),
            ContentModel.TYPE_FOLDER).getChildRef();
    
    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
}
 
Example 11
Source File: BaseCMISTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    
    cmisDictionaryService = (CMISDictionaryService) ctx.getBean("OpenCMISDictionaryService");
    cmisMapping = (CMISMapping) ctx.getBean("OpenCMISMapping");
    cmisQueryService = (CMISQueryService) ctx.getBean("OpenCMISQueryService");
    cmisConnector = (CMISConnector) ctx.getBean("CMISConnector");
    dictionaryService = (DictionaryService) ctx.getBean("dictionaryService");
    nodeService = (NodeService) ctx.getBean("nodeService");
    fileFolderService = (FileFolderService) ctx.getBean("fileFolderService");
    namespaceService = (NamespaceService) ctx.getBean("namespaceService");
    
    transactionService = (TransactionService) ctx.getBean("transactionComponent");
    authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    
    searchService = (SearchService) ctx.getBean("searchService");
    
    contentService = (ContentService) ctx.getBean("contentService");
    
    permissionService = (PermissionService) ctx.getBean("permissionService");
    
    versionService = (VersionService) ctx.getBean("versionService");
    
    authenticationService = (MutableAuthenticationService) ctx.getBean("authenticationService");
    authenticationDAO = (MutableAuthenticationDao) ctx.getBean("authenticationDao");
    
    thumbnailService = (ThumbnailService) ctx.getBean("thumbnailService");
    
    permissionModelDao = (ModelDAO) ctx.getBean("permissionsModelDAO");
    
    dictionaryDAO = (DictionaryDAO) ctx.getBean("dictionaryDAO");
    namespaceDao = (NamespaceDAO) ctx.getBean("namespaceDAO");

    testTX = transactionService.getUserTransaction();
    testTX.begin();
    // Authenticate as the admin user
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    
    String storeName = "CMISTest-" + getStoreName() + "-" + (new Date().getTime());
    this.storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, storeName);
    rootNodeRef = nodeService.getRootNode(storeRef);
    
    if(authenticationDAO.userExists("cmis"))
    {
        authenticationService.deleteAuthentication("cmis");
    }
    authenticationService.createAuthentication("cmis", "cmis".toCharArray());        
}
 
Example 12
Source File: PeopleImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
  public Person create(Person person)
  {
      validateCreatePersonData(person);

      if (! isAdminAuthority())
      {
          // note: do an explict check for admin here (since personExists does not throw 403 unlike createPerson,
          // hence next block would cause 409 to be returned)
          throw new PermissionDeniedException();
      }

      // Unfortunately PersonService.createPerson(...) only throws an AlfrescoRuntimeException
      // rather than a more specific exception and does not use a message ID either, so there's
      // no sensible way to know that it was thrown due to the user already existing - hence this check here.
      if (personService.personExists(person.getUserName()))
      {
          throw new ConstraintViolatedException("Person '" + person.getUserName() + "' already exists.");
      }

      // set enabled default value true
      if (person.isEnabled() == null)
      {
          person.setEnabled(true);
      }

      Map<QName, Serializable> props = person.toProperties();

MutableAuthenticationService mas = (MutableAuthenticationService) authenticationService;
mas.createAuthentication(person.getUserName(), person.getPassword().toCharArray());
mas.setAuthenticationEnabled(person.getUserName(), person.isEnabled());

// Add custom properties
if (person.getProperties() != null)
{
	Map<String, Object> customProps = person.getProperties();
	props.putAll(nodes.mapToNodeProperties(customProps));
}

NodeRef nodeRef = personService.createPerson(props);

// Add custom aspects
nodes.addCustomAspects(nodeRef, person.getAspectNames(), EXCLUDED_ASPECTS);

      // Write the contents of PersonUpdate.getDescription() text to a content file
      // and store the content URL in ContentModel.PROP_PERSONDESC
      if (person.getDescription() != null)
      {
          savePersonDescription(person.getDescription(), nodeRef);
      }

      // Return a fresh retrieval
      return getPerson(person.getUserName());
  }
 
Example 13
Source File: TestPeople.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Test
public void testGetPerson_withCustomProps() throws PublicApiException
{
    // Create the person directly using the Java services - we don't want to test
    // the REST API's "create person" function here, so we're isolating this test from it.
    MutableAuthenticationService authService = applicationContext.getBean("AuthenticationService", MutableAuthenticationService.class);
    PreferenceService prefService = applicationContext.getBean("PreferenceService", PreferenceService.class);
    Map<QName, Serializable> nodeProps = new HashMap<>();
    // The papi:lunchable aspect should be auto-added for the papi:lunch property
    nodeProps.put(PROP_LUNCH, "Falafel wrap");
    nodeProps.put(PROP_LUNCH_COMMENTS, "");
    
    // These properties should not be present when a person is retrieved
    // since they are present as top-level fields.
    String userName = "docbrown@" + account1.getId();
    nodeProps.put(ContentModel.PROP_USERNAME, userName);
    nodeProps.put(ContentModel.PROP_FIRSTNAME, "Doc");
    nodeProps.put(ContentModel.PROP_LASTNAME, "Brown");
    nodeProps.put(ContentModel.PROP_JOBTITLE, "Inventor");
    nodeProps.put(ContentModel.PROP_LOCATION, "Location");
    nodeProps.put(ContentModel.PROP_TELEPHONE, "123345");
    nodeProps.put(ContentModel.PROP_MOBILE, "456456");
    nodeProps.put(ContentModel.PROP_EMAIL, "[email protected]");
    nodeProps.put(ContentModel.PROP_ORGANIZATION, "Acme");
    nodeProps.put(ContentModel.PROP_COMPANYADDRESS1, "123 Acme Crescent");
    nodeProps.put(ContentModel.PROP_COMPANYADDRESS2, "Cholsey");
    nodeProps.put(ContentModel.PROP_COMPANYADDRESS3, "Oxfordshire");
    nodeProps.put(ContentModel.PROP_COMPANYPOSTCODE, "OX10 1AB");
    nodeProps.put(ContentModel.PROP_COMPANYTELEPHONE, "098876234");
    nodeProps.put(ContentModel.PROP_COMPANYFAX, "098234876");
    nodeProps.put(ContentModel.PROP_COMPANYEMAIL, "[email protected]");
    nodeProps.put(ContentModel.PROP_SKYPE, "doc.brown");
    nodeProps.put(ContentModel.PROP_INSTANTMSG, "doc.brown.instmsg");
    nodeProps.put(ContentModel.PROP_USER_STATUS, "status");
    nodeProps.put(ContentModel.PROP_USER_STATUS_TIME, new Date());
    nodeProps.put(ContentModel.PROP_GOOGLEUSERNAME, "doc.brown.google");
    nodeProps.put(ContentModel.PROP_SIZE_QUOTA, 12345000);
    nodeProps.put(ContentModel.PROP_SIZE_CURRENT, 1230);
    nodeProps.put(ContentModel.PROP_EMAIL_FEED_DISABLED, false);
    // TODO: PROP_PERSON_DESCRIPTION?
    
    // Namespaces that should be filtered
    nodeProps.put(ContentModel.PROP_ENABLED, true);
    nodeProps.put(ContentModel.PROP_SYS_NAME, "name-value");
    
    // Create a password and enable the user so that we can check the usr:* props aren't present later.
    AuthenticationUtil.setFullyAuthenticatedUser("admin@"+account1.getId());
    authService.createAuthentication(userName, "password".toCharArray());
    authService.setAuthenticationEnabled(userName, true);
    personService.createPerson(nodeProps);

    // Set a preference, so that we can test that we're filtering this property correctly.
    prefService.setPreferences(userName, Collections.singletonMap("olives", "green"));
    
    // Get the person using the REST API
    publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin"));
    Person person = people.getPerson(userName);
    
    // Did we get the correct aspects/properties?
    assertEquals(userName, person.getId());
    assertEquals("Doc", person.getFirstName());
    assertEquals("Falafel wrap", person.getProperties().get("papi:lunch"));
    assertTrue(person.getAspectNames().contains("papi:lunchable"));

    // Empty (zero length) string values are considered to be
    // null values, and will be represented the same as null
    // values (i.e. by non-existence of the property).
    assertNull(person.getProperties().get("papi:lunchcomments"));
    
    // Check that no properties are present that should have been filtered by namespace.
    for (String key : person.getProperties().keySet())
    {
        if (key.startsWith("cm:") || key.startsWith("sys:") || key.startsWith("usr:"))
        {
            Object value = person.getProperties().get(key);
            String keyValueStr = String.format("(key=%s, value=%s)", key, value);
            fail("Property " + keyValueStr +
                    " found with namespace that should have been excluded.");
        }
    }
}