use of com.novell.ldap.client.SchemaParser in project pwm by pwm-project.
the class EdirSchemaExtender method readSchemaAttributes.
private Map<String, SchemaParser> readSchemaAttributes() throws ChaiUnavailableException, ChaiOperationException {
final Map<String, SchemaParser> returnObj = new LinkedHashMap<>();
final Set<String> valuesFromLdap = schemaEntry.readMultiStringAttribute(LDAP_SCHEMA_ATTR_ATTRS);
for (final String key : valuesFromLdap) {
SchemaParser schemaParser = null;
try {
schemaParser = new SchemaParser(key);
} catch (Exception e) {
LOGGER.error("error parsing schema attribute definition: " + e.getMessage());
}
if (schemaParser != null) {
for (final String attrName : schemaParser.getNames()) {
returnObj.put(attrName, schemaParser);
}
}
}
return returnObj;
}
use of com.novell.ldap.client.SchemaParser in project pwm by pwm-project.
the class EdirSchemaExtender method execute.
private void execute(final boolean readOnly) throws PwmUnrecoverableException {
activityLog.delete(0, activityLog.length());
logActivity("connecting to " + schemaEntry.getChaiProvider().getChaiConfiguration().bindURLsAsList().iterator().next());
stateMap.clear();
try {
final Map<String, SchemaParser> existingAttrs = readSchemaAttributes();
for (final SchemaDefinition schemaDefinition : SchemaDefinition.getPwmSchemaDefinitions()) {
if (schemaDefinition.getSchemaType() == SchemaDefinition.SchemaType.attribute) {
checkAttribute(readOnly, schemaDefinition, existingAttrs);
}
}
final Map<String, SchemaParser> existingObjectclasses = readSchemaObjectclasses();
for (final SchemaDefinition schemaDefinition : SchemaDefinition.getPwmSchemaDefinitions()) {
if (schemaDefinition.getSchemaType() == SchemaDefinition.SchemaType.objectclass) {
checkObjectclass(readOnly, schemaDefinition, existingObjectclasses);
}
}
} catch (ChaiUnavailableException e) {
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_DIRECTORY_UNAVAILABLE, e.getMessage()));
} catch (ChaiOperationException e) {
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_UNKNOWN, e.getMessage()));
}
}
use of com.novell.ldap.client.SchemaParser in project pwm by pwm-project.
the class EdirSchemaExtender method checkObjectclass.
private void checkObjectclass(final boolean readOnly, final SchemaDefinition schemaDefinition, final Map<String, SchemaParser> existingAttrs) throws ChaiUnavailableException {
final String name = schemaDefinition.getName();
if (existingAttrs.containsKey(name)) {
final SchemaParser existingValue = existingAttrs.get(name);
logActivity("objectclass '" + name + "' exists");
final boolean objectclassIsCorrect = checkObjectclassCorrectness(schemaDefinition, existingValue);
stateMap.put(name, objectclassIsCorrect ? SchemaDefinition.State.correct : SchemaDefinition.State.incorrect);
if (!readOnly && !objectclassIsCorrect) {
logActivity("beginning update for objectclass '" + name + "'");
try {
schemaEntry.replaceAttribute(LDAP_SCHEMA_ATTR_CLASSES, existingValue.getRawString(), schemaDefinition.getDefinition());
logActivity("+ objectclass '" + name + "' has been modified");
stateMap.put(name, SchemaDefinition.State.correct);
} catch (ChaiOperationException e) {
logActivity("error while updating objectclass definition '" + name + "', error: " + e.getMessage());
}
}
} else {
logActivity("objectclass '" + name + "' does not exist");
stateMap.put(name, SchemaDefinition.State.missing);
if (!readOnly) {
logActivity("beginning add for objectclass '" + name + "'");
try {
schemaEntry.addAttribute(LDAP_SCHEMA_ATTR_CLASSES, schemaDefinition.getDefinition());
logActivity("+ objectclass '" + name + "' has been added");
stateMap.put(name, SchemaDefinition.State.correct);
} catch (ChaiOperationException e) {
logActivity("error while updating objectclass definition '" + name + "', error: " + e.getMessage());
}
}
}
}
use of com.novell.ldap.client.SchemaParser in project pwm by pwm-project.
the class EdirSchemaExtender method readSchemaObjectclasses.
private Map<String, SchemaParser> readSchemaObjectclasses() throws ChaiUnavailableException, ChaiOperationException {
final Map<String, SchemaParser> returnObj = new LinkedHashMap<>();
final Set<String> valuesFromLdap = schemaEntry.readMultiStringAttribute(LDAP_SCHEMA_ATTR_CLASSES);
for (final String key : valuesFromLdap) {
SchemaParser schemaParser = null;
try {
schemaParser = new SchemaParser(key);
} catch (Exception e) {
LOGGER.error("error parsing schema objectclasses definition: " + e.getMessage());
}
if (schemaParser != null) {
for (final String attrName : schemaParser.getNames()) {
returnObj.put(attrName, schemaParser);
}
}
}
return returnObj;
}
use of com.novell.ldap.client.SchemaParser in project pwm by pwm-project.
the class EdirSchemaExtender method checkAttribute.
private void checkAttribute(final boolean readOnly, final SchemaDefinition schemaDefinition, final Map<String, SchemaParser> existingAttrs) throws ChaiUnavailableException {
final String name = schemaDefinition.getName();
if (existingAttrs.containsKey(name)) {
final SchemaParser existingValue = existingAttrs.get(name);
logActivity("attribute '" + name + "' exists");
final boolean attributeIsCorrect = checkAttributeCorrectness(schemaDefinition, existingValue);
stateMap.put(name, attributeIsCorrect ? SchemaDefinition.State.correct : SchemaDefinition.State.incorrect);
if (!readOnly && !attributeIsCorrect) {
logActivity("beginning update for attribute '" + name + "'");
try {
schemaEntry.replaceAttribute(LDAP_SCHEMA_ATTR_ATTRS, existingValue.getRawString(), schemaDefinition.getDefinition());
logActivity("+ attribute '" + name + "' has been modified");
stateMap.put(name, SchemaDefinition.State.correct);
} catch (ChaiOperationException e) {
logActivity("error while updating attribute definition '" + name + "', error: " + e.getMessage());
}
}
} else {
logActivity("attribute '" + name + "' does not exist");
if (!readOnly) {
logActivity("beginning add for attribute '" + name + "'");
try {
schemaEntry.addAttribute(LDAP_SCHEMA_ATTR_ATTRS, schemaDefinition.getDefinition());
stateMap.put(name, SchemaDefinition.State.missing);
logActivity("+ attribute '" + name + "' has been added");
stateMap.put(name, SchemaDefinition.State.correct);
} catch (ChaiOperationException e) {
logActivity("error while adding attribute definition '" + name + "', error: " + e.getMessage());
}
}
}
}
Aggregations