use of org.craftercms.profile.management.exceptions.ResourceNotFoundException 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.management.exceptions.ResourceNotFoundException 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.management.exceptions.ResourceNotFoundException 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 + "'");
}
}
use of org.craftercms.profile.management.exceptions.ResourceNotFoundException in project profile by craftercms.
the class AccessTokenController method getAccessToken.
@RequestMapping(value = URL_GET_ACCESS_TOKEN, method = RequestMethod.GET)
@ResponseBody
public AccessToken getAccessToken(@PathVariable(PATH_VAR_ID) String id) throws ProfileException {
checkIfAllowed(id, Action.GET_PROFILE);
AccessToken token = accessTokenService.getToken(id);
if (token != null) {
return token;
} else {
throw new ResourceNotFoundException("No access token found with ID '" + id + "'");
}
}
use of org.craftercms.profile.management.exceptions.ResourceNotFoundException in project profile by craftercms.
the class ProfileController method updateProfile.
@RequestMapping(value = URL_UPDATE_PROFILE, method = RequestMethod.POST)
@ResponseBody
public Map<String, String> updateProfile(@RequestBody Profile profile) throws ProfileException {
String id = profile.getId().toString();
Profile currentProfile = profileService.getProfile(id);
if (currentProfile != null) {
checkIfAllowed(currentProfile, Action.UPDATE_PROFILE);
profileService.updateProfile(id, profile.getUsername(), profile.getPassword(), profile.getEmail(), profile.isEnabled(), profile.getRoles(), profile.getAttributes(), ProfileConstants.NO_ATTRIBUTE);
return Collections.singletonMap(MODEL_MESSAGE, String.format(MSG_PROFILE_UPDATED_FORMAT, id));
} else {
throw new ResourceNotFoundException("No profile found for ID '" + id + "'");
}
}
Aggregations