Search in sources :

Example 16 with Extension

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

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

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

the class ResourceTypeWS method getUserResourceType.

private ResourceType getUserResourceType() {
    Class<? extends BaseScimResource> cls = UserResource.class;
    List<Extension> usrExtensions = extService.getResourceExtensions(cls);
    List<SchemaExtensionHolder> schemaExtensions = new ArrayList<SchemaExtensionHolder>();
    for (Extension extension : usrExtensions) {
        SchemaExtensionHolder userExtensionSchema = new SchemaExtensionHolder();
        userExtensionSchema.setSchema(extension.getUrn());
        userExtensionSchema.setRequired(false);
        schemaExtensions.add(userExtensionSchema);
    }
    ResourceType usrRT = new ResourceType();
    fillResourceType(usrRT, ScimResourceUtil.getSchemaAnnotation(cls), userService.getEndpointUrl(), getResourceLocation(USER_SUFFIX), schemaExtensions);
    return usrRT;
}
Also used : Extension(org.gluu.oxtrust.model.scim2.extensions.Extension) SchemaExtensionHolder(org.gluu.oxtrust.model.scim2.provider.resourcetypes.SchemaExtensionHolder) UserResource(org.gluu.oxtrust.model.scim2.user.UserResource) ArrayList(java.util.ArrayList) ResourceType(org.gluu.oxtrust.model.scim2.provider.resourcetypes.ResourceType)

Example 19 with Extension

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

the class SchemaWebService method getSchemaInstance.

private SchemaResource getSchemaInstance(Class<? extends BaseScimResource> clazz, String urn) throws Exception {
    if (ScimResourceUtil.getDefaultSchemaUrn(clazz).equals(urn))
        // Process core attributes
        return getSchemaInstance(clazz);
    else {
        // process extension attributes
        SchemaResource resource = null;
        Class<? extends BaseScimResource> schemaCls = SchemaResource.class;
        // Find the appropriate extension
        List<Extension> extensions = extService.getResourceExtensions(clazz);
        for (Extension extension : extensions) {
            if (extension.getUrn().equals(urn)) {
                Meta meta = new Meta();
                meta.setResourceType(ScimResourceUtil.getType(schemaCls));
                meta.setLocation(endpointUrl + "/" + urn);
                resource = new SchemaResource();
                resource.setId(urn);
                resource.setName(extension.getName());
                resource.setDescription(extension.getDescription());
                resource.setMeta(meta);
                List<SchemaAttribute> attribs = new ArrayList<SchemaAttribute>();
                for (ExtensionField field : extension.getFields().values()) {
                    SchemaAttribute schAttr = new SchemaAttribute();
                    schAttr.setName(field.getName());
                    schAttr.setMultiValued(field.isMultiValued());
                    schAttr.setDescription(field.getDescription());
                    schAttr.setRequired(false);
                    schAttr.setCanonicalValues(null);
                    schAttr.setCaseExact(false);
                    schAttr.setMutability(AttributeDefinition.Mutability.READ_WRITE.getName());
                    schAttr.setReturned(AttributeDefinition.Returned.DEFAULT.getName());
                    schAttr.setUniqueness(AttributeDefinition.Uniqueness.NONE.getName());
                    schAttr.setReferenceTypes(null);
                    AttributeDefinition.Type type = field.getAttributeDefinitionType();
                    schAttr.setType(type == null ? null : type.getName());
                    schAttr.setSubAttributes(null);
                    attribs.add(schAttr);
                }
                resource.setAttributes(attribs);
                break;
            }
        }
        return resource;
    }
}
Also used : Extension(org.gluu.oxtrust.model.scim2.extensions.Extension) Meta(org.gluu.oxtrust.model.scim2.Meta) ExtensionField(org.gluu.oxtrust.model.scim2.extensions.ExtensionField) AttributeDefinition(org.gluu.oxtrust.model.scim2.AttributeDefinition) SchemaAttribute(org.gluu.oxtrust.model.scim2.provider.schema.SchemaAttribute) SchemaResource(org.gluu.oxtrust.model.scim2.provider.schema.SchemaResource)

Example 20 with Extension

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

the class ExtensionService method getResourceExtensions.

public List<Extension> getResourceExtensions(Class<? extends BaseScimResource> cls) {
    List<Extension> list = new ArrayList<Extension>();
    try {
        // Currently support one extension only for User Resource
        if (cls.equals(UserResource.class)) {
            Map<String, ExtensionField> fields = new HashMap<String, ExtensionField>();
            for (GluuAttribute attribute : attrService.getSCIMRelatedAttributes()) {
                if (attribute.getOxSCIMCustomAttribute().equals(ScimCustomAtribute.TRUE)) {
                    // first non-null check is needed because certain entries do not have the multivalue attribute set
                    boolean multi = attribute.getOxMultivaluedAttribute() != null && attribute.getOxMultivaluedAttribute().equals(OxMultivalued.TRUE);
                    ExtensionField field = new ExtensionField();
                    field.setDescription(attribute.getDescription());
                    field.setType(attribute.getDataType());
                    field.setMultiValued(multi);
                    field.setName(attribute.getName());
                    fields.put(attribute.getName(), field);
                }
            }
            Extension ext = new Extension(USER_EXT_SCHEMA_ID);
            ext.setFields(fields);
            ext.setName(USER_EXT_SCHEMA_NAME);
            ext.setDescription(USER_EXT_SCHEMA_DESCRIPTION);
            list.add(ext);
        }
    } catch (Exception e) {
        log.error("An error ocurred when building extension for {}", cls.getName());
        log.error(e.getMessage(), e);
    }
    return list;
}
Also used : Extension(org.gluu.oxtrust.model.scim2.extensions.Extension) ExtensionField(org.gluu.oxtrust.model.scim2.extensions.ExtensionField) GluuAttribute(org.xdi.model.GluuAttribute)

Aggregations

Extension (org.bouncycastle.asn1.x509.Extension)76 Extensions (org.bouncycastle.asn1.x509.Extensions)39 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)33 DEROctetString (org.bouncycastle.asn1.DEROctetString)28 IOException (java.io.IOException)27 Enumeration (java.util.Enumeration)22 HashSet (java.util.HashSet)21 Date (java.util.Date)18 X500Name (org.bouncycastle.asn1.x500.X500Name)17 BigInteger (java.math.BigInteger)15 ArrayList (java.util.ArrayList)15 Extension (org.gluu.oxtrust.model.scim2.extensions.Extension)14 Set (java.util.Set)13 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)12 X509CertificateHolder (org.bouncycastle.cert.X509CertificateHolder)12 X509Certificate (java.security.cert.X509Certificate)11 LinkedList (java.util.LinkedList)11 DERIA5String (org.bouncycastle.asn1.DERIA5String)11 DERSequence (org.bouncycastle.asn1.DERSequence)11 CertificateEncodingException (java.security.cert.CertificateEncodingException)10