Search in sources :

Example 11 with SchemaEntry

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

the class UpdateAttributeAction method containsAttributeInGluuObjectClasses.

private boolean containsAttributeInGluuObjectClasses(String attributeName) {
    String[] objectClasses = ArrayHelper.arrayMerge(new String[] { "gluuPerson" }, appConfiguration.getPersonObjectClassTypes());
    SchemaEntry schemaEntry = schemaService.getSchema();
    Set<String> attributeNames = schemaService.getObjectClassesAttributes(schemaEntry, objectClasses);
    String atributeNameToSearch = StringHelper.toLowerCase(attributeName);
    boolean result = attributeNames.contains(atributeNameToSearch);
    return result;
}
Also used : SchemaEntry(org.gluu.model.SchemaEntry)

Example 12 with SchemaEntry

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

the class Shibboleth3ConfService method createAttributeMap.

private HashMap<String, Object> createAttributeMap(Set<GluuAttribute> attributes) {
    HashMap<String, Object> resolver = new HashMap<String, Object>();
    List<String> attributeNames = new ArrayList<>();
    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();
        // 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)) {
            AttributeTypeDefinition attributeTypeDefinition = shemaService.getAttributeTypeDefinition(attributeTypes, attributeName);
            if (attributeTypeDefinition == null) {
                log.error("Failed to get OID for attribute name {}", attributeName);
                return null;
            }
            saml2String = String.format("urn:oid:%s", attributeTypeDefinition.getOID());
        }
        attributeSAML2Strings.put(attributeName, saml2String);
    }
    resolver.put("attributes", attributes);
    resolver.put("attributeSAML1Strings", attributeSAML1Strings);
    resolver.put("attributeSAML2Strings", attributeSAML2Strings);
    return resolver;
}
Also used : AttributeTypeDefinition(com.unboundid.ldap.sdk.schema.AttributeTypeDefinition) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SchemaEntry(org.gluu.model.SchemaEntry) GluuAttribute(org.gluu.model.GluuAttribute)

Example 13 with SchemaEntry

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

the class SchemaService method removeObjectClass.

/**
 * Remove object class
 *
 * @param objectClass
 *            Object class name
 */
public void removeObjectClass(String objectClass) {
    SchemaEntry schema = getSchema();
    String objectClassDefinition = getObjectClassDefinition(schema, objectClass);
    if (objectClassDefinition != null) {
        removeObjectClassWithDefinition(objectClassDefinition);
    }
}
Also used : SchemaEntry(org.gluu.model.SchemaEntry)

Example 14 with SchemaEntry

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

the class SchemaService method addObjectClass.

/**
 * Add new object class with specified attributes
 *
 * @param objectClass
 *            Object class name
 * @param attributeTypes
 *            Attribute types
 */
public void addObjectClass(String objectClass, String attributeTypes, String schemaAddObjectClassWithoutAttributeTypesDefinition, String schemaAddObjectClassWithAttributeTypesDefinition) {
    SchemaEntry schemaEntry = new SchemaEntry();
    schemaEntry.setDn(getDnForSchema());
    String objectClassDefinition;
    if (StringHelper.isEmpty(attributeTypes)) {
        objectClassDefinition = String.format(schemaAddObjectClassWithoutAttributeTypesDefinition, objectClass, objectClass);
    } else {
        objectClassDefinition = String.format(schemaAddObjectClassWithAttributeTypesDefinition, objectClass, objectClass, attributeTypes);
    }
    schemaEntry.addObjectClass(objectClassDefinition);
    log.debug("Adding new objectClass: {}", schemaEntry);
    PersistenceEntryManager ldapPersistenceEntryManager = getPersistenceEntryManager();
    ldapPersistenceEntryManager.merge(schemaEntry);
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) SchemaEntry(org.gluu.model.SchemaEntry)

Example 15 with SchemaEntry

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

the class SchemaService method addAttributeTypeToObjectClass.

/**
 * Add attribute type to object class
 *
 * @param objectClass
 *            Object class name
 * @param attributeType
 *            Attribute type name
 * @throws Exception
 */
public void addAttributeTypeToObjectClass(String objectClass, String attributeType) throws Exception {
    SchemaEntry schema = getSchema();
    String objectClassDefinition = getObjectClassDefinition(schema, objectClass);
    if (objectClassDefinition == null) {
        throw new InvalidSchemaUpdateException(String.format("Can't add attributeType %s to objectClass %s because objectClass doesn't exist", attributeType, objectClass));
    }
    String newObjectClassDefinition = null;
    String attributeTypesStartPattern = "MAY ( ";
    int index = objectClassDefinition.indexOf(attributeTypesStartPattern);
    if (index != -1) {
        int index2 = objectClassDefinition.indexOf(")", index);
        newObjectClassDefinition = objectClassDefinition.substring(0, index2) + "$ " + attributeType + " " + objectClassDefinition.substring(index2);
    } else {
        attributeTypesStartPattern = "MUST objectClass ";
        index = objectClassDefinition.indexOf(attributeTypesStartPattern);
        if (index != -1) {
            int index2 = index + attributeTypesStartPattern.length();
            newObjectClassDefinition = objectClassDefinition.substring(0, index2) + "MAY ( " + attributeType + " ) " + objectClassDefinition.substring(index2);
        }
    }
    log.debug("Current object class definition:" + objectClassDefinition);
    log.debug("New object class definition:" + newObjectClassDefinition);
    if (newObjectClassDefinition == null) {
        throw new InvalidSchemaUpdateException(String.format("Invalid objectClass definition format"));
    }
    // Remove OC definition
    removeObjectClassWithDefinition(objectClassDefinition);
    // Add updated OC definition
    SchemaEntry newSchemaEntry = new SchemaEntry();
    newSchemaEntry.setDn(getDnForSchema());
    newSchemaEntry.addObjectClass(newObjectClassDefinition);
    log.debug("Adding attributeType to objectClass: {}", newSchemaEntry);
    PersistenceEntryManager ldapPersistenceEntryManager = getPersistenceEntryManager();
    ldapPersistenceEntryManager.merge(newSchemaEntry);
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) SchemaEntry(org.gluu.model.SchemaEntry) InvalidSchemaUpdateException(org.gluu.util.exception.InvalidSchemaUpdateException)

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