Search in sources :

Example 1 with AttributeTypeDefinition

use of com.unboundid.ldap.sdk.schema.AttributeTypeDefinition in project oxCore by GluuFederation.

the class SchemaService method getAttributeTypeDefinitions.

public List<AttributeTypeDefinition> getAttributeTypeDefinitions(SchemaEntry schemaEntry, List<String> attributeNames) {
    if (schemaEntry == null) {
        return null;
    }
    String[] attrs = attributeNames.toArray(new String[attributeNames.size()]);
    for (int i = 0; i < attrs.length; i++) {
        attrs[i] = "'" + attrs[i].toLowerCase() + "'";
    }
    List<AttributeTypeDefinition> result = new ArrayList<AttributeTypeDefinition>();
    for (String attributeTypeDefinition : schemaEntry.getAttributeTypes()) {
        for (String name : attrs) {
            if (attributeTypeDefinition.toLowerCase().contains(name)) {
                try {
                    result.add(new AttributeTypeDefinition(attributeTypeDefinition));
                } catch (Exception ex) {
                    log.error("Failed to get attribute type definition by string {0}", ex, attributeTypeDefinition);
                }
            }
        }
    }
    return result;
}
Also used : AttributeTypeDefinition(com.unboundid.ldap.sdk.schema.AttributeTypeDefinition) ArrayList(java.util.ArrayList) InvalidSchemaUpdateException(org.xdi.util.exception.InvalidSchemaUpdateException)

Example 2 with AttributeTypeDefinition

use of com.unboundid.ldap.sdk.schema.AttributeTypeDefinition in project oxCore by GluuFederation.

the class SchemaService method getAttributeTypeDefinition.

/**
	 * Get attribute type schema definition string
	 * 
	 * @param schemaEntry
	 *            Schema
	 * @param attributeType
	 *            Attribute type name
	 * @return Attribute type schema definition string
	 */
public String getAttributeTypeDefinition(SchemaEntry schemaEntry, String attributeType) {
    if ((schemaEntry == null) || (attributeType == null)) {
        return null;
    }
    String lowerCaseAttributeType = StringHelper.toLowerCase(attributeType);
    List<AttributeTypeDefinition> attributeTypes = getAttributeTypeDefinitions(schemaEntry, Arrays.asList(new String[] { lowerCaseAttributeType }));
    AttributeTypeDefinition attributeTypeDefinition = getAttributeTypeDefinition(attributeTypes, lowerCaseAttributeType);
    return (attributeTypeDefinition == null) ? null : attributeTypeDefinition.toString();
}
Also used : AttributeTypeDefinition(com.unboundid.ldap.sdk.schema.AttributeTypeDefinition)

Example 3 with AttributeTypeDefinition

use of com.unboundid.ldap.sdk.schema.AttributeTypeDefinition in project oxTrust by GluuFederation.

the class UpdateTrustRelationshipAction method getSAML2URI.

public String getSAML2URI(GluuAttribute attribute) {
    if (StringHelper.isNotEmpty(attribute.getSaml2Uri())) {
        return "SAML1 URI: " + attribute.getSaml2Uri();
    }
    List<String> attributeNames = new ArrayList<String>();
    attributeNames.add(attribute.getName());
    SchemaEntry schemaEntry = shemaService.getSchema();
    List<AttributeTypeDefinition> attributeTypes = shemaService.getAttributeTypeDefinitions(schemaEntry, attributeNames);
    String attributeName = attribute.getName();
    AttributeTypeDefinition attributeTypeDefinition = shemaService.getAttributeTypeDefinition(attributeTypes, attributeName);
    if (attributeTypeDefinition == null) {
        log.error("Failed to get OID for attribute name {}", attributeName);
        return null;
    }
    return "SAML2 URI: urn:oid:" + attributeTypeDefinition.getOID();
}
Also used : AttributeTypeDefinition(com.unboundid.ldap.sdk.schema.AttributeTypeDefinition) ArrayList(java.util.ArrayList) SchemaEntry(org.xdi.model.SchemaEntry)

Example 4 with AttributeTypeDefinition

use of com.unboundid.ldap.sdk.schema.AttributeTypeDefinition in project oxTrust by GluuFederation.

the class Shibboleth3ConfService method initAttributeParamMap.

private HashMap<String, Object> initAttributeParamMap(List<GluuSAMLTrustRelationship> trustRelationships) {
    HashMap<String, Object> attrParams = new HashMap<String, Object>();
    // Collect attributes
    List<GluuAttribute> attributes = new ArrayList<GluuAttribute>();
    List<String> attributeNames = new ArrayList<String>();
    for (GluuSAMLTrustRelationship trustRelationship : trustRelationships) {
        for (GluuCustomAttribute customAttribute : trustRelationship.getReleasedCustomAttributes()) {
            GluuAttribute metadata = customAttribute.getMetadata();
            if (!attributes.contains(metadata)) {
                attributes.add(metadata);
                String attributeName = metadata.getName();
                attributeNames.add(attributeName);
            }
        }
    }
    SchemaEntry schemaEntry = shemaService.getSchema();
    List<AttributeTypeDefinition> attributeTypes = shemaService.getAttributeTypeDefinitions(schemaEntry, attributeNames);
    Map<String, String> attributeSAML1Strings = new HashMap<String, String>();
    Map<String, String> attributeSAML2Strings = new HashMap<String, String>();
    for (GluuAttribute metadata : attributes) {
        String attributeName = metadata.getName();
        AttributeTypeDefinition attributeTypeDefinition = shemaService.getAttributeTypeDefinition(attributeTypes, attributeName);
        if (attributeTypeDefinition == null) {
            log.error("Failed to get OID for attribute name {}", attributeName);
            return null;
        }
        //
        // urn::dir:attribute-def:$attribute.name
        // urn:oid:$attrParams.attributeOids.get($attribute.name)
        String saml1String = metadata.getSaml1Uri();
        if (StringHelper.isEmpty(saml1String)) {
            boolean standard = metadata.isCustom() || StringHelper.isEmpty(metadata.getUrn()) || (!StringHelper.isEmpty(metadata.getUrn()) && metadata.getUrn().startsWith("urn:gluu:dir:attribute-def:"));
            saml1String = String.format("urn:%s:dir:attribute-def:%s", standard ? "gluu" : "mace", attributeName);
        }
        attributeSAML1Strings.put(attributeName, saml1String);
        String saml2String = metadata.getSaml2Uri();
        if (StringHelper.isEmpty(saml2String)) {
            saml2String = String.format("urn:oid:%s", attributeTypeDefinition.getOID());
        }
        attributeSAML2Strings.put(attributeName, saml2String);
    }
    attrParams.put("attributes", attributes);
    attrParams.put("attributeSAML1Strings", attributeSAML1Strings);
    attrParams.put("attributeSAML2Strings", attributeSAML2Strings);
    return attrParams;
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SchemaEntry(org.xdi.model.SchemaEntry) GluuAttribute(org.xdi.model.GluuAttribute) AttributeTypeDefinition(com.unboundid.ldap.sdk.schema.AttributeTypeDefinition)

Example 5 with AttributeTypeDefinition

use of com.unboundid.ldap.sdk.schema.AttributeTypeDefinition in project oxCore by GluuFederation.

the class AttributeService method getDefaultSaml2Uri.

public String getDefaultSaml2Uri(String name) {
    SchemaEntry schemaEntry = schemaService.getSchema();
    List<String> attributeNames = new ArrayList<String>();
    attributeNames.add(name);
    List<AttributeTypeDefinition> attributeTypes = schemaService.getAttributeTypeDefinitions(schemaEntry, attributeNames);
    AttributeTypeDefinition attributeTypeDefinition = schemaService.getAttributeTypeDefinition(attributeTypes, name);
    return String.format("urn:oid:%s", attributeTypeDefinition.getOID());
}
Also used : AttributeTypeDefinition(com.unboundid.ldap.sdk.schema.AttributeTypeDefinition) ArrayList(java.util.ArrayList) SchemaEntry(org.xdi.model.SchemaEntry)

Aggregations

AttributeTypeDefinition (com.unboundid.ldap.sdk.schema.AttributeTypeDefinition)5 ArrayList (java.util.ArrayList)4 SchemaEntry (org.xdi.model.SchemaEntry)3 HashMap (java.util.HashMap)1 GluuCustomAttribute (org.gluu.oxtrust.model.GluuCustomAttribute)1 GluuSAMLTrustRelationship (org.gluu.oxtrust.model.GluuSAMLTrustRelationship)1 GluuAttribute (org.xdi.model.GluuAttribute)1 InvalidSchemaUpdateException (org.xdi.util.exception.InvalidSchemaUpdateException)1