Search in sources :

Example 16 with SecretEncryptionConfiguration

use of org.pac4j.jwt.config.encryption.SecretEncryptionConfiguration in project cas by apereo.

the class TokenAuthenticationActionTests method verifyAction.

@Test
public void verifyAction() throws Exception {
    val g = new JwtGenerator();
    g.setSignatureConfiguration(new SecretSignatureConfiguration(SIGNING_SECRET, JWSAlgorithm.HS256));
    g.setEncryptionConfiguration(new SecretEncryptionConfiguration(ENCRYPTION_SECRET, JWEAlgorithm.DIR, EncryptionMethod.A192CBC_HS384));
    val profile = new CommonProfile();
    profile.setId("casuser");
    profile.addAttribute("uid", "uid");
    profile.addAttribute("givenName", "CASUser");
    profile.addAttribute("memberOf", CollectionUtils.wrapSet("system", "cas", "admin"));
    val token = g.generate(profile);
    val request = new MockHttpServletRequest();
    request.addHeader(TokenConstants.PARAMETER_NAME_TOKEN, token);
    val context = new MockRequestContext();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService("https://example.token.org"));
    assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, this.action.getObject().execute(context).getId());
}
Also used : lombok.val(lombok.val) JwtGenerator(org.pac4j.jwt.profile.JwtGenerator) CommonProfile(org.pac4j.core.profile.CommonProfile) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) SecretEncryptionConfiguration(org.pac4j.jwt.config.encryption.SecretEncryptionConfiguration) MockRequestContext(org.springframework.webflow.test.MockRequestContext) SecretSignatureConfiguration(org.pac4j.jwt.config.signature.SecretSignatureConfiguration) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

SecretEncryptionConfiguration (org.pac4j.jwt.config.encryption.SecretEncryptionConfiguration)16 Test (org.junit.Test)11 SecretSignatureConfiguration (org.pac4j.jwt.config.signature.SecretSignatureConfiguration)11 JwtGenerator (org.pac4j.jwt.profile.JwtGenerator)11 JwtAuthenticator (org.pac4j.jwt.credentials.authenticator.JwtAuthenticator)7 FacebookProfile (org.pac4j.oauth.profile.facebook.FacebookProfile)6 lombok.val (lombok.val)4 CommonProfile (org.pac4j.core.profile.CommonProfile)4 TokenCredentials (org.pac4j.core.credentials.TokenCredentials)3 EncryptionMethod (com.nimbusds.jose.EncryptionMethod)2 JWEAlgorithm (com.nimbusds.jose.JWEAlgorithm)2 Test (org.junit.jupiter.api.Test)2 EncryptionConfiguration (org.pac4j.jwt.config.encryption.EncryptionConfiguration)2 ECSignatureConfiguration (org.pac4j.jwt.config.signature.ECSignatureConfiguration)2 SignatureConfiguration (org.pac4j.jwt.config.signature.SignatureConfiguration)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 HashSet (java.util.HashSet)1 CredentialsException (org.pac4j.core.exception.CredentialsException)1 TechnicalException (org.pac4j.core.exception.TechnicalException)1