Merge branch 'RED-8343-fix' into 'main'

RED-8343: change 500 to 403

See merge request fforesight/tenant-user-management-service!78
This commit is contained in:
Yannik Hampe 2024-02-05 11:11:31 +01:00
commit 7f220bd348

View File

@ -45,23 +45,19 @@ public class UserPreferenceController implements UserPreferenceResource, PublicR
@PreAuthorize("hasAuthority('" + UserManagementPermissions.MANAGE_USER_PREFERENCES + "')")
public void setAttribute(@PathVariable(KEY_PARAMETER_NAME) String key, List<String> values) {
try {
String userId = KeycloakSecurity.getUserId();
String userId = KeycloakSecurity.getUserId();
var userResource = userService.getUserResource(userId);
var userRepresentation = userResource.toRepresentation();
var userResource = userService.getUserResource(userId);
var userRepresentation = userResource.toRepresentation();
var attributes = userRepresentation.getAttributes();
if (attributes == null) {
attributes = new HashMap<>();
}
attributes.put(key, values);
userRepresentation.setAttributes(attributes);
userResource.update(userRepresentation);
} catch(NotFoundException exception) {
throw new ForbiddenException("user could not be authenticated because user data does not exist");
var attributes = userRepresentation.getAttributes();
if (attributes == null) {
attributes = new HashMap<>();
}
attributes.put(key, values);
userRepresentation.setAttributes(attributes);
userResource.update(userRepresentation);
}