Search in sources :

Example 11 with DataStorageMethod

use of password.pwm.config.option.DataStorageMethod in project pwm by pwm-project.

the class OtpService method writeOTPUserConfiguration.

public void writeOTPUserConfiguration(final PwmSession pwmSession, final UserIdentity userIdentity, final OTPUserRecord otp) throws PwmOperationalException, ChaiUnavailableException, PwmUnrecoverableException {
    int attempts = 0;
    int successes = 0;
    final Configuration config = pwmApplication.getConfig();
    final List<DataStorageMethod> otpSecretStorageLocations = config.getOtpSecretStorageLocations(PwmSetting.OTP_SECRET_READ_PREFERENCE);
    final String userGUID = readGuidIfNeeded(pwmApplication, pwmSession == null ? null : pwmSession.getLabel(), otpSecretStorageLocations, userIdentity);
    final StringBuilder errorMsgs = new StringBuilder();
    if (otpSecretStorageLocations != null) {
        for (final DataStorageMethod otpSecretStorageLocation : otpSecretStorageLocations) {
            attempts++;
            final OtpOperator operator = operatorMap.get(otpSecretStorageLocation);
            if (operator != null) {
                try {
                    operator.writeOtpUserConfiguration(pwmSession, userIdentity, userGUID, otp);
                    successes++;
                } catch (PwmUnrecoverableException e) {
                    LOGGER.error(pwmSession, "error writing to " + otpSecretStorageLocation + ", error: " + e.getMessage());
                    errorMsgs.append(otpSecretStorageLocation).append(" error: ").append(e.getMessage());
                }
            } else {
                LOGGER.warn(pwmSession, String.format("storage location %s not implemented", otpSecretStorageLocation.toString()));
            }
        }
    }
    if (attempts == 0) {
        final String errorMsg = "no OTP secret save methods are available or configured";
        final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_WRITING_OTP_SECRET, errorMsg);
        throw new PwmOperationalException(errorInfo);
    }
    if (attempts != successes) {
        // should be impossible to read here, but just in case.
        final String errorMsg = "OTP secret write only partially successful; attempts=" + attempts + ", successes=" + successes + ", errors: " + errorMsgs.toString();
        final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_WRITING_OTP_SECRET, errorMsg);
        throw new PwmOperationalException(errorInfo);
    }
}
Also used : OtpOperator(password.pwm.util.operations.otp.OtpOperator) LocalDbOtpOperator(password.pwm.util.operations.otp.LocalDbOtpOperator) LdapOtpOperator(password.pwm.util.operations.otp.LdapOtpOperator) DbOtpOperator(password.pwm.util.operations.otp.DbOtpOperator) ErrorInformation(password.pwm.error.ErrorInformation) Configuration(password.pwm.config.Configuration) DataStorageMethod(password.pwm.config.option.DataStorageMethod) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmOperationalException(password.pwm.error.PwmOperationalException)

Example 12 with DataStorageMethod

use of password.pwm.config.option.DataStorageMethod in project pwm by pwm-project.

the class OtpService method clearOTPUserConfiguration.

public void clearOTPUserConfiguration(final PwmSession pwmSession, final UserIdentity userIdentity) throws PwmOperationalException, ChaiUnavailableException, PwmUnrecoverableException {
    LOGGER.trace(pwmSession, "beginning clear otp user configuration");
    int attempts = 0;
    int successes = 0;
    final Configuration config = pwmApplication.getConfig();
    final List<DataStorageMethod> otpSecretStorageLocations = config.getOtpSecretStorageLocations(PwmSetting.OTP_SECRET_READ_PREFERENCE);
    final String userGUID = readGuidIfNeeded(pwmApplication, pwmSession.getLabel(), otpSecretStorageLocations, userIdentity);
    final StringBuilder errorMsgs = new StringBuilder();
    if (otpSecretStorageLocations != null) {
        for (final DataStorageMethod otpSecretStorageLocation : otpSecretStorageLocations) {
            attempts++;
            final OtpOperator operator = operatorMap.get(otpSecretStorageLocation);
            if (operator != null) {
                try {
                    operator.clearOtpUserConfiguration(pwmSession, userIdentity, userGUID);
                    successes++;
                } catch (PwmUnrecoverableException e) {
                    LOGGER.error(pwmSession, "error clearing " + otpSecretStorageLocation + ", error: " + e.getMessage());
                    errorMsgs.append(otpSecretStorageLocation).append(" error: ").append(e.getMessage());
                }
            } else {
                LOGGER.warn(pwmSession, String.format("Storage location %s not implemented", otpSecretStorageLocation.toString()));
            }
        }
    }
    if (attempts == 0) {
        final String errorMsg = "no OTP secret clear methods are available or configured";
        // @todo: replace error message
        final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_WRITING_OTP_SECRET, errorMsg);
        throw new PwmOperationalException(errorInfo);
    }
    if (attempts != successes) {
        // should be impossible to read here, but just in case.
        final String errorMsg = "OTP secret clearing only partially successful; attempts=" + attempts + ", successes=" + successes + ", error: " + errorMsgs.toString();
        // @todo: replace error message
        final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_WRITING_OTP_SECRET, errorMsg);
        throw new PwmOperationalException(errorInfo);
    }
}
Also used : OtpOperator(password.pwm.util.operations.otp.OtpOperator) LocalDbOtpOperator(password.pwm.util.operations.otp.LocalDbOtpOperator) LdapOtpOperator(password.pwm.util.operations.otp.LdapOtpOperator) DbOtpOperator(password.pwm.util.operations.otp.DbOtpOperator) ErrorInformation(password.pwm.error.ErrorInformation) Configuration(password.pwm.config.Configuration) DataStorageMethod(password.pwm.config.option.DataStorageMethod) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmOperationalException(password.pwm.error.PwmOperationalException)

Example 13 with DataStorageMethod

use of password.pwm.config.option.DataStorageMethod in project pwm by pwm-project.

the class AppDashboardData method getServiceData.

private static List<ServiceData> getServiceData(final PwmApplication pwmApplication) {
    final Map<String, ServiceData> returnData = new TreeMap<>();
    for (final PwmService pwmService : pwmApplication.getPwmServices()) {
        final PwmService.ServiceInfo serviceInfo = pwmService.serviceInfo();
        final Collection<DataStorageMethod> storageMethods = serviceInfo == null ? Collections.emptyList() : serviceInfo.getUsedStorageMethods() == null ? Collections.emptyList() : serviceInfo.getUsedStorageMethods();
        final Map<String, String> debugData = serviceInfo == null ? Collections.emptyMap() : serviceInfo.getDebugProperties() == null ? Collections.emptyMap() : serviceInfo.getDebugProperties();
        returnData.put(pwmService.getClass().getSimpleName(), new ServiceData(pwmService.getClass().getSimpleName(), pwmService.status(), storageMethods, pwmService.healthCheck(), debugData));
    }
    return Collections.unmodifiableList(new ArrayList<>(returnData.values()));
}
Also used : PwmService(password.pwm.svc.PwmService) DataStorageMethod(password.pwm.config.option.DataStorageMethod) TreeMap(java.util.TreeMap)

Aggregations

DataStorageMethod (password.pwm.config.option.DataStorageMethod)13 Configuration (password.pwm.config.Configuration)8 ErrorInformation (password.pwm.error.ErrorInformation)7 PwmOperationalException (password.pwm.error.PwmOperationalException)7 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)7 PwmException (password.pwm.error.PwmException)4 TreeMap (java.util.TreeMap)3 TimeDuration (password.pwm.util.java.TimeDuration)3 DbOtpOperator (password.pwm.util.operations.otp.DbOtpOperator)3 LdapOtpOperator (password.pwm.util.operations.otp.LdapOtpOperator)3 LocalDbOtpOperator (password.pwm.util.operations.otp.LocalDbOtpOperator)3 OtpOperator (password.pwm.util.operations.otp.OtpOperator)3 Answer (com.novell.ldapchai.cr.Answer)2 IOException (java.io.IOException)2 BigInteger (java.math.BigInteger)2 Map (java.util.Map)2 TimerTask (java.util.TimerTask)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 DataStore (password.pwm.util.DataStore)2