use of password.pwm.config.Configuration in project pwm by pwm-project.
the class GuestRegistrationServlet method processAction.
protected void processAction(final PwmRequest pwmRequest) throws ServletException, ChaiUnavailableException, IOException, PwmUnrecoverableException {
// Fetch the session state bean.
final PwmSession pwmSession = pwmRequest.getPwmSession();
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final GuestRegistrationBean guestRegistrationBean = pwmApplication.getSessionStateService().getBean(pwmRequest, GuestRegistrationBean.class);
final Configuration config = pwmApplication.getConfig();
if (!config.readSettingAsBoolean(PwmSetting.GUEST_ENABLE)) {
pwmRequest.respondWithError(PwmError.ERROR_SERVICE_NOT_AVAILABLE.toInfo());
return;
}
if (!pwmSession.getSessionManager().checkPermission(pwmApplication, Permission.GUEST_REGISTRATION)) {
pwmRequest.respondWithError(PwmError.ERROR_UNAUTHORIZED.toInfo());
return;
}
checkConfiguration(config);
final GuestRegistrationAction action = readProcessAction(pwmRequest);
if (action != null) {
pwmRequest.validatePwmFormID();
switch(action) {
case create:
handleCreateRequest(pwmRequest, guestRegistrationBean);
return;
case search:
handleSearchRequest(pwmRequest, guestRegistrationBean);
return;
case update:
handleUpdateRequest(pwmRequest, guestRegistrationBean);
return;
case selectPage:
handleSelectPageRequest(pwmRequest, guestRegistrationBean);
return;
default:
JavaHelper.unhandledSwitchStatement(action);
}
}
this.forwardToJSP(pwmRequest, guestRegistrationBean);
}
use of password.pwm.config.Configuration in project pwm by pwm-project.
the class GuestRegistrationServlet method readExpirationFromRequest.
private static Instant readExpirationFromRequest(final PwmRequest pwmRequest) throws PwmOperationalException, ChaiUnavailableException, ChaiOperationException, PwmUnrecoverableException {
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final Configuration config = pwmApplication.getConfig();
final long durationValueDays = config.readSettingAsLong(PwmSetting.GUEST_MAX_VALID_DAYS);
final String expirationAttribute = config.readSettingAsString(PwmSetting.GUEST_EXPIRATION_ATTRIBUTE);
if (durationValueDays == 0 || expirationAttribute == null || expirationAttribute.length() <= 0) {
return null;
}
final String expirationDateStr = pwmRequest.readParameterAsString(HTTP_PARAM_EXPIRATION_DATE);
final Date expirationDate;
try {
expirationDate = new SimpleDateFormat("yyyy-MM-dd").parse(expirationDateStr);
} catch (ParseException e) {
final String errorMsg = "unable to read expiration date value: " + e.getMessage();
throw new PwmOperationalException(new ErrorInformation(PwmError.ERROR_FIELD_REQUIRED, errorMsg, new String[] { "expiration date" }));
}
if (expirationDate.before(new Date())) {
final String errorMsg = "expiration date must be in the future";
throw new PwmOperationalException(new ErrorInformation(PwmError.ERROR_FIELD_REQUIRED, errorMsg));
}
final long durationValueMs = durationValueDays * 24 * 60 * 60 * 1000;
final long futureDateMs = System.currentTimeMillis() + durationValueMs;
final Instant futureDate = Instant.ofEpochMilli(futureDateMs);
if (expirationDate.after(Date.from(futureDate))) {
final String errorMsg = "expiration date must be sooner than " + futureDate.toString();
throw new PwmOperationalException(new ErrorInformation(PwmError.ERROR_FIELD_REQUIRED, errorMsg));
}
LOGGER.trace(pwmRequest, "read expiration date as " + expirationDate.toString());
return expirationDate.toInstant();
}
use of password.pwm.config.Configuration in project pwm by pwm-project.
the class GuestRegistrationServlet method sendUpdateGuestEmailConfirmation.
private void sendUpdateGuestEmailConfirmation(final PwmRequest pwmRequest, final UserInfo guestUserInfo) throws PwmUnrecoverableException {
final Configuration config = pwmRequest.getConfig();
final Locale locale = pwmRequest.getLocale();
final EmailItemBean configuredEmailSetting = config.readSettingAsEmail(PwmSetting.EMAIL_UPDATEGUEST, locale);
if (configuredEmailSetting == null) {
LOGGER.debug(pwmRequest, "unable to send updated guest user email: no email configured");
return;
}
pwmRequest.getPwmApplication().getEmailQueue().submitEmail(configuredEmailSetting, guestUserInfo, null);
}
use of password.pwm.config.Configuration in project pwm by pwm-project.
the class SetupOtpServlet method preProcessCheck.
@Override
public ProcessStatus preProcessCheck(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException, ServletException {
// fetch the required beans / managers
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final PwmSession pwmSession = pwmRequest.getPwmSession();
final Configuration config = pwmApplication.getConfig();
final SetupOtpProfile setupOtpProfile = getSetupOtpProfile(pwmRequest);
if (setupOtpProfile == null || !setupOtpProfile.readSettingAsBoolean(PwmSetting.OTP_ALLOW_SETUP)) {
final String errorMsg = "setup OTP is not enabled";
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_SERVICE_NOT_AVAILABLE, errorMsg);
LOGGER.error(pwmRequest, errorInformation);
pwmRequest.respondWithError(errorInformation);
return ProcessStatus.Halt;
}
// check whether the setup can be stored
if (!canSetupOtpSecret(config)) {
LOGGER.error(pwmSession, "OTP Secret cannot be setup");
pwmRequest.respondWithError(PwmError.ERROR_INVALID_CONFIG.toInfo());
return ProcessStatus.Halt;
}
if (pwmSession.getLoginInfoBean().getType() == AuthenticationType.AUTH_WITHOUT_PASSWORD) {
LOGGER.error(pwmSession, "OTP Secret requires a password login");
throw new PwmUnrecoverableException(PwmError.ERROR_PASSWORD_REQUIRED);
}
final SetupOtpBean otpBean = getSetupOtpBean(pwmRequest);
initializeBean(pwmRequest, otpBean);
return ProcessStatus.Continue;
}
use of password.pwm.config.Configuration in project pwm by pwm-project.
the class SetupOtpServlet method initializeBean.
private void initializeBean(final PwmRequest pwmRequest, final SetupOtpBean otpBean) throws PwmUnrecoverableException {
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final PwmSession pwmSession = pwmRequest.getPwmSession();
// has pre-existing, nothing to do.
if (otpBean.isHasPreExistingOtp()) {
return;
}
final OtpService service = pwmApplication.getOtpService();
final UserIdentity theUser = pwmSession.getUserInfo().getUserIdentity();
// first time here
if (otpBean.getOtpUserRecord() == null) {
final OTPUserRecord existingUserRecord;
try {
existingUserRecord = service.readOTPUserConfiguration(pwmRequest.getSessionLabel(), theUser);
} catch (ChaiUnavailableException e) {
throw PwmUnrecoverableException.fromChaiException(e);
}
if (existingUserRecord != null) {
otpBean.setHasPreExistingOtp(true);
LOGGER.trace(pwmSession, "user has existing otp record");
return;
}
}
// make a new user record.
if (otpBean.getOtpUserRecord() == null) {
try {
final Configuration config = pwmApplication.getConfig();
final SetupOtpProfile setupOtpProfile = getSetupOtpProfile(pwmRequest);
final String identifierConfigValue = setupOtpProfile.readSettingAsString(PwmSetting.OTP_SECRET_IDENTIFIER);
final String identifier = pwmSession.getSessionManager().getMacroMachine(pwmApplication).expandMacros(identifierConfigValue);
final OTPUserRecord otpUserRecord = new OTPUserRecord();
final List<String> rawRecoveryCodes = pwmApplication.getOtpService().initializeUserRecord(setupOtpProfile, otpUserRecord, pwmRequest.getSessionLabel(), identifier);
otpBean.setOtpUserRecord(otpUserRecord);
otpBean.setRecoveryCodes(rawRecoveryCodes);
LOGGER.trace(pwmSession, "generated new otp record");
if (config.isDevDebugMode()) {
LOGGER.trace(pwmRequest, "newly generated otp record: " + JsonUtil.serialize(otpUserRecord));
}
} catch (Exception e) {
final String errorMsg = "error setting up new OTP secret: " + e.getMessage();
LOGGER.error(pwmSession, errorMsg);
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg));
}
}
}
Aggregations