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: {}", newSchemaEntry);
ldapEntryManager.merge(newSchemaEntry);
}
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: {}", schemaEntry);
ldapEntryManager.remove(schemaEntry);
}
}
use of org.xdi.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;
}
use of org.xdi.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;
}
use of org.xdi.model.SchemaEntry 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);
if (attributeTypeDefinition != null) {
return String.format("urn:oid:%s", attributeTypeDefinition.getOID());
}
return "";
}
Aggregations