Search in sources :

Example 1 with SchemaParser

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;
}
Also used : SchemaParser(com.novell.ldap.client.SchemaParser) IOException(java.io.IOException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with SchemaParser

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()));
    }
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) SchemaParser(com.novell.ldap.client.SchemaParser)

Example 3 with SchemaParser

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());
            }
        }
    }
}
Also used : ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) SchemaParser(com.novell.ldap.client.SchemaParser)

Example 4 with SchemaParser

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;
}
Also used : SchemaParser(com.novell.ldap.client.SchemaParser) IOException(java.io.IOException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with SchemaParser

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());
            }
        }
    }
}
Also used : ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) SchemaParser(com.novell.ldap.client.SchemaParser)

Aggregations

SchemaParser (com.novell.ldap.client.SchemaParser)5 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)5 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)3 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)3 IOException (java.io.IOException)2 LinkedHashMap (java.util.LinkedHashMap)2 ErrorInformation (password.pwm.error.ErrorInformation)1