@Override
@PUT
public Object put(Context context, Request request, Response response, Object payload)
throws ResourceException
{
UserToRoleResourceRequest mappingRequest = (UserToRoleResourceRequest) payload;
if (mappingRequest.getData() == null) {
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST,
"User Role Mapping was not found in the Request.");
}
String userId = this.getUserId(request);
String sourceId = this.getSourceId(request);
// check if the user exists
try {
if (this.getSecuritySystem().getUser(userId, sourceId) == null) {
throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "User with id '" + userId + "' not found.");
}
}
catch (UserNotFoundException e) {
throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "User with id '" + userId + "' not found.");
}
catch (NoSuchUserManagerException e) {
this.getLogger().warn(e.getMessage(), e);
throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "User with id '" + userId + "' not found.");
}
// get the dto
UserToRoleResource userToRole = mappingRequest.getData();
Set<RoleIdentifier> roleIdentifiers = this.restToSecurityModel(userToRole);
if (roleIdentifiers.size() == 0) {
throw new PlexusResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Configuration error.",