use of org.wso2.charon3.core.exceptions.CharonException in project charon by wso2.
the class GroupResource method getGroup.
@GET
@Produces({ "application/json", "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 getGroup(@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 group endpoint and hand-over the request.
GroupResourceManager groupResourceManager = new GroupResourceManager();
SCIMResponse scimResponse = groupResourceManager.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 GroupResource method createGroup.
@ApiOperation(value = "Return the group which was created", notes = "Returns HTTP 201 if the group is successfully created.")
@POST
@Produces({ "application/json", "application/scim+json" })
@Consumes("application/scim+json")
@ApiResponses(value = { @ApiResponse(code = 201, message = "Valid group is created"), @ApiResponse(code = 404, message = "Group is not found") })
public Response createGroup(@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 group endpoint and hand-over the request.
GroupResourceManager groupResourceManager = new GroupResourceManager();
SCIMResponse response = groupResourceManager.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 ResourceManagerUtil method getOnlyRequiredAttributesURIs.
/*
* this method is to get the uri list of the attributes which need to retrieved from the databases.
* Note that we should consider the 'attributes' and 'excludedAttributes' parameters for this process.
*
* @param schema
* @param requestedAttributes
* @param requestedExcludingAttributes
* @return
* @throws CharonException
*/
public static Map<String, Boolean> getOnlyRequiredAttributesURIs(SCIMResourceTypeSchema schema, String requestedAttributes, String requestedExcludingAttributes) throws CharonException {
ArrayList<AttributeSchema> attributeSchemaArrayList = (ArrayList<AttributeSchema>) CopyUtil.deepCopy(schema.getAttributesList());
List<String> requestedAttributesList = null;
List<String> requestedExcludingAttributesList = null;
if (requestedAttributes != null) {
// make a list from the comma separated requestedAttributes
requestedAttributesList = Arrays.asList(requestedAttributes.split(","));
}
if (requestedExcludingAttributes != null) {
// make a list from the comma separated requestedExcludingAttributes
requestedExcludingAttributesList = Arrays.asList(requestedExcludingAttributes.split(","));
}
ArrayList<AttributeSchema> attributeList = schema.getAttributesList();
for (AttributeSchema attributeSchema : attributeList) {
// check for never/request attributes.
if (attributeSchema.getReturned().equals(SCIMDefinitions.Returned.NEVER)) {
removeAttributesFromList(attributeSchemaArrayList, attributeSchema.getName());
}
// If so return it.
if (requestedAttributes == null && requestedExcludingAttributes == null) {
if (attributeSchema.getReturned().equals(SCIMDefinitions.Returned.REQUEST)) {
removeAttributesFromList(attributeSchemaArrayList, attributeSchema.getName());
}
} else {
// A request should only contains either attributes or exclude attribute params. Not both
if (requestedAttributes != null) {
// and add only the requested attributes
if ((attributeSchema.getReturned().equals(SCIMDefinitions.Returned.DEFAULT) || attributeSchema.getReturned().equals(SCIMDefinitions.Returned.REQUEST)) && (!requestedAttributesList.contains(attributeSchema.getName()) && !isSubAttributeExistsInList(requestedAttributesList, attributeSchema))) {
removeAttributesFromList(attributeSchemaArrayList, attributeSchema.getName());
}
} else if (requestedExcludingAttributes != null) {
// removing attributes which has returned as request. This is because no request is made
if (attributeSchema.getReturned().equals(SCIMDefinitions.Returned.REQUEST)) {
removeAttributesFromList(attributeSchemaArrayList, attributeSchema.getName());
}
// removed from the default set of attributes
if ((attributeSchema.getReturned().equals(SCIMDefinitions.Returned.DEFAULT)) && requestedExcludingAttributesList.contains(attributeSchema.getName())) {
removeAttributesFromList(attributeSchemaArrayList, attributeSchema.getName());
}
}
}
getOnlyRequiredSubAttributesURIs(attributeSchema, attributeSchemaArrayList, requestedAttributes, requestedExcludingAttributes, requestedAttributesList, requestedExcludingAttributesList);
}
return convertSchemasToURIs(attributeSchemaArrayList);
}
use of org.wso2.charon3.core.exceptions.CharonException in project charon by wso2.
the class InMemoryUserManager method listGroups.
private List<Object> listGroups(Map<String, Boolean> requiredAttributes) {
List<Object> groupList = new ArrayList<>();
groupList.add(0, 0);
for (Group group : inMemoryGroupList.values()) {
groupList.add(group);
}
groupList.set(0, groupList.size() - 1);
try {
return (List<Object>) CopyUtil.deepCopy(groupList);
} catch (CharonException e) {
logger.error("Error in listing groups");
return null;
}
}
Aggregations