use of com.nimbusds.jwt.JWTClaimsSet in project carbon-apimgt by wso2.
the class JWTWithRSASignatureImplTestCase method testRSASignAndSerializeWithNullRSAPrivateKey.
@Test(description = "Test RSA sign and serialize when RSA Private key is null", expectedExceptions = IllegalArgumentException.class)
public void testRSASignAndSerializeWithNullRSAPrivateKey() throws APIManagementException {
JWTWithRSASignatureImpl jwtWithRSASignature = new JWTWithRSASignatureImpl();
JWTClaimsSet jwtClaimsSet = Mockito.mock(JWTClaimsSet.class);
jwtWithRSASignature.rsaSignAndSerialize(null, jwtClaimsSet);
}
use of com.nimbusds.jwt.JWTClaimsSet in project pac4j by pac4j.
the class JwtAuthenticator method createJwtProfile.
@SuppressWarnings("unchecked")
protected void createJwtProfile(final TokenCredentials credentials, final JWT jwt) throws ParseException {
final JWTClaimsSet claimSet = jwt.getJWTClaimsSet();
String subject = claimSet.getSubject();
if (subject == null) {
throw new TechnicalException("JWT must contain a subject ('sub' claim)");
}
final Date expirationTime = claimSet.getExpirationTime();
if (expirationTime != null) {
final Date now = new Date();
if (expirationTime.before(now)) {
logger.error("The JWT is expired: no profile is built");
return;
}
}
final Map<String, Object> attributes = new HashMap<>(claimSet.getClaims());
attributes.remove(JwtClaims.SUBJECT);
final List<String> roles = (List<String>) attributes.get(JwtGenerator.INTERNAL_ROLES);
attributes.remove(JwtGenerator.INTERNAL_ROLES);
final List<String> permissions = (List<String>) attributes.get(JwtGenerator.INTERNAL_PERMISSIONS);
attributes.remove(JwtGenerator.INTERNAL_PERMISSIONS);
final CommonProfile profile = ProfileHelper.restoreOrBuildProfile(getProfileDefinition(), subject, attributes, null);
if (roles != null) {
profile.addRoles(roles);
}
if (permissions != null) {
profile.addPermissions(permissions);
}
credentials.setUserProfile(profile);
}
use of com.nimbusds.jwt.JWTClaimsSet in project pac4j by pac4j.
the class JwtGenerator method buildJwtClaimsSet.
protected JWTClaimsSet buildJwtClaimsSet(final U profile) {
// claims builder with subject and issue time
final JWTClaimsSet.Builder builder = new JWTClaimsSet.Builder().subject(profile.getTypedId()).issueTime(new Date());
// add attributes
final Map<String, Object> attributes = profile.getAttributes();
for (final Map.Entry<String, Object> entry : attributes.entrySet()) {
builder.claim(entry.getKey(), entry.getValue());
}
builder.claim(INTERNAL_ROLES, profile.getRoles());
builder.claim(INTERNAL_PERMISSIONS, profile.getPermissions());
// claims
return builder.build();
}
use of com.nimbusds.jwt.JWTClaimsSet in project pac4j by pac4j.
the class ECSignatureConfigurationTests method testSignVerify.
@Test
public void testSignVerify() throws JOSEException {
final ECSignatureConfiguration config = new ECSignatureConfiguration(buildKeyPair());
final JWTClaimsSet claims = new JWTClaimsSet.Builder().subject(VALUE).build();
final SignedJWT signedJwt = config.sign(claims);
assertTrue(config.verify(signedJwt));
}
use of com.nimbusds.jwt.JWTClaimsSet in project pac4j by pac4j.
the class RSASignatureConfigurationTests method testSignVerify.
@Test
public void testSignVerify() throws JOSEException {
final RSASignatureConfiguration config = new RSASignatureConfiguration(buildKeyPair());
final JWTClaimsSet claims = new JWTClaimsSet.Builder().subject(VALUE).build();
final SignedJWT signedJwt = config.sign(claims);
assertTrue(config.verify(signedJwt));
}
Aggregations