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

The following examples show how to use org.alfresco.service.cmr.security.MutableAuthenticationService#deleteAuthentication() . 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: 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 2
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 3
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 4
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 5
Source File: TestWithUserUtils.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void deleteUser(String user_name, String pwd, NodeRef ref, NodeService service, MutableAuthenticationService service2)
{
    service2.deleteAuthentication(user_name);
}
 
Example 6
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());        
}