use of com.nimbusds.jose.JWSSigner in project knox by apache.
the class JWKSResourceTest method getTestToken.
private JWT getTestToken(final String algorithm) {
String[] claimArray = new String[6];
claimArray[0] = "KNOXSSO";
claimArray[1] = "joe@example.com";
claimArray[2] = null;
claimArray[3] = null;
claimArray[4] = "E0LDZulQ0XE_otJ5aoQtQu-RnXv8hU-M9U4dD7vDioA";
claimArray[5] = null;
final JWT token = new JWTToken(algorithm, claimArray, Collections.singletonList("aud"), false);
final JWSSigner signer = new RSASSASigner(privateKey, true);
token.sign(signer);
return token;
}
use of com.nimbusds.jose.JWSSigner in project knox by apache.
the class JWTTokenTest method testTokenSignatureRS512.
@Test
public void testTokenSignatureRS512() throws Exception {
String[] claims = new String[6];
claims[0] = "KNOXSSO";
claims[1] = "john.doe@example.com";
claims[2] = "https://login.example.com";
claims[3] = Long.toString((System.currentTimeMillis() / 1000) + 300);
claims[4] = "E0LDZulQ0XE_otJ5aoQtQu-RnXv8hU-M9U4dD7vDioA";
claims[5] = null;
JWT token = new JWTToken(JWSAlgorithm.RS512.getName(), claims);
assertEquals("KNOXSSO", token.getIssuer());
assertEquals("john.doe@example.com", token.getSubject());
assertEquals("https://login.example.com", token.getAudience());
assertTrue(token.getHeader().contains(JWSAlgorithm.RS512.getName()));
// Sign the token
JWSSigner signer = new RSASSASigner(privateKey);
token.sign(signer);
assertTrue(token.getSignaturePayload().length > 0);
// Verify the signature
JWSVerifier verifier = new RSASSAVerifier(publicKey);
assertTrue(token.verify(verifier));
}
use of com.nimbusds.jose.JWSSigner in project ratauth by alfa-laboratory.
the class HS256TokenProcessor method createToken.
@Override
@SneakyThrows
public String createToken(String clientId, String secret, String identifier, Date created, Date expiresIn, Set<String> audience, Set<String> scopes, Collection<String> authContext, String userId, Map<String, Object> userInfo) {
final JWSSigner signer = new MACSigner(Base64.getDecoder().decode(secret));
final List<String> aud = new ArrayList<>(audience);
aud.add(clientId);
// Prepare JWT with claims set
JWTClaimsSet.Builder jwtBuilder = new JWTClaimsSet.Builder().issuer(issuer).subject(userId).expirationTime(expiresIn).audience(aud).claim(SCOPE, scopes).claim(CLIENT_ID, clientId).claim(ACR_VALUES, authContext).jwtID(identifier).issueTime(created);
userInfo.forEach(jwtBuilder::claim);
SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.HS256), jwtBuilder.build());
// Apply the HMAC protection
signedJWT.sign(signer);
// eyJhbGciOiJIUzI1NiJ9.SGVsbG8sIHdvcmxkIQ.onO9Ihudz3WkiauDO2Uhyuz0Y18UASXlSc1eS0NkWyA
return signedJWT.serialize();
}
use of com.nimbusds.jose.JWSSigner in project perry by ca-cwds.
the class JwtService method sign.
private SignedJWT sign(JWTClaimsSet claimsSet) throws JwtException {
try {
JWSSigner signer = new RSASSASigner(keyProvider.getSigningKey());
SignedJWT signedJWT = new SignedJWT(jwsHeader(), claimsSet);
signedJWT.sign(signer);
return signedJWT;
} catch (Exception e) {
throw new JwtException(e);
}
}
use of com.nimbusds.jose.JWSSigner in project carbon-apimgt by wso2.
the class JWTWithRSASignatureImpl method rsaSignAndSerialize.
/**
* {@inheritDoc}
*/
@Override
public String rsaSignAndSerialize(RSAPrivateKey rsaPrivateKey, JWTClaimsSet claimsSet) throws APIManagementException {
if (rsaPrivateKey == null) {
throw new IllegalArgumentException("The private key must not be null");
}
if (claimsSet == null) {
throw new IllegalArgumentException("The JWTClaimsSet must not be null");
}
JWSSigner signer = new RSASSASigner(rsaPrivateKey);
SignedJWT jwt = new SignedJWT(new JWSHeader(JWSAlgorithm.RS256), claimsSet);
try {
jwt.sign(signer);
} catch (JOSEException e) {
throw new APIManagementException("Error signing JWT ", e);
}
return jwt.serialize();
}
Aggregations