Search in sources :

Example 6 with Type

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

the class ResourceValidator method validateExtendedAttributes.

/**
 * Inspects the resource passed in the constructor and for every extended attribute (see {@link BaseScimResource#getCustomAttributes()},
 * the attribute's value is checked to see if it complies with the data type it is supposed to belong to. This
 * information is obtained from the list of <code>Extension</code>s passed in the constructor (every {@link ExtensionField}
 * has an associated {@link ExtensionField#getType() type}.
 * <p>When an attribute is {@link ExtensionField#isMultiValued() multi-valued}, every single item inside the collection
 * is validated.</p>
 * @throws SCIMException When any of the validations do not pass or an attribute seems not to be part of a known schema.
 */
public void validateExtendedAttributes() throws SCIMException {
    // Note: throughout this method, we always ignore presence of nulls
    // Gets all extended attributes (see the @JsonAnySetter annotation in BaseScimResource)
    Map<String, Object> extendedAttributes = resource.getCustomAttributes();
    // Iterate over every extension of the resource object (in practice it will be just one at most)
    for (String schema : extendedAttributes.keySet()) {
        // Validate if the schema referenced in the extended attributes is contained in the valid set of extension
        Extension extension = null;
        for (Extension ext : extensions) if (ext.getUrn().equals(schema)) {
            extension = ext;
            break;
        }
        if (extension != null) {
            log.debug("validateExtendedAttributes. Revising attributes under schema {}", schema);
            try {
                // Obtains a generic map consisting of all name/value(s) pairs associated to this schema
                Map<String, Object> attrsMap = IntrospectUtil.strObjMap(extendedAttributes.get(schema));
                for (String attr : attrsMap.keySet()) {
                    Object value = attrsMap.get(attr);
                    if (value != null) {
                        /*
                             Gets the class associated to the value of current attribute. For extended attributes, we
                             should only see coming: String, Integer, Double, boolean, and Collection.
                             Different things will be rejected
                             */
                        Class cls = value.getClass();
                        boolean isCollection = IntrospectUtil.isCollection(cls);
                        // If the attribute coming is unknown, NPE will be thrown and we are covered
                        log.debug("validateExtendedAttributes. Got value(s) for attribute '{}'", attr);
                        // Check if the multivalued custom attribute is consistent with the nature of the value itself
                        if (isCollection == extension.getFields().get(attr).isMultiValued()) {
                            if (isCollection) {
                                for (Object elem : (Collection) value) if (elem != null)
                                    validateDataTypeExtendedAttr(extension, attr, elem);
                            } else
                                validateDataTypeExtendedAttr(extension, attr, value);
                        } else
                            throw new SCIMException(ERROR_PARSING_EXTENDED);
                    }
                }
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                throw new SCIMException(ERROR_PARSING_EXTENDED);
            }
        } else
            throw new SCIMException(String.format(UNKNOWN_EXTENSION, schema));
    }
}
Also used : Extension(org.gluu.oxtrust.model.scim2.extensions.Extension) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) SCIMException(org.gluu.oxtrust.model.exception.SCIMException)

Example 7 with Type

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

the class ResourceValidator method validateSchemasAttribute.

/**
 * Inspects the {@link BaseScimResource#getSchemas() schemas} attribute of the resource passed in the constructor and
 * checks the default schema <code>urn</code> associated to the resource type is present in the list. If some of the
 * <code>urn</code>s part of the <code>Extension</code>s passed in the constructor are contained in the list, the validation is also
 * successful.
 * <p>This method should be called after a successful call to {@link #validateRequiredAttributes()}.</p>
 * @throws SCIMException If there is no {@link BaseScimResource#getSchemas() schemas} in this resource or if some of
 * the <code>urn</code>s there are not known.
 */
public void validateSchemasAttribute() throws SCIMException {
    Set<String> schemaList = new HashSet<String>(resource.getSchemas());
    if (schemaList.size() == 0)
        throw new SCIMException(WRONG_SCHEMAS_ATTR);
    Set<String> allSchemas = new HashSet<String>();
    allSchemas.add(ScimResourceUtil.getDefaultSchemaUrn(resourceClass));
    for (Extension ext : extensions) allSchemas.add(ext.getUrn());
    schemaList.removeAll(allSchemas);
    if (// means that some wrong extension urn is there
    schemaList.size() > 0)
        throw new SCIMException(WRONG_SCHEMAS_ATTR);
}
Also used : Extension(org.gluu.oxtrust.model.scim2.extensions.Extension) SCIMException(org.gluu.oxtrust.model.exception.SCIMException)

Example 8 with Type

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

the class SchemaTypeGroupSerializer method serialize.

@Override
public void serialize(Group group, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
    log.info(" serialize() ");
    try {
        ObjectMapper mapper = new ObjectMapper();
        mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
        JsonNode rootNode = mapper.convertValue(group, JsonNode.class);
        Iterator<Map.Entry<String, JsonNode>> iterator = rootNode.getFields();
        while (iterator.hasNext()) {
            Map.Entry<String, JsonNode> rootNodeEntry = iterator.next();
            if (rootNodeEntry.getValue() instanceof ObjectNode) {
            // Definitely maybe in the near future
            } else if (rootNodeEntry.getValue() instanceof ArrayNode) {
                AttributeHolder arrayNodeAttributeHolder = new AttributeHolder();
                arrayNodeAttributeHolder.setName(rootNodeEntry.getKey());
                if (rootNodeEntry.getKey().equalsIgnoreCase("members")) {
                    arrayNodeAttributeHolder.setDescription(rootNodeEntry.getKey() + " list; using sub-attributes in a query filter is not supported (cross-querying)");
                    arrayNodeAttributeHolder.setCaseExact(Boolean.TRUE);
                    List<String> referenceTypes = new ArrayList<String>();
                    referenceTypes.add("User");
                    arrayNodeAttributeHolder.setReferenceTypes(referenceTypes);
                } else {
                    arrayNodeAttributeHolder.setDescription(rootNodeEntry.getKey() + " list");
                    arrayNodeAttributeHolder.setCaseExact(Boolean.FALSE);
                }
                arrayNodeAttributeHolder.setRequired(Boolean.FALSE);
                arrayNodeAttributeHolder.setMultiValued(Boolean.TRUE);
                if (rootNodeEntry.getKey().equalsIgnoreCase("schemas")) {
                    arrayNodeAttributeHolder.setUniqueness("server");
                    arrayNodeAttributeHolder.setType("string");
                    arrayNodeAttributeHolder.setCaseExact(Boolean.TRUE);
                    arrayNodeAttributeHolder.setMutability("readOnly");
                    arrayNodeAttributeHolder.setReturned("always");
                } else {
                    arrayNodeAttributeHolder.setType("complex");
                }
                List<AttributeHolder> arrayNodeMapAttributeHolders = new ArrayList<AttributeHolder>();
                Iterator<JsonNode> arrayNodeIterator = rootNodeEntry.getValue().getElements();
                while (arrayNodeIterator.hasNext()) {
                    JsonNode jsonNode = arrayNodeIterator.next();
                    Iterator<Map.Entry<String, JsonNode>> arrayNodeMapIterator = jsonNode.getFields();
                    while (arrayNodeMapIterator.hasNext()) {
                        Map.Entry<String, JsonNode> arrayNodeMapRootNodeEntry = arrayNodeMapIterator.next();
                        AttributeHolder arrayNodeMapAttributeHolder = new AttributeHolder();
                        if (rootNodeEntry.getKey().equalsIgnoreCase("members") && arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("reference")) {
                            arrayNodeMapAttributeHolder.setName("$ref");
                        } else {
                            arrayNodeMapAttributeHolder.setName(arrayNodeMapRootNodeEntry.getKey());
                        }
                        arrayNodeMapAttributeHolder.setType("string");
                        arrayNodeMapAttributeHolder.setDescription(arrayNodeMapRootNodeEntry.getKey());
                        if (arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("value") || arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("type")) {
                            arrayNodeMapAttributeHolder.setRequired(Boolean.TRUE);
                        } else {
                            arrayNodeMapAttributeHolder.setRequired(Boolean.FALSE);
                        }
                        arrayNodeMapAttributeHolders.add(arrayNodeMapAttributeHolder);
                    }
                    arrayNodeAttributeHolder.setSubAttributes(arrayNodeMapAttributeHolders);
                    attributeHolders.add(arrayNodeAttributeHolder);
                }
            } else {
                if (!rootNodeEntry.getKey().equalsIgnoreCase("externalId")) {
                    AttributeHolder attributeHolder = new AttributeHolder();
                    attributeHolder.setName(rootNodeEntry.getKey());
                    if (rootNodeEntry.getValue().isBoolean()) {
                        attributeHolder.setType("boolean");
                    } else {
                        attributeHolder.setType("string");
                    }
                    attributeHolder.setDescription(rootNodeEntry.getKey());
                    attributeHolder.setRequired(Boolean.FALSE);
                    if (rootNodeEntry.getKey().equalsIgnoreCase("id")) {
                        attributeHolder.setUniqueness("server");
                        attributeHolder.setCaseExact(Boolean.TRUE);
                        attributeHolder.setMutability("readOnly");
                        attributeHolder.setReturned("always");
                    }
                    if (rootNodeEntry.getKey().equalsIgnoreCase("displayName")) {
                        attributeHolder.setReturned("always");
                    }
                    attributeHolders.add(attributeHolder);
                }
            }
        }
        GroupCoreSchema groupCoreSchema = (GroupCoreSchema) schemaType;
        groupCoreSchema.setAttributeHolders(attributeHolders);
        schemaType = groupCoreSchema;
    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException("Unexpected processing error; please check the Group class structure.");
    }
}
Also used : AttributeHolder(org.gluu.oxtrust.model.scim2.schema.AttributeHolder) ObjectNode(org.codehaus.jackson.node.ObjectNode) JsonNode(org.codehaus.jackson.JsonNode) IOException(java.io.IOException) GroupCoreSchema(org.gluu.oxtrust.model.scim2.schema.core.GroupCoreSchema) IOException(java.io.IOException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ArrayNode(org.codehaus.jackson.node.ArrayNode) Map(java.util.Map) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 9 with Type

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

the class ExtensionDeserializer method deserialize.

@Override
public Extension deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
    log.info(" deserialize() ");
    try {
        if (id == null || id.isEmpty()) {
            throw new IllegalArgumentException("The URN cannot be null or empty");
        }
        JsonNode rootNode = jsonParser.readValueAsTree();
        if (!rootNode.isObject()) {
            throw new IllegalArgumentException("Extension is of wrong JSON type");
        }
        Extension.Builder extensionBuilder = new Extension.Builder(id);
        Iterator<Map.Entry<String, JsonNode>> fieldIterator = rootNode.getFields();
        while (fieldIterator.hasNext()) {
            Map.Entry<String, JsonNode> entry = fieldIterator.next();
            GluuAttribute gluuAttribute = attributeService.getAttributeByName(entry.getKey());
            if (gluuAttribute != null) {
                if (!(gluuAttribute.getOxSCIMCustomAttribute() != null && gluuAttribute.getOxSCIMCustomAttribute().equals(ScimCustomAtribute.TRUE))) {
                    log.info(" NOT A CUSTOM ATTRIBUTE: " + gluuAttribute.getName());
                    throw new IllegalArgumentException("NOT A CUSTOM ATTRIBUTE: " + gluuAttribute.getName());
                }
                GluuAttributeDataType attributeDataType = gluuAttribute.getDataType();
                if ((gluuAttribute.getOxMultivaluedAttribute() != null) && gluuAttribute.getOxMultivaluedAttribute().equals(OxMultivalued.TRUE)) {
                    if (entry.getValue() instanceof ArrayNode) {
                        ArrayNode arrayNode = (ArrayNode) entry.getValue();
                        ObjectMapper mapper = new ObjectMapper();
                        mapper.disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
                        if (attributeDataType.equals(GluuAttributeDataType.STRING) || attributeDataType.equals(GluuAttributeDataType.PHOTO)) {
                            List<String> stringList = Arrays.asList(mapper.readValue(arrayNode, String[].class));
                            extensionBuilder.setFieldAsList(entry.getKey(), stringList);
                        } else if (attributeDataType.equals(GluuAttributeDataType.DATE)) {
                            // For validation
                            List<Date> dateList = Arrays.asList(mapper.readValue(arrayNode, Date[].class));
                            extensionBuilder.setFieldAsList(entry.getKey(), Arrays.asList(mapper.readValue(arrayNode, String[].class)));
                        } else if (attributeDataType.equals(GluuAttributeDataType.NUMERIC)) {
                            List<BigDecimal> numberList = Arrays.asList(mapper.readValue(arrayNode, BigDecimal[].class));
                            extensionBuilder.setFieldAsList(entry.getKey(), numberList);
                        } else {
                            log.info(" NO MATCH: attributeDataType.getDisplayName() = " + attributeDataType.getDisplayName());
                            throw new IllegalArgumentException("JSON type not supported: " + entry.getValue().toString());
                        }
                    } else {
                        throw new IllegalArgumentException("Attribute \"" + entry.getKey() + "\" is multi-valued but passed value is not of array type.");
                    }
                } else {
                    if (entry.getValue() instanceof ArrayNode) {
                        throw new IllegalArgumentException("Attribute \"" + entry.getKey() + "\" is not multi-valued but passed value is of array type.");
                    } else {
                        if (attributeDataType.equals(GluuAttributeDataType.STRING) || attributeDataType.equals(GluuAttributeDataType.PHOTO)) {
                            handleString(extensionBuilder, entry);
                        } else if (attributeDataType.equals(GluuAttributeDataType.DATE)) {
                            handleDateTime(extensionBuilder, entry);
                        } else if (attributeDataType.equals(GluuAttributeDataType.NUMERIC)) {
                            handleNumber(extensionBuilder, entry);
                        } else {
                            log.info(" NO MATCH: attributeDataType.getDisplayName() = " + attributeDataType.getDisplayName());
                            throw new IllegalArgumentException("JSON type not supported: " + entry.getValue().toString());
                        }
                    }
                }
            } else {
                throw new IllegalArgumentException("NOT FOUND: custom attribute = " + entry.getKey());
            }
        }
        return extensionBuilder.build();
    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException(INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
Also used : JsonNode(org.codehaus.jackson.JsonNode) GluuAttributeDataType(org.xdi.model.GluuAttributeDataType) IOException(java.io.IOException) Date(java.util.Date) BigDecimal(java.math.BigDecimal) IOException(java.io.IOException) GluuAttribute(org.xdi.model.GluuAttribute) Extension(org.gluu.oxtrust.model.scim2.Extension) List(java.util.List) ArrayNode(org.codehaus.jackson.node.ArrayNode) Map(java.util.Map) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 10 with Type

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

the class UserExtensionsTest method testCreatePersonFromJsonString.

@Test
@Parameters({ "test.scim2.userext.create_json" })
public void testCreatePersonFromJsonString(final String createJson) throws Exception {
    System.out.println(" testCreatePersonFromJsonString() ");
    // Create custom attributes
    // String, not
    GluuAttribute scimCustomFirst = null;
    // multi-valued
    if (attributeService.getAttributeByName("scimCustomFirst") == null) {
        scimCustomFirst = createCustomAttribute(attributeService, schemaService, appConfiguration, "scimCustomFirst", "Custom First", "First custom attribute", GluuAttributeDataType.STRING, OxMultivalued.FALSE);
    }
    // Date, multi-valued
    GluuAttribute scimCustomSecond = null;
    if (attributeService.getAttributeByName("scimCustomSecond") == null) {
        scimCustomSecond = createCustomAttribute(attributeService, schemaService, appConfiguration, "scimCustomSecond", "Custom Second", "Second custom attribute", GluuAttributeDataType.DATE, OxMultivalued.TRUE);
    }
    // Numeric, not
    GluuAttribute scimCustomThird = null;
    // multi-valued
    if (attributeService.getAttributeByName("scimCustomThird") == null) {
        scimCustomThird = createCustomAttribute(attributeService, schemaService, appConfiguration, "scimCustomThird", "Custom Third", "Third custom attribute", GluuAttributeDataType.NUMERIC, OxMultivalued.FALSE);
    }
    // String CREATEJSON =
    // "{\"schemas\":[\"urn:ietf:params:scim:schemas:core:2.0:User\",\"urn:ietf:params:scim:schemas:extension:gluu:2.0:User\"],\"urn:ietf:params:scim:schemas:extension:gluu:2.0:User\":
    // {\"scimCustomFirst\":\"[1000,2000]\",\"scimCustomSecond\":[\"2016-02-23T15:35:22Z\"],\"scimCustomThird\":3000},\"externalId\":\"scimclient\",\"userName\":\"userjson.add.username\",\"name\":{\"givenName\":\"json\",\"familyName\":\"json\",\"middleName\":\"N/A\",\"honorificPrefix\":\"N/A\",\"honorificSuffix\":\"N/A\"},\"displayName\":\"json
    // json\",\"nickName\":\"json\",\"profileUrl\":\"http://www.gluu.org/\",\"emails\":[{\"value\":\"json@gluu.org\",\"type\":\"work\",\"primary\":\"true\"},{\"value\":\"json2@gluu.org\",\"type\":\"home\",\"primary\":\"false\"}],\"addresses\":[{\"type\":\"work\",\"streetAddress\":\"621
    // East 6th Street Suite
    // 200\",\"locality\":\"Austin\",\"region\":\"TX\",\"postalCode\":\"78701\",\"country\":\"US\",\"formatted\":\"621
    // East 6th Street Suite 200 Austin , TX 78701
    // US\",\"primary\":\"true\"}],\"phoneNumbers\":[{\"value\":\"646-345-2346\",\"type\":\"work\"}],\"ims\":[{\"value\":\"nynytest_user\",\"type\":\"Skype\"}],\"userType\":\"CEO\",\"title\":\"CEO\",\"preferredLanguage\":\"en-us\",\"locale\":\"en_US\",\"active\":\"true\",\"password\":\"secret\",\"roles\":[{\"value\":\"Owner\"}],\"entitlements\":[{\"value\":\"full
    // access\"}],\"x509Certificates\":[{\"value\":\"MIIDQzCCAqygAwIBAgICEAAwDQYJKoZIhvcNAQEFBQAwTjELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFDASBgNVBAoMC2V4YW1wbGUuY29tMRQwEgYDVQQDDAtleGFtcGxlLmNvbTAeFw0xMTEwMjIwNjI0MzFaFw0xMjEwMDQwNjI0MzFa
    // MH8xCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRQwEgYDVQQKDAtleGFtcGxlLmNvbTEhMB8GA1UEAwwYTXMuIEJhcmJhcmEgSiBKZW5zZW4gSUlJMSIwIAYJKoZIhvcNAQkBFhNiamVuc2VuQGV4YW1wbGUuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7Kr+Dcds/JQ5GwejJFcBIP682X3xpjis56AK02bc1FLgzdLI8auoR+cC9/Vrh5t66HkQIOdA4unHh0AaZ4xL5PhVbXIPMB5vAPKpzz5iPSi8xO8SL7I7SDhcBVJhqVqr3HgllEG6UClDdHO7nkLuwXq8HcISKkbT5WFTVfFZzidPl8HZ7DhXkZIRtJwBweq4bvm3hM1Os7UQH05ZS6cVDgweKNwdLLrT51ikSQG3DYrl+ft781UQRIqxgwqCfXEuDiinPh0kkvIi5jivVu1Z9QiwlYEdRbLJ4zJQBmDrSGTMYn4lRc2HgHO4DqB/bnMVorHB0CC6AV1QoFK4GPe1LwIDAQABo3sweTAJBgNVHRMEAjAAMCwGCWCGSAGG+EIBDQQfFh1PcGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZpY2F0ZTAdBgNVHQ4EFgQU8pD0U0vsZIsaA16lL8En8bx0F/gwHwYDVR0jBBgwFoAUdGeKitcaF7gnzsNwDx708kqaVt0wDQYJKoZIhvcNAQEFBQADgYEAA81SsFnOdYJtNg5Tcq+/ByEDrBgnusx0jloUhByPMEVkoMZ3J7j1ZgI8rAbOkNngX8+pKfTiDz1RC4+dx8oU6Za+4NJXUjlL5CvV6BEYb1+QAEJwitTVvxB/A67g42/vzgAtoRUeDov1+GFiBZ+GNF/cAYKcMtGcrs2i97ZkJMo=\"}],\"meta\":{\"created\":\"2010-01-23T04:56:22Z\",\"lastModified\":\"2011-05-13T04:42:34Z\",\"version\":\"aversion\",\"location\":\"http://localhost:8080/identity/seam/resource/restv1/Users/8c4b6c26-efaf-4840-bddf-c0146a8eb2a9\"}}";
    ObjectMapper mapper = new ObjectMapper();
    mapper.disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
    SimpleModule simpleModule = new SimpleModule("SimpleModule", new Version(1, 0, 0, ""));
    simpleModule.addDeserializer(User.class, new UserDeserializer());
    mapper.registerModule(simpleModule);
    User user = mapper.readValue(createJson, User.class);
    String testUserName = user.getUserName() + " (" + System.currentTimeMillis() + ")";
    user.setUserName(testUserName);
    Extension extension = user.getExtension(Constants.USER_EXT_SCHEMA_ID);
    assertNotNull(extension, "(Deserialization) Custom extension not deserialized.");
    Extension.Field customFirstField = extension.getFields().get("scimCustomFirst");
    assertNotNull(customFirstField, "(Deserialization) \"scimCustomFirst\" field not deserialized.");
    assertEquals(customFirstField.getValue(), "[1000,2000]");
    System.out.println("##### (Deserialization) customFirstField.getValue() = " + customFirstField.getValue());
    Extension.Field customSecondField = extension.getFields().get("scimCustomSecond");
    assertNotNull(customSecondField, "(Deserialization) \"scimCustomSecond\" field not deserialized.");
    List<Date> dateList = Arrays.asList(mapper.readValue(customSecondField.getValue(), Date[].class));
    assertEquals(dateList.size(), 1);
    System.out.println("##### (Deserialization) dateList.get(0) = " + dateList.get(0));
    Extension.Field customThirdField = extension.getFields().get("scimCustomThird");
    assertNotNull(customThirdField, "(Deserialization) \"scimCustomThird\" field not deserialized.");
    assertEquals(new BigDecimal(customThirdField.getValue()), new BigDecimal(3000));
    System.out.println("##### (Deserialization) customThirdField.getValue() = " + customThirdField.getValue());
    // Create Person
    GluuCustomPerson gluuPerson = copyUtils2.copy(user, null, false);
    assertNotNull(gluuPerson, "gluuPerson is null!");
    System.out.println(">>>>> gluuPerson.getUid() = " + gluuPerson.getUid());
    String inum = personService.generateInumForNewPerson();
    String dn = personService.getDnForPerson(inum);
    String iname = personService.generateInameForNewPerson(user.getUserName());
    gluuPerson.setDn(dn);
    gluuPerson.setInum(inum);
    gluuPerson.setIname(iname);
    gluuPerson.setCommonName(gluuPerson.getGivenName() + " " + gluuPerson.getSurname());
    personService.addPerson(gluuPerson);
    // Retrieve Person
    GluuCustomPerson retrievedPerson = personService.getPersonByUid(gluuPerson.getUid());
    assertNotNull(retrievedPerson, "Failed to find person.");
    User newPerson = copyUtils2.copy(retrievedPerson, null);
    extension = newPerson.getExtension(Constants.USER_EXT_SCHEMA_ID);
    assertNotNull(extension, "(Persistence) Custom extension not persisted.");
    customFirstField = extension.getFields().get("scimCustomFirst");
    assertNotNull(customFirstField, "(Persistence) \"scimCustomFirst\" field not persisted.");
    assertEquals(customFirstField.getValue(), "[1000,2000]");
    System.out.println("##### (Persistence) customFirstField.getValue() = " + customFirstField.getValue());
    customSecondField = extension.getFields().get("scimCustomSecond");
    assertNotNull(customSecondField, "(Persistence) \"scimCustomSecond\" field not persisted.");
    dateList = Arrays.asList(mapper.readValue(customSecondField.getValue(), Date[].class));
    assertEquals(dateList.size(), 1);
    System.out.println("##### (Persistence) dateList.get(0) = " + dateList.get(0));
    customThirdField = extension.getFields().get("scimCustomThird");
    assertNotNull(customThirdField, "(Persistence) \"scimCustomThird\" field not persisted.");
    assertEquals(new BigDecimal(customThirdField.getValue()), new BigDecimal(3000));
    System.out.println("##### (Persistence) customThirdField.getValue() = " + customThirdField.getValue());
    // Remove Person
    memberService.removePerson(retrievedPerson);
// Remove custom attributes
// schemaService.removeAttributeTypeFromObjectClass(scimCustomFirst.getOrigin(),
// scimCustomFirst.getName());
// schemaService.removeStringAttribute(scimCustomFirst.getName());
// attributeService.removeAttribute(scimCustomFirst);
// schemaService.removeAttributeTypeFromObjectClass(scimCustomSecond.getOrigin(),
// scimCustomSecond.getName());
// schemaService.removeStringAttribute(scimCustomSecond.getName());
// attributeService.removeAttribute(scimCustomSecond);
// schemaService.removeAttributeTypeFromObjectClass(scimCustomThird.getOrigin(),
// scimCustomThird.getName());
// schemaService.removeStringAttribute(scimCustomThird.getName());
// attributeService.removeAttribute(scimCustomThird);
}
Also used : UserDeserializer(org.gluu.oxtrust.service.scim2.jackson.custom.UserDeserializer) User(org.gluu.oxtrust.model.scim2.User) Date(java.util.Date) BigDecimal(java.math.BigDecimal) GluuAttribute(org.xdi.model.GluuAttribute) Extension(org.gluu.oxtrust.model.scim2.Extension) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) Version(org.codehaus.jackson.Version) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.gluu.oxtrust.action.test.BaseTest)

Aggregations

Extension (org.gluu.oxtrust.model.scim2.extensions.Extension)6 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)5 ExtensionField (org.gluu.oxtrust.model.scim2.extensions.ExtensionField)4 IOException (java.io.IOException)3 List (java.util.List)3 Map (java.util.Map)3 JsonNode (org.codehaus.jackson.JsonNode)3 ArrayNode (org.codehaus.jackson.node.ArrayNode)3 SCIMException (org.gluu.oxtrust.model.exception.SCIMException)3 Attribute (org.gluu.oxtrust.model.scim2.annotations.Attribute)3 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Iterator (java.util.Iterator)2 ObjectNode (org.codehaus.jackson.node.ObjectNode)2 Type (org.gluu.oxtrust.model.scim2.AttributeDefinition.Type)2 Extension (org.gluu.oxtrust.model.scim2.Extension)2 AttributeHolder (org.gluu.oxtrust.model.scim2.schema.AttributeHolder)2 CompValueType (org.gluu.oxtrust.service.antlr.scimFilter.enums.CompValueType)2 GluuAttribute (org.xdi.model.GluuAttribute)2