|
@@ -28,6 +28,7 @@ import com.novell.ldapchai.provider.ChaiProvider;
|
|
|
import password.pwm.PwmApplication;
|
|
|
import password.pwm.PwmApplicationMode;
|
|
|
import password.pwm.PwmConstants;
|
|
|
+import password.pwm.bean.SessionLabel;
|
|
|
import password.pwm.bean.UserIdentity;
|
|
|
import password.pwm.bean.UserInfoBean;
|
|
|
import password.pwm.config.PwmSetting;
|
|
@@ -112,13 +113,13 @@ public class ReportService implements PwmService {
|
|
|
this.pwmApplication = pwmApplication;
|
|
|
|
|
|
if (pwmApplication.getApplicationMode() == PwmApplicationMode.READ_ONLY) {
|
|
|
- LOGGER.debug(PwmConstants.REPORTING_SESSION_LABEL,"application mode is read-only, will remain closed");
|
|
|
+ LOGGER.debug(SessionLabel.REPORTING_SESSION_LABEL,"application mode is read-only, will remain closed");
|
|
|
status = STATUS.CLOSED;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (pwmApplication.getLocalDB() == null || LocalDB.Status.OPEN != pwmApplication.getLocalDB().status()) {
|
|
|
- LOGGER.debug(PwmConstants.REPORTING_SESSION_LABEL,"LocalDB is not open, will remain closed");
|
|
|
+ LOGGER.debug(SessionLabel.REPORTING_SESSION_LABEL,"LocalDB is not open, will remain closed");
|
|
|
status = STATUS.CLOSED;
|
|
|
return;
|
|
|
}
|
|
@@ -127,7 +128,7 @@ public class ReportService implements PwmService {
|
|
|
userCacheService = new UserCacheService();
|
|
|
userCacheService.init(pwmApplication);
|
|
|
} catch (Exception e) {
|
|
|
- LOGGER.error(PwmConstants.REPORTING_SESSION_LABEL,"unable to init cache service");
|
|
|
+ LOGGER.error(SessionLabel.REPORTING_SESSION_LABEL,"unable to init cache service");
|
|
|
status = STATUS.CLOSED;
|
|
|
return;
|
|
|
}
|
|
@@ -172,7 +173,7 @@ public class ReportService implements PwmService {
|
|
|
try {
|
|
|
pwmApplication.writeAppAttribute(PwmApplication.AppAttribute.REPORT_STATUS, reportStatus);
|
|
|
} catch (Exception e) {
|
|
|
- LOGGER.error(PwmConstants.REPORTING_SESSION_LABEL,"error writing cached report dredge info into memory: " + e.getMessage());
|
|
|
+ LOGGER.error(SessionLabel.REPORTING_SESSION_LABEL,"error writing cached report dredge info into memory: " + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -199,7 +200,7 @@ public class ReportService implements PwmService {
|
|
|
{
|
|
|
executorService.execute(new ClearTask());
|
|
|
executorService.execute(new ReadLDAPTask());
|
|
|
- LOGGER.trace(PwmConstants.REPORTING_SESSION_LABEL,"submitted new ldap dredge task to executorService");
|
|
|
+ LOGGER.trace(SessionLabel.REPORTING_SESSION_LABEL,"submitted new ldap dredge task to executorService");
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
@@ -283,10 +284,10 @@ public class ReportService implements PwmService {
|
|
|
returnBean = userCacheService.readStorageKey(key);
|
|
|
if (returnBean != null) {
|
|
|
if (returnBean.getCacheTimestamp() == null) {
|
|
|
- LOGGER.debug(PwmConstants.REPORTING_SESSION_LABEL,"purging record due to missing cache timestamp: " + JsonUtil.serialize(returnBean));
|
|
|
+ LOGGER.debug(SessionLabel.REPORTING_SESSION_LABEL,"purging record due to missing cache timestamp: " + JsonUtil.serialize(returnBean));
|
|
|
userCacheService.removeStorageKey(key);
|
|
|
} else if (TimeDuration.fromCurrent(returnBean.getCacheTimestamp()).isLongerThan(settings.getMaxCacheAge())) {
|
|
|
- LOGGER.debug(PwmConstants.REPORTING_SESSION_LABEL,"purging record due to old age timestamp: " + JsonUtil.serialize(returnBean));
|
|
|
+ LOGGER.debug(SessionLabel.REPORTING_SESSION_LABEL,"purging record due to old age timestamp: " + JsonUtil.serialize(returnBean));
|
|
|
userCacheService.removeStorageKey(key);
|
|
|
} else {
|
|
|
return returnBean;
|
|
@@ -368,11 +369,11 @@ public class ReportService implements PwmService {
|
|
|
if (e instanceof PwmException) {
|
|
|
if (((PwmException) e).getErrorInformation().getError() == PwmError.ERROR_DIRECTORY_UNAVAILABLE) {
|
|
|
if (executorService != null) {
|
|
|
- LOGGER.error(PwmConstants.REPORTING_SESSION_LABEL, "directory unavailable error during background SearchLDAP, will retry; error: " + e.getMessage());
|
|
|
+ LOGGER.error(SessionLabel.REPORTING_SESSION_LABEL, "directory unavailable error during background SearchLDAP, will retry; error: " + e.getMessage());
|
|
|
executorService.schedule(new ReadLDAPTask(), 10, TimeUnit.MINUTES);
|
|
|
}
|
|
|
} else {
|
|
|
- LOGGER.error(PwmConstants.REPORTING_SESSION_LABEL, "error during background ReadData: " + e.getMessage());
|
|
|
+ LOGGER.error(SessionLabel.REPORTING_SESSION_LABEL, "error during background ReadData: " + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
} finally {
|
|
@@ -391,7 +392,7 @@ public class ReportService implements PwmService {
|
|
|
|
|
|
final Iterator<UserIdentity> memQueue = LdapOperationsHelper.readAllUsersFromLdap(
|
|
|
pwmApplication,
|
|
|
- PwmConstants.REPORTING_SESSION_LABEL,
|
|
|
+ SessionLabel.REPORTING_SESSION_LABEL,
|
|
|
settings.getSearchFilter(),
|
|
|
settings.getMaxSearchSize()
|
|
|
);
|
|
@@ -432,11 +433,11 @@ public class ReportService implements PwmService {
|
|
|
if (e instanceof PwmException) {
|
|
|
if (((PwmException) e).getErrorInformation().getError() == PwmError.ERROR_DIRECTORY_UNAVAILABLE) {
|
|
|
if (executorService != null) {
|
|
|
- LOGGER.error(PwmConstants.REPORTING_SESSION_LABEL, "directory unavailable error during background ReadData, will retry; error: " + e.getMessage());
|
|
|
+ LOGGER.error(SessionLabel.REPORTING_SESSION_LABEL, "directory unavailable error during background ReadData, will retry; error: " + e.getMessage());
|
|
|
executorService.schedule(new ProcessWorkQueueTask(), 10, TimeUnit.MINUTES);
|
|
|
}
|
|
|
} else {
|
|
|
- LOGGER.error(PwmConstants.REPORTING_SESSION_LABEL, "error during background ReadData: " + e.getMessage());
|
|
|
+ LOGGER.error(SessionLabel.REPORTING_SESSION_LABEL, "error during background ReadData: " + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
} finally {
|
|
@@ -447,7 +448,7 @@ public class ReportService implements PwmService {
|
|
|
private void processWorkQueue()
|
|
|
throws ChaiUnavailableException, ChaiOperationException, PwmOperationalException, PwmUnrecoverableException
|
|
|
{
|
|
|
- LOGGER.debug(PwmConstants.REPORTING_SESSION_LABEL, "beginning process to updating user cache records from ldap");
|
|
|
+ LOGGER.debug(SessionLabel.REPORTING_SESSION_LABEL, "beginning process to updating user cache records from ldap");
|
|
|
if (status != STATUS.OPEN) {
|
|
|
return;
|
|
|
}
|
|
@@ -467,17 +468,17 @@ public class ReportService implements PwmService {
|
|
|
final Lock updateTimeLock = new ReentrantLock();
|
|
|
|
|
|
try {
|
|
|
- LOGGER.trace(PwmConstants.REPORTING_SESSION_LABEL, "about to begin ldap processing with thread count of " + threadCount);
|
|
|
+ LOGGER.trace(SessionLabel.REPORTING_SESSION_LABEL, "about to begin ldap processing with thread count of " + threadCount);
|
|
|
final BlockingThreadPool threadService = new BlockingThreadPool(threadCount, "reporting-thread");
|
|
|
while (status == STATUS.OPEN && !dnQueue.isEmpty() && !cancelFlag) {
|
|
|
final UserIdentity userIdentity = UserIdentity.fromDelimitedKey(dnQueue.poll());
|
|
|
if (pwmApplication.getConfig().isDevDebugMode()) {
|
|
|
- LOGGER.trace(PwmConstants.REPORTING_SESSION_LABEL, "submit " + Instant.now().toString()
|
|
|
+ LOGGER.trace(SessionLabel.REPORTING_SESSION_LABEL, "submit " + Instant.now().toString()
|
|
|
+ " size=" + threadService.getQueue().size());
|
|
|
}
|
|
|
threadService.blockingSubmit(() -> {
|
|
|
if (pwmApplication.getConfig().isDevDebugMode()) {
|
|
|
- LOGGER.trace(PwmConstants.REPORTING_SESSION_LABEL, "start " + Instant.now().toString()
|
|
|
+ LOGGER.trace(SessionLabel.REPORTING_SESSION_LABEL, "start " + Instant.now().toString()
|
|
|
+ " size=" + threadService.getQueue().size());
|
|
|
}
|
|
|
try {
|
|
@@ -504,18 +505,18 @@ public class ReportService implements PwmService {
|
|
|
errorMsg += e instanceof PwmException ? ((PwmException) e).getErrorInformation().toDebugStr() : e.getMessage();
|
|
|
final ErrorInformation errorInformation;
|
|
|
errorInformation = new ErrorInformation(PwmError.ERROR_REPORTING_ERROR,errorMsg);
|
|
|
- LOGGER.error(PwmConstants.REPORTING_SESSION_LABEL,errorInformation.toDebugStr(), e);
|
|
|
+ LOGGER.error(SessionLabel.REPORTING_SESSION_LABEL,errorInformation.toDebugStr(), e);
|
|
|
reportStatus.setLastError(errorInformation);
|
|
|
reportStatus.setErrors(reportStatus.getErrors() + 1);
|
|
|
}
|
|
|
if (pwmApplication.getConfig().isDevDebugMode()) {
|
|
|
- LOGGER.trace(PwmConstants.REPORTING_SESSION_LABEL, "finish " + Instant.now().toString()
|
|
|
+ LOGGER.trace(SessionLabel.REPORTING_SESSION_LABEL, "finish " + Instant.now().toString()
|
|
|
+ " size=" + threadService.getQueue().size());
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
if (pwmApplication.getConfig().isDevDebugMode()) {
|
|
|
- LOGGER.trace(PwmConstants.REPORTING_SESSION_LABEL, "exit " + Instant.now().toString()
|
|
|
+ LOGGER.trace(SessionLabel.REPORTING_SESSION_LABEL, "exit " + Instant.now().toString()
|
|
|
+ " size=" + threadService.getQueue().size());
|
|
|
}
|
|
|
|
|
@@ -528,7 +529,7 @@ public class ReportService implements PwmService {
|
|
|
reportStatus.setFinishDate(Instant.now());
|
|
|
saveTempData();
|
|
|
}
|
|
|
- LOGGER.debug(PwmConstants.REPORTING_SESSION_LABEL,"update user cache process completed: " + JsonUtil.serialize(reportStatus));
|
|
|
+ LOGGER.debug(SessionLabel.REPORTING_SESSION_LABEL,"update user cache process completed: " + JsonUtil.serialize(reportStatus));
|
|
|
}
|
|
|
|
|
|
|
|
@@ -549,7 +550,7 @@ public class ReportService implements PwmService {
|
|
|
final UserInfoBean userInfoBean = new UserInfoBean();
|
|
|
final UserStatusReader.Settings readerSettings = new UserStatusReader.Settings();
|
|
|
final ChaiProvider chaiProvider = pwmApplication.getProxyChaiProvider(userIdentity.getLdapProfileID());
|
|
|
- final UserStatusReader userStatusReader = new UserStatusReader(pwmApplication,PwmConstants.REPORTING_SESSION_LABEL,readerSettings);
|
|
|
+ final UserStatusReader userStatusReader = new UserStatusReader(pwmApplication, SessionLabel.REPORTING_SESSION_LABEL,readerSettings);
|
|
|
userStatusReader.populateUserInfoBean(
|
|
|
userInfoBean,
|
|
|
PwmConstants.DEFAULT_LOCALE,
|
|
@@ -561,7 +562,7 @@ public class ReportService implements PwmService {
|
|
|
userCacheService.store(newUserCacheRecord);
|
|
|
summaryData.update(newUserCacheRecord);
|
|
|
|
|
|
- LOGGER.trace(PwmConstants.REPORTING_SESSION_LABEL,"stored cache for " + userIdentity);
|
|
|
+ LOGGER.trace(SessionLabel.REPORTING_SESSION_LABEL,"stored cache for " + userIdentity);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -584,7 +585,7 @@ public class ReportService implements PwmService {
|
|
|
|
|
|
try (ClosableIterator<UserCacheRecord> iterator = iterator()) {
|
|
|
final int totalRecords = userCacheService.size();
|
|
|
- LOGGER.debug(PwmConstants.REPORTING_SESSION_LABEL, "beginning cache review process of " + totalRecords + " records");
|
|
|
+ LOGGER.debug(SessionLabel.REPORTING_SESSION_LABEL, "beginning cache review process of " + totalRecords + " records");
|
|
|
Instant lastLogOutputTime = Instant.now();
|
|
|
|
|
|
while (!cancelFlag && iterator.hasNext() && status == STATUS.OPEN) {
|
|
@@ -598,14 +599,14 @@ public class ReportService implements PwmService {
|
|
|
|
|
|
if (TimeDuration.fromCurrent(lastLogOutputTime).isLongerThan(30, TimeUnit.SECONDS)) {
|
|
|
final TimeDuration progressDuration = TimeDuration.fromCurrent(startTime);
|
|
|
- LOGGER.trace(PwmConstants.REPORTING_SESSION_LABEL,
|
|
|
+ LOGGER.trace(SessionLabel.REPORTING_SESSION_LABEL,
|
|
|
"cache review process in progress, examined " + examinedRecords
|
|
|
+ " in " + progressDuration.asCompactString());
|
|
|
lastLogOutputTime = Instant.now();
|
|
|
}
|
|
|
}
|
|
|
final TimeDuration totalTime = TimeDuration.fromCurrent(startTime);
|
|
|
- LOGGER.info(PwmConstants.REPORTING_SESSION_LABEL,
|
|
|
+ LOGGER.info(SessionLabel.REPORTING_SESSION_LABEL,
|
|
|
"completed cache review process of " + examinedRecords
|
|
|
+ " cached report records in " + totalTime.asCompactString());
|
|
|
}
|
|
@@ -626,7 +627,7 @@ public class ReportService implements PwmService {
|
|
|
try {
|
|
|
initTempData();
|
|
|
} catch (LocalDBException | PwmUnrecoverableException e) {
|
|
|
- LOGGER.error(PwmConstants.REPORTING_SESSION_LABEL, "error during initialization: " + e.getMessage());
|
|
|
+ LOGGER.error(SessionLabel.REPORTING_SESSION_LABEL, "error during initialization: " + e.getMessage());
|
|
|
status = STATUS.CLOSED;
|
|
|
return;
|
|
|
}
|
|
@@ -649,17 +650,17 @@ public class ReportService implements PwmService {
|
|
|
try {
|
|
|
reportStatus = pwmApplication.readAppAttribute(PwmApplication.AppAttribute.REPORT_STATUS, ReportStatusInfo.class);
|
|
|
} catch (Exception e) {
|
|
|
- LOGGER.error(PwmConstants.REPORTING_SESSION_LABEL,"error loading cached report status info into memory: " + e.getMessage());
|
|
|
+ LOGGER.error(SessionLabel.REPORTING_SESSION_LABEL,"error loading cached report status info into memory: " + e.getMessage());
|
|
|
}
|
|
|
|
|
|
boolean clearFlag = false;
|
|
|
if (reportStatus == null) {
|
|
|
clearFlag = true;
|
|
|
- LOGGER.debug(PwmConstants.REPORTING_SESSION_LABEL,"report service did not close cleanly, will clear data.");
|
|
|
+ LOGGER.debug(SessionLabel.REPORTING_SESSION_LABEL,"report service did not close cleanly, will clear data.");
|
|
|
} else {
|
|
|
final String currentSettingCache = settings.getSettingsHash();
|
|
|
if (reportStatus.getSettingsHash() != null && !reportStatus.getSettingsHash().equals(currentSettingCache)) {
|
|
|
- LOGGER.error(PwmConstants.REPORTING_SESSION_LABEL, "configuration has changed, will clear cached report data");
|
|
|
+ LOGGER.error(SessionLabel.REPORTING_SESSION_LABEL, "configuration has changed, will clear cached report data");
|
|
|
clearFlag = true;
|
|
|
}
|
|
|
}
|
|
@@ -677,20 +678,20 @@ public class ReportService implements PwmService {
|
|
|
try {
|
|
|
doClear();
|
|
|
} catch (LocalDBException | PwmUnrecoverableException e) {
|
|
|
- LOGGER.error(PwmConstants.REPORTING_SESSION_LABEL, "error during clear operation: " + e.getMessage());
|
|
|
+ LOGGER.error(SessionLabel.REPORTING_SESSION_LABEL, "error during clear operation: " + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void doClear() throws LocalDBException, PwmUnrecoverableException {
|
|
|
final Instant startTime = Instant.now();
|
|
|
- LOGGER.debug(PwmConstants.REPORTING_SESSION_LABEL,"clearing cached report data");
|
|
|
+ LOGGER.debug(SessionLabel.REPORTING_SESSION_LABEL,"clearing cached report data");
|
|
|
clearWorkQueue();
|
|
|
if (userCacheService != null) {
|
|
|
userCacheService.clear();
|
|
|
}
|
|
|
summaryData = ReportSummaryData.newSummaryData(settings.getTrackDays());
|
|
|
reportStatus = new ReportStatusInfo(settings.getSettingsHash());
|
|
|
- LOGGER.debug(PwmConstants.REPORTING_SESSION_LABEL,"finished clearing report " + TimeDuration.fromCurrent(startTime).asCompactString());
|
|
|
+ LOGGER.debug(SessionLabel.REPORTING_SESSION_LABEL,"finished clearing report " + TimeDuration.fromCurrent(startTime).asCompactString());
|
|
|
}
|
|
|
}
|
|
|
}
|