use of org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException in project charon by wso2.
the class ResourceTypeResourceManager method listWithGET.
@Override
public SCIMResponse listWithGET(UserManager userManager, String filter, int startIndex, int count, String sortBy, String sortOrder, 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 ServiceProviderConfigResourceManager 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 ServiceProviderConfigResourceManager 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);
}
use of org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException in project charon by wso2.
the class ServiceProviderConfigResourceManager method listWithGET.
@Override
public SCIMResponse listWithGET(UserManager userManager, String filter, int startIndex, int count, String sortBy, String sortOrder, 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 UserResourceManager method create.
/*
* Returns SCIMResponse based on the sucess or failure of the create user operation
*
* @param scimObjectString -raw string containing user info
* @return usermanager - usermanager instance defined by the external implementor of charon
*/
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();
// 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);
// get the URIs of required attributes which must be given a value
Map<String, Boolean> requiredAttributes = ResourceManagerUtil.getOnlyRequiredAttributesURIs((SCIMResourceTypeSchema) CopyUtil.deepCopy(schema), attributes, excludeAttributes);
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.createUser(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) {
// because inside API code throws CharonException.
if (e.getStatus() == -1) {
e.setStatus(ResponseCodeConstants.CODE_INTERNAL_ERROR);
}
return AbstractResourceManager.encodeSCIMException(e);
} catch (BadRequestException e) {
return AbstractResourceManager.encodeSCIMException(e);
} catch (ConflictException e) {
return AbstractResourceManager.encodeSCIMException(e);
} catch (InternalErrorException e) {
return AbstractResourceManager.encodeSCIMException(e);
} catch (NotFoundException e) {
return AbstractResourceManager.encodeSCIMException(e);
}
}
Aggregations