Search in sources :

Example 1 with SchemaEntry

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

the class SchemaService method addStringAttribute.

/**
	 * Add new attribute type
	 */
public void addStringAttribute(String oid, String name, String schemaAddAttributeDefinition) throws Exception {
    log.info("getting a new instance SchemaEntry ");
    SchemaEntry schemaEntry = new SchemaEntry();
    log.info("setting the DN ");
    schemaEntry.setDn(getDnForSchema());
    log.info("adding attribute name ");
    log.info("applicationConfiguration.getSchemaAddAttributeDefinition() : ", schemaAddAttributeDefinition);
    log.info("oid : ", oid);
    log.info("name : ", name);
    schemaEntry.addAttributeType(String.format(schemaAddAttributeDefinition, oid, name));
    log.debug("Adding new attributeType: {0}", schemaEntry);
    log.info("merging data");
    ldapEntryManager.merge(schemaEntry);
}
Also used : SchemaEntry(org.xdi.model.SchemaEntry)

Example 2 with SchemaEntry

use of org.xdi.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: {0}", schemaEntry);
    ldapEntryManager.merge(schemaEntry);
}
Also used : SchemaEntry(org.xdi.model.SchemaEntry)

Example 3 with SchemaEntry

use of org.xdi.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: {0}", newSchemaEntry);
    ldapEntryManager.merge(newSchemaEntry);
}
Also used : SchemaEntry(org.xdi.model.SchemaEntry) InvalidSchemaUpdateException(org.xdi.util.exception.InvalidSchemaUpdateException)

Example 4 with SchemaEntry

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

the class SchemaService method removeStringAttribute.

/**
	 * Remove string attribute
	 * 
	 * @param attributeType
	 *            Attribute type name
	 * @throws Exception
	 */
public void removeStringAttribute(String attributeType) throws Exception {
    SchemaEntry schema = getSchema();
    String attributeTypeDefinition = getAttributeTypeDefinition(schema, attributeType);
    if (attributeTypeDefinition != null) {
        SchemaEntry schemaEntry = new SchemaEntry();
        schemaEntry.setDn(getDnForSchema());
        schemaEntry.addAttributeType(attributeTypeDefinition);
        log.debug("Removing attributeType: {0}", schemaEntry);
        ldapEntryManager.remove(schemaEntry);
    }
}
Also used : SchemaEntry(org.xdi.model.SchemaEntry)

Example 5 with SchemaEntry

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

the class SchemaService method removeAttributeTypeFromObjectClass.

/**
	 * Remove attribute type from object class
	 * 
	 * @param objectClass
	 *            Object class name
	 * @param attributeType
	 *            Attribute type name
	 * @throws Exception
	 */
public void removeAttributeTypeFromObjectClass(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 attributeTypePattern = "$ " + attributeType + " ";
    int index = objectClassDefinition.indexOf(attributeTypePattern);
    if (index == -1) {
        attributeTypePattern = " " + attributeType + " $";
        index = objectClassDefinition.indexOf(attributeTypePattern);
        if (index == -1) {
            attributeTypePattern = " MAY ( " + attributeType + " )";
            index = objectClassDefinition.indexOf(attributeTypePattern);
            if (index == -1) {
                throw new InvalidSchemaUpdateException(String.format("Invalid objectClass definition format"));
            }
        }
    }
    String newObjectClassDefinition = objectClassDefinition.substring(0, index) + objectClassDefinition.substring(index + attributeTypePattern.length());
    // Remove OC definition
    removeObjectClassWithDefinition(objectClassDefinition);
    // Add updated OC definition
    SchemaEntry schemaEntry = new SchemaEntry();
    schemaEntry.setDn(getDnForSchema());
    schemaEntry.addObjectClass(newObjectClassDefinition);
    log.debug("Removing attributeType from objectClass: {0}", schemaEntry);
    ldapEntryManager.merge(schemaEntry);
}
Also used : SchemaEntry(org.xdi.model.SchemaEntry) InvalidSchemaUpdateException(org.xdi.util.exception.InvalidSchemaUpdateException)

Aggregations

SchemaEntry (org.xdi.model.SchemaEntry)12 AttributeTypeDefinition (com.unboundid.ldap.sdk.schema.AttributeTypeDefinition)3 ArrayList (java.util.ArrayList)3 InvalidSchemaUpdateException (org.xdi.util.exception.InvalidSchemaUpdateException)2 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