Search in sources :

Example 81 with CharonException

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);
    }
}
Also used : UserManager(org.wso2.charon3.core.extensions.UserManager) GroupResourceManager(org.wso2.charon3.core.protocol.endpoints.GroupResourceManager) CharonException(org.wso2.charon3.core.exceptions.CharonException) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 82 with CharonException

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);
    }
}
Also used : UserManager(org.wso2.charon3.core.extensions.UserManager) GroupResourceManager(org.wso2.charon3.core.protocol.endpoints.GroupResourceManager) CharonException(org.wso2.charon3.core.exceptions.CharonException) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 83 with CharonException

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);
}
Also used : SCIMAttributeSchema(org.wso2.charon3.core.schema.SCIMAttributeSchema) AttributeSchema(org.wso2.charon3.core.schema.AttributeSchema) ArrayList(java.util.ArrayList)

Example 84 with CharonException

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;
    }
}
Also used : Group(org.wso2.charon3.core.objects.Group) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CharonException(org.wso2.charon3.core.exceptions.CharonException)

Aggregations

CharonException (org.wso2.charon3.core.exceptions.CharonException)46 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)44 SimpleAttribute (org.wso2.charon3.core.attributes.SimpleAttribute)34 ComplexAttribute (org.wso2.charon3.core.attributes.ComplexAttribute)32 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)31 MultiValuedAttribute (org.wso2.charon3.core.attributes.MultiValuedAttribute)28 Attribute (org.wso2.charon3.core.attributes.Attribute)27 HashMap (java.util.HashMap)22 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)19 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)19 NotFoundException (org.wso2.charon3.core.exceptions.NotFoundException)18 AbstractSCIMObject (org.wso2.charon3.core.objects.AbstractSCIMObject)17 JSONEncoder (org.wso2.charon3.core.encoder.JSONEncoder)15 UserManager (org.wso2.charon3.core.extensions.UserManager)15 JSONObject (org.json.JSONObject)14 JSONDecoder (org.wso2.charon3.core.encoder.JSONDecoder)14 NotImplementedException (org.wso2.charon3.core.exceptions.NotImplementedException)14 JSONException (org.json.JSONException)13 User (org.wso2.charon3.core.objects.User)13 ApiOperation (io.swagger.annotations.ApiOperation)12