use of org.wso2.charon3.core.protocol.SCIMResponse in project charon by wso2.
the class UserResource method getUsersByPost.
@POST
@Path("/.search")
@Produces({ "application/json", "application/scim+json" })
@Consumes("application/scim+json")
@ApiOperation(value = "Return users according to the filter, sort and pagination parameters", notes = "Returns HTTP 404 if the users are not found.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Valid users are found"), @ApiResponse(code = 404, message = "Valid users are not found") })
public Response getUsersByPost(String resourceString) throws FormatNotSupportedException, CharonException {
try {
// obtain the user store manager
UserManager userManager = DefaultCharonManager.getInstance().getUserManager();
// create charon-SCIM user resource manager and hand-over the request.
UserResourceManager userResourceManager = new UserResourceManager();
SCIMResponse scimResponse = userResourceManager.listWithPOST(resourceString, userManager);
return buildResponse(scimResponse);
} catch (CharonException e) {
throw new CharonException(e.getDetail(), e);
}
}
use of org.wso2.charon3.core.protocol.SCIMResponse in project charon by wso2.
the class UserResource method getUser.
@GET
@Path("/{id}")
@Produces({ "application/json", "application/scim+json" })
@ApiOperation(value = "Return the user with the given id", notes = "Returns HTTP 200 if the user is found.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Valid user is found"), @ApiResponse(code = 404, message = "Valid user is not found") })
public Response getUser(@ApiParam(value = SCIMProviderConstants.ID_DESC, required = true) @PathParam(SCIMProviderConstants.ID) String id, @ApiParam(value = SCIMProviderConstants.ATTRIBUTES_DESC, required = false) @QueryParam(SCIMProviderConstants.ATTRIBUTES) String attribute, @ApiParam(value = SCIMProviderConstants.EXCLUDED_ATTRIBUTES_DESC, required = false) @QueryParam(SCIMProviderConstants.EXCLUDE_ATTRIBUTES) String excludedAttributes) throws FormatNotSupportedException, CharonException {
try {
// obtain the user store manager
UserManager userManager = DefaultCharonManager.getInstance().getUserManager();
// create charon-SCIM user endpoint and hand-over the request.
UserResourceManager userResourceManager = new UserResourceManager();
SCIMResponse scimResponse = userResourceManager.get(id, userManager, attribute, excludedAttributes);
// appropriately.
return buildResponse(scimResponse);
} catch (CharonException e) {
throw new CharonException(e.getDetail(), e);
}
}
use of org.wso2.charon3.core.protocol.SCIMResponse in project charon by wso2.
the class UserResource method getUser.
@GET
@Produces({ "application/json", "application/scim+json" })
@ApiOperation(value = "Return users according to the filter, sort and pagination parameters", notes = "Returns HTTP 404 if the users are not found.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Valid users are found"), @ApiResponse(code = 404, message = "Valid users are not found") })
public Response getUser(@ApiParam(value = SCIMProviderConstants.ATTRIBUTES_DESC, required = false) @QueryParam(SCIMProviderConstants.ATTRIBUTES) String attribute, @ApiParam(value = SCIMProviderConstants.EXCLUDED_ATTRIBUTES_DESC, required = false) @QueryParam(SCIMProviderConstants.EXCLUDE_ATTRIBUTES) String excludedAttributes, @ApiParam(value = SCIMProviderConstants.FILTER_DESC, required = false) @QueryParam(SCIMProviderConstants.FILTER) String filter, @ApiParam(value = SCIMProviderConstants.START_INDEX_DESC, required = false) @QueryParam(SCIMProviderConstants.START_INDEX) int startIndex, @ApiParam(value = SCIMProviderConstants.COUNT_DESC, required = false) @QueryParam(SCIMProviderConstants.COUNT) int count, @ApiParam(value = SCIMProviderConstants.SORT_BY_DESC, required = false) @QueryParam(SCIMProviderConstants.SORT_BY) String sortBy, @ApiParam(value = SCIMProviderConstants.SORT_ORDER_DESC, required = false) @QueryParam(SCIMProviderConstants.SORT_ORDER) String sortOrder) throws FormatNotSupportedException, CharonException {
try {
// obtain the user store manager
UserManager userManager = DefaultCharonManager.getInstance().getUserManager();
// create charon-SCIM user resource manager and hand-over the request.
UserResourceManager userResourceManager = new UserResourceManager();
SCIMResponse scimResponse = userResourceManager.listWithGET(userManager, filter, startIndex, count, sortBy, sortOrder, attribute, excludedAttributes);
return buildResponse(scimResponse);
} catch (CharonException e) {
throw new CharonException(e.getDetail(), e);
}
}
use of org.wso2.charon3.core.protocol.SCIMResponse in project charon by wso2.
the class GroupResourceManager method create.
/*
* Create group in the service provider given the submitted payload that contains the SCIM group
* resource, format and the handler to usermanager.
*
* @param scimObjectString - Payload of HTTP request, which contains the SCIM object.
* @param usermanager
* @param attributes
* @param excludeAttributes
* @return
*/
@Override
public SCIMResponse create(String scimObjectString, UserManager userManager, String attributes, String excludeAttributes) {
JSONEncoder encoder = null;
JSONDecoder decoder = null;
try {
// obtain the json encoder
encoder = getEncoder();
// obtain the json decoder
decoder = getDecoder();
// returns core-group schema
SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getGroupResourceSchema();
// 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 group object, encoded in the submitted payload.
Group group = (Group) decoder.decodeResource(scimObjectString, schema, new Group());
// validate decoded group
ServerSideValidator.validateCreatedSCIMObject(group, SCIMSchemaDefinitions.SCIM_GROUP_SCHEMA);
// handover the SCIM User object to the group usermanager provided by the SP.
Group createdGroup;
// need to send back the newly created group in the response payload
createdGroup = ((UserManager) userManager).createGroup(group, requiredAttributes);
// encode the newly created SCIM group object and add id attribute to Location header.
String encodedGroup;
Map<String, String> httpHeaders = new HashMap<String, String>();
if (createdGroup != null) {
encodedGroup = encoder.encodeSCIMObject(createdGroup);
// add location header
httpHeaders.put(SCIMConstants.LOCATION_HEADER, getResourceEndpointURL(SCIMConstants.GROUP_ENDPOINT) + "/" + createdGroup.getId());
httpHeaders.put(SCIMConstants.CONTENT_TYPE_HEADER, SCIMConstants.APPLICATION_JSON);
} else {
String message = "Newly created Group resource is null..";
throw new InternalErrorException(message);
}
// put the uri of the Group object in the response header parameter.
return new SCIMResponse(ResponseCodeConstants.CODE_CREATED, encodedGroup, httpHeaders);
} catch (InternalErrorException e) {
return encodeSCIMException(e);
} catch (BadRequestException e) {
return encodeSCIMException(e);
} catch (ConflictException e) {
return encodeSCIMException(e);
} catch (CharonException e) {
return encodeSCIMException(e);
} catch (NotFoundException e) {
return encodeSCIMException(e);
} catch (NotImplementedException e) {
return encodeSCIMException(e);
}
}
use of org.wso2.charon3.core.protocol.SCIMResponse in project charon by wso2.
the class GroupResourceManager method get.
/*
* Retrieves a group resource given an unique group id. Mapped to HTTP GET request.
*
* @param id - unique resource id
* @param usermanager
* @param attributes
* @param excludeAttributes
* @return SCIM response to be returned.
*/
@Override
public SCIMResponse get(String id, UserManager userManager, String attributes, String excludeAttributes) {
JSONEncoder encoder = null;
try {
// obtain the correct encoder according to the format requested.
encoder = getEncoder();
// returns core-group schema
SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getGroupResourceSchema();
// 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 usermanager to GroupResourceEndpoint.
// retrieve the group from the provided usermanager.
Group group = ((UserManager) userManager).getGroup(id, requiredAttributes);
// if group not found, return an error in relevant format.
if (group == null) {
String message = "Group not found in the user store.";
throw new NotFoundException(message);
}
ServerSideValidator.validateRetrievedSCIMObjectInList(group, schema, attributes, excludeAttributes);
// convert the group into specific format.
String encodedGroup = encoder.encodeSCIMObject(group);
// if there are any http headers to be added in the response header.
Map<String, String> httpHeaders = new HashMap<String, String>();
httpHeaders.put(SCIMConstants.CONTENT_TYPE_HEADER, SCIMConstants.APPLICATION_JSON);
return new SCIMResponse(ResponseCodeConstants.CODE_OK, encodedGroup, httpHeaders);
} catch (NotFoundException e) {
return encodeSCIMException(e);
} catch (BadRequestException e) {
return encodeSCIMException(e);
} catch (CharonException e) {
return encodeSCIMException(e);
} catch (NotImplementedException e) {
return encodeSCIMException(e);
}
}
Aggregations