Search in sources :

Example 6 with SchemaEntry

use of org.gluu.model.SchemaEntry in project oxCore by GluuFederation.

the class AttributeService method getDefaultSaml2Uri.

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

Example 7 with SchemaEntry

use of org.gluu.model.SchemaEntry in project oxTrust by GluuFederation.

the class Shibboleth3ConfService method generateGluuAttributeRulesFile.

public boolean generateGluuAttributeRulesFile(List<GluuAttribute> attributes) {
    boolean ret = false;
    log.info(">>>>>>>>>> IN Shibboleth3ConfService.generateGluuAttributeRulesFile() ...");
    if (appConfiguration.getShibboleth3IdpRootDir() == null) {
        throw new InvalidConfigurationException("Failed to update configuration due to undefined IDP root folder");
    }
    VelocityContext context = new VelocityContext();
    List<String> attributeNames = new ArrayList<String>();
    for (GluuAttribute attribute : attributes) {
        attributeNames.add(attribute.getName());
    }
    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();
        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)) {
            AttributeTypeDefinition attributeTypeDefinition = shemaService.getAttributeTypeDefinition(attributeTypes, attributeName);
            if (attributeTypeDefinition == null) {
                log.error("Failed to get OID for attribute name {}", attributeName);
                return false;
            }
            saml2String = String.format("urn:oid:%s", attributeTypeDefinition.getOID());
        }
        attributeSaml2Strings.put(attributeName, saml2String);
    }
    context.put("attributes", attributes);
    context.put("attributeSaml1Strings", attributeSaml1Strings);
    context.put("attributeSaml2Strings", attributeSaml2Strings);
    String gluuAttributesRules = generateConfFile(SHIB_IDP_GLUU_ATTRIBUTE_RULES_FILE, context);
    log.info("Gluu attributes rules file path is {}", getGluuAttributesRulesFilePath());
    ret = writeConfFile(getGluuAttributesRulesFilePath(), gluuAttributesRules);
    log.info(">>>>>>>>>>> LEAVING Shibboleth3ConfService.generateGluuAttributeRulesFile() ...");
    return ret;
}
Also used : AttributeTypeDefinition(com.unboundid.ldap.sdk.schema.AttributeTypeDefinition) HashMap(java.util.HashMap) VelocityContext(org.apache.velocity.VelocityContext) ArrayList(java.util.ArrayList) SchemaEntry(org.gluu.model.SchemaEntry) InvalidConfigurationException(org.gluu.util.exception.InvalidConfigurationException) GluuAttribute(org.gluu.model.GluuAttribute)

Example 8 with SchemaEntry

use of org.gluu.model.SchemaEntry 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.gluu.model.SchemaEntry)

Example 9 with SchemaEntry

use of org.gluu.model.SchemaEntry in project oxTrust by GluuFederation.

the class CacheRefreshTimer method validateTargetServerSchema.

private boolean validateTargetServerSchema(List<String> targetObjectClasses, List<String> targetAttributes) {
    SchemaEntry schemaEntry = schemaService.getSchema();
    if (schemaEntry == null) {
        // Destination server not requires schema validation
        return true;
    }
    Set<String> objectClassesAttributesSet = schemaService.getObjectClassesAttributes(schemaEntry, targetObjectClasses.toArray(new String[0]));
    Set<String> targetAttributesSet = new LinkedHashSet<String>();
    for (String attrbute : targetAttributes) {
        targetAttributesSet.add(StringHelper.toLowerCase(attrbute));
    }
    targetAttributesSet.removeAll(objectClassesAttributesSet);
    if (targetAttributesSet.size() == 0) {
        return true;
    }
    log.error("Skipping target entries update. Destination server schema doesn't has next attributes: '{}'", targetAttributesSet);
    return false;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SchemaEntry(org.gluu.model.SchemaEntry)

Example 10 with SchemaEntry

use of org.gluu.model.SchemaEntry in project oxTrust by GluuFederation.

the class UpdateAttributeAction method determineOrigin.

private String determineOrigin(String attributeName) {
    String[] objectClasses = ArrayHelper.arrayMerge(new String[] { "gluuPerson" }, appConfiguration.getPersonObjectClassTypes());
    SchemaEntry schemaEntry = schemaService.getSchema();
    for (String objectClass : objectClasses) {
        Set<String> attributeNames = schemaService.getObjectClassesAttributes(schemaEntry, new String[] { objectClass });
        String atributeNameToSearch = StringHelper.toLowerCase(attributeName);
        boolean contains = attributeNames.contains(atributeNameToSearch);
        if (contains) {
            return objectClass;
        }
    }
    log.error("Failed to determine object class by attribute name '{}'", attributeName);
    return null;
}
Also used : SchemaEntry(org.gluu.model.SchemaEntry)

Aggregations

SchemaEntry (org.gluu.model.SchemaEntry)15 PersistenceEntryManager (org.gluu.persist.PersistenceEntryManager)7 AttributeTypeDefinition (com.unboundid.ldap.sdk.schema.AttributeTypeDefinition)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)2 GluuAttribute (org.gluu.model.GluuAttribute)2 InvalidSchemaUpdateException (org.gluu.util.exception.InvalidSchemaUpdateException)2 LinkedHashSet (java.util.LinkedHashSet)1 VelocityContext (org.apache.velocity.VelocityContext)1 InvalidConfigurationException (org.gluu.util.exception.InvalidConfigurationException)1