use of com.nimbusds.jose.crypto.RSASSASigner in project ORCID-Source by ORCID.
the class OpenIDConnectKeyService method sign.
/**
* Get the private key for signing
*
* @return
* @throws JOSEException
*/
public SignedJWT sign(JWTClaimsSet claims) throws JOSEException {
JWSSigner signer = new RSASSASigner(privateJWK);
JWSHeader.Builder head = new JWSHeader.Builder(defaultAlg);
head.keyID(getDefaultKeyID());
SignedJWT signedJWT = new SignedJWT(head.build(), claims);
signedJWT.sign(signer);
return signedJWT;
/* For HMAC we could do the following. This may be useful for the implicit flow:
ClientDetailsEntity clientEntity = clientDetailsEntityCacheManager.retrieve(authentication.getOAuth2Request().getClientId());
JWSSigner signer = new MACSigner(StringUtils.rightPad(clientEntity.getDecryptedClientSecret(), 32, "#").getBytes());
signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.HS256), claims.build());
signedJWT.sign(signer);
*/
}
use of com.nimbusds.jose.crypto.RSASSASigner in project knox by apache.
the class JWTTokenTest method testTokenSignatureRS512.
@Test
public void testTokenSignatureRS512() throws Exception {
String[] claims = new String[4];
claims[0] = "KNOXSSO";
claims[1] = "john.doe@example.com";
claims[2] = "https://login.example.com";
claims[3] = Long.toString((System.currentTimeMillis() / 1000) + 300);
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((RSAPublicKey) publicKey);
assertTrue(token.verify(verifier));
}
use of com.nimbusds.jose.crypto.RSASSASigner in project pac4j by pac4j.
the class RSASignatureConfiguration method sign.
@Override
public SignedJWT sign(JWTClaimsSet claims) {
init();
CommonHelper.assertNotNull("privateKey", privateKey);
try {
final JWSSigner signer = new RSASSASigner(this.privateKey);
final SignedJWT signedJWT = new SignedJWT(new JWSHeader(algorithm), claims);
signedJWT.sign(signer);
return signedJWT;
} catch (final JOSEException e) {
throw new TechnicalException(e);
}
}
use of com.nimbusds.jose.crypto.RSASSASigner in project ovirt-engine by oVirt.
the class OpenIdUtils method createJWT.
/**
* Create a Java web token and sign with the RSA key. Used by the openid userinfo endpoint to send userinfo back.
*/
public static String createJWT(HttpServletRequest request, SsoSession ssoSession, String clientId) throws JOSEException {
// Create RSA-signer with the private key
JWSSigner signer = new RSASSASigner(keyPair.getPrivate());
SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.RS256), createJWTClaimSet(request, ssoSession, clientId));
signedJWT.sign(signer);
return signedJWT.serialize();
}
use of com.nimbusds.jose.crypto.RSASSASigner in project spring-security by spring-projects.
the class OAuth2ResourceServerBeanDefinitionParserTests method jwtFromIssuer.
private String jwtFromIssuer(String issuer) throws Exception {
Map<String, Object> claims = new HashMap<>();
claims.put(JwtClaimNames.ISS, issuer);
claims.put(JwtClaimNames.SUB, "test-subject");
claims.put("scope", "message:read");
JWSObject jws = new JWSObject(new JWSHeader.Builder(JWSAlgorithm.RS256).keyID("1").build(), new Payload(new JSONObject(claims)));
jws.sign(new RSASSASigner(TestKeys.DEFAULT_PRIVATE_KEY));
return jws.serialize();
}
Aggregations