use of org.craftercms.profile.api.Tenant in project profile by craftercms.
the class TenantServiceImplTest method getTenant2.
private Tenant getTenant2() {
Tenant tenant = new Tenant();
tenant.setId(TENANT2_ID);
tenant.setName(TENANT2_NAME);
tenant.setVerifyNewProfiles(true);
tenant.setAvailableRoles(SetUtils.asSet(ROLE1, ROLE2));
tenant.setAttributeDefinitions(new ArrayList<>(Collections.singletonList(getAttribute1Definition())));
return tenant;
}
use of org.craftercms.profile.api.Tenant in project profile by craftercms.
the class TenantServiceImplTest method testUpdateTenant.
@Test
public void testUpdateTenant() throws Exception {
AttributeDefinition def1 = new AttributeDefinition();
def1.setName(ATTRIB1_NAME);
AttributeDefinition def2 = new AttributeDefinition();
def2.setName(ATTRIB2_NAME);
def2.setDefaultValue(DEFAULT_ATTRIB_VALUE);
Tenant expected = getTenant1();
expected.getAvailableRoles().remove(ROLE1);
expected.getAttributeDefinitions().remove(def1);
expected.getAttributeDefinitions().add(def2);
Map<String, Object> expectedSetParams = new HashMap<>();
expectedSetParams.put("verifyNewProfiles", expected.isVerifyNewProfiles());
expectedSetParams.put("availableRoles", expected.getAvailableRoles());
expectedSetParams.put("ssoEnabled", expected.isSsoEnabled());
expectedSetParams.put("attributeDefinitions", expected.getAttributeDefinitions());
Tenant actual = tenantService.updateTenant(expected);
assertEqualTenants(expected, actual);
verify(profileRepository).removeRoleFromAll(TENANT1_NAME, ROLE1);
verify(profileRepository).removeAttributeFromAll(TENANT1_NAME, ATTRIB1_NAME);
verify(profileRepository).updateAllWithDefaultValue(TENANT1_NAME, ATTRIB2_NAME, DEFAULT_ATTRIB_VALUE);
verify(tenantRepository).update(TENANT1_ID.toString(), "{$set: #}", false, false, expectedSetParams);
}
use of org.craftercms.profile.api.Tenant in project profile by craftercms.
the class TenantController method getTenant.
@RequestMapping(value = URL_GET_TENANT, method = RequestMethod.GET)
@ResponseBody
public Tenant getTenant(@PathVariable(PATH_VAR_NAME) String name) throws ProfileException {
checkIfAllowed(name, Action.GET_TENANT);
Tenant tenant = tenantService.getTenant(name);
if (tenant != null) {
return tenant;
} else {
throw new ResourceNotFoundException("No tenant found with name '" + name + "'");
}
}
use of org.craftercms.profile.api.Tenant in project profile by craftercms.
the class TenantController method updateTenant.
@RequestMapping(value = URL_UPDATE_TENANT, method = RequestMethod.POST)
@ResponseBody
public Map<String, String> updateTenant(@RequestBody Tenant tenant) throws ProfileException {
String name = tenant.getName();
checkIfAllowed(name, Action.UPDATE_TENANT);
Tenant currentTenant = tenantService.getTenant(name);
if (currentTenant != null) {
if (!currentTenant.getAvailableRoles().contains(AuthorizationUtils.SUPERADMIN_ROLE) && tenant.getAvailableRoles().contains(AuthorizationUtils.SUPERADMIN_ROLE)) {
throw new ActionDeniedException(Action.UPDATE_TENANT.toString(), name);
}
if (currentTenant.getAvailableRoles().contains(AuthorizationUtils.SUPERADMIN_ROLE) && !tenant.getAvailableRoles().contains(AuthorizationUtils.SUPERADMIN_ROLE)) {
throw new ActionDeniedException(Action.UPDATE_TENANT.toString(), name);
}
tenantService.updateTenant(tenant);
return Collections.singletonMap(MODEL_MESSAGE, String.format(MSG_TENANT_UPDATED_FORMAT, name));
} else {
throw new ResourceNotFoundException("No tenant found with name '" + name + "'");
}
}
use of org.craftercms.profile.api.Tenant in project profile by craftercms.
the class TenantController method deleteTenant.
@RequestMapping(value = URL_DELETE_TENANT, method = RequestMethod.POST)
@ResponseBody
public Map<String, String> deleteTenant(@PathVariable(PATH_VAR_NAME) String name) throws ProfileException {
checkIfAllowed(name, Action.DELETE_TENANT);
Tenant tenant = tenantService.getTenant(name);
if (tenant != null) {
tenantService.deleteTenant(name);
return Collections.singletonMap(MODEL_MESSAGE, String.format(MSG_TENANT_DELETED_FORMAT, name));
} else {
throw new ResourceNotFoundException("No tenant found with name '" + name + "'");
}
}
Aggregations