Search in sources :

Example 31 with Tenant

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

the class TenantServiceImpl method updateTenant.

protected Tenant updateTenant(String tenantName, UpdateCallback callback) throws ProfileException {
    Tenant tenant = getTenant(tenantName);
    if (tenant != null) {
        checkIfTenantActionIsAllowed(tenantName, TenantAction.UPDATE_TENANT);
        UpdateHelper updateHelper = new UpdateHelper();
        TenantUpdater tenantUpdater = new TenantUpdater(tenant, updateHelper, tenantRepository);
        callback.doWithTenant(tenantUpdater);
        try {
            tenantUpdater.update();
        } catch (MongoDataException e) {
            throw new I10nProfileException(ERROR_KEY_UPDATE_TENANT_ERROR, e, tenant.getName());
        }
    } else {
        throw new NoSuchTenantException(tenantName);
    }
    return tenant;
}
Also used : NoSuchTenantException(org.craftercms.profile.exceptions.NoSuchTenantException) UpdateHelper(org.craftercms.commons.mongo.UpdateHelper) Tenant(org.craftercms.profile.api.Tenant) TenantUpdater(org.craftercms.profile.utils.db.TenantUpdater) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException)

Example 32 with Tenant

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

the class TenantServiceImpl method removeAttributeDefinitions.

@Override
public Tenant removeAttributeDefinitions(final String tenantName, final Collection<String> attributeNames) throws ProfileException {
    for (String attributeName : attributeNames) {
        removeAttributeFromProfiles(tenantName, attributeName);
    }
    Tenant tenant = updateTenant(tenantName, new UpdateCallback() {

        @Override
        public void doWithTenant(TenantUpdater tenantUpdater) throws ProfileException {
            tenantUpdater.removeAttributeDefinitions(attributeNames);
        }
    });
    logger.debug(LOG_KEY_ATTRIBUTE_DEFINITIONS_REMOVED, attributeNames, 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 33 with Tenant

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

the class TenantServiceImpl method updateAttributeDefinitions.

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

        @Override
        public void doWithTenant(TenantUpdater tenantUpdater) throws ProfileException {
            tenantUpdater.updateAttributeDefinitions(attributeDefinitions);
        }
    });
    logger.debug(LOG_KEY_ATTRIBUTE_DEFINITIONS_UPDATED, attributeDefinitions, 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 34 with Tenant

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

the class MellonAutoLoginProcessor method processRequest.

@Override
public void processRequest(RequestContext context, RequestSecurityProcessorChain processorChain) throws Exception {
    HttpServletRequest request = context.getRequest();
    String username = request.getHeader(usernameHeaderName);
    Authentication auth = SecurityUtils.getAuthentication(request);
    if (StringUtils.isNotEmpty(username) && (auth == null || !auth.getProfile().getUsername().equals(username))) {
        String[] tenantNames = tenantsResolver.getTenants();
        Tenant tenant = getSsoEnabledTenant(tenantNames);
        if (tenant != null) {
            Profile profile = profileService.getProfileByUsername(tenant.getName(), username);
            if (profile == null) {
                profile = createProfileWithSsoInfo(username, tenant, request);
            }
            SecurityUtils.setAuthentication(request, authenticationManager.authenticateUser(profile));
        } else {
            logger.warn("An SSO login was attempted, but none of the tenants [{}] is enabled for SSO", tenantNames);
        }
    }
    processorChain.processRequest(context);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Tenant(org.craftercms.profile.api.Tenant) Authentication(org.craftercms.security.authentication.Authentication) Profile(org.craftercms.profile.api.Profile)

Example 35 with Tenant

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

the class TenantUtils method getTenantNames.

/**
 * Returns a list with the names of all tenants.
 *
 * @param tenantService the service that retrieves the {@link org.craftercms.profile.api.Tenant}s.
 *
 * @return the list of tenant names
 */
public static List<String> getTenantNames(TenantService tenantService) throws ProfileException {
    List<Tenant> tenants = tenantService.getAllTenants();
    List<String> tenantNames = new ArrayList<>(tenants.size());
    if (CollectionUtils.isNotEmpty(tenants)) {
        for (Tenant tenant : tenants) {
            tenantNames.add(tenant.getName());
        }
    }
    return tenantNames;
}
Also used : Tenant(org.craftercms.profile.api.Tenant) ArrayList(java.util.ArrayList)

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