private Optional<UserDto> getUserFromToken(HttpServletRequest request, HttpServletResponse response) { Optional<JwtHttpHandler.Token> token = jwtHttpHandler.getToken(request, response); if (!token.isPresent()) { return Optional.empty(); } Date now = new Date(system2.now()); int refreshIntervalInMinutes = Integer.parseInt(settingsByKey.get(SONAR_WEB_SSO_REFRESH_INTERVAL_IN_MINUTES.getKey())); Long lastFreshTime = (Long) token.get().getProperties().get(LAST_REFRESH_TIME_TOKEN_PARAM); if (lastFreshTime == null || now.after(addMinutes(new Date(lastFreshTime), refreshIntervalInMinutes))) { return Optional.empty(); } return Optional.of(token.get().getUserDto()); }
private static void setupCommits( Injector injector ) throws Exception { // Commits shouldn't have the same createDate b/c of issues with sorting them Date now = new Date(); commitDao = injector.getInstance( CommitDao.class ); Commit commit = new BasicCommit( COMMIT_ID_1, // commitId MODULE_ID_1, // moduleId "742e2a76a6ba161f9efb87ce58a9187e", // warMD5 now, // createDate "/some/dummy/path" ); commitDao.save( commit ); commit = new BasicCommit( COMMIT_ID_2, // commitId MODULE_ID_2, // moduleId "395cfdfc3b77242a6f957d6d92da8958", // warMD5 DateUtils.addMinutes( now, 1 ), // createDate "/some/dummy/path" ); commitDao.save( commit ); commit = new BasicCommit( COMMIT_ID_3, // commitId MODULE_ID_2, // moduleId "b9860ffa5e39b6f7123ed8c72c4b7046", // warMD5 DateUtils.addMinutes( now, 2 ), // createDate "/some/dummy/path" ); commitDao.save( commit ); }
/** * Adjust offset, offset will always be in min. * * @param date the date * @param offset the offset * @return the date * @throws IOException Signals that an I/O exception has occurred. */ public Date adjustOffset(Date date, int offset) throws IOException { return org.apache.commons.lang.time.DateUtils.addMinutes(date, offset); }
/** * Adjust offset, offset will always be in min. * * @param date the date * @param offset the offset * @return the date * @throws IOException Signals that an I/O exception has occurred. */ public Date adjustOffset(Date date, int offset) throws IOException { return org.apache.commons.lang.time.DateUtils.addMinutes(date, offset); }
/** * 平移当前时间,以分为单元,minutes * * @param minutes * @return */ public static Date addCurMin(long minutes) { return DateUtils.addMinutes(new Date(), (int) minutes); }
/** * 平移当前时间,以分为单元,minutes * * @param minutes * @return */ public static Date addCurMin(long minutes) { return DateUtils.addMinutes(new Date(), (int) minutes); }
private static Date addRandomMinutes(final Date nextMidnight) { return DateUtils.addMinutes(nextMidnight, new Random().nextInt(60)); }
public void setExpirationTime(String key, int expiresInMinute) { Date expirationTime = DateUtils.addMinutes(new Date(), expiresInMinute); expirationTimes.put(key.toString(), expirationTime); }
public void setExpirationTime(String targetCache, String key, int expiresInMinute) { Date expirationTime = DateUtils.addMinutes(new Date(), expiresInMinute); this.setExpirationTime(targetCache, key, expirationTime); }
public Date diff(Integer i) { return DateUtils.addMinutes(AbstractDateParamFilter.this.clock.current(), i.intValue()); }
/** * lock temporarily * * @param lockForMinutes lock time in minutes */ public void lockAccountTemporarily(int lockForMinutes) { Preconditions.checkArgument(lockForMinutes > 0); accountLocked = false; accountLockedUntil = DateUtils.addMinutes(new Date(), lockForMinutes); logger.info("temporarily locking account ["+getLogin()+"], locked until: "+getAccountLockedUntil()); }
private Optional<UserDto> getUserFromToken(HttpServletRequest request, HttpServletResponse response) { Optional<JwtHttpHandler.Token> token = jwtHttpHandler.getToken(request, response); if (!token.isPresent()) { return Optional.empty(); } Date now = new Date(system2.now()); int refreshIntervalInMinutes = Integer.parseInt(settingsByKey.get(SONAR_WEB_SSO_REFRESH_INTERVAL_IN_MINUTES.getKey())); Long lastFreshTime = (Long) token.get().getProperties().get(LAST_REFRESH_TIME_TOKEN_PARAM); if (lastFreshTime == null || now.after(addMinutes(new Date(lastFreshTime), refreshIntervalInMinutes))) { return Optional.empty(); } return Optional.of(token.get().getUserDto()); }
/** * Czasowe zablokowanie konta * * @param lockForMinutes na ile minut ma być zablokowane konto */ protected void lockAccountTemporarily(int lockForMinutes) { Preconditions.checkArgument(lockForMinutes > 0); setAccountLocked(false); setAccountLockedUntil(DateUtils.addMinutes(new Date(), lockForMinutes)); logger.info("temporarily locking account [" + getLogin() + "], locked until: " + getAccountLockedUntil()); }
protected static Date computeEffectiveTime(TimestampDelay timestampDelay) { Date result = null; if (timestampDelay.getExpected() != null) { result = DateUtils.addMinutes(timestampDelay.getExpected(), timestampDelay.getDelay().intValue()); } return result; }
private static Date computeEffectiveTime(TimestampDelay timestampDelay) { Date result = null; if (timestampDelay != null && timestampDelay.getExpected() != null) { result = DateUtils.addMinutes(timestampDelay.getExpected(), timestampDelay.getDelay() != null ? timestampDelay.getDelay().intValue() : 0); } return result; }
protected void lockUser(String userId, String invalidPassword) throws ParseException { Date now = ClockUtil.getCurrentTime(); try { for (int i = 0; i <= 11; i++) { assertFalse(identityService.checkPassword(userId, invalidPassword)); now = DateUtils.addMinutes(ClockUtil.getCurrentTime(), 1); ClockUtil.setCurrentTime(now); } } catch (Exception e) { e.printStackTrace(); } }
@Test public void testScheduleJobForBatchWindow() throws ParseException { ClockUtil.setCurrentTime(currentDate); processEngineConfiguration.initHistoryCleanup(); Job job = historyService.cleanUpHistoryAsync(); assertFalse(startDateForCheck.after(job.getDuedate())); // job due date is not before start date assertTrue(endDateForCheck.after(job.getDuedate())); ClockUtil.setCurrentTime(DateUtils.addMinutes(endDateForCheck, -1)); job = historyService.cleanUpHistoryAsync(); assertFalse(startDateForCheck.after(job.getDuedate())); assertTrue(endDateForCheck.after(job.getDuedate())); ClockUtil.setCurrentTime(DateUtils.addMinutes(endDateForCheck, 1)); job = historyService.cleanUpHistoryAsync(); assertTrue(endDateForCheck.before(job.getDuedate())); }
@Test public void testUsuccessfulAttemptsResultInException() throws ParseException { User user = identityService.newUser("johndoe"); user.setPassword("xxx"); identityService.saveUser(user); thrown.expect(AuthenticationException.class); thrown.expectMessage("The user with id 'johndoe' is permanently locked. Please contact your admin to unlock the account."); Date now = sdf.parse("2000-01-24T13:00:00"); ClockUtil.setCurrentTime(now); for (int i = 0; i <= 11; i++) { assertFalse(identityService.checkPassword("johndoe", "invalid pwd")); now = DateUtils.addMinutes(now, 1); ClockUtil.setCurrentTime(now); } }
@Test public void testRetryMixConfiguration() throws ParseException { // given BpmnModelInstance bpmnModelInstance = prepareProcessFailingServiceTaskWithRetryCycle("R3/PT1M"); testRule.deploy(bpmnModelInstance); ClockUtil.setCurrentTime(SIMPLE_DATE_FORMAT.parse("2017-01-01T09:55:00")); ProcessInstance pi = runtimeService.startProcessInstanceByKey(PROCESS_ID); assertNotNull(pi); Date currentTime = SIMPLE_DATE_FORMAT.parse("2017-01-01T10:00:00"); ClockUtil.setCurrentTime(currentTime); String processInstanceId = pi.getProcessInstanceId(); int jobRetries; for (int i = 0; i < 3; i++) { jobRetries = executeJob(processInstanceId); assertEquals(2 - i, jobRetries); currentTime = DateUtils.addMinutes(currentTime, 1); assertLockExpirationTime(currentTime); ClockUtil.setCurrentTime(currentTime); } }
@Test public void testSingleRetryInterval() throws ParseException { // given BpmnModelInstance bpmnModelInstance = prepareProcessFailingServiceTaskWithRetryCycle("PT8M "); testRule.deploy(bpmnModelInstance); ClockUtil.setCurrentTime(SIMPLE_DATE_FORMAT.parse("2017-01-01T09:55:00")); ProcessInstance pi = runtimeService.startProcessInstanceByKey(PROCESS_ID); assertNotNull(pi); Date currentTime = SIMPLE_DATE_FORMAT.parse("2017-01-01T10:00:00"); ClockUtil.setCurrentTime(currentTime); String processInstanceId = pi.getProcessInstanceId(); int jobRetries = executeJob(processInstanceId); assertEquals(1, jobRetries); currentTime = DateUtils.addMinutes(currentTime, 8); assertLockExpirationTime(currentTime); ClockUtil.setCurrentTime(currentTime); jobRetries = executeJob(processInstanceId); assertEquals(0, jobRetries); }