use of org.wso2.charon3.core.exceptions.CharonException in project charon by wso2.
the class DefaultAttributeFactory method createAttribute.
/*
* Returns the defined type of attribute with the user defined value
* included and necessary attribute characteristics set
* @param attributeSchema - Attribute schema
* @param attribute - attribute
* @return Attribute
*/
public static Attribute createAttribute(AttributeSchema attributeSchema, AbstractAttribute attribute) throws CharonException, BadRequestException {
attribute.setMutability(attributeSchema.getMutability());
attribute.setRequired(attributeSchema.getRequired());
attribute.setReturned(attributeSchema.getReturned());
attribute.setCaseExact(attributeSchema.getCaseExact());
attribute.setMultiValued(attributeSchema.getMultiValued());
attribute.setDescription(attributeSchema.getDescription());
attribute.setUniqueness(attributeSchema.getUniqueness());
attribute.setURI(attributeSchema.getURI());
// Default attribute factory knows about SCIMAttribute schema
try {
// set data type of the attribute value, if simple attribute
if (attribute instanceof SimpleAttribute) {
return createSimpleAttribute(attributeSchema, (SimpleAttribute) attribute);
} else {
attribute.setType(attributeSchema.getType());
}
return attribute;
} catch (CharonException e) {
String error = "Unknown attribute schema.";
throw new CharonException(error);
} catch (BadRequestException e) {
String error = "Violation in attribute schema. DataType doesn't match that of the value.";
throw new BadRequestException(error, ResponseCodeConstants.INVALID_VALUE);
}
}
use of org.wso2.charon3.core.exceptions.CharonException in project charon by wso2.
the class UserResource method updateUser.
@PUT
@Path("{id}")
@Produces({ "application/json", "application/scim+json" })
@Consumes("application/scim+json")
@ApiOperation(value = "Return the updated user", notes = "Returns HTTP 404 if the user is not found.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "User is updated"), @ApiResponse(code = 404, message = "Valid user is not found") })
public Response updateUser(@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 user endpoint and hand-over the request.
UserResourceManager userResourceManager = new UserResourceManager();
SCIMResponse response = userResourceManager.updateWithPUT(id, resourceString, userManager, attribute, excludedAttributes);
return buildResponse(response);
} 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 createUser.
@ApiOperation(value = "Return the user which was created", notes = "Returns HTTP 201 if the user is successfully created.")
@POST
@Produces({ "application/json", "application/scim+json" })
@Consumes("application/scim+json")
@ApiResponses(value = { @ApiResponse(code = 201, message = "Valid user is created"), @ApiResponse(code = 404, message = "User is not found") })
public Response createUser(@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 CharonException, FormatNotSupportedException {
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 response = userResourceManager.create(resourceString, userManager, attribute, excludedAttributes);
return buildResponse(response);
} 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 deleteUser.
@DELETE
@Path("/{id}")
@Produces({ "application/json", "application/scim+json" })
@ApiOperation(value = "Delete the user with the given id", notes = "Returns HTTP 204 if the user is successfully deleted.")
@ApiResponses(value = { @ApiResponse(code = 204, message = "User is deleted"), @ApiResponse(code = 404, message = "Valid user is not found") })
public Response deleteUser(@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 user resource manager and hand-over the request.
UserResourceManager userResourceManager = new UserResourceManager();
SCIMResponse scimResponse = userResourceManager.delete(id, userManager);
// 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 GroupResource method getGroup.
@GET
@Path("/{id}")
@Produces({ "application/json", "application/scim+json" })
@ApiOperation(value = "Return the group with the given id", notes = "Returns HTTP 200 if the group is found.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Valid group is found"), @ApiResponse(code = 404, message = "Valid group is not found") })
public Response getGroup(@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 group endpoint and hand-over the request.
GroupResourceManager groupResourceManager = new GroupResourceManager();
SCIMResponse scimResponse = groupResourceManager.get(id, userManager, attribute, excludedAttributes);
// appropriately.
return buildResponse(scimResponse);
} catch (CharonException e) {
throw new CharonException(e.getDetail(), e);
}
}
Aggregations