use of org.wso2.charon3.core.exceptions.CharonException 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.exceptions.CharonException 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.exceptions.CharonException 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.exceptions.CharonException in project charon by wso2.
the class ServerSideValidator method validateCreatedSCIMObject.
/*
* Validate created SCIMObject according to the spec
*
* @param scimObject
* @param resourceSchema
* @throw CharonException
* @throw BadRequestException
* @throw NotFoundException
*/
public static void validateCreatedSCIMObject(AbstractSCIMObject scimObject, SCIMResourceTypeSchema resourceSchema) throws CharonException, BadRequestException, NotFoundException {
if (scimObject instanceof User) {
// set display names for complex multivalued attributes
setDisplayNameInComplexMultiValuedAttributes(scimObject, resourceSchema);
}
// remove any read only attributes
removeAnyReadOnlyAttributes(scimObject, resourceSchema);
// add created and last modified dates
String id = UUID.randomUUID().toString();
scimObject.setId(id);
Date date = new Date();
// set the created date and time
scimObject.setCreatedDate(AttributeUtil.parseDateTime(AttributeUtil.formatDateTime(date)));
// creates date and the last modified are the same if not updated.
scimObject.setLastModified(AttributeUtil.parseDateTime(AttributeUtil.formatDateTime(date)));
// set location and resourceType
if (resourceSchema.isSchemaAvailable(SCIMConstants.USER_CORE_SCHEMA_URI)) {
String location = createLocationHeader(AbstractResourceManager.getResourceEndpointURL(SCIMConstants.USER_ENDPOINT), scimObject.getId());
scimObject.setLocation(location);
scimObject.setResourceType(SCIMConstants.USER);
} else if (resourceSchema.isSchemaAvailable(SCIMConstants.GROUP_CORE_SCHEMA_URI)) {
String location = createLocationHeader(AbstractResourceManager.getResourceEndpointURL(SCIMConstants.GROUP_ENDPOINT), scimObject.getId());
scimObject.setLocation(location);
scimObject.setResourceType(SCIMConstants.GROUP);
}
// check for required attributes
validateSCIMObjectForRequiredAttributes(scimObject, resourceSchema);
validateSchemaList(scimObject, resourceSchema);
}
use of org.wso2.charon3.core.exceptions.CharonException in project charon by wso2.
the class PatchOperationUtil method doPatchRemoveWithFiltersForLevelTwo.
/*
*
* @param oldResource
* @param attributeParts
* @param expressionNode
* @return
* @throws BadRequestException
* @throws CharonException
*/
private static AbstractSCIMObject doPatchRemoveWithFiltersForLevelTwo(AbstractSCIMObject oldResource, String[] attributeParts, ExpressionNode expressionNode) throws BadRequestException, CharonException {
Attribute attribute = oldResource.getAttribute(attributeParts[0]);
if (attribute != null) {
if (attribute.getMultiValued()) {
List<Attribute> subValues = ((MultiValuedAttribute) attribute).getAttributeValues();
if (subValues != null) {
for (Attribute subValue : subValues) {
Map<String, Attribute> subAttributes = ((ComplexAttribute) subValue).getSubAttributesList();
// this map is to avoid concurrent modification exception.
Map<String, Attribute> tempSubAttributes = (Map<String, Attribute>) CopyUtil.deepCopy(subAttributes);
for (Iterator<Attribute> iterator = tempSubAttributes.values().iterator(); iterator.hasNext(); ) {
Attribute subAttribute = iterator.next();
if (subAttribute.getName().equals(expressionNode.getAttributeValue())) {
if (((SimpleAttribute) subAttribute).getValue().equals(expressionNode.getValue())) {
Attribute removingAttribute = subAttributes.get(attributeParts[1]);
if (removingAttribute == null) {
throw new BadRequestException("No such sub attribute with the name : " + attributeParts[1] + " " + "within the attribute " + attributeParts[0], ResponseCodeConstants.INVALID_PATH);
}
if (removingAttribute.getMutability().equals(SCIMDefinitions.Mutability.READ_ONLY) || removingAttribute.getRequired().equals(true)) {
throw new BadRequestException("Can not remove a required attribute or a read-only attribute", ResponseCodeConstants.MUTABILITY);
} else {
((ComplexAttribute) subValue).removeSubAttribute(removingAttribute.getName());
}
}
}
}
}
if (subValues.size() == 0) {
// if the attribute has no values, make it unassigned
oldResource.deleteAttribute(attribute.getName());
}
}
} else if (attribute.getType().equals(SCIMDefinitions.DataType.COMPLEX)) {
// this is only valid for extension
Attribute subAttribute = attribute.getSubAttribute(attributeParts[1]);
if (subAttribute == null) {
throw new BadRequestException("No such sub attribute with the name : " + attributeParts[1] + " " + "within the attribute " + attributeParts[0], ResponseCodeConstants.INVALID_PATH);
}
List<Attribute> subValues = ((MultiValuedAttribute) (subAttribute)).getAttributeValues();
if (subValues != null) {
for (Iterator<Attribute> subValueIterator = subValues.iterator(); subValueIterator.hasNext(); ) {
Attribute subValue = subValueIterator.next();
Map<String, Attribute> subValuesSubAttribute = ((ComplexAttribute) subValue).getSubAttributesList();
for (Iterator<Attribute> iterator = subValuesSubAttribute.values().iterator(); iterator.hasNext(); ) {
Attribute subSubAttribute = iterator.next();
if (subSubAttribute.getName().equals(expressionNode.getAttributeValue())) {
if (((SimpleAttribute) (subSubAttribute)).getValue().equals(expressionNode.getValue())) {
if (subValue.getMutability().equals(SCIMDefinitions.Mutability.READ_ONLY) || subValue.getRequired().equals(true)) {
throw new BadRequestException("Can not remove a required attribute or a read-only attribute", ResponseCodeConstants.MUTABILITY);
} else {
subValueIterator.remove();
}
}
}
}
}
// if the attribute has no values, make it unassigned
if (((MultiValuedAttribute) (subAttribute)).getAttributeValues().size() == 0) {
((ComplexAttribute) attribute).removeSubAttribute(subAttribute.getName());
}
}
} else {
throw new BadRequestException("Attribute : " + expressionNode.getAttributeValue() + " " + "is not a multivalued attribute.", ResponseCodeConstants.INVALID_PATH);
}
} else {
throw new BadRequestException("No such attribute with the name : " + attributeParts[0] + " " + "in the current resource", ResponseCodeConstants.INVALID_PATH);
}
return oldResource;
}
Aggregations