use of org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException in project charon by wso2.
the class MeResourceManager method getUserName.
public String getUserName(String scimObjectString) throws CharonException {
try {
// obtain the json encoder
JSONDecoder decoder = getDecoder();
// obtain the schema corresponding to user
// unless configured returns core-user schema or else returns extended user schema)
SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getUserResourceSchema();
// decode the SCIM User object, encoded in the submitted payload.
User user = (User) decoder.decodeResource(scimObjectString, schema, new User());
return user.getUserName();
} catch (BadRequestException | InternalErrorException | CharonException e) {
throw new CharonException("Error in getting the username from the anonymous request");
}
}
use of org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException in project charon by wso2.
the class MeResourceManager method create.
@Override
public SCIMResponse create(String scimObjectString, UserManager userManager, String attributes, String excludeAttributes) {
JSONEncoder encoder = null;
try {
// obtain the json encoder
encoder = getEncoder();
// obtain the json decoder
JSONDecoder decoder = getDecoder();
// obtain the schema corresponding to user
// unless configured returns core-user schema or else returns extended user schema)
SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getUserResourceSchema();
// get the URIs of required attributes which must be given a value
Map<String, Boolean> requiredAttributes = ResourceManagerUtil.getOnlyRequiredAttributesURIs((SCIMResourceTypeSchema) CopyUtil.deepCopy(schema), attributes, excludeAttributes);
// decode the SCIM User object, encoded in the submitted payload.
User user = (User) decoder.decodeResource(scimObjectString, schema, new User());
// validate the created user.
ServerSideValidator.validateCreatedSCIMObject(user, schema);
User createdUser;
if (userManager != null) {
/*handover the SCIM User object to the user usermanager provided by the SP.
need to send back the newly created user in the response payload*/
createdUser = userManager.createMe(user, requiredAttributes);
} else {
String error = "Provided user manager handler is null.";
// throw internal server error.
throw new InternalErrorException(error);
}
// encode the newly created SCIM user object and add id attribute to Location header.
String encodedUser;
Map<String, String> responseHeaders = new HashMap<String, String>();
if (createdUser != null) {
// create a deep copy of the user object since we are going to change it.
User copiedUser = (User) CopyUtil.deepCopy(createdUser);
// need to remove password before returning
ServerSideValidator.validateReturnedAttributes(copiedUser, attributes, excludeAttributes);
encodedUser = encoder.encodeSCIMObject(copiedUser);
// add location header
responseHeaders.put(SCIMConstants.LOCATION_HEADER, getResourceEndpointURL(SCIMConstants.USER_ENDPOINT) + "/" + createdUser.getId());
responseHeaders.put(SCIMConstants.CONTENT_TYPE_HEADER, SCIMConstants.APPLICATION_JSON);
} else {
String error = "Newly created User resource is null.";
throw new InternalErrorException(error);
}
// put the uri of the User object in the response header parameter.
return new SCIMResponse(ResponseCodeConstants.CODE_CREATED, encodedUser, responseHeaders);
} catch (CharonException e) {
return encodeSCIMException(e);
} catch (BadRequestException e) {
return encodeSCIMException(e);
} catch (ConflictException e) {
return encodeSCIMException(e);
} catch (InternalErrorException e) {
return encodeSCIMException(e);
} catch (NotFoundException e) {
return encodeSCIMException(e);
}
}
use of org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException in project charon by wso2.
the class ResourceTypeResourceManager method updateWithPUT.
@Override
public SCIMResponse updateWithPUT(String existingId, String scimObjectString, UserManager userManager, String attributes, String excludeAttributes) {
String error = "Request is undefined";
BadRequestException badRequestException = new BadRequestException(error, ResponseCodeConstants.INVALID_PATH);
return encodeSCIMException(badRequestException);
}
use of org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException in project charon by wso2.
the class ResourceTypeResourceManager method delete.
@Override
public SCIMResponse delete(String id, UserManager userManager) {
String error = "Request is undefined";
BadRequestException badRequestException = new BadRequestException(error, ResponseCodeConstants.INVALID_PATH);
return encodeSCIMException(badRequestException);
}
use of org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException in project charon by wso2.
the class ResourceTypeResourceManager method updateWithPATCH.
@Override
public SCIMResponse updateWithPATCH(String existingId, String scimObjectString, UserManager userManager, String attributes, String excludeAttributes) {
String error = "Request is undefined";
BadRequestException badRequestException = new BadRequestException(error, ResponseCodeConstants.INVALID_PATH);
return encodeSCIMException(badRequestException);
}
Aggregations