use of password.pwm.bean.UserIdentity in project pwm by pwm-project.
the class IntruderManager method mark.
public void mark(final RecordType recordType, final String subject, final SessionLabel sessionLabel) throws PwmUnrecoverableException {
if (recordType == null) {
throw new IllegalArgumentException("recordType is required");
}
if (subject == null || subject.length() < 1) {
return;
}
if (recordType == RecordType.ADDRESS) {
try {
final InetAddress inetAddress = InetAddress.getByName(subject);
if (inetAddress.isAnyLocalAddress() || inetAddress.isLoopbackAddress() || inetAddress.isLinkLocalAddress()) {
LOGGER.debug("disregarding local address intruder attempt from: " + subject);
return;
}
} catch (Exception e) {
LOGGER.error("error examining address: " + subject);
}
}
final RecordManager manager = recordManagers.get(recordType);
manager.markSubject(subject);
if (recordType == RecordType.USER_ID) {
final UserIdentity userIdentity = UserIdentity.fromKey(subject, pwmApplication);
final UserAuditRecord auditRecord = new AuditRecordFactory(pwmApplication).createUserAuditRecord(AuditEvent.INTRUDER_USER_ATTEMPT, userIdentity, sessionLabel);
pwmApplication.getAuditManager().submit(auditRecord);
} else {
// send intruder attempt audit event
final Map<String, Object> messageObj = new LinkedHashMap<>();
messageObj.put("type", recordType);
messageObj.put("subject", subject);
final String message = JsonUtil.serializeMap(messageObj);
final SystemAuditRecord auditRecord = new AuditRecordFactory(pwmApplication).createSystemAuditRecord(AuditEvent.INTRUDER_ATTEMPT, message);
pwmApplication.getAuditManager().submit(auditRecord);
}
try {
check(recordType, subject);
} catch (PwmUnrecoverableException e) {
if (!manager.isAlerted(subject)) {
if (recordType == RecordType.USER_ID) {
final UserIdentity userIdentity = UserIdentity.fromKey(subject, pwmApplication);
final UserAuditRecord auditRecord = new AuditRecordFactory(pwmApplication).createUserAuditRecord(AuditEvent.INTRUDER_USER_LOCK, userIdentity, sessionLabel);
pwmApplication.getAuditManager().submit(auditRecord);
sendAlert(manager.readIntruderRecord(subject), sessionLabel);
} else {
// send intruder attempt lock event
final Map<String, Object> messageObj = new LinkedHashMap<>();
messageObj.put("type", recordType);
messageObj.put("subject", subject);
final String message = JsonUtil.serializeMap(messageObj);
final SystemAuditRecord auditRecord = new AuditRecordFactory(pwmApplication).createSystemAuditRecord(AuditEvent.INTRUDER_LOCK, message);
pwmApplication.getAuditManager().submit(auditRecord);
}
manager.markAlerted(subject);
final StatisticsManager statisticsManager = pwmApplication.getStatisticsManager();
if (statisticsManager != null && statisticsManager.status() == STATUS.OPEN) {
statisticsManager.incrementValue(Statistic.INTRUDER_ATTEMPTS);
statisticsManager.updateEps(EpsStatistic.INTRUDER_ATTEMPTS, 1);
statisticsManager.incrementValue(recordType.getLockStatistic());
}
}
throw e;
}
delayPenalty(manager.readIntruderRecord(subject), sessionLabel == null ? null : sessionLabel);
}
use of password.pwm.bean.UserIdentity in project pwm by pwm-project.
the class IntruderManager method sendAlert.
private void sendAlert(final IntruderRecord intruderRecord, final SessionLabel sessionLabel) {
if (intruderRecord == null) {
return;
}
if (intruderRecord.getType() == RecordType.USER_ID) {
try {
final UserIdentity identity = UserIdentity.fromDelimitedKey(intruderRecord.getSubject());
sendIntruderNoticeEmail(pwmApplication, sessionLabel, identity);
} catch (PwmUnrecoverableException e) {
LOGGER.error("unable to send intruder mail, can't read userDN/ldapProfile from stored record: " + e.getMessage());
}
}
}
use of password.pwm.bean.UserIdentity in project pwm by pwm-project.
the class LdapPermissionTester method discoverMatchingUsers.
public static Map<UserIdentity, Map<String, String>> discoverMatchingUsers(final PwmApplication pwmApplication, final int maxResultSize, final List<UserPermission> userPermissions, final SessionLabel sessionLabel) throws Exception {
final UserSearchEngine userSearchEngine = pwmApplication.getUserSearchEngine();
final Map<UserIdentity, Map<String, String>> results = new TreeMap<>();
for (final UserPermission userPermission : userPermissions) {
if ((maxResultSize) - results.size() > 0) {
final SearchConfiguration.SearchConfigurationBuilder builder = SearchConfiguration.builder();
switch(userPermission.getType()) {
case ldapQuery:
{
builder.filter(userPermission.getLdapQuery());
if (userPermission.getLdapBase() != null && !userPermission.getLdapBase().isEmpty()) {
builder.enableContextValidation(false);
builder.contexts(Collections.singletonList(userPermission.getLdapBase()));
}
}
break;
case ldapGroup:
{
builder.groupDN(userPermission.getLdapBase());
}
break;
default:
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_UNKNOWN, "unknown permission type: " + userPermission.getType()));
}
if (userPermission.getLdapProfileID() != null && !userPermission.getLdapProfileID().isEmpty() && !userPermission.getLdapProfileID().equals(PwmConstants.PROFILE_ID_ALL)) {
builder.ldapProfile(userPermission.getLdapProfileID());
}
final SearchConfiguration searchConfiguration = builder.build();
try {
results.putAll(userSearchEngine.performMultiUserSearch(searchConfiguration, (maxResultSize) - results.size(), Collections.emptyList(), sessionLabel));
} catch (PwmUnrecoverableException e) {
LOGGER.error("error reading matching users: " + e.getMessage());
throw new PwmOperationalException(e.getErrorInformation());
}
}
}
return results;
}
use of password.pwm.bean.UserIdentity in project pwm by pwm-project.
the class UserSearchResults method defaultSort.
private static Map<UserIdentity, Map<String, String>> defaultSort(final Map<UserIdentity, Map<String, String>> results, final Map<String, String> headerAttributeMap) {
if (headerAttributeMap == null || headerAttributeMap.isEmpty() || results == null) {
return results;
}
final String sortAttribute = headerAttributeMap.keySet().iterator().next();
final Comparator<UserIdentity> comparator = new Comparator<UserIdentity>() {
@Override
public int compare(final UserIdentity o1, final UserIdentity o2) {
final String s1 = getSortValueByIdentity(o1);
final String s2 = getSortValueByIdentity(o2);
return s1.compareTo(s2);
}
private String getSortValueByIdentity(final UserIdentity userIdentity) {
final Map<String, String> valueMap = results.get(userIdentity);
if (valueMap != null) {
final String sortValue = valueMap.get(sortAttribute);
if (sortValue != null) {
return sortValue;
}
}
return "";
}
};
final List<UserIdentity> identitySortMap = new ArrayList<>();
identitySortMap.addAll(results.keySet());
identitySortMap.sort(comparator);
final Map<UserIdentity, Map<String, String>> sortedResults = new LinkedHashMap<>();
for (final UserIdentity userIdentity : identitySortMap) {
sortedResults.put(userIdentity, results.get(userIdentity));
}
return sortedResults;
}
use of password.pwm.bean.UserIdentity in project pwm by pwm-project.
the class UserSearchResults method resultsAsJsonOutput.
public List<Map<String, Object>> resultsAsJsonOutput(final PwmApplication pwmApplication, final UserIdentity ignoreUser) throws PwmUnrecoverableException {
final List<Map<String, Object>> outputList = new ArrayList<>();
int idCounter = 0;
for (final UserIdentity userIdentity : this.getResults().keySet()) {
if (ignoreUser == null || !ignoreUser.equals(userIdentity)) {
final Map<String, Object> rowMap = new LinkedHashMap<>();
for (final String attribute : this.getHeaderAttributeMap().keySet()) {
rowMap.put(attribute, this.getResults().get(userIdentity).get(attribute));
}
rowMap.put("userKey", userIdentity.toObfuscatedKey(pwmApplication));
rowMap.put("id", idCounter);
outputList.add(rowMap);
idCounter++;
}
}
return outputList;
}
Aggregations