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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations