use of password.pwm.PwmApplication in project pwm by pwm-project.
the class PwmLogManager method initializeLocalDBLogger.
public static LocalDBLogger initializeLocalDBLogger(final PwmApplication pwmApplication) {
final LocalDB localDB = pwmApplication.getLocalDB();
if (pwmApplication.getApplicationMode() == PwmApplicationMode.READ_ONLY) {
LOGGER.trace("skipping initialization of LocalDBLogger due to read-only mode");
return null;
}
// initialize the localDBLogger
final LocalDBLogger localDBLogger;
final PwmLogLevel localDBLogLevel = pwmApplication.getConfig().getEventLogLocalDBLevel();
try {
localDBLogger = initLocalDBLogger(localDB, pwmApplication);
if (localDBLogger != null) {
PwmLogger.setLocalDBLogger(localDBLogLevel, localDBLogger);
}
} catch (Exception e) {
LOGGER.warn("unable to initialize localDBLogger: " + e.getMessage());
return null;
}
// add appender for other packages;
try {
final LocalDBLog4jAppender localDBLog4jAppender = new LocalDBLog4jAppender(localDBLogger);
localDBLog4jAppender.setThreshold(localDBLogLevel.getLog4jLevel());
for (final Package logPackage : LOGGING_PACKAGES) {
if (logPackage != null && !logPackage.equals(PwmApplication.class.getPackage())) {
final Logger logger = Logger.getLogger(logPackage.getName());
logger.addAppender(localDBLog4jAppender);
logger.setLevel(Level.TRACE);
}
}
} catch (Exception e) {
LOGGER.warn("unable to initialize localDBLogger/extraAppender: " + e.getMessage());
}
return localDBLogger;
}
use of password.pwm.PwmApplication in project pwm by pwm-project.
the class MacroMachine method effectiveScopes.
private static Set<MacroImplementation.Scope> effectiveScopes(final MacroImplementation.MacroRequestInfo macroRequestInfo) {
final Set<MacroImplementation.Scope> scopes = new HashSet<>();
scopes.add(MacroImplementation.Scope.Static);
final PwmApplication pwmApplication = macroRequestInfo.getPwmApplication();
final PwmApplicationMode mode = pwmApplication != null ? pwmApplication.getApplicationMode() : PwmApplicationMode.ERROR;
final boolean appModeOk = mode == PwmApplicationMode.RUNNING || mode == PwmApplicationMode.CONFIGURATION;
if (appModeOk) {
scopes.add(MacroImplementation.Scope.System);
if (macroRequestInfo.getUserInfo() != null) {
scopes.add(MacroImplementation.Scope.User);
}
}
return Collections.unmodifiableSet(scopes);
}
use of password.pwm.PwmApplication in project pwm by pwm-project.
the class UserReportCommand method doCommand.
@Override
@SuppressFBWarnings("DM_EXIT")
void doCommand() throws Exception {
final File outputFile = (File) cliEnvironment.getOptions().get(OUTPUT_FILE_OPTIONNAME);
try (OutputStream outputFileStream = new BufferedOutputStream(new FileOutputStream(outputFile))) {
final PwmApplication pwmApplication = cliEnvironment.getPwmApplication();
final ReportService userReport = pwmApplication.getReportService();
if (userReport.status() != PwmService.STATUS.OPEN) {
out("report service is not open or enabled");
final List<HealthRecord> healthIssues = userReport.healthCheck();
if (healthIssues != null) {
for (final HealthRecord record : healthIssues) {
out("report health status: " + record.toDebugString(Locale.getDefault(), pwmApplication.getConfig()));
}
}
return;
}
final ReportCsvUtility reportCsvUtility = new ReportCsvUtility(pwmApplication);
reportCsvUtility.outputToCsv(outputFileStream, true, PwmConstants.DEFAULT_LOCALE);
} catch (IOException e) {
out("unable to open file '" + outputFile.getAbsolutePath() + "' for writing");
System.exit(-1);
throw new Exception();
}
out("report output complete.");
}
use of password.pwm.PwmApplication in project pwm by pwm-project.
the class TokenInfoCommand method doCommand.
public void doCommand() throws Exception {
final String tokenKey = (String) cliEnvironment.getOptions().get(TOKEN_KEY_OPTIONNAME);
final PwmApplication pwmApplication = cliEnvironment.getPwmApplication();
final TokenService tokenService = pwmApplication.getTokenService();
TokenPayload tokenPayload = null;
Exception lookupError = null;
try {
tokenPayload = tokenService.retrieveTokenData(SessionLabel.TOKEN_SESSION_LABEL, tokenKey);
} catch (Exception e) {
lookupError = e;
}
out(" token: " + tokenKey);
if (lookupError != null) {
out("result: error during token lookup: " + lookupError.toString());
} else if (tokenPayload == null) {
out("result: token not found");
} else {
out(" name: " + tokenPayload.getName());
out(" user: " + tokenPayload.getUserIdentity());
out("issued: " + JavaHelper.toIsoDate(tokenPayload.getIssueTime()));
out("expire: " + JavaHelper.toIsoDate(tokenPayload.getExpiration()));
for (final String key : tokenPayload.getData().keySet()) {
final String value = tokenPayload.getData().get(key);
out(" payload key: " + key);
out(" value: " + value);
}
}
pwmApplication.shutdown();
JavaHelper.pause(1000);
}
use of password.pwm.PwmApplication in project pwm by pwm-project.
the class ForgottenPasswordUtil method doActionSendNewPassword.
static void doActionSendNewPassword(final PwmRequest pwmRequest) throws ChaiUnavailableException, IOException, ServletException, PwmUnrecoverableException {
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final ForgottenPasswordBean forgottenPasswordBean = ForgottenPasswordServlet.forgottenPasswordBean(pwmRequest);
final ForgottenPasswordProfile forgottenPasswordProfile = forgottenPasswordProfile(pwmRequest.getPwmApplication(), forgottenPasswordBean);
final RecoveryAction recoveryAction = ForgottenPasswordUtil.getRecoveryAction(pwmApplication.getConfig(), forgottenPasswordBean);
LOGGER.trace(pwmRequest, "beginning process to send new password to user");
if (!forgottenPasswordBean.getProgress().isAllPassed()) {
return;
}
final UserIdentity userIdentity = forgottenPasswordBean.getUserIdentity();
final ChaiUser theUser = pwmRequest.getPwmApplication().getProxiedChaiUser(userIdentity);
try {
// try unlocking user
theUser.unlockPassword();
LOGGER.trace(pwmRequest, "unlock account succeeded");
} catch (ChaiOperationException e) {
final String errorMsg = "unable to unlock user " + theUser.getEntryDN() + " error: " + e.getMessage();
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNLOCK_FAILURE, errorMsg);
LOGGER.error(pwmRequest.getPwmSession(), errorInformation.toDebugStr());
pwmRequest.respondWithError(errorInformation);
return;
}
try {
final UserInfo userInfo = UserInfoFactory.newUserInfoUsingProxy(pwmApplication, pwmRequest.getSessionLabel(), userIdentity, pwmRequest.getLocale());
LOGGER.info(pwmRequest, "user successfully supplied password recovery responses, emailing new password to: " + theUser.getEntryDN());
// add post change actions
ForgottenPasswordServlet.addPostChangeAction(pwmRequest, userIdentity);
// create new password
final PasswordData newPassword = RandomPasswordGenerator.createRandomPassword(pwmRequest.getSessionLabel(), userInfo.getPasswordPolicy(), pwmApplication);
LOGGER.trace(pwmRequest, "generated random password value based on password policy for " + userIdentity.toDisplayString());
// set the password
try {
theUser.setPassword(newPassword.getStringValue());
LOGGER.trace(pwmRequest, "set user " + userIdentity.toDisplayString() + " password to system generated random value");
} catch (ChaiException e) {
throw PwmUnrecoverableException.fromChaiException(e);
}
if (recoveryAction == RecoveryAction.SENDNEWPW_AND_EXPIRE) {
LOGGER.debug(pwmRequest, "marking user " + userIdentity.toDisplayString() + " password as expired");
theUser.expirePassword();
}
// mark the event log
{
final AuditRecord auditRecord = new AuditRecordFactory(pwmApplication).createUserAuditRecord(AuditEvent.RECOVER_PASSWORD, userIdentity, pwmRequest.getSessionLabel());
pwmApplication.getAuditManager().submit(auditRecord);
}
final MessageSendMethod messageSendMethod = forgottenPasswordProfile.readSettingAsEnum(PwmSetting.RECOVERY_SENDNEWPW_METHOD, MessageSendMethod.class);
// send email or SMS
final String toAddress = PasswordUtility.sendNewPassword(userInfo, pwmApplication, newPassword, pwmRequest.getLocale(), messageSendMethod);
pwmRequest.getPwmResponse().forwardToSuccessPage(Message.Success_PasswordSend, toAddress);
} catch (PwmException e) {
LOGGER.warn(pwmRequest, "unexpected error setting new password during recovery process for user: " + e.getMessage());
pwmRequest.respondWithError(e.getErrorInformation());
} catch (ChaiOperationException e) {
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, "unexpected ldap error while processing recovery action " + recoveryAction + ", error: " + e.getMessage());
LOGGER.warn(pwmRequest, errorInformation.toDebugStr());
pwmRequest.respondWithError(errorInformation);
} finally {
ForgottenPasswordServlet.clearForgottenPasswordBean(pwmRequest);
// the user should not be authenticated, this is a safety method
pwmRequest.getPwmSession().unauthenticateUser(pwmRequest);
// the password set flag should not have been set, this is a safety method
pwmRequest.getPwmSession().getSessionStateBean().setPasswordModified(false);
}
}
Aggregations