Java Code Examples for org.alfresco.repo.security.authentication.AuthenticationUtil#setMtEnabled()

The following examples show how to use org.alfresco.repo.security.authentication.AuthenticationUtil#setMtEnabled() . 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: MultiTAdminServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void stopTenants()
{
    tenantDeployers.clear();
    tenantDeployers = null;
    AuthenticationUtil.setMtEnabled(false);
}
 
Example 2
Source File: MultiTServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
public void setUp() throws Exception
{
    multiTServiceImpl = applicationContext.getBean("tenantService", MultiTServiceImpl.class);
    tenantAdminService = applicationContext.getBean("tenantAdminService", TenantAdminService.class);
    personService = applicationContext.getBean("PersonService", PersonService.class);
    tenantService = applicationContext.getBean("tenantService", TenantService.class);
    authenticationService = applicationContext.getBean("AuthenticationService", MutableAuthenticationService.class);
    transactionService = applicationContext.getBean("TransactionService", TransactionService.class);
    nodeService = applicationContext.getBean("NodeService", NodeService.class);
    searchService = applicationContext.getBean("SearchService", SearchService.class);
    namespaceService = applicationContext.getBean("NamespaceService", NamespaceService.class);

    DOMAIN = GUID.generate();
    USER1 = GUID.generate();
    USER2 = GUID.generate();
    USER3 = GUID.generate();
    USER2_WITH_DOMAIN = USER2 + TenantService.SEPARATOR + DOMAIN;
    STRING = GUID.generate();
    TENANT_STRING = addDomainToId(STRING, DOMAIN);
    STRING_WITH_EXISTENT_DOMAIN = TenantService.SEPARATOR + DOMAIN + TenantService.SEPARATOR;
    STRING_WITH_NONEXITENT_DOMAIN = TenantService.SEPARATOR + STRING + TenantService.SEPARATOR;
    TENANT_STORE = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, addDomainToId("SpacesStore", DOMAIN));
    TENANT_NODE_REF = new NodeRef(PROTOCOL, addDomainToId(IDENTIFIER, DOMAIN), ID);
    TENANT_STORE_REF = new StoreRef(PROTOCOL, addDomainToId(IDENTIFIER, DOMAIN));
    TENANT_QNAME = QName.createQName(addDomainToId(NAMESPACE_URI, DOMAIN), LOCAL_NAME);
    tenantAssocRef = new AssociationRef(TENANT_NODE_REF, QNAME, TENANT_NODE_REF);
    childAssocRef = new ChildAssociationRef(QNAME, NODE_REF, QNAME, NODE_REF);
    tenantChildAssocRef = new ChildAssociationRef(QNAME, TENANT_NODE_REF, QNAME, TENANT_NODE_REF);

    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());

    mtEnabled = AuthenticationUtil.isMtEnabled();
    AuthenticationUtil.setMtEnabled(false);
}
 
Example 3
Source File: MultiTServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@After
public void tearDown() throws Exception
{
    deleteTenant(DOMAIN);
    AuthenticationUtil.setMtEnabled(mtEnabled);
    AuthenticationUtil.clearCurrentSecurityContext();
}
 
Example 4
Source File: DiscussionServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@AfterClass public static void deleteClassTestNodesAndUsers() throws Exception
{
    performDeletionOfNodes(CLASS_TEST_NODES_TO_TIDY);
    deleteUser(TEST_USER);
    deleteTenant();
    
    TenantContextHolder.setTenantDomain("");
    AuthenticationUtil.setMtEnabled(false);
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
}
 
Example 5
Source File: MultiTAdminServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void startTenants()
{
    AuthenticationUtil.setMtEnabled(true);
    
    // initialise the tenant admin service and status of tenants (using attribute service)
    // note: this requires that the repository schema has already been initialised
    
    // register dictionary - to allow enable/disable tenant callbacks
    register(dictionaryComponent);
    
    if (isTenantDeployer(tenantFileContentStore))
    {
        // register file store - to allow enable/disable tenant callbacks
        // note: tenantFileContentStore must be registed before dictionaryRepositoryBootstrap
        register(tenantDeployer(tenantFileContentStore), 0);
    }
    
    UserTransaction userTransaction = transactionService.getUserTransaction();
    
    try
    {
        authenticationContext.setSystemUserAsCurrentUser();
        userTransaction.begin();
        
        // bootstrap Tenant Service internal cache
        List<Tenant> tenants = getAllTenants();
        
        int enabledCount = 0;
        int disabledCount = 0;
        
        for (Tenant tenant : tenants)
        {
            if ((! (isTenantRoutingContentStore(tenantFileContentStore))) && (! tenantFileContentStore.getRootLocation().equals(tenant.getRootContentStoreDir())))
            {
                // eg. ALF-14121 - MT will not work with replicating-content-services-context.sample if tenants are not co-mingled
                throw new AlfrescoRuntimeException("MT: cannot start tenants - TenantRoutingContentStore is not configured AND not all tenants use co-mingled content store");
            }
            
            String tenantDomain = tenant.getTenantDomain();
            
            if (tenant.isEnabled())
            {
                // notify tenant deployers registered so far ...
                notifyAfterEnableTenant(tenantDomain);
                enabledCount++;
            }
            else
            {
                disabledCount++;
                
                if (logger.isDebugEnabled())
                {
                    logger.debug("Tenant disabled: " + tenantDomain);
                }
            }
        }
        
        userTransaction.commit();
        
        if ((enabledCount+disabledCount) == 0)
        {
            AuthenticationUtil.setMtEnabled(false); // explicitly disable if there are no tenants
        }
        
        if (logger.isInfoEnabled() && ((enabledCount+disabledCount) > 0))
        {
            logger.info(String.format("Alfresco Multi-Tenant startup - %d enabled tenants, %d disabled tenants",
                                      enabledCount, disabledCount));
        }
        else if (logger.isDebugEnabled())
        {
            logger.debug(String.format("Alfresco Multi-Tenant startup - %d enabled tenants, %d disabled tenants",
                         enabledCount, disabledCount));
        }
    }
    catch(Throwable e)
    {
        // rollback the transaction
        try { if (userTransaction != null) {userTransaction.rollback();} } catch (Exception ex) {}
        throw new AlfrescoRuntimeException("Failed to bootstrap tenants", e);
    }
    finally
    {
        authenticationContext.clearCurrentSecurityContext();
    }
}