List of usage examples for org.joda.time LocalDateTime plusYears
public LocalDateTime plusYears(int years)
From source file:org.jtwig.functions.builtin.DateFunctions.java
License:Apache License
private Date modify(String modifyString, LocalDateTime localDateTime) throws FunctionException { LocalDateTime result;//from w ww . j a va2s . co m Matcher matcher = compile(MODIFY_PATTERN).matcher(modifyString); matcher.find(); int signal = 1; if (matcher.group(1).equals("-")) signal = -1; int val = Integer.valueOf(matcher.group(2)) * signal; String type = matcher.group(3).toLowerCase(); if (type.startsWith("day")) result = localDateTime.plusDays(val); else if (type.startsWith("month")) result = localDateTime.plusMonths(val); else if (type.startsWith("year")) result = localDateTime.plusYears(val); else if (type.startsWith("second")) result = localDateTime.plusSeconds(val); else if (type.startsWith("hour")) result = localDateTime.plusHours(val); else if (type.startsWith("minute")) result = localDateTime.plusMinutes(val); else throw new FunctionException("Unknown type " + matcher.group(3)); return result.toDate(); }
From source file:org.xwiki.contrib.oidc.provider.internal.OIDCManager.java
License:Open Source License
/** * Generate an OIDC ID Token.//from ww w. j av a 2 s .co m * * @param clientID the client id * @param userReference the reference of the user * @param nonce the nonce * @param claims the custom fields to return * @return the id token * @throws ParseException when failing to create the id token * @throws MalformedURLException when failing to get issuer * @since 1.3 */ public JWT createdIdToken(ClientID clientID, DocumentReference userReference, Nonce nonce, ClaimsRequest claims) throws ParseException, MalformedURLException { Issuer issuer = getIssuer(); Subject subject = getSubject(userReference); List<Audience> audiences = clientID != null ? Arrays.asList(new Audience(clientID)) : Collections.<Audience>emptyList(); LocalDateTime now = LocalDateTime.now(); LocalDateTime now1year = now.plusYears(1); IDTokenClaimsSet idTokenClaimSet = new IDTokenClaimsSet(issuer, subject, audiences, now1year.toDate(), now.toDate()); idTokenClaimSet.setNonce(nonce); // Add custom claims if (claims != null) { for (Entry claim : claims.getIDTokenClaims()) { switch (claim.getClaimName()) { case OIDCIdToken.CLAIM_XWIKI_INSTANCE_ID: idTokenClaimSet.setClaim(OIDCIdToken.CLAIM_XWIKI_INSTANCE_ID, this.instance.getInstanceId()); break; default: break; } } } // Convert to JWT return new PlainJWT(idTokenClaimSet.toJWTClaimsSet()); }