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());
}
}
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();
}
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;
}
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;
}
Aggregations