use of com.nimbusds.jwt.JWTClaimsSet in project hadoop by apache.
the class TestJWTRedirectAuthentictionHandler method getJWT.
protected SignedJWT getJWT(String sub, Date expires, RSAPrivateKey privateKey) throws Exception {
JWTClaimsSet claimsSet = new JWTClaimsSet();
claimsSet.setSubject(sub);
claimsSet.setIssueTime(new Date(new Date().getTime()));
claimsSet.setIssuer("https://c2id.com");
claimsSet.setCustomClaim("scope", "openid");
claimsSet.setExpirationTime(expires);
List<String> aud = new ArrayList<String>();
aud.add("bar");
claimsSet.setAudience("bar");
JWSHeader header = new JWSHeader.Builder(JWSAlgorithm.RS256).build();
SignedJWT signedJWT = new SignedJWT(header, claimsSet);
JWSSigner signer = new RSASSASigner(privateKey);
signedJWT.sign(signer);
return signedJWT;
}
use of com.nimbusds.jwt.JWTClaimsSet in project cas by apereo.
the class JWTTicketGrantingTicketResourceEntityResponseFactoryTests method verifyTicketGrantingTicketAsJwt.
@Test
public void verifyTicketGrantingTicketAsJwt() throws Exception {
final AuthenticationResult result = CoreAuthenticationTestUtils.getAuthenticationResult(authenticationSystemSupport, CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword("casuser"));
final TicketGrantingTicket tgt = centralAuthenticationService.createTicketGrantingTicket(result);
final MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter(TokenConstants.PARAMETER_NAME_TOKEN, Boolean.TRUE.toString());
final ResponseEntity<String> response = ticketGrantingTicketResourceEntityResponseFactory.build(tgt, request);
assertNotNull(response);
assertEquals(HttpStatus.CREATED, response.getStatusCode());
final Object jwt = this.tokenCipherExecutor.decode(response.getBody());
final JWTClaimsSet claims = JWTClaimsSet.parse(jwt.toString());
assertEquals(claims.getSubject(), tgt.getAuthentication().getPrincipal().getId());
}
use of com.nimbusds.jwt.JWTClaimsSet in project cas by apereo.
the class JWTTokenTicketBuilder method buildJwt.
private String buildJwt(final String jwtId, final String audience, final Date issueDate, final String subject, final Date validUntilDate, final Map<String, Object> attributes) {
final JWTClaimsSet.Builder claims = new JWTClaimsSet.Builder().audience(audience).issuer(casSeverPrefix).jwtID(jwtId).issueTime(issueDate).subject(subject);
attributes.forEach(claims::claim);
claims.expirationTime(validUntilDate);
final JWTClaimsSet claimsSet = claims.build();
final JSONObject object = claimsSet.toJSONObject();
final String jwtJson = object.toJSONString();
LOGGER.debug("Generated JWT [{}]", JsonValue.readJSON(jwtJson).toString(Stringify.FORMATTED));
if (tokenCipherExecutor.isEnabled()) {
return tokenCipherExecutor.encode(jwtJson);
}
final String token = new PlainJWT(claimsSet).serialize();
return token;
}
use of com.nimbusds.jwt.JWTClaimsSet in project cas by apereo.
the class JWTTokenTicketBuilderTests method verifyJwtForTicketGrantingTicket.
@Test
public void verifyJwtForTicketGrantingTicket() throws Exception {
final MockTicketGrantingTicket tgt = new MockTicketGrantingTicket("casuser");
final String jwt = tokenTicketBuilder.build(tgt);
assertNotNull(jwt);
final Object result = tokenCipherExecutor.decode(jwt);
final JWTClaimsSet claims = JWTClaimsSet.parse(result.toString());
assertEquals(claims.getSubject(), tgt.getAuthentication().getPrincipal().getId());
}
use of com.nimbusds.jwt.JWTClaimsSet in project cas by apereo.
the class JWTTokenTicketBuilderWithoutEncryptionTests method verifyJwtForServiceTicket.
@Test
public void verifyJwtForServiceTicket() throws Exception {
final String jwt = tokenTicketBuilder.build("ST-123456", CoreAuthenticationTestUtils.getService());
assertNotNull(jwt);
final Object result = tokenCipherExecutor.decode(jwt);
final JWTClaimsSet claims = JWTClaimsSet.parse(result.toString());
assertEquals("casuser", claims.getSubject());
}
Aggregations