Search in sources :

Example 1 with ConfigObjectRecord

use of com.novell.ldapchai.util.ConfigObjectRecord in project pwm by pwm-project.

the class LdapXmlUserHistory method updateUserHistoryImpl.

private void updateUserHistoryImpl(final UserAuditRecord auditRecord) throws PwmUnrecoverableException, ChaiUnavailableException {
    // user info
    final UserIdentity userIdentity;
    if (auditRecord instanceof HelpdeskAuditRecord && auditRecord.getType() == AuditEvent.Type.HELPDESK) {
        final HelpdeskAuditRecord helpdeskAuditRecord = (HelpdeskAuditRecord) auditRecord;
        userIdentity = new UserIdentity(helpdeskAuditRecord.getTargetDN(), helpdeskAuditRecord.getTargetLdapProfile());
    } else {
        userIdentity = new UserIdentity(auditRecord.getPerpetratorDN(), auditRecord.getPerpetratorLdapProfile());
    }
    final ChaiUser theUser = pwmApplication.getProxiedChaiUser(userIdentity);
    // settings
    final String corRecordIdentifer = COR_RECORD_ID;
    final LdapProfile ldapProfile = userIdentity.getLdapProfile(pwmApplication.getConfig());
    final String corAttribute = ldapProfile.readSettingAsString(PwmSetting.EVENTS_LDAP_ATTRIBUTE);
    // quit if settings no good;
    if (corAttribute == null || corAttribute.length() < 1) {
        LOGGER.debug("no user event log attribute configured, skipping write of log data");
        return;
    }
    // read current value;
    final StoredHistory storedHistory;
    final ConfigObjectRecord theCor;
    final List corList;
    try {
        corList = ConfigObjectRecord.readRecordFromLDAP(theUser, corAttribute, corRecordIdentifer, null, null);
    } catch (Exception e) {
        final String errorMsg = "error reading LDAP user event history for user " + userIdentity.toDisplayString() + ", error: " + e.getMessage();
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
        LOGGER.error(errorInformation.toDebugStr(), e);
        throw new PwmUnrecoverableException(errorInformation, e);
    }
    try {
        if (!corList.isEmpty()) {
            theCor = (ConfigObjectRecord) corList.get(0);
        } else {
            theCor = ConfigObjectRecord.createNew(theUser, corAttribute, corRecordIdentifer, null, null);
        }
        storedHistory = StoredHistory.fromXml(theCor.getPayload());
    } catch (Exception e) {
        LOGGER.error("ldap error writing user event log: " + e.getMessage());
        return;
    }
    // add next record to blob
    final StoredEvent storedEvent = StoredEvent.fromAuditRecord(auditRecord);
    storedHistory.addEvent(storedEvent);
    // trim the blob.
    final int maxUserEvents = (int) pwmApplication.getConfig().readSettingAsLong(PwmSetting.EVENTS_LDAP_MAX_EVENTS);
    storedHistory.trim(maxUserEvents);
    // write the blob.
    try {
        theCor.updatePayload(storedHistory.toXml());
    } catch (ChaiOperationException e) {
        LOGGER.error("ldap error writing user event log: " + e.getMessage());
    }
}
Also used : UserIdentity(password.pwm.bean.UserIdentity) ConfigObjectRecord(com.novell.ldapchai.util.ConfigObjectRecord) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) LdapProfile(password.pwm.config.profile.LdapProfile) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) JDOMException(org.jdom2.JDOMException) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) IOException(java.io.IOException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) ErrorInformation(password.pwm.error.ErrorInformation) ChaiUser(com.novell.ldapchai.ChaiUser) LinkedList(java.util.LinkedList) List(java.util.List) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException)

Example 2 with ConfigObjectRecord

use of com.novell.ldapchai.util.ConfigObjectRecord in project pwm by pwm-project.

the class LdapXmlUserHistory method readUserHistory.

private StoredHistory readUserHistory(final PwmApplication pwmApplication, final UserIdentity userIdentity, final ChaiUser chaiUser) throws ChaiUnavailableException, PwmUnrecoverableException {
    final LdapProfile ldapProfile = userIdentity.getLdapProfile(pwmApplication.getConfig());
    final String corAttribute = ldapProfile.readSettingAsString(PwmSetting.EVENTS_LDAP_ATTRIBUTE);
    if (corAttribute == null || corAttribute.length() < 1) {
        LOGGER.trace("no user event log attribute configured, skipping read of log data");
        return new StoredHistory();
    }
    try {
        final List corList = ConfigObjectRecord.readRecordFromLDAP(chaiUser, corAttribute, COR_RECORD_ID, null, null);
        if (!corList.isEmpty()) {
            final ConfigObjectRecord theCor = (ConfigObjectRecord) corList.get(0);
            return StoredHistory.fromXml(theCor.getPayload());
        }
    } catch (ChaiOperationException e) {
        LOGGER.error("ldap error reading user event log: " + e.getMessage());
    }
    return new StoredHistory();
}
Also used : LinkedList(java.util.LinkedList) List(java.util.List) ConfigObjectRecord(com.novell.ldapchai.util.ConfigObjectRecord) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) LdapProfile(password.pwm.config.profile.LdapProfile)

Example 3 with ConfigObjectRecord

use of com.novell.ldapchai.util.ConfigObjectRecord in project ldapchai by ldapchai.

the class ChaiResponseSet method write.

boolean write(final ChaiUser user) throws ChaiUnavailableException, ChaiOperationException {
    if (this.state != STATE.NEW) {
        throw new IllegalStateException("ResponseSet not suitable for writing (not in NEW state)");
    }
    final String corAttribute = user.getChaiProvider().getChaiConfiguration().getSetting(ChaiSetting.CR_CHAI_STORAGE_ATTRIBUTE);
    final String corRecordIdentifier = user.getChaiProvider().getChaiConfiguration().getSetting(ChaiSetting.CR_CHAI_STORAGE_RECORD_ID);
    try {
        final ConfigObjectRecord theCor;
        final List<ConfigObjectRecord> corList = ConfigObjectRecord.readRecordFromLDAP(user, corAttribute, corRecordIdentifier, null, null);
        if (!corList.isEmpty()) {
            theCor = corList.get(0);
        } else {
            theCor = ConfigObjectRecord.createNew(user, corAttribute, corRecordIdentifier, null, null);
        }
        final String attributePaylod = rsToChaiXML(this);
        theCor.updatePayload(attributePaylod);
    } catch (ChaiOperationException e) {
        LOGGER.warn("ldap error writing response set: " + e.getMessage());
        throw e;
    } catch (ChaiValidationException e) {
        LOGGER.warn("validation error", e);
        throw new ChaiOperationException(e.getMessage(), ChaiError.UNKNOWN);
    }
    LOGGER.info("successfully wrote Chai challenge/response set for user " + user.getEntryDN());
    this.state = STATE.WRITTEN;
    return true;
}
Also used : ChaiValidationException(com.novell.ldapchai.exception.ChaiValidationException) ConfigObjectRecord(com.novell.ldapchai.util.ConfigObjectRecord) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException)

Example 4 with ConfigObjectRecord

use of com.novell.ldapchai.util.ConfigObjectRecord in project ldapchai by ldapchai.

the class ChaiResponseSet method readUserResponseSet.

static ChaiResponseSet readUserResponseSet(final ChaiUser theUser) throws ChaiUnavailableException, ChaiValidationException, ChaiOperationException {
    final String corRecordIdentifer = theUser.getChaiProvider().getChaiConfiguration().getSetting(ChaiSetting.CR_CHAI_STORAGE_RECORD_ID);
    final String corAttribute = theUser.getChaiProvider().getChaiConfiguration().getSetting(ChaiSetting.CR_CHAI_STORAGE_ATTRIBUTE);
    final ChaiResponseSet returnVal;
    final List<ConfigObjectRecord> corList = ConfigObjectRecord.readRecordFromLDAP(theUser, corAttribute, corRecordIdentifer, null, null);
    String payload = "";
    if (!corList.isEmpty()) {
        final ConfigObjectRecord theCor = corList.get(0);
        payload = theCor.getPayload();
    }
    returnVal = ChaiResponseXmlParser.parseChaiResponseSetXML(payload);
    if (returnVal == null) {
        return null;
    }
    return returnVal;
}
Also used : ConfigObjectRecord(com.novell.ldapchai.util.ConfigObjectRecord)

Aggregations

ConfigObjectRecord (com.novell.ldapchai.util.ConfigObjectRecord)4 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)3 LinkedList (java.util.LinkedList)2 List (java.util.List)2 LdapProfile (password.pwm.config.profile.LdapProfile)2 ChaiUser (com.novell.ldapchai.ChaiUser)1 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)1 ChaiValidationException (com.novell.ldapchai.exception.ChaiValidationException)1 IOException (java.io.IOException)1 JDOMException (org.jdom2.JDOMException)1 UserIdentity (password.pwm.bean.UserIdentity)1 ErrorInformation (password.pwm.error.ErrorInformation)1 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)1