Search in sources :

Example 6 with SignatureAlgorithm

use of org.springframework.security.oauth2.jose.jws.SignatureAlgorithm in project spring-security by spring-projects.

the class JwtDecoderProviderConfigurationUtilsTests method getSignatureAlgorithmsWhenJwkSetSpecifiesFamilyThenUses.

@Test
public void getSignatureAlgorithmsWhenJwkSetSpecifiesFamilyThenUses() throws Exception {
    JWKSource<SecurityContext> jwkSource = mock(JWKSource.class);
    // Test parameters are from Anders Rundgren, public only
    ECKey ecKey = new ECKey.Builder(Curve.P_256, new Base64URL("3l2Da_flYc-AuUTm2QzxgyvJxYM_2TeB9DMlwz7j1PE"), new Base64URL("-kjT7Wrfhwsi9SG6H4UXiyUiVE9GHCLauslksZ3-_t0")).keyUse(KeyUse.SIGNATURE).build();
    RSAKey rsaKey = new RSAKey.Builder(TestKeys.DEFAULT_PUBLIC_KEY).keyUse(KeyUse.ENCRYPTION).build();
    given(jwkSource.get(any(JWKSelector.class), isNull())).willReturn(Arrays.asList(ecKey, rsaKey));
    Set<SignatureAlgorithm> algorithms = JwtDecoderProviderConfigurationUtils.getSignatureAlgorithms(jwkSource);
    assertThat(algorithms).contains(SignatureAlgorithm.ES256, SignatureAlgorithm.ES384, SignatureAlgorithm.ES512);
}
Also used : JWKSelector(com.nimbusds.jose.jwk.JWKSelector) RSAKey(com.nimbusds.jose.jwk.RSAKey) SecurityContext(com.nimbusds.jose.proc.SecurityContext) ECKey(com.nimbusds.jose.jwk.ECKey) SignatureAlgorithm(org.springframework.security.oauth2.jose.jws.SignatureAlgorithm) Base64URL(com.nimbusds.jose.util.Base64URL) Test(org.junit.jupiter.api.Test)

Example 7 with SignatureAlgorithm

use of org.springframework.security.oauth2.jose.jws.SignatureAlgorithm in project spring-security by spring-projects.

the class JwtDecoderProviderConfigurationUtils method getSignatureAlgorithms.

static Set<SignatureAlgorithm> getSignatureAlgorithms(JWKSource<SecurityContext> jwkSource) {
    Set<JWSAlgorithm> jwsAlgorithms = getJWSAlgorithms(jwkSource);
    Set<SignatureAlgorithm> signatureAlgorithms = new HashSet<>();
    for (JWSAlgorithm jwsAlgorithm : jwsAlgorithms) {
        SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.from(jwsAlgorithm.getName());
        if (signatureAlgorithm != null) {
            signatureAlgorithms.add(signatureAlgorithm);
        }
    }
    return signatureAlgorithms;
}
Also used : SignatureAlgorithm(org.springframework.security.oauth2.jose.jws.SignatureAlgorithm) JWSAlgorithm(com.nimbusds.jose.JWSAlgorithm) HashSet(java.util.HashSet)

Aggregations

SignatureAlgorithm (org.springframework.security.oauth2.jose.jws.SignatureAlgorithm)7 SecurityContext (com.nimbusds.jose.proc.SecurityContext)4 Test (org.junit.jupiter.api.Test)4 JWSAlgorithm (com.nimbusds.jose.JWSAlgorithm)3 JWKSelector (com.nimbusds.jose.jwk.JWKSelector)3 RSAKey (com.nimbusds.jose.jwk.RSAKey)3 OAuth2Error (org.springframework.security.oauth2.core.OAuth2Error)3 MacAlgorithm (org.springframework.security.oauth2.jose.jws.MacAlgorithm)3 SecretKeySpec (javax.crypto.spec.SecretKeySpec)2 OAuth2AuthenticationException (org.springframework.security.oauth2.core.OAuth2AuthenticationException)2 JwsAlgorithm (org.springframework.security.oauth2.jose.jws.JwsAlgorithm)2 Algorithm (com.nimbusds.jose.Algorithm)1 JOSEObjectType (com.nimbusds.jose.JOSEObjectType)1 JWSHeader (com.nimbusds.jose.JWSHeader)1 JWSSigner (com.nimbusds.jose.JWSSigner)1 MACSigner (com.nimbusds.jose.crypto.MACSigner)1 RSASSASigner (com.nimbusds.jose.crypto.RSASSASigner)1 ECKey (com.nimbusds.jose.jwk.ECKey)1 JWKSource (com.nimbusds.jose.jwk.source.JWKSource)1 BadJOSEException (com.nimbusds.jose.proc.BadJOSEException)1