Search in sources :

Example 1 with Operation

use of org.gluu.oxtrust.model.scim2.Operation in project oxTrust by GluuFederation.

the class BulkWebService method processUserOperation.

private BulkOperation processUserOperation(BulkOperation operation, Map<String, String> processedBulkIds) throws Exception {
    log.info(" Operation is for User ");
    // Intercept bulkId
    User user = null;
    if (operation.getData() != null) {
        // Required in a request when
        // "method" is "POST", "PUT", or
        // "PATCH".
        String serializedData = serialize(operation.getData());
        for (Map.Entry<String, String> entry : processedBulkIds.entrySet()) {
            String key = "bulkId:" + entry.getKey();
            serializedData = serializedData.replaceAll(key, entry.getValue());
        }
        user = deserializeToUser(serializedData);
    }
    String userRootEndpoint = appConfiguration.getBaseEndpoint() + "/scim/v2/Users/";
    if (operation.getMethod().equalsIgnoreCase(HttpMethod.POST)) {
        log.info(" Method is POST ");
        try {
            user = scim2UserService.createUser(user);
            GluuCustomPerson gluuPerson = personService.getPersonByUid(user.getUserName());
            String inum = gluuPerson.getInum();
            // String location = (new
            // StringBuilder()).append(domain).append("/Users/").append(inum).toString();
            String location = userRootEndpoint + inum;
            operation.setLocation(location);
            operation.setStatus(String.valueOf(Response.Status.CREATED.getStatusCode()));
            operation.setResponse(user);
            // Set aside successfully-processed bulkId
            // bulkId is only required in POST
            processedBulkIds.put(operation.getBulkId(), user.getId());
        } catch (DuplicateEntryException ex) {
            log.error("DuplicateEntryException", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.CONFLICT.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, ex.getMessage()));
        } catch (PersonRequiredFieldsException ex) {
            log.error("PersonRequiredFieldsException: ", ex);
            operation.setStatus(String.valueOf(Response.Status.BAD_REQUEST.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_VALUE, ex.getMessage()));
        } catch (Exception ex) {
            log.error("Failed to create user", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, null, INTERNAL_SERVER_ERROR_MESSAGE));
        }
    } else if (operation.getMethod().equalsIgnoreCase(HttpMethod.PUT)) {
        log.info(" Method is PUT ");
        String path = operation.getPath();
        String id = getId(path);
        for (Map.Entry<String, String> entry : processedBulkIds.entrySet()) {
            String key = "bulkId:" + entry.getKey();
            if (id.equalsIgnoreCase(key)) {
                id = id.replaceAll(key, entry.getValue());
                break;
            }
        }
        try {
            user = scim2UserService.updateUser(id, user);
            // String location = (new
            // StringBuilder()).append(domain).append("/Users/").append(personiD).toString();
            String location = userRootEndpoint + id;
            operation.setLocation(location);
            operation.setStatus(String.valueOf(Response.Status.OK.getStatusCode()));
            operation.setResponse(user);
            // bulkId is only required in POST
            if (operation.getBulkId() != null) {
                processedBulkIds.put(operation.getBulkId(), user.getId());
            }
        } catch (EntryPersistenceException ex) {
            log.error("Failed to update user", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.NOT_FOUND.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found"));
        } catch (DuplicateEntryException ex) {
            log.error("DuplicateEntryException", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.CONFLICT.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, ex.getMessage()));
        } catch (Exception ex) {
            log.error("Failed to update user", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, null, INTERNAL_SERVER_ERROR_MESSAGE));
        }
    } else if (operation.getMethod().equalsIgnoreCase(HttpMethod.DELETE)) {
        log.info(" Method is DELETE ");
        String path = operation.getPath();
        String id = getId(path);
        for (Map.Entry<String, String> entry : processedBulkIds.entrySet()) {
            String key = "bulkId:" + entry.getKey();
            if (id.equalsIgnoreCase(key)) {
                id = id.replaceAll(key, entry.getValue());
                break;
            }
        }
        try {
            scim2UserService.deleteUser(id);
            // Location may be omitted on DELETE
            operation.setStatus(String.valueOf(Response.Status.OK.getStatusCode()));
            operation.setResponse("User " + id + " deleted");
            // bulkId is only required in POST
            if (operation.getBulkId() != null) {
                processedBulkIds.put(operation.getBulkId(), id);
            }
        } catch (EntryPersistenceException ex) {
            log.error("Failed to delete user", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.NOT_FOUND.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.NOT_FOUND, null, "Resource " + id + " not found"));
        } catch (Exception ex) {
            log.error("Failed to delete user", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, null, INTERNAL_SERVER_ERROR_MESSAGE));
        }
    }
    return operation;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) User(org.gluu.oxtrust.model.scim2.User) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) PersonRequiredFieldsException(org.gluu.oxtrust.exception.PersonRequiredFieldsException) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) PersonRequiredFieldsException(org.gluu.oxtrust.exception.PersonRequiredFieldsException) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException)

Example 2 with Operation

use of org.gluu.oxtrust.model.scim2.Operation in project oxTrust by GluuFederation.

the class BulkWebService method processGroupOperation.

private BulkOperation processGroupOperation(BulkOperation operation, Map<String, String> processedBulkIds) throws Exception {
    log.info(" Operation is for Group ");
    // Intercept bulkId
    Group group = null;
    if (operation.getData() != null) {
        // Required in a request when
        // "method" is "POST", "PUT", or
        // "PATCH".
        String serializedData = serialize(operation.getData());
        for (Map.Entry<String, String> entry : processedBulkIds.entrySet()) {
            String key = "bulkId:" + entry.getKey();
            serializedData = serializedData.replaceAll(key, entry.getValue());
        }
        group = deserializeToGroup(serializedData);
    }
    String groupRootEndpoint = appConfiguration.getBaseEndpoint() + "/scim/v2/Groups/";
    if (operation.getMethod().equalsIgnoreCase(HttpMethod.POST)) {
        log.info(" Method is POST ");
        try {
            group = scim2GroupService.createGroup(group);
            GluuGroup gluuGroup = groupService.getGroupByDisplayName(group.getDisplayName());
            String id = gluuGroup.getInum();
            // String location = (new
            // StringBuilder()).append(domain).append("/Groups/").append(id).toString();
            String location = groupRootEndpoint + id;
            operation.setLocation(location);
            operation.setStatus(String.valueOf(Response.Status.CREATED.getStatusCode()));
            operation.setResponse(group);
            // Set aside successfully-processed bulkId
            // bulkId is only required in POST
            processedBulkIds.put(operation.getBulkId(), group.getId());
        } catch (DuplicateEntryException ex) {
            log.error("DuplicateEntryException", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.CONFLICT.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, ex.getMessage()));
        } catch (Exception ex) {
            log.error("Failed to create group", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, null, INTERNAL_SERVER_ERROR_MESSAGE));
        }
    } else if (operation.getMethod().equalsIgnoreCase(HttpMethod.PUT)) {
        log.info(" Method is PUT ");
        String path = operation.getPath();
        String id = getId(path);
        for (Map.Entry<String, String> entry : processedBulkIds.entrySet()) {
            String key = "bulkId:" + entry.getKey();
            if (id.equalsIgnoreCase(key)) {
                id = id.replaceAll(key, entry.getValue());
                break;
            }
        }
        try {
            group = scim2GroupService.updateGroup(id, group);
            // String location = (new
            // StringBuilder()).append(domain).append("/Groups/").append(groupiD).toString();
            String location = groupRootEndpoint + id;
            operation.setLocation(location);
            operation.setStatus(String.valueOf(Response.Status.OK.getStatusCode()));
            operation.setResponse(group);
            // bulkId is only required in POST
            if (operation.getBulkId() != null) {
                processedBulkIds.put(operation.getBulkId(), group.getId());
            }
        } catch (EntryPersistenceException ex) {
            log.error("Failed to update group", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.NOT_FOUND.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found"));
        } catch (DuplicateEntryException ex) {
            log.error("DuplicateEntryException", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.CONFLICT.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, ex.getMessage()));
        } catch (Exception ex) {
            log.error("Failed to update group", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, null, INTERNAL_SERVER_ERROR_MESSAGE));
        }
    } else if (operation.getMethod().equalsIgnoreCase(HttpMethod.DELETE)) {
        log.info(" Method is DELETE ");
        String path = operation.getPath();
        String id = getId(path);
        for (Map.Entry<String, String> entry : processedBulkIds.entrySet()) {
            String key = "bulkId:" + entry.getKey();
            if (id.equalsIgnoreCase(key)) {
                id = id.replaceAll(key, entry.getValue());
                break;
            }
        }
        try {
            scim2GroupService.deleteGroup(id);
            // Location may be omitted on DELETE
            operation.setStatus(String.valueOf(Response.Status.OK.getStatusCode()));
            operation.setResponse("Group " + id + " deleted");
            // bulkId is only required in POST
            if (operation.getBulkId() != null) {
                processedBulkIds.put(operation.getBulkId(), id);
            }
        } catch (EntryPersistenceException ex) {
            log.error("Failed to delete group", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.NOT_FOUND.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.NOT_FOUND, null, "Resource " + id + " not found"));
        } catch (Exception ex) {
            log.error("Failed to delete group", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, null, INTERNAL_SERVER_ERROR_MESSAGE));
        }
    }
    return operation;
}
Also used : GluuGroup(org.gluu.oxtrust.model.GluuGroup) Group(org.gluu.oxtrust.model.scim2.Group) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) GluuGroup(org.gluu.oxtrust.model.GluuGroup) PersonRequiredFieldsException(org.gluu.oxtrust.exception.PersonRequiredFieldsException) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException)

Example 3 with Operation

use of org.gluu.oxtrust.model.scim2.Operation in project oxTrust by GluuFederation.

the class Scim2UserService method removeUserPatch.

private void removeUserPatch(Operation operation, String id) throws Exception {
    User user = operation.getValue();
    GluuCustomPerson updatedGluuPerson = patchUtil.removePatch(user, validUsernameByInum(user, id));
    log.info(" Setting meta: removeUserPatch update user ");
    setMeta(updatedGluuPerson);
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) User(org.gluu.oxtrust.model.scim2.User) ScimPatchUser(org.gluu.oxtrust.model.scim2.ScimPatchUser)

Example 4 with Operation

use of org.gluu.oxtrust.model.scim2.Operation in project oxTrust by GluuFederation.

the class Scim2UserService method replaceUserPatch.

private void replaceUserPatch(Operation operation, String id) throws Exception {
    User user = operation.getValue();
    GluuCustomPerson updatedGluuPerson = patchUtil.replacePatch(user, validUsernameByInum(user, id));
    log.info(" Setting meta: replaceUserPatch update user ");
    setMeta(updatedGluuPerson);
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) User(org.gluu.oxtrust.model.scim2.User) ScimPatchUser(org.gluu.oxtrust.model.scim2.ScimPatchUser)

Example 5 with Operation

use of org.gluu.oxtrust.model.scim2.Operation in project oxTrust by GluuFederation.

the class Scim2UserService method patchUser.

public User patchUser(String id, ScimPatchUser patchUser) throws Exception {
    for (Operation operation : patchUser.getOperatons()) {
        String val = operation.getOperationName();
        if (val.equalsIgnoreCase("replace")) {
            replaceUserPatch(operation, id);
        }
        if (val.equalsIgnoreCase("remove")) {
            removeUserPatch(operation, id);
        }
        if (val.equalsIgnoreCase("add")) {
            addUserPatch(operation, id);
        }
    }
    GluuCustomPerson gluuPerson = personService.getPersonByInum(id);
    User updatedUser = copyUtils2.copy(gluuPerson, null);
    return updatedUser;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) User(org.gluu.oxtrust.model.scim2.User) ScimPatchUser(org.gluu.oxtrust.model.scim2.ScimPatchUser) Operation(org.gluu.oxtrust.model.scim2.Operation)

Aggregations

Operation (net.opengis.ows.v_1_0_0.Operation)10 DomainType (net.opengis.ows.v_1_0_0.DomainType)8 ArrayList (java.util.ArrayList)7 OperationsMetadata (net.opengis.ows.v_1_0_0.OperationsMetadata)5 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)5 User (org.gluu.oxtrust.model.scim2.User)4 LinkedHashMap (java.util.LinkedHashMap)3 CapabilitiesType (net.opengis.cat.csw.v_2_0_2.CapabilitiesType)3 PersonRequiredFieldsException (org.gluu.oxtrust.exception.PersonRequiredFieldsException)3 ScimPatchUser (org.gluu.oxtrust.model.scim2.ScimPatchUser)3 Map (java.util.Map)2 QName (javax.xml.namespace.QName)2 GetCapabilitiesType (net.opengis.cat.csw.v_2_0_2.GetCapabilitiesType)2 CswException (org.codice.ddf.spatial.ogc.csw.catalog.common.CswException)2 GetCapabilitiesRequest (org.codice.ddf.spatial.ogc.csw.catalog.common.GetCapabilitiesRequest)2 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)2 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)2 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 Metacard (ddf.catalog.data.Metacard)1 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1