use of password.pwm.util.java.TimeDuration in project pwm by pwm-project.
the class RequestInitializationFilter method checkIdleTimeout.
private void checkIdleTimeout(final PwmRequest pwmRequest) throws PwmUnrecoverableException {
final TimeDuration maxDurationForRequest = IdleTimeoutCalculator.idleTimeoutForRequest(pwmRequest);
final TimeDuration currentDuration = TimeDuration.fromCurrent(pwmRequest.getHttpServletRequest().getSession().getLastAccessedTime());
if (currentDuration.isLongerThan(maxDurationForRequest)) {
LOGGER.debug("unauthenticated session due to idle time, max for request is " + maxDurationForRequest.asCompactString() + ", session idle time is " + currentDuration.asCompactString());
pwmRequest.getPwmSession().unauthenticateUser(pwmRequest);
}
}
use of password.pwm.util.java.TimeDuration in project pwm by pwm-project.
the class HelpdeskVerificationStateBean method fromClientString.
static HelpdeskVerificationStateBean fromClientString(final PwmRequest pwmRequest, final String rawValue) throws PwmUnrecoverableException {
final int maxAgeSeconds = Integer.parseInt(pwmRequest.getConfig().readAppProperty(AppProperty.HELPDESK_VERIFICATION_TIMEOUT_SECONDS));
final TimeDuration maxAge = new TimeDuration(maxAgeSeconds, TimeUnit.SECONDS);
final UserIdentity actor = pwmRequest.getUserInfoIfLoggedIn();
HelpdeskVerificationStateBean state = null;
if (rawValue != null && !rawValue.isEmpty()) {
state = pwmRequest.getPwmApplication().getSecureService().decryptObject(rawValue, HelpdeskVerificationStateBean.class);
if (!state.getActor().equals(actor)) {
state = null;
}
}
state = state != null ? state : new HelpdeskVerificationStateBean(actor);
state.maximumAge = maxAge;
state.purgeOldRecords();
LOGGER.debug(pwmRequest, "read current state: " + JsonUtil.serialize(state));
return state;
}
use of password.pwm.util.java.TimeDuration in project pwm by pwm-project.
the class NewUserServlet method restCheckProgress.
@ActionHandler(action = "checkProgress")
private ProcessStatus restCheckProgress(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException {
final NewUserBean newUserBean = getNewUserBean(pwmRequest);
final Instant startTime = newUserBean.getCreateStartTime();
if (startTime == null) {
pwmRequest.respondWithError(PwmError.ERROR_INCORRECT_REQ_SEQUENCE.toInfo(), true);
return ProcessStatus.Halt;
}
final NewUserProfile newUserProfile = NewUserServlet.getNewUserProfile(pwmRequest);
final long minWaitTime = newUserProfile.readSettingAsLong(PwmSetting.NEWUSER_MINIMUM_WAIT_TIME) * 1000L;
final Instant completeTime = Instant.ofEpochMilli(startTime.toEpochMilli() + minWaitTime);
final BigDecimal percentComplete;
final boolean complete;
// be sure minimum wait time has passed
if (Instant.now().isAfter(completeTime)) {
percentComplete = new BigDecimal("100");
complete = true;
} else {
final TimeDuration elapsedTime = TimeDuration.fromCurrent(startTime);
complete = false;
percentComplete = new Percent(elapsedTime.getTotalMilliseconds(), minWaitTime).asBigDecimal();
}
final LinkedHashMap<String, Object> outputMap = new LinkedHashMap<>();
outputMap.put("percentComplete", percentComplete);
outputMap.put("complete", complete);
final RestResultBean restResultBean = RestResultBean.withData(outputMap);
LOGGER.trace(pwmRequest, "returning result for restCheckProgress: " + JsonUtil.serialize(restResultBean));
pwmRequest.outputJsonResult(restResultBean);
return ProcessStatus.Halt;
}
use of password.pwm.util.java.TimeDuration in project pwm by pwm-project.
the class NewUserUtils method checkForTokenVerificationProgress.
static ProcessStatus checkForTokenVerificationProgress(final PwmRequest pwmRequest, final NewUserBean newUserBean, final NewUserProfile newUserProfile) throws PwmUnrecoverableException, ServletException, IOException {
final Map<String, TokenDestinationItem.Type> requiredTokenValidations = determineTokenValidationsRequired(pwmRequest, newUserBean, newUserProfile);
if (!requiredTokenValidations.isEmpty()) {
final Set<String> remainingValidations = new HashSet<>(requiredTokenValidations.keySet());
remainingValidations.removeAll(newUserBean.getCompletedTokenFields());
if (!remainingValidations.isEmpty()) {
if (StringUtil.isEmpty(newUserBean.getCurrentTokenField())) {
newUserBean.setCurrentTokenField(remainingValidations.iterator().next());
newUserBean.setTokenSent(false);
}
if (!newUserBean.isTokenSent()) {
final TokenDestinationItem tokenDestinationItem = tokenDestinationItemForCurrentValidation(pwmRequest, newUserBean, newUserProfile);
if (pwmRequest.getConfig().getTokenStorageMethod() == TokenStorageMethod.STORE_LDAP) {
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, null, new String[] { "cannot generate new user tokens when storage type is configured as STORE_LDAP." }));
}
final Map<String, String> tokenPayloadMap = NewUserFormUtils.toTokenPayload(pwmRequest, newUserBean);
final MacroMachine macroMachine = createMacroMachineForNewUser(pwmRequest.getPwmApplication(), pwmRequest.getSessionLabel(), newUserBean.getNewUserForm(), tokenDestinationItem);
final TimeDuration tokenLifetime = figureTokenLifetime(pwmRequest.getConfig(), newUserProfile, tokenDestinationItem);
TokenUtil.initializeAndSendToken(pwmRequest, TokenUtil.TokenInitAndSendRequest.builder().userInfo(null).tokenDestinationItem(tokenDestinationItem).emailToSend(PwmSetting.EMAIL_NEWUSER_VERIFICATION).tokenType(TokenType.NEWUSER).smsToSend(PwmSetting.SMS_NEWUSER_TOKEN_TEXT).inputTokenData(tokenPayloadMap).macroMachine(macroMachine).tokenLifetime(tokenLifetime).build());
newUserBean.setTokenSent(true);
}
NewUserServlet.forwardToEnterCode(pwmRequest, newUserProfile, newUserBean);
return ProcessStatus.Halt;
}
}
return ProcessStatus.Continue;
}
use of password.pwm.util.java.TimeDuration in project pwm by pwm-project.
the class HelpdeskCardInfoBean method makeHelpdeskCardInfo.
static HelpdeskCardInfoBean makeHelpdeskCardInfo(final PwmRequest pwmRequest, final HelpdeskProfile helpdeskProfile, final UserIdentity userIdentity) throws PwmUnrecoverableException, ChaiUnavailableException {
final HelpdeskCardInfoBean.HelpdeskCardInfoBeanBuilder builder = HelpdeskCardInfoBean.builder();
final Instant startTime = Instant.now();
LOGGER.trace(pwmRequest, "beginning to assemble card data report for user " + userIdentity);
final Locale actorLocale = pwmRequest.getLocale();
final ChaiUser theUser = HelpdeskServlet.getChaiUser(pwmRequest, helpdeskProfile, userIdentity);
if (!theUser.exists()) {
return null;
}
final UserInfo userInfo = UserInfoFactory.newUserInfo(pwmRequest.getPwmApplication(), pwmRequest.getSessionLabel(), actorLocale, userIdentity, theUser.getChaiProvider());
final MacroMachine macroMachine = MacroMachine.forUser(pwmRequest.getPwmApplication(), pwmRequest.getSessionLabel(), userInfo, null);
builder.userKey(userIdentity.toObfuscatedKey(pwmRequest.getPwmApplication()));
builder.photoURL(figurePhotoURL(pwmRequest, helpdeskProfile, theUser, macroMachine, userIdentity));
builder.displayNames(figureDisplayNames(pwmRequest.getPwmApplication(), helpdeskProfile, pwmRequest.getSessionLabel(), userInfo));
final TimeDuration timeDuration = TimeDuration.fromCurrent(startTime);
final HelpdeskCardInfoBean helpdeskCardInfoBean = builder.build();
if (pwmRequest.getConfig().isDevDebugMode()) {
LOGGER.trace(pwmRequest, "completed assembly of card data report for user " + userIdentity + " in " + timeDuration.asCompactString() + ", contents: " + JsonUtil.serialize(helpdeskCardInfoBean));
}
return builder.build();
}
Aggregations