Search in sources :

Example 81 with Store

use of org.wso2.siddhi.query.api.execution.query.input.store.Store in project charon by wso2.

the class UserResourceManager method get.

/*
     * Retrieves a user resource given an unique user id. Mapped to HTTP GET request.
     *
     * @param id          - unique resource id
     * @param usermanager - usermanager instance defined by the external implementor of charon
     * @return SCIM response to be returned.
     */
public SCIMResponse get(String id, UserManager userManager, String attributes, String excludeAttributes) {
    JSONEncoder encoder = null;
    try {
        // obtain the json encoder
        encoder = getEncoder();
        // obtain the schema corresponding to user
        // unless configured returns core-user schema or else returns extended user schema)
        SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getUserResourceSchema();
        // get the URIs of required attributes which must be given a value
        Map<String, Boolean> requiredAttributes = ResourceManagerUtil.getOnlyRequiredAttributesURIs((SCIMResourceTypeSchema) CopyUtil.deepCopy(schema), attributes, excludeAttributes);
        /*API user should pass a usermanager impl to UserResourceEndpoint.
            retrieve the user from the provided UM handler.*/
        User user = ((UserManager) userManager).getUser(id, requiredAttributes);
        // if user not found, return an error in relevant format.
        if (user == null) {
            String error = "User not found in the user store.";
            throw new NotFoundException(error);
        }
        // perform service provider side validation.
        ServerSideValidator.validateRetrievedSCIMObject(user, schema, attributes, excludeAttributes);
        // convert the user into requested format.
        String encodedUser = encoder.encodeSCIMObject(user);
        // 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);
        responseHeaders.put(SCIMConstants.LOCATION_HEADER, getResourceEndpointURL(SCIMConstants.USER_ENDPOINT) + "/" + user.getId());
        return new SCIMResponse(ResponseCodeConstants.CODE_OK, encodedUser, responseHeaders);
    } catch (NotFoundException e) {
        return AbstractResourceManager.encodeSCIMException(e);
    } catch (CharonException e) {
        return AbstractResourceManager.encodeSCIMException(e);
    } catch (BadRequestException e) {
        return AbstractResourceManager.encodeSCIMException(e);
    }
}
Also used : User(org.wso2.charon3.core.objects.User) HashMap(java.util.HashMap) NotFoundException(org.wso2.charon3.core.exceptions.NotFoundException) UserManager(org.wso2.charon3.core.extensions.UserManager) 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 82 with Store

use of org.wso2.siddhi.query.api.execution.query.input.store.Store 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);
    }
}
Also used : UserManager(org.wso2.charon3.core.extensions.UserManager) CharonException(org.wso2.charon3.core.exceptions.CharonException) UserResourceManager(org.wso2.charon3.core.protocol.endpoints.UserResourceManager) 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)

Example 83 with Store

use of org.wso2.siddhi.query.api.execution.query.input.store.Store 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);
    }
}
Also used : UserManager(org.wso2.charon3.core.extensions.UserManager) CharonException(org.wso2.charon3.core.exceptions.CharonException) UserResourceManager(org.wso2.charon3.core.protocol.endpoints.UserResourceManager) 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 84 with Store

use of org.wso2.siddhi.query.api.execution.query.input.store.Store 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);
    }
}
Also used : UserManager(org.wso2.charon3.core.extensions.UserManager) CharonException(org.wso2.charon3.core.exceptions.CharonException) UserResourceManager(org.wso2.charon3.core.protocol.endpoints.UserResourceManager) 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 85 with Store

use of org.wso2.siddhi.query.api.execution.query.input.store.Store 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);
    }
}
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) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

HashMap (java.util.HashMap)25 Test (org.testng.annotations.Test)21 ArrayList (java.util.ArrayList)18 CharonException (org.wso2.charon3.core.exceptions.CharonException)18 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)18 UserManager (org.wso2.charon3.core.extensions.UserManager)15 Produces (javax.ws.rs.Produces)14 ApiOperation (io.swagger.annotations.ApiOperation)12 ApiResponses (io.swagger.annotations.ApiResponses)12 Path (javax.ws.rs.Path)10 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)10 Map (java.util.Map)9 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)8 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)8 UserStoreException (org.wso2.carbon.user.api.UserStoreException)8 Consumes (javax.ws.rs.Consumes)7 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)7 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)7 Response (feign.Response)6 IOException (java.io.IOException)6