Search in sources :

Example 21 with Tenant

use of org.craftercms.profile.api.Tenant in project profile by craftercms.

the class TenantServiceImpl method addRoles.

@Override
public Tenant addRoles(String tenantName, final Collection<String> roles) throws ProfileException {
    Tenant tenant = updateTenant(tenantName, new UpdateCallback() {

        @Override
        public void doWithTenant(TenantUpdater tenantUpdater) throws ProfileException {
            tenantUpdater.addAvailableRoles(roles);
        }
    });
    logger.debug(LOG_KEY_ROLES_ADDED, roles, tenantName);
    return tenant;
}
Also used : Tenant(org.craftercms.profile.api.Tenant) TenantUpdater(org.craftercms.profile.utils.db.TenantUpdater) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) ProfileException(org.craftercms.profile.api.exceptions.ProfileException)

Example 22 with Tenant

use of org.craftercms.profile.api.Tenant in project profile by craftercms.

the class TenantServiceImpl method updateTenant.

@Override
public Tenant updateTenant(final Tenant tenant) throws ProfileException {
    final String tenantName = tenant.getName();
    Tenant updatedTenant = updateTenant(tenant.getName(), new UpdateCallback() {

        @Override
        public void doWithTenant(TenantUpdater tenantUpdater) throws ProfileException {
            Tenant originalTenant = tenantUpdater.getTenant();
            Collection<String> originalRoles = originalTenant.getAvailableRoles();
            Collection<String> newRoles = tenant.getAvailableRoles();
            Collection<AttributeDefinition> originalDefinitions = originalTenant.getAttributeDefinitions();
            Collection<AttributeDefinition> newDefinitions = tenant.getAttributeDefinitions();
            Collection<String> removedRoles = CollectionUtils.subtract(originalRoles, newRoles);
            Collection<AttributeDefinition> removedDefinitions = CollectionUtils.subtract(originalDefinitions, newDefinitions);
            for (String removedRole : removedRoles) {
                removeRoleFromProfiles(tenantName, removedRole);
            }
            for (AttributeDefinition removedDefinition : removedDefinitions) {
                removeAttributeFromProfiles(tenantName, removedDefinition.getName());
            }
            tenantUpdater.setVerifyNewProfiles(tenant.isVerifyNewProfiles());
            tenantUpdater.setSsoEnabled(tenant.isSsoEnabled());
            tenantUpdater.setAvailableRoles(tenant.getAvailableRoles());
            tenantUpdater.setAttributeDefinitions(tenant.getAttributeDefinitions());
        }
    });
    for (AttributeDefinition definition : updatedTenant.getAttributeDefinitions()) {
        addDefaultValue(tenantName, definition.getName(), definition.getDefaultValue());
    }
    return updatedTenant;
}
Also used : Tenant(org.craftercms.profile.api.Tenant) TenantUpdater(org.craftercms.profile.utils.db.TenantUpdater) Collection(java.util.Collection) AttributeDefinition(org.craftercms.profile.api.AttributeDefinition) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) ProfileException(org.craftercms.profile.api.exceptions.ProfileException)

Example 23 with Tenant

use of org.craftercms.profile.api.Tenant in project profile by craftercms.

the class TenantServiceImpl method removeRoles.

@Override
public Tenant removeRoles(final String tenantName, final Collection<String> roles) throws ProfileException {
    Tenant tenant = updateTenant(tenantName, new UpdateCallback() {

        @Override
        public void doWithTenant(TenantUpdater tenantUpdater) throws ProfileException {
            for (String role : roles) {
                removeRoleFromProfiles(tenantName, role);
            }
            tenantUpdater.removeAvailableRoles(roles);
        }
    });
    logger.debug(LOG_KEY_ROLES_REMOVED, roles, tenantName);
    return tenant;
}
Also used : Tenant(org.craftercms.profile.api.Tenant) TenantUpdater(org.craftercms.profile.utils.db.TenantUpdater) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) ProfileException(org.craftercms.profile.api.exceptions.ProfileException)

Example 24 with Tenant

use of org.craftercms.profile.api.Tenant in project profile by craftercms.

the class TenantServiceIT method testRemoveRoles.

@Test
public void testRemoveRoles() throws Exception {
    tenantService.createTenant(getCorporateTenant());
    try {
        Tenant tenant = tenantService.removeRoles(CORPORATE_TENANT_NAME, Arrays.asList(ADMIN_ROLE));
        Set<String> expectedRoles = new HashSet<>(CORPORATE_ROLES);
        expectedRoles.remove(ADMIN_ROLE);
        assertNotNull(tenant);
        assertEquals(expectedRoles, tenant.getAvailableRoles());
    } finally {
        tenantService.deleteTenant(CORPORATE_TENANT_NAME);
    }
}
Also used : Tenant(org.craftercms.profile.api.Tenant) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 25 with Tenant

use of org.craftercms.profile.api.Tenant in project profile by craftercms.

the class TenantServiceIT method testDeleteTenant.

@Test
public void testDeleteTenant() throws Exception {
    Tenant tenant = tenantService.createTenant(getCorporateTenant());
    assertNotNull(tenant);
    tenantService.deleteTenant(tenant.getName());
    tenant = tenantService.getTenant(tenant.getName());
    assertNull(tenant);
}
Also used : Tenant(org.craftercms.profile.api.Tenant) Test(org.junit.Test)

Aggregations

Tenant (org.craftercms.profile.api.Tenant)46 Test (org.junit.Test)21 I10nProfileException (org.craftercms.profile.api.exceptions.I10nProfileException)12 AttributeDefinition (org.craftercms.profile.api.AttributeDefinition)8 TenantUpdater (org.craftercms.profile.utils.db.TenantUpdater)8 HashMap (java.util.HashMap)7 ProfileException (org.craftercms.profile.api.exceptions.ProfileException)7 Mockito.anyString (org.mockito.Mockito.anyString)7 MongoDataException (org.craftercms.commons.mongo.MongoDataException)5 Profile (org.craftercms.profile.api.Profile)5 ResourceNotFoundException (org.craftercms.profile.management.exceptions.ResourceNotFoundException)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 HashSet (java.util.HashSet)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Date (java.util.Date)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 DuplicateKeyException (org.craftercms.commons.mongo.DuplicateKeyException)1 UpdateHelper (org.craftercms.commons.mongo.UpdateHelper)1