use of org.wso2.charon3.core.protocol.SCIMResponse in project charon by wso2.
the class GroupResource method getGroupsByPost.
@POST
@Path("/.search")
@Produces({ "application/json", "application/scim+json" })
@Consumes("application/scim+json")
@ApiOperation(value = "Return groups according to the filter, sort and pagination parameters", notes = "Returns HTTP 404 if the groups are not found.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Valid groups are found"), @ApiResponse(code = 404, message = "Valid groups are not found") })
public Response getGroupsByPost(String resourceString) throws FormatNotSupportedException, CharonException {
try {
// obtain the user store manager
UserManager userManager = DefaultCharonManager.getInstance().getUserManager();
// create charon-SCIM group endpoint and hand-over the request.
GroupResourceManager groupResourceManager = new GroupResourceManager();
SCIMResponse scimResponse = groupResourceManager.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 GroupResource method deleteGroup.
@DELETE
@Path("/{id}")
@Produces({ "application/json", "application/scim+json" })
@ApiOperation(value = "Delete the group with the given id", notes = "Returns HTTP 204 if the group is successfully deleted.")
@ApiResponses(value = { @ApiResponse(code = 204, message = "Group is deleted"), @ApiResponse(code = 404, message = "Valid group is not found") })
public Response deleteGroup(@ApiParam(value = SCIMProviderConstants.ID_DESC, required = true) @PathParam(SCIMProviderConstants.ID) String id) throws FormatNotSupportedException, CharonException {
try {
// obtain the user store manager
UserManager userManager = DefaultCharonManager.getInstance().getUserManager();
// create charon-SCIM group endpoint and hand-over the request.
GroupResourceManager groupResourceManager = new GroupResourceManager();
SCIMResponse scimResponse = groupResourceManager.delete(id, userManager);
// 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 GroupResource method updateGroup.
@PUT
@Path("{id}")
@Produces({ "application/json", "application/scim+json" })
@Consumes("application/scim+json")
@ApiOperation(value = "Return the updated group", notes = "Returns HTTP 404 if the group is not found.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Group is updated"), @ApiResponse(code = 404, message = "Valid group is not found") })
public Response updateGroup(@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, String resourceString) throws FormatNotSupportedException, CharonException {
try {
// obtain the user store manager
UserManager userManager = DefaultCharonManager.getInstance().getUserManager();
// create charon-SCIM group endpoint and hand-over the request.
GroupResourceManager groupResourceManager = new GroupResourceManager();
SCIMResponse response = groupResourceManager.updateWithPUT(id, resourceString, userManager, attribute, excludedAttributes);
return buildResponse(response);
} catch (CharonException e) {
throw new CharonException(e.getDetail(), e);
}
}
use of org.wso2.charon3.core.protocol.SCIMResponse in project charon by wso2.
the class BulkResourceManager method processBulkData.
public SCIMResponse processBulkData(String data, UserManager userManager) {
BulkResponseData bulkResponseData;
try {
// Get encoder and decoder from AbstractResourceEndpoint
encoder = getEncoder();
decoder = getDecoder();
BulkRequestData bulkRequestDataObject;
// decode the request
bulkRequestDataObject = decoder.decodeBulkData(data);
bulkRequestProcessor.setFailOnError(bulkRequestDataObject.getFailOnErrors());
bulkRequestProcessor.setUserManager(userManager);
// Get bulk response data
bulkResponseData = bulkRequestProcessor.processBulkRequests(bulkRequestDataObject);
// encode the BulkResponseData object
String finalEncodedResponse = encoder.encodeBulkResponseData(bulkResponseData);
// careate SCIM response message
Map<String, String> responseHeaders = new HashMap<String, String>();
// add location header
responseHeaders.put(SCIMConstants.CONTENT_TYPE_HEADER, SCIMConstants.APPLICATION_JSON);
// create the final response
return new SCIMResponse(ResponseCodeConstants.CODE_OK, finalEncodedResponse, responseHeaders);
} catch (CharonException e) {
return AbstractResourceManager.encodeSCIMException(e);
} catch (BadRequestException e) {
return AbstractResourceManager.encodeSCIMException(e);
} catch (InternalErrorException e) {
return AbstractResourceManager.encodeSCIMException(e);
}
}
use of org.wso2.charon3.core.protocol.SCIMResponse in project charon by wso2.
the class GroupResourceManager method listWithPOST.
/*
* this facilitates the querying using HTTP POST
* @param resourceString
* @param usermanager
* @return
*/
@Override
public SCIMResponse listWithPOST(String resourceString, UserManager userManager) {
JSONEncoder encoder = null;
JSONDecoder decoder = null;
try {
// obtain the json encoder
encoder = getEncoder();
// obtain the json decoder
decoder = getDecoder();
// return core group schema
SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getGroupResourceSchema();
// create the search request object
SearchRequest searchRequest = decoder.decodeSearchRequestBody(resourceString, schema);
searchRequest.setCount(ResourceManagerUtil.processCount(searchRequest.getCountStr()));
searchRequest.setStartIndex(ResourceManagerUtil.processCount(searchRequest.getStartIndexStr()));
if (searchRequest.getSchema() != null && !searchRequest.getSchema().equals(SCIMConstants.SEARCH_SCHEMA_URI)) {
throw new BadRequestException("Provided schema is invalid", ResponseCodeConstants.INVALID_VALUE);
}
// check whether provided sortOrder is valid or not
if (searchRequest.getSortOder() != null) {
if (!(searchRequest.getSortOder().equalsIgnoreCase(SCIMConstants.OperationalConstants.ASCENDING) || searchRequest.getSortOder().equalsIgnoreCase(SCIMConstants.OperationalConstants.DESCENDING))) {
String error = " Invalid sortOrder value is specified";
throw new BadRequestException(error, ResponseCodeConstants.INVALID_VALUE);
}
}
// ascending.
if (searchRequest.getSortOder() == null && searchRequest.getSortBy() != null) {
searchRequest.setSortOder(SCIMConstants.OperationalConstants.ASCENDING);
}
// get the URIs of required attributes which must be given a value
Map<String, Boolean> requiredAttributes = ResourceManagerUtil.getOnlyRequiredAttributesURIs((SCIMResourceTypeSchema) CopyUtil.deepCopy(schema), searchRequest.getAttributesAsString(), searchRequest.getExcludedAttributesAsString());
List<Object> returnedGroups;
int totalResults = 0;
// API user should pass a usermanager usermanager to UserResourceEndpoint.
if (userManager != null) {
List<Object> tempList = userManager.listGroupsWithPost(searchRequest, requiredAttributes);
totalResults = (int) tempList.get(0);
tempList.remove(0);
returnedGroups = tempList;
for (Object group : returnedGroups) {
// perform service provider side validation.
ServerSideValidator.validateRetrievedSCIMObjectInList((Group) group, schema, searchRequest.getAttributesAsString(), searchRequest.getExcludedAttributesAsString());
}
// create a listed resource object out of the returned users list.
ListedResource listedResource = createListedResource(returnedGroups, searchRequest.getStartIndex(), totalResults);
// convert the listed resource into specific format.
String encodedListedResource = encoder.encodeSCIMObject(listedResource);
// 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);
return new SCIMResponse(ResponseCodeConstants.CODE_OK, encodedListedResource, responseHeaders);
} else {
String error = "Provided user manager handler is null.";
// throw internal server error.
throw new InternalErrorException(error);
}
} catch (CharonException e) {
return AbstractResourceManager.encodeSCIMException(e);
} catch (NotFoundException e) {
return AbstractResourceManager.encodeSCIMException(e);
} catch (InternalErrorException e) {
return AbstractResourceManager.encodeSCIMException(e);
} catch (BadRequestException e) {
return AbstractResourceManager.encodeSCIMException(e);
} catch (NotImplementedException e) {
return AbstractResourceManager.encodeSCIMException(e);
}
}
Aggregations