Search in sources :

Example 71 with TimeDuration

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

Example 72 with TimeDuration

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;
}
Also used : UserIdentity(password.pwm.bean.UserIdentity) TimeDuration(password.pwm.util.java.TimeDuration)

Example 73 with TimeDuration

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;
}
Also used : Percent(password.pwm.util.java.Percent) Instant(java.time.Instant) NewUserProfile(password.pwm.config.profile.NewUserProfile) BigDecimal(java.math.BigDecimal) LinkedHashMap(java.util.LinkedHashMap) TimeDuration(password.pwm.util.java.TimeDuration) NewUserBean(password.pwm.http.bean.NewUserBean) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 74 with TimeDuration

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;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) TokenType(password.pwm.svc.token.TokenType) MacroMachine(password.pwm.util.macro.MacroMachine) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) TimeDuration(password.pwm.util.java.TimeDuration) TokenDestinationItem(password.pwm.bean.TokenDestinationItem) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 75 with TimeDuration

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();
}
Also used : Locale(java.util.Locale) ChaiUser(com.novell.ldapchai.ChaiUser) Instant(java.time.Instant) MacroMachine(password.pwm.util.macro.MacroMachine) UserInfo(password.pwm.ldap.UserInfo) TimeDuration(password.pwm.util.java.TimeDuration)

Aggregations

TimeDuration (password.pwm.util.java.TimeDuration)75 Instant (java.time.Instant)28 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)22 ErrorInformation (password.pwm.error.ErrorInformation)19 PwmException (password.pwm.error.PwmException)14 ArrayList (java.util.ArrayList)12 LinkedHashMap (java.util.LinkedHashMap)12 IOException (java.io.IOException)9 Configuration (password.pwm.config.Configuration)8 PwmOperationalException (password.pwm.error.PwmOperationalException)8 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)7 Map (java.util.Map)7 UserIdentity (password.pwm.bean.UserIdentity)7 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 List (java.util.List)6 MacroMachine (password.pwm.util.macro.MacroMachine)6 BigDecimal (java.math.BigDecimal)5 Date (java.util.Date)5 Locale (java.util.Locale)5