Search in sources :

Example 21 with User

use of org.gluu.oxtrust.model.scim2.User 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 22 with User

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

the class UserDeserializer method deserialize.

@Override
public User deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
    log.info(" deserialize() ");
    try {
        JsonNode rootNode = jsonParser.readValueAsTree();
        ObjectMapper mapper = new ObjectMapper();
        mapper.disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
        User user = mapper.readValue(rootNode.toString(), User.class);
        if (user.getSchemas() == null) {
            throw new IllegalArgumentException("Required field \"schemas\" is null or missing.");
        } else if (!user.getSchemas().contains(Constants.USER_CORE_SCHEMA_ID)) {
            throw new IllegalArgumentException("User Core schema is required.");
        } else if (user.getSchemas().contains(Constants.USER_EXT_SCHEMA_ID)) {
            JsonNode userExtensionNode = rootNode.get(Constants.USER_EXT_SCHEMA_ID);
            if (userExtensionNode != null) {
                ExtensionDeserializer deserializer = new ExtensionDeserializer();
                deserializer.setId(Constants.USER_EXT_SCHEMA_ID);
                SimpleModule deserializerModule = new SimpleModule("ExtensionDeserializerModule", new Version(1, 0, 0, ""));
                deserializerModule.addDeserializer(Extension.class, deserializer);
                mapper.registerModule(deserializerModule);
                Extension extension = mapper.readValue(userExtensionNode.toString(), Extension.class);
                user.addExtension(extension);
            } else {
                throw new IllegalArgumentException("User Extension schema is indicated, but value body is absent.");
            }
        }
        return user;
    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException(INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
Also used : Extension(org.gluu.oxtrust.model.scim2.Extension) User(org.gluu.oxtrust.model.scim2.User) Version(org.codehaus.jackson.Version) JsonNode(org.codehaus.jackson.JsonNode) IOException(java.io.IOException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule) IOException(java.io.IOException)

Example 23 with User

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

the class UserSerializer method serializeUserExtension.

protected void serializeUserExtension(Map.Entry<String, JsonNode> rootNodeEntry, ObjectMapper mapper, User user, JsonGenerator jsonGenerator) throws Exception {
    Extension extension = user.getExtension(rootNodeEntry.getKey());
    Map<String, Object> list = new HashMap<String, Object>();
    boolean enclosingWritten = false;
    for (Map.Entry<String, Extension.Field> extEntry : extension.getFields().entrySet()) {
        if (attributes != null && attributes.size() > 0) {
            for (String attribute : attributes) {
                attribute = FilterUtil.stripScim2Schema(attribute);
                if (extEntry.getKey().equalsIgnoreCase(attribute)) {
                    if (!enclosingWritten) {
                        jsonGenerator.writeFieldName(rootNodeEntry.getKey());
                        enclosingWritten = true;
                    }
                    break;
                }
            }
        } else {
            if (!enclosingWritten) {
                jsonGenerator.writeFieldName(rootNodeEntry.getKey());
                enclosingWritten = true;
            }
        }
        if (enclosingWritten) {
            GluuAttribute gluuAttribute = attributeService.getAttributeByName(extEntry.getKey());
            GluuAttributeDataType attributeDataType = gluuAttribute.getDataType();
            if ((gluuAttribute.getOxMultivaluedAttribute() != null) && gluuAttribute.getOxMultivaluedAttribute().equals(OxMultivalued.TRUE)) {
                if (attributeDataType.equals(GluuAttributeDataType.STRING) || attributeDataType.equals(GluuAttributeDataType.PHOTO)) {
                    List<String> stringList = Arrays.asList(mapper.readValue(extEntry.getValue().getValue(), String[].class));
                    list.put(extEntry.getKey(), stringList);
                } else if (attributeDataType.equals(GluuAttributeDataType.DATE)) {
                    List<Date> dateList = Arrays.asList(mapper.readValue(extEntry.getValue().getValue(), Date[].class));
                    List<String> stringList = new ArrayList<String>();
                    DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime().withZoneUTC();
                    for (Date date : dateList) {
                        String dateString = dateTimeFormatter.print(date.getTime());
                        stringList.add(dateString);
                    }
                    list.put(extEntry.getKey(), stringList);
                } else if (attributeDataType.equals(GluuAttributeDataType.NUMERIC)) {
                    List<BigDecimal> numberList = Arrays.asList(mapper.readValue(extEntry.getValue().getValue(), BigDecimal[].class));
                    list.put(extEntry.getKey(), numberList);
                }
            } else {
                list.put(extEntry.getKey(), extEntry.getValue().getValue());
            }
        }
    }
    if (enclosingWritten) {
        jsonGenerator.writeObject(list);
    }
}
Also used : HashMap(java.util.HashMap) GluuAttributeDataType(org.xdi.model.GluuAttributeDataType) Date(java.util.Date) BigDecimal(java.math.BigDecimal) GluuAttribute(org.xdi.model.GluuAttribute) Extension(org.gluu.oxtrust.model.scim2.Extension) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 24 with User

use of org.gluu.oxtrust.model.scim2.User 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 25 with User

use of org.gluu.oxtrust.model.scim2.User 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

User (org.gluu.oxtrust.model.scim2.User)18 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)15 ArrayList (java.util.ArrayList)12 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)12 ScimPatchUser (org.gluu.oxtrust.model.scim2.ScimPatchUser)11 PersonRequiredFieldsException (org.gluu.oxtrust.exception.PersonRequiredFieldsException)10 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)10 User (org.openstack4j.model.identity.v3.User)10 DefaultValue (javax.ws.rs.DefaultValue)9 HeaderParam (javax.ws.rs.HeaderParam)9 Produces (javax.ws.rs.Produces)9 URI (java.net.URI)8 Response (javax.ws.rs.core.Response)8 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)8 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)7 IOException (java.io.IOException)7 Date (java.util.Date)7 Map (java.util.Map)7 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)7 VirtualListViewResponse (org.xdi.ldap.model.VirtualListViewResponse)7