Search in sources :

Example 6 with RsaVerifier

use of org.springframework.security.jwt.crypto.sign.RsaVerifier in project spring-security-oauth by spring-projects.

the class JwtAccessTokenConverterTests method rsaKeyCreatesValidRsaSignedTokens.

@Test
public void rsaKeyCreatesValidRsaSignedTokens() throws Exception {
    String rsaKey = "-----BEGIN RSA PRIVATE KEY-----  \n" + "MIIBywIBAAJhAOTeb4AZ+NwOtPh+ynIgGqa6UWNVe6JyJi+loPmPZdpHtzoqubnC \n" + "wEs6JSiSZ3rButEAw8ymgLV6iBY02hdjsl3h5Z0NWaxx8dzMZfXe4EpfB04ISoqq\n" + "hZCxchvuSDP4eQIDAQABAmEAqUuYsuuDWFRQrZgsbGsvC7G6zn3HLIy/jnM4NiJK\n" + "t0JhWNeN9skGsR7bqb1Sak2uWqW8ZqnqgAC32gxFRYHTavJEk6LTaHWovwDEhPqc\n" + "Zs+vXd6tZojJQ35chR/slUEBAjEA/sAd1oFLWb6PHkaz7r2NllwUBTvXL4VcMWTS\n" + "pN+5cU41i9fsZcHw6yZEl+ZCicDxAjEA5f3R+Bj42htNI7eylebew1+sUnFv1xT8\n" + "jlzxSzwVkoZo+vef7OD6OcFLeInAHzAJAjEAs6izolK+3ETa1CRSwz0lPHQlnmdM\n" + "Y/QuR5tuPt6U/saEVuJpkn4LNRtg5qt6I4JRAjAgFRYTG7irBB/wmZFp47izXEc3\n" + "gOdvA1hvq3tlWU5REDrYt24xpviA0fvrJpwMPbECMAKDKdiDi6Q4/iBkkzNMefA8\n" + "7HX27b9LR33don/1u/yvzMUo+lrRdKAFJ+9GPE9XFA== \n" + "-----END RSA PRIVATE KEY----- ";
    tokenEnhancer.setSigningKey(rsaKey);
    OAuth2Authentication authentication = new OAuth2Authentication(createOAuth2Request("foo", null), userAuthentication);
    OAuth2AccessToken token = tokenEnhancer.enhance(new DefaultOAuth2AccessToken("FOO"), authentication);
    JwtHelper.decodeAndVerify(token.getValue(), new RsaVerifier(rsaKey));
}
Also used : RsaVerifier(org.springframework.security.jwt.crypto.sign.RsaVerifier) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) Test(org.junit.Test)

Example 7 with RsaVerifier

use of org.springframework.security.jwt.crypto.sign.RsaVerifier in project tutorials by eugenp.

the class OpenIdConnectFilter method verifier.

private RsaVerifier verifier(String kid) throws Exception {
    JwkProvider provider = new UrlJwkProvider(new URL(jwkUrl));
    Jwk jwk = provider.get(kid);
    return new RsaVerifier((RSAPublicKey) jwk.getPublicKey());
}
Also used : RsaVerifier(org.springframework.security.jwt.crypto.sign.RsaVerifier) UrlJwkProvider(com.auth0.jwk.UrlJwkProvider) JwkProvider(com.auth0.jwk.JwkProvider) UrlJwkProvider(com.auth0.jwk.UrlJwkProvider) URL(java.net.URL) Jwk(com.auth0.jwk.Jwk)

Aggregations

RsaVerifier (org.springframework.security.jwt.crypto.sign.RsaVerifier)7 Test (org.junit.Test)3 IOException (java.io.IOException)2 MacSigner (org.springframework.security.jwt.crypto.sign.MacSigner)2 RsaSigner (org.springframework.security.jwt.crypto.sign.RsaSigner)2 SignatureVerifier (org.springframework.security.jwt.crypto.sign.SignatureVerifier)2 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)2 InvalidTokenException (org.springframework.security.oauth2.common.exceptions.InvalidTokenException)2 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)2 Jwk (com.auth0.jwk.Jwk)1 JwkProvider (com.auth0.jwk.JwkProvider)1 UrlJwkProvider (com.auth0.jwk.UrlJwkProvider)1 BigInteger (java.math.BigInteger)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 RSAPublicKey (java.security.interfaces.RSAPublicKey)1 RSAPublicKeySpec (java.security.spec.RSAPublicKeySpec)1 HashMap (java.util.HashMap)1 Jwt (org.springframework.security.jwt.Jwt)1 InvalidSignatureException (org.springframework.security.jwt.crypto.sign.InvalidSignatureException)1