use of org.wso2.charon3.core.exceptions.BadRequestException in project charon by wso2.
the class MeResourceManager method get.
@Override
public SCIMResponse get(String userName, UserManager userManager, String attributes, String excludeAttributes) {
JSONEncoder encoder = null;
try {
// obtain the json encoder
encoder = getEncoder();
// 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);
/*API user should pass a usermanager impl to UserResourceEndpoint.
retrieve the user from the provided UM handler.*/
User user = ((UserManager) userManager).getMe(userName, requiredAttributes);
// if user not found, return an error in relevant format.
if (user == null) {
String error = "User not found in the user store.";
throw new NotFoundException(error);
}
// perform service provider side validation.
ServerSideValidator.validateRetrievedSCIMObject(user, schema, attributes, excludeAttributes);
// convert the user into requested format.
String encodedUser = encoder.encodeSCIMObject(user);
// if there are any http headers to be added in the response header.
Map<String, String> responseHeaders = new HashMap<String, String>();
responseHeaders.put(SCIMConstants.CONTENT_TYPE_HEADER, SCIMConstants.APPLICATION_JSON);
responseHeaders.put(SCIMConstants.LOCATION_HEADER, getResourceEndpointURL(SCIMConstants.USER_ENDPOINT) + "/" + user.getId());
return new SCIMResponse(ResponseCodeConstants.CODE_OK, encodedUser, responseHeaders);
} catch (NotFoundException e) {
return encodeSCIMException(e);
} catch (CharonException e) {
return encodeSCIMException(e);
} catch (BadRequestException e) {
return encodeSCIMException(e);
}
}
use of org.wso2.charon3.core.exceptions.BadRequestException in project charon by wso2.
the class ResourceTypeResourceManager method getResourceType.
/*
* return RESOURCE_TYPE schema
*
* @return
*/
private SCIMResponse getResourceType() {
JSONEncoder encoder = null;
try {
// obtain the json encoder
encoder = getEncoder();
// obtain the json decoder
JSONDecoder decoder = getDecoder();
// get the service provider config schema
SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getResourceTypeResourceSchema();
// create a string in json format for user resource type with relevant values
String scimUserObjectString = encoder.buildUserResourceTypeJsonBody();
// create a string in json format for group resource type with relevant values
String scimGroupObjectString = encoder.buildGroupResourceTypeJsonBody();
// build the user abstract scim object
AbstractSCIMObject userResourceTypeObject = (AbstractSCIMObject) decoder.decodeResource(scimUserObjectString, schema, new AbstractSCIMObject());
// add meta data
userResourceTypeObject = ServerSideValidator.validateResourceTypeSCIMObject(userResourceTypeObject);
// build the group abstract scim object
AbstractSCIMObject groupResourceTypeObject = (AbstractSCIMObject) decoder.decodeResource(scimGroupObjectString, schema, new AbstractSCIMObject());
// add meta data
groupResourceTypeObject = ServerSideValidator.validateResourceTypeSCIMObject(groupResourceTypeObject);
// build the root abstract scim object
AbstractSCIMObject resourceTypeObject = buildCombinedResourceType(userResourceTypeObject, groupResourceTypeObject);
// encode the newly created SCIM Resource Type object.
String encodedObject;
Map<String, String> responseHeaders = new HashMap<String, String>();
if (resourceTypeObject != null) {
// create a deep copy of the resource type object since we are going to change it.
AbstractSCIMObject copiedObject = (AbstractSCIMObject) CopyUtil.deepCopy(resourceTypeObject);
encodedObject = encoder.encodeSCIMObject(copiedObject);
// add location header
responseHeaders.put(SCIMConstants.LOCATION_HEADER, getResourceEndpointURL(SCIMConstants.RESOURCE_TYPE_ENDPOINT));
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 resource type object in the response header parameter.
return new SCIMResponse(ResponseCodeConstants.CODE_OK, encodedObject, responseHeaders);
} catch (CharonException e) {
return encodeSCIMException(e);
} catch (BadRequestException e) {
return encodeSCIMException(e);
} catch (InternalErrorException e) {
return encodeSCIMException(e);
} catch (NotFoundException e) {
return encodeSCIMException(e);
} catch (JSONException e) {
return null;
}
}
use of org.wso2.charon3.core.exceptions.BadRequestException in project charon by wso2.
the class ResourceTypeResourceManager method listWithPOST.
@Override
public SCIMResponse listWithPOST(String resourceString, UserManager userManager) {
String error = "Request is undefined";
BadRequestException badRequestException = new BadRequestException(error, ResponseCodeConstants.INVALID_PATH);
return encodeSCIMException(badRequestException);
}
use of org.wso2.charon3.core.exceptions.BadRequestException in project charon by wso2.
the class ResourceTypeResourceManager method create.
@Override
public SCIMResponse create(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.charon3.core.exceptions.BadRequestException in project charon by wso2.
the class ServiceProviderConfigResourceManager 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);
}
Aggregations