Search in sources :

Example 21 with Extension

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

the class ExtensionService method getFieldOfExtendedAttribute.

public ExtensionField getFieldOfExtendedAttribute(Class<? extends BaseScimResource> cls, String attribute) {
    List<Extension> extensions = getResourceExtensions(cls);
    ExtensionField field = null;
    try {
        for (Extension ext : extensions) {
            if (attribute.startsWith(ext.getUrn() + ":")) {
                attribute = attribute.substring(ext.getUrn().length() + 1);
                for (ExtensionField f : ext.getFields().values()) if (attribute.equals(f.getName())) {
                    field = f;
                    break;
                }
            }
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return field;
}
Also used : Extension(org.gluu.oxtrust.model.scim2.extensions.Extension) ExtensionField(org.gluu.oxtrust.model.scim2.extensions.ExtensionField)

Example 22 with Extension

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

the class Scim2UserService method transferExtendedAttributesToResource.

private void transferExtendedAttributesToResource(GluuCustomPerson person, BaseScimResource resource) {
    log.debug("transferExtendedAttributesToResource of type {}", ScimResourceUtil.getType(resource.getClass()));
    // Gets the list of extensions associated to the resource passed. In practice, this will be at most a singleton list
    List<Extension> extensions = extService.getResourceExtensions(resource.getClass());
    // Iterate over every extension to copy extended attributes from person to resource
    for (Extension extension : extensions) {
        Map<String, ExtensionField> fields = extension.getFields();
        // Create empty map to store the values of the extended attributes found for current extension in object person
        Map<String, Object> map = new HashMap<String, Object>();
        log.debug("transferExtendedAttributesToResource. Revising attributes of extension '{}'", extension.getUrn());
        // Iterate over every attribute part of this extension
        for (String attr : fields.keySet()) {
            // Gets the values associated to this attribute that were found in LDAP
            String[] values = person.getAttributes(attr);
            if (values != null) {
                log.debug("transferExtendedAttributesToResource. Copying to resource the value(s) for attribute '{}'", attr);
                ExtensionField field = fields.get(attr);
                if (field.isMultiValued())
                    map.put(attr, extService.convertValues(field, values));
                else
                    map.put(attr, extService.convertValues(field, values).get(0));
            }
        }
        // Stores all extended attributes (with their values) in the resource object
        if (map.size() > 0) {
            resource.addCustomAttributes(extension.getUrn(), map);
        }
    }
    for (String urn : resource.getCustomAttributes().keySet()) resource.getSchemas().add(urn);
}
Also used : Extension(org.gluu.oxtrust.model.scim2.extensions.Extension) ExtensionField(org.gluu.oxtrust.model.scim2.extensions.ExtensionField) HashMap(java.util.HashMap)

Example 23 with Extension

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

the class Scim2UserService method transferExtendedAttributesToPerson.

/**
 * Takes all extended attributes found in the SCIM resource and copies them to a GluuCustomPerson
 * This method is called after validations take place (see associated decorator for User Service), so all inputs are
 * OK and can go straight to LDAP with no runtime surprises
 * @param resource A SCIM resource used as origin of data
 * @param person a GluuCustomPerson used as destination
 */
private void transferExtendedAttributesToPerson(BaseScimResource resource, GluuCustomPerson person) {
    try {
        // Gets all the extended attributes for this resource
        Map<String, Object> extendedAttrs = resource.getCustomAttributes();
        // Iterates over all extensions this type of resource might have
        for (Extension extension : extService.getResourceExtensions(resource.getClass())) {
            Object val = extendedAttrs.get(extension.getUrn());
            if (val != null) {
                // Obtains the attribute/value(s) pairs in the current extension
                Map<String, Object> attrsMap = IntrospectUtil.strObjMap(val);
                for (String attribute : attrsMap.keySet()) {
                    Object value = attrsMap.get(attribute);
                    // Ignore if the attribute is unassigned in this resource: destination will not be changed in this regard
                    if (value != null) {
                        // Get properly formatted string representations for the value(s) associated to the attribute
                        List<String> values = extService.getStringAttributeValues(extension.getFields().get(attribute), value);
                        log.debug("transferExtendedAttributesToPerson. Setting attribute '{}' with values {}", attribute, values.toString());
                        person.setAttribute(attribute, values.toArray(new String[] {}));
                    }
                }
            }
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : Extension(org.gluu.oxtrust.model.scim2.extensions.Extension) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 24 with Extension

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

the class ScimResourceSerializer method buildIncludeSet.

private void buildIncludeSet(SortedSet<String> include, Class<? extends BaseScimResource> resourceClass, List<String> schemas, String attributes, String exclussions) {
    Set<String> tempSet;
    Set<String> alwaysSet = IntrospectUtil.alwaysCoreAttrs.get(resourceClass).keySet();
    Set<String> neverSet = IntrospectUtil.neverCoreAttrs.get(resourceClass).keySet();
    Set<String> defaultSet = new HashSet<String>();
    // Here we assume all attributes part of extensions have returnability="default"...
    SortedSet<String> extendedSet = new TreeSet<String>();
    for (Extension ext : extService.getResourceExtensions(resourceClass)) {
        extendedSet.add(ext.getUrn());
        extendedSet.addAll(IntrospectUtil.getPathsInExtension(ext));
    }
    defaultSet.addAll(IntrospectUtil.defaultCoreAttrs.get(resourceClass).keySet());
    defaultSet.addAll(extendedSet);
    String defaultSchema = ScimResourceUtil.getDefaultSchemaUrn(resourceClass);
    if (attributes != null) {
        log.info("buildIncludeSet. Processing attributes query param (excludedAttributes ignored)");
        extendedSet.addAll(IntrospectUtil.allAttrs.get(resourceClass));
        tempSet = expandAttributesPaths(attributes, defaultSchema, schemas, extendedSet);
        tempSet.removeAll(neverSet);
        include.addAll(tempSet);
    } else if (exclussions != null) {
        log.info("buildIncludeSet. Processing excludedAttributes query param");
        extendedSet.addAll(IntrospectUtil.allAttrs.get(resourceClass));
        tempSet = defaultSet;
        tempSet.removeAll(expandAttributesPaths(exclussions, defaultSchema, schemas, extendedSet));
        include.addAll(tempSet);
    } else {
        log.info("buildIncludeSet. No attributes neither excludedAttributes query param were passed");
        include.addAll(defaultSet);
    }
    include.addAll(alwaysSet);
}
Also used : Extension(org.gluu.oxtrust.model.scim2.extensions.Extension)

Example 25 with Extension

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

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