Search in sources :

Example 31 with PwmUnrecoverableException

use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.

the class DatabaseUserHistory method updateUserHistory.

@Override
public void updateUserHistory(final UserAuditRecord auditRecord) throws PwmUnrecoverableException {
    // 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 String guid;
    try {
        guid = LdapOperationsHelper.readLdapGuidValue(pwmApplication, null, userIdentity, false);
    } catch (ChaiUnavailableException e) {
        LOGGER.error("unable to read guid for user '" + userIdentity + "', cannot update user history, error: " + e.getMessage());
        return;
    }
    try {
        final StoredHistory storedHistory;
        storedHistory = readStoredHistory(guid);
        storedHistory.getRecords().add(auditRecord);
        writeStoredHistory(guid, storedHistory);
    } catch (DatabaseException e) {
        throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_DB_UNAVAILABLE, e.getMessage()));
    }
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) UserIdentity(password.pwm.bean.UserIdentity) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) DatabaseException(password.pwm.util.db.DatabaseException)

Example 32 with PwmUnrecoverableException

use of password.pwm.error.PwmUnrecoverableException 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 33 with PwmUnrecoverableException

use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.

the class LdapXmlUserHistory method readUserHistory.

public List<UserAuditRecord> readUserHistory(final UserInfo userInfo) throws PwmUnrecoverableException {
    try {
        final ChaiUser theUser = pwmApplication.getProxiedChaiUser(userInfo.getUserIdentity());
        final StoredHistory storedHistory = readUserHistory(pwmApplication, userInfo.getUserIdentity(), theUser);
        return storedHistory.asAuditRecords(userInfo);
    } catch (ChaiUnavailableException e) {
        throw new PwmUnrecoverableException(PwmError.forChaiError(e.getErrorCode()));
    }
}
Also used : ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) ChaiUser(com.novell.ldapchai.ChaiUser) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException)

Example 34 with PwmUnrecoverableException

use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.

the class PwNotifyDbStorageService method readStoredState.

@Override
public StoredNotificationState readStoredState(final UserIdentity userIdentity, final SessionLabel sessionLabel) throws PwmUnrecoverableException {
    final String guid;
    try {
        guid = LdapOperationsHelper.readLdapGuidValue(pwmApplication, sessionLabel, userIdentity, true);
    } catch (ChaiUnavailableException e) {
        throw new PwmUnrecoverableException(PwmUnrecoverableException.fromChaiException(e).getErrorInformation());
    }
    if (StringUtil.isEmpty(guid)) {
        throw new PwmUnrecoverableException(PwmError.ERROR_MISSING_GUID);
    }
    final String rawDbValue;
    try {
        rawDbValue = pwmApplication.getDatabaseAccessor().get(TABLE, guid);
    } catch (DatabaseException e) {
        throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_DB_UNAVAILABLE, e.getMessage()));
    }
    return JsonUtil.deserialize(rawDbValue, StoredNotificationState.class);
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) DatabaseException(password.pwm.util.db.DatabaseException)

Example 35 with PwmUnrecoverableException

use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.

the class UserInfoReader method readMultiStringAttributesImpl.

private Map<String, List<String>> readMultiStringAttributesImpl(final Collection<String> attributes) throws PwmUnrecoverableException {
    if (chaiUser == null || attributes == null || attributes.isEmpty()) {
        return Collections.emptyMap();
    }
    // figure out uncached attributes.
    final Set<String> uncachedAttributes = new HashSet<>(attributes);
    uncachedAttributes.removeAll(cacheMap.keySet());
    // read uncached attributes into cache
    if (!uncachedAttributes.isEmpty()) {
        final Map<String, Map<String, List<String>>> results;
        try {
            results = chaiUser.getChaiProvider().searchMultiValues(chaiUser.getEntryDN(), "(objectclass=*)", uncachedAttributes, SearchScope.BASE);
        } catch (ChaiOperationException e) {
            final String msg = "ldap operational error while reading user data" + e.getMessage();
            LOGGER.error(sessionLabel, msg);
            throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_LDAP_DATA_ERROR, msg));
        } catch (ChaiUnavailableException e) {
            throw PwmUnrecoverableException.fromChaiException(e);
        }
        if (results == null || results.size() != 1) {
            final String msg = "ldap server did not return requested user entry " + chaiUser.getEntryDN() + " while attempting to read attribute data";
            LOGGER.error(sessionLabel, msg);
            throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_LDAP_DATA_ERROR, msg));
        }
        final Map<String, List<String>> allAttributeValues = results.values().iterator().next();
        for (final String attribute : uncachedAttributes) {
            final List<String> attributeValues = allAttributeValues.get(attribute);
            if (attributeValues == null) {
                cacheMap.put(attribute, Collections.emptyList());
            } else {
                cacheMap.put(attribute, Collections.unmodifiableList(attributeValues));
            }
        }
    }
    // build result data from cache
    final Map<String, List<String>> returnMap = new HashMap<>();
    for (final String attribute : attributes) {
        final List<String> cachedValue = cacheMap.get(attribute);
        returnMap.put(attribute, cachedValue);
    }
    return Collections.unmodifiableMap(returnMap);
}
Also used : ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) ErrorInformation(password.pwm.error.ErrorInformation) List(java.util.List) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HashSet(java.util.HashSet)

Aggregations

PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)282 ErrorInformation (password.pwm.error.ErrorInformation)201 PwmOperationalException (password.pwm.error.PwmOperationalException)85 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)75 IOException (java.io.IOException)72 PwmException (password.pwm.error.PwmException)69 PwmApplication (password.pwm.PwmApplication)48 UserIdentity (password.pwm.bean.UserIdentity)48 Configuration (password.pwm.config.Configuration)43 ServletException (javax.servlet.ServletException)38 LinkedHashMap (java.util.LinkedHashMap)37 Instant (java.time.Instant)35 ArrayList (java.util.ArrayList)31 PwmSession (password.pwm.http.PwmSession)30 Map (java.util.Map)28 ChaiUser (com.novell.ldapchai.ChaiUser)26 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)25 FormConfiguration (password.pwm.config.value.data.FormConfiguration)24 HashMap (java.util.HashMap)23 ChaiException (com.novell.ldapchai.exception.ChaiException)22