List of usage examples for java.time.temporal ChronoUnit MINUTES
ChronoUnit MINUTES
To view the source code for java.time.temporal ChronoUnit MINUTES.
Click Source Link
From source file:org.apache.hadoop.yarn.server.resourcemanager.security.TestHopsworksRMAppSecurityActions.java
@Test public void testGenerateJWT() throws Exception { ApplicationId appId = ApplicationId.newInstance(System.currentTimeMillis(), 1); JWTSecurityHandler.JWTMaterialParameter jwtParam = createJWTParameter(appId); RMAppSecurityActions actor = RMAppSecurityActionsFactory.getInstance().getActor(conf); String jwt = actor.generateJWT(jwtParam); Assert.assertNotNull(jwt);// ww w . ja v a 2 s . c om String[] tokenizedSubject = JWT_SUBJECT.split("__"); JWT decoded = JWTParser.parse(jwt); String subject = decoded.getJWTClaimsSet().getSubject(); Assert.assertEquals(tokenizedSubject[1], subject); // Test generate and fall-back to application submitter appId = ApplicationId.newInstance(System.currentTimeMillis(), 2); jwtParam = new JWTSecurityHandler.JWTMaterialParameter(appId, "dorothy"); jwtParam.setRenewable(false); LocalDateTime now = DateUtils.getNow(); LocalDateTime expiresAt = now.plus(10L, ChronoUnit.MINUTES); jwtParam.setExpirationDate(expiresAt); jwtParam.setValidNotBefore(now); jwtParam.setAudiences(new String[] { "job" }); jwt = actor.generateJWT(jwtParam); decoded = JWTParser.parse(jwt); subject = decoded.getJWTClaimsSet().getSubject(); Assert.assertEquals("dorothy", subject); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"); LocalDateTime nbfFromToken = DateUtils.date2LocalDateTime(decoded.getJWTClaimsSet().getNotBeforeTime()); Assert.assertEquals(now.format(formatter), nbfFromToken.format(formatter)); LocalDateTime expirationFromToken = DateUtils .date2LocalDateTime(decoded.getJWTClaimsSet().getExpirationTime()); Assert.assertEquals(expiresAt.format(formatter), expirationFromToken.format(formatter)); }
From source file:com.simiacryptus.util.Util.java
/** * Cvt temporal unit.//from www . j av a 2 s . c o m * * @param units the units * @return the temporal unit */ @javax.annotation.Nonnull public static TemporalUnit cvt(@javax.annotation.Nonnull final TimeUnit units) { switch (units) { case DAYS: return ChronoUnit.DAYS; case HOURS: return ChronoUnit.HOURS; case MINUTES: return ChronoUnit.MINUTES; case SECONDS: return ChronoUnit.SECONDS; case NANOSECONDS: return ChronoUnit.NANOS; case MICROSECONDS: return ChronoUnit.MICROS; case MILLISECONDS: return ChronoUnit.MILLIS; default: throw new IllegalArgumentException(units.toString()); } }
From source file:net.dv8tion.jda.entities.impl.GuildImpl.java
@Override public boolean checkVerification() { if (api.getSelfInfo().isBot()) return true; if (canSendVerification) return true; switch (verificationLevel) { case HIGH:/*w ww . j a va 2 s .c om*/ if (ChronoUnit.MINUTES.between(getJoinDateForUser(api.getSelfInfo()), OffsetDateTime.now()) < 10) break; case MEDIUM: if (ChronoUnit.MINUTES.between(MiscUtil.getCreationTime(api.getSelfInfo()), OffsetDateTime.now()) < 5) break; case LOW: if (!api.getSelfInfo().isVerified()) break; case NONE: canSendVerification = true; return true; } return false; }
From source file:org.apache.hadoop.yarn.server.resourcemanager.security.TestHopsworksRMAppSecurityActions.java
private JWTSecurityHandler.JWTMaterialParameter createJWTParameter(ApplicationId appId) { return createJWTParameter(appId, 10, ChronoUnit.MINUTES); }
From source file:jenkins.security.apitoken.ApiTokenStatsTest.java
@Test public void testDayDifference() throws Exception { final String ID = UUID.randomUUID().toString(); ApiTokenStats tokenStats = new ApiTokenStats(); tokenStats.setParent(tmp.getRoot()); ApiTokenStats.SingleTokenStats stats = tokenStats.updateUsageForId(ID); assertThat(stats.getNumDaysUse(), lessThan(1L)); Field field = ApiTokenStats.SingleTokenStats.class.getDeclaredField("lastUseDate"); field.setAccessible(true);/*from w w w .j a v a 2 s .c om*/ field.set(stats, new Date(new Date().toInstant().minus(2, ChronoUnit.DAYS) // to ensure we have more than 2 days .minus(5, ChronoUnit.MINUTES).toEpochMilli())); assertThat(stats.getNumDaysUse(), greaterThanOrEqualTo(2L)); }
From source file:org.apache.hadoop.yarn.server.resourcemanager.security.TestHopsworksRMAppSecurityActions.java
@Test public void testConfUpdate() throws Exception { LocalDateTime now = LocalDateTime.now(); Date nbf = DateUtils.localDateTime2Date(now); LocalDateTime expiration = now.plus(10, ChronoUnit.MINUTES); Date expirationDate = DateUtils.localDateTime2Date(expiration); JWTClaimsSet masterClaims = new JWTClaimsSet(); masterClaims.setSubject("master_token"); masterClaims.setExpirationTime(expirationDate); masterClaims.setNotBeforeTime(nbf);/* www . jav a2s .c om*/ String newMasterToken = jwtIssuer.generate(masterClaims); Assert.assertNotNull(newMasterToken); String[] newRenewalTokens = new String[5]; JWTClaimsSet renewClaims = new JWTClaimsSet(); renewClaims.setSubject("renew_token"); renewClaims.setExpirationTime(expirationDate); renewClaims.setNotBeforeTime(nbf); for (int i = 0; i < newRenewalTokens.length; i++) { String renewToken = jwtIssuer.generate(renewClaims); Assert.assertNotNull(renewToken); newRenewalTokens[i] = renewToken; } RMAppSecurityActions actor = new TestingHopsworksActions(newMasterToken, expirationDate, newRenewalTokens); ((Configurable) actor).setConf(conf); actor.init(); TimeUnit.MILLISECONDS.sleep(500); // Renewal must have happened, check new values in ssl-server Configuration sslConf = new Configuration(); sslConf.addResource(conf.get(SSLFactory.SSL_SERVER_CONF_KEY)); String newMasterTokenConf = sslConf.get(YarnConfiguration.RM_JWT_MASTER_TOKEN, ""); Assert.assertEquals(newMasterToken, newMasterTokenConf); for (int i = 0; i < newRenewalTokens.length; i++) { String confKey = String.format(YarnConfiguration.RM_JWT_RENEW_TOKEN_PATTERN, i); String newRenewalToken = sslConf.get(confKey, ""); Assert.assertEquals(newRenewalTokens[i], newRenewalToken); } DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"); Assert.assertEquals(expiration.format(formatter), ((HopsworksRMAppSecurityActions) actor).getMasterTokenExpiration().format(formatter)); actor.destroy(); }
From source file:org.codice.ddf.catalog.ui.query.monitor.impl.WorkspaceQueryServiceImpl.java
private Date calculateQueryTimeInterval() { return Date.from(Instant.now().minus(queryTimeInterval, ChronoUnit.MINUTES)); }
From source file:net.dv8tion.jda.core.entities.impl.GuildImpl.java
@Override public boolean checkVerification() { if (api.getAccountType() == AccountType.BOT) return true; if (canSendVerification) return true; switch (verificationLevel) { case HIGH:/* www. j a v a2 s. c o m*/ if (ChronoUnit.MINUTES.between(getSelfMember().getJoinDate(), OffsetDateTime.now()) < 10) break; case MEDIUM: if (ChronoUnit.MINUTES.between(MiscUtil.getCreationTime(api.getSelfUser()), OffsetDateTime.now()) < 5) break; case LOW: if (!api.getSelfUser().isVerified()) break; case NONE: canSendVerification = true; return true; } return false; }
From source file:org.apache.hadoop.yarn.server.resourcemanager.security.TestHopsworksRMAppSecurityActions.java
@Test public void testServiceJWTRenewalRetry() throws Exception { LocalDateTime expiration = DateUtils.getNow().plus(10, ChronoUnit.MINUTES); Date expirationDate = DateUtils.localDateTime2Date(expiration); JWTClaimsSet claims = new JWTClaimsSet(); claims.setSubject("test"); claims.setExpirationTime(expirationDate); String newMasterToken = jwtIssuer.generate(claims); String[] renewTokens = new String[5]; for (int i = 0; i < renewTokens.length; i++) { renewTokens[i] = jwtIssuer.generate(claims); }//from ww w . j av a 2s .co m RMAppSecurityActions actor = new FailingTestHopsworksActions(newMasterToken, expirationDate, renewTokens); ((Configurable) actor).setConf(conf); actor.init(); int secondsWaited = 0; while (!((FailingTestHopsworksActions) actor).succeedRenewing && secondsWaited++ < 10) { TimeUnit.SECONDS.sleep(1); } // Renewal should intentionally fail but finally it should succeed Assert.assertTrue(((FailingTestHopsworksActions) actor).succeedRenewing); Assert.assertTrue(((FailingTestHopsworksActions) actor).usedOneTimeTokens.size() > 1); actor.destroy(); }
From source file:ws.salient.session.Session.java
public boolean expired(Instant instant) { Instant minsAgo = Instant.now().minus(15, ChronoUnit.MINUTES); return (instant != null && instant.isBefore(minsAgo)); }