Search in sources :

Example 11 with UserManager

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

the class ResourceTypeResourceManager method create.

@Override
public SCIMResponse create(String scimObjectString, UserManager userManager, String attributes, String excludeAttributes) {
    String error = "Request is undefined";
    BadRequestException badRequestException = new BadRequestException(error, ResponseCodeConstants.INVALID_PATH);
    return encodeSCIMException(badRequestException);
}
Also used : BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException)

Example 12 with UserManager

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

the class ServiceProviderConfigResourceManager method delete.

@Override
public SCIMResponse delete(String id, UserManager userManager) {
    String error = "Request is undefined";
    BadRequestException badRequestException = new BadRequestException(error, ResponseCodeConstants.INVALID_PATH);
    return encodeSCIMException(badRequestException);
}
Also used : BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException)

Example 13 with UserManager

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

the class ServiceProviderConfigResourceManager method create.

@Override
public SCIMResponse create(String scimObjectString, UserManager userManager, String attributes, String excludeAttributes) {
    String error = "Request is undefined";
    BadRequestException badRequestException = new BadRequestException(error, ResponseCodeConstants.INVALID_PATH);
    return encodeSCIMException(badRequestException);
}
Also used : BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException)

Example 14 with UserManager

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

the class ServiceProviderConfigResourceManager method listWithPOST.

@Override
public SCIMResponse listWithPOST(String resourceString, UserManager userManager) {
    String error = "Request is undefined";
    BadRequestException badRequestException = new BadRequestException(error, ResponseCodeConstants.INVALID_PATH);
    return encodeSCIMException(badRequestException);
}
Also used : BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException)

Example 15 with UserManager

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

the class UserResourceManager method updateWithPUT.

/*
     * To update the user by giving entire attribute set
     *
     * @param existingId
     * @param scimObjectString
     * @param usermanager
     * @return
     */
public SCIMResponse updateWithPUT(String existingId, String scimObjectString, UserManager userManager, String attributes, String excludeAttributes) {
    // needs to validate the incoming object. eg: id can not be set by the consumer.
    JSONEncoder encoder = null;
    JSONDecoder decoder = null;
    try {
        // obtain the json encoder
        encoder = getEncoder();
        // obtain the json decoder.
        decoder = getDecoder();
        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);
        // decode the SCIM User object, encoded in the submitted payload.
        User user = (User) decoder.decodeResource(scimObjectString, schema, new User());
        User updatedUser = null;
        if (userManager != null) {
            // retrieve the old object
            User oldUser = userManager.getUser(existingId, ResourceManagerUtil.getAllAttributeURIs(schema));
            if (oldUser != null) {
                User validatedUser = (User) ServerSideValidator.validateUpdatedSCIMObject(oldUser, user, schema);
                updatedUser = userManager.updateUser(validatedUser, requiredAttributes);
            } else {
                String error = "No user exists with the given id: " + existingId;
                throw new NotFoundException(error);
            }
        } else {
            String error = "Provided user manager handler is null.";
            throw new InternalErrorException(error);
        }
        // encode the newly created SCIM user object and add id attribute to Location header.
        String encodedUser;
        Map<String, String> httpHeaders = new HashMap<String, String>();
        if (updatedUser != null) {
            // create a deep copy of the user object since we are going to change it.
            User copiedUser = (User) CopyUtil.deepCopy(updatedUser);
            // need to remove password before returning
            ServerSideValidator.validateReturnedAttributes(copiedUser, attributes, excludeAttributes);
            encodedUser = encoder.encodeSCIMObject(copiedUser);
            // add location header
            httpHeaders.put(SCIMConstants.LOCATION_HEADER, getResourceEndpointURL(SCIMConstants.USER_ENDPOINT) + "/" + updatedUser.getId());
            httpHeaders.put(SCIMConstants.CONTENT_TYPE_HEADER, SCIMConstants.APPLICATION_JSON);
        } else {
            String error = "Updated User resource is null.";
            throw new CharonException(error);
        }
        // put the uri of the User object in the response header parameter.
        return new SCIMResponse(ResponseCodeConstants.CODE_OK, encodedUser, httpHeaders);
    } catch (NotFoundException e) {
        return AbstractResourceManager.encodeSCIMException(e);
    } catch (BadRequestException e) {
        return AbstractResourceManager.encodeSCIMException(e);
    } catch (CharonException e) {
        return AbstractResourceManager.encodeSCIMException(e);
    } catch (InternalErrorException e) {
        return AbstractResourceManager.encodeSCIMException(e);
    } catch (NotImplementedException e) {
        return AbstractResourceManager.encodeSCIMException(e);
    }
}
Also used : User(org.wso2.charon3.core.objects.User) 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) 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)

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