Search in sources :

Example 11 with PwmApplication

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;
}
Also used : PwmApplication(password.pwm.PwmApplication) Logger(org.apache.log4j.Logger) LocalDB(password.pwm.util.localdb.LocalDB) LocalDBException(password.pwm.util.localdb.LocalDBException) IOException(java.io.IOException)

Example 12 with PwmApplication

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);
}
Also used : PwmApplication(password.pwm.PwmApplication) PwmApplicationMode(password.pwm.PwmApplicationMode) HashSet(java.util.HashSet)

Example 13 with PwmApplication

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.");
}
Also used : PwmApplication(password.pwm.PwmApplication) HealthRecord(password.pwm.health.HealthRecord) ReportService(password.pwm.svc.report.ReportService) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) ReportCsvUtility(password.pwm.svc.report.ReportCsvUtility) IOException(java.io.IOException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) IOException(java.io.IOException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 14 with PwmApplication

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);
}
Also used : PwmApplication(password.pwm.PwmApplication) TokenPayload(password.pwm.svc.token.TokenPayload) TokenService(password.pwm.svc.token.TokenService)

Example 15 with PwmApplication

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);
    }
}
Also used : ForgottenPasswordProfile(password.pwm.config.profile.ForgottenPasswordProfile) PwmApplication(password.pwm.PwmApplication) UserIdentity(password.pwm.bean.UserIdentity) UserInfo(password.pwm.ldap.UserInfo) MessageSendMethod(password.pwm.config.option.MessageSendMethod) PwmException(password.pwm.error.PwmException) ErrorInformation(password.pwm.error.ErrorInformation) AuditRecordFactory(password.pwm.svc.event.AuditRecordFactory) ChaiUser(com.novell.ldapchai.ChaiUser) RecoveryAction(password.pwm.config.option.RecoveryAction) PasswordData(password.pwm.util.PasswordData) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) AuditRecord(password.pwm.svc.event.AuditRecord) ForgottenPasswordBean(password.pwm.http.bean.ForgottenPasswordBean) ChaiException(com.novell.ldapchai.exception.ChaiException)

Aggregations

PwmApplication (password.pwm.PwmApplication)120 PwmSession (password.pwm.http.PwmSession)55 ErrorInformation (password.pwm.error.ErrorInformation)54 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)49 PwmOperationalException (password.pwm.error.PwmOperationalException)36 Configuration (password.pwm.config.Configuration)33 UserIdentity (password.pwm.bean.UserIdentity)27 FormConfiguration (password.pwm.config.value.data.FormConfiguration)25 PwmException (password.pwm.error.PwmException)25 IOException (java.io.IOException)22 ServletException (javax.servlet.ServletException)18 UserInfo (password.pwm.ldap.UserInfo)18 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)17 ChaiUser (com.novell.ldapchai.ChaiUser)16 Locale (java.util.Locale)13 ActionConfiguration (password.pwm.config.value.data.ActionConfiguration)13 SearchConfiguration (password.pwm.ldap.search.SearchConfiguration)13 MacroMachine (password.pwm.util.macro.MacroMachine)12 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)11 Instant (java.time.Instant)10