Search in sources :

Example 16 with UserManager

use of org.wso2.charon3.core.extensions.UserManager in project charon by wso2.

the class UserResourceManager method listWithPOST.

/*
     * this facilitates the querying using HTTP POST
     * @param resourceString
     * @param usermanager
     * @return
     */
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();
        // unless configured returns core-user schema or else returns extended user schema)
        SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getUserResourceSchema();
        // create the search request object
        SearchRequest searchRequest = decoder.decodeSearchRequestBody(resourceString, schema);
        searchRequest.setCount(ResourceManagerUtil.processCount(searchRequest.getCountStr()));
        searchRequest.setStartIndex(ResourceManagerUtil.processCount(searchRequest.getStartIndexStr()));
        // 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> returnedUsers;
        int totalResults = 0;
        // API user should pass a usermanager usermanager to UserResourceEndpoint.
        if (userManager != null) {
            List<Object> tempList = userManager.listUsersWithPost(searchRequest, requiredAttributes);
            totalResults = (int) tempList.get(0);
            tempList.remove(0);
            returnedUsers = tempList;
            for (Object user : returnedUsers) {
                // perform service provider side validation.
                ServerSideValidator.validateRetrievedSCIMObjectInList((User) user, schema, searchRequest.getAttributesAsString(), searchRequest.getExcludedAttributesAsString());
            }
            // create a listed resource object out of the returned users list.
            ListedResource listedResource = createListedResource(returnedUsers, 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);
    }
}
Also used : SearchRequest(org.wso2.charon3.core.utils.codeutils.SearchRequest) HashMap(java.util.HashMap) NotImplementedException(org.wso2.charon3.core.exceptions.NotImplementedException) NotFoundException(org.wso2.charon3.core.exceptions.NotFoundException) InternalErrorException(org.wso2.charon3.core.exceptions.InternalErrorException) JSONDecoder(org.wso2.charon3.core.encoder.JSONDecoder) ListedResource(org.wso2.charon3.core.objects.ListedResource) BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException) JSONEncoder(org.wso2.charon3.core.encoder.JSONEncoder) SCIMResourceTypeSchema(org.wso2.charon3.core.schema.SCIMResourceTypeSchema) CharonException(org.wso2.charon3.core.exceptions.CharonException) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse)

Example 17 with UserManager

use of org.wso2.charon3.core.extensions.UserManager in project charon by wso2.

the class UserResourceManager method listWithGET.

/*
     * To list all the resources of resource endpoint.
     *
     * @param usermanager
     * @param filter
     * @param startIndex
     * @param count
     * @param sortBy
     * @param sortOrder
     * @param attributes
     * @param excludeAttributes
     * @return
     */
public SCIMResponse listWithGET(UserManager userManager, String filter, int startIndex, int count, String sortBy, String sortOrder, String attributes, String excludeAttributes) {
    FilterTreeManager filterTreeManager = null;
    Node rootNode = null;
    JSONEncoder encoder = null;
    try {
        // According to SCIM 2.0 spec minus values will be considered as 0
        if (count < 0) {
            count = 0;
        }
        // According to SCIM 2.0 spec minus values will be considered as 1
        if (startIndex < 1) {
            startIndex = 1;
        }
        if (sortOrder != null) {
            if (!(sortOrder.equalsIgnoreCase(SCIMConstants.OperationalConstants.ASCENDING) || sortOrder.equalsIgnoreCase(SCIMConstants.OperationalConstants.DESCENDING))) {
                String error = " Invalid sortOrder value is specified";
                throw new BadRequestException(error, ResponseCodeConstants.INVALID_VALUE);
            }
        }
        // ascending.
        if (sortOrder == null && sortBy != null) {
            sortOrder = SCIMConstants.OperationalConstants.ASCENDING;
        }
        // unless configured returns core-user schema or else returns extended user schema)
        SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getUserResourceSchema();
        if (filter != null) {
            filterTreeManager = new FilterTreeManager(filter, schema);
            rootNode = filterTreeManager.buildTree();
        }
        // obtain the json encoder
        encoder = getEncoder();
        // get the URIs of required attributes which must be given a value
        Map<String, Boolean> requiredAttributes = ResourceManagerUtil.getOnlyRequiredAttributesURIs((SCIMResourceTypeSchema) CopyUtil.deepCopy(schema), attributes, excludeAttributes);
        List<Object> returnedUsers;
        int totalResults = 0;
        // API user should pass a usermanager usermanager to UserResourceEndpoint.
        if (userManager != null) {
            List<Object> tempList = userManager.listUsersWithGET(rootNode, startIndex, count, sortBy, sortOrder, requiredAttributes);
            totalResults = (int) tempList.get(0);
            tempList.remove(0);
            returnedUsers = tempList;
            for (Object user : returnedUsers) {
                // perform service provider side validation.
                ServerSideValidator.validateRetrievedSCIMObjectInList((User) user, schema, attributes, excludeAttributes);
            }
            // create a listed resource object out of the returned users list.
            ListedResource listedResource = createListedResource(returnedUsers, startIndex, 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);
    } catch (IOException e) {
        String error = "Error in tokenization of the input filter";
        CharonException charonException = new CharonException(error);
        return AbstractResourceManager.encodeSCIMException(charonException);
    }
}
Also used : HashMap(java.util.HashMap) Node(org.wso2.charon3.core.utils.codeutils.Node) NotImplementedException(org.wso2.charon3.core.exceptions.NotImplementedException) NotFoundException(org.wso2.charon3.core.exceptions.NotFoundException) InternalErrorException(org.wso2.charon3.core.exceptions.InternalErrorException) IOException(java.io.IOException) FilterTreeManager(org.wso2.charon3.core.utils.codeutils.FilterTreeManager) ListedResource(org.wso2.charon3.core.objects.ListedResource) BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException) JSONEncoder(org.wso2.charon3.core.encoder.JSONEncoder) SCIMResourceTypeSchema(org.wso2.charon3.core.schema.SCIMResourceTypeSchema) CharonException(org.wso2.charon3.core.exceptions.CharonException) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse)

Example 18 with UserManager

use of org.wso2.charon3.core.extensions.UserManager 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);
    }
}
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) Path(javax.ws.rs.Path) 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 19 with UserManager

use of org.wso2.charon3.core.extensions.UserManager 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);
    }
}
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) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 20 with UserManager

use of org.wso2.charon3.core.extensions.UserManager 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);
    }
}
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) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)29 CharonException (org.wso2.charon3.core.exceptions.CharonException)29 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)29 HashMap (java.util.HashMap)17 NotFoundException (org.wso2.charon3.core.exceptions.NotFoundException)16 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)16 UserManager (org.wso2.charon3.core.extensions.UserManager)15 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)14 JSONEncoder (org.wso2.charon3.core.encoder.JSONEncoder)13 ApiOperation (io.swagger.annotations.ApiOperation)12 ApiResponses (io.swagger.annotations.ApiResponses)12 Produces (javax.ws.rs.Produces)12 NotImplementedException (org.wso2.charon3.core.exceptions.NotImplementedException)12 JSONDecoder (org.wso2.charon3.core.encoder.JSONDecoder)11 Path (javax.ws.rs.Path)8 User (org.wso2.charon3.core.objects.User)8 Consumes (javax.ws.rs.Consumes)6 GroupResourceManager (org.wso2.charon3.core.protocol.endpoints.GroupResourceManager)6 UserResourceManager (org.wso2.charon3.core.protocol.endpoints.UserResourceManager)6 GET (javax.ws.rs.GET)4