Search in sources :

Example 16 with FacebookProfile

use of org.pac4j.oauth.profile.facebook.FacebookProfile in project pac4j by pac4j.

the class JwtTests method testGenerateAuthenticateDifferentEncryptionConfiguration.

@Test
public void testGenerateAuthenticateDifferentEncryptionConfiguration() {
    final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>();
    generator.setEncryptionConfiguration(new SecretEncryptionConfiguration(KEY2));
    final FacebookProfile profile = createProfile();
    final String token = generator.generate(profile);
    final JwtAuthenticator jwtAuthenticator = new JwtAuthenticator();
    jwtAuthenticator.addEncryptionConfiguration(new SecretEncryptionConfiguration(MAC_SECRET));
    final Exception e = TestsHelper.expectException(() -> assertToken(profile, token, jwtAuthenticator));
    assertTrue(e.getMessage().startsWith("No encryption algorithm found for JWT:"));
}
Also used : JwtGenerator(org.pac4j.jwt.profile.JwtGenerator) JwtAuthenticator(org.pac4j.jwt.credentials.authenticator.JwtAuthenticator) SecretEncryptionConfiguration(org.pac4j.jwt.config.encryption.SecretEncryptionConfiguration) FacebookProfile(org.pac4j.oauth.profile.facebook.FacebookProfile) TechnicalException(org.pac4j.core.exception.TechnicalException) CredentialsException(org.pac4j.core.exception.CredentialsException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Test(org.junit.Test)

Example 17 with FacebookProfile

use of org.pac4j.oauth.profile.facebook.FacebookProfile in project pac4j by pac4j.

the class JwtTests method testGenerateAuthenticateNotSigned.

@Test
public void testGenerateAuthenticateNotSigned() {
    final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>();
    generator.setEncryptionConfiguration(new SecretEncryptionConfiguration(MAC_SECRET));
    final FacebookProfile profile = createProfile();
    final String token = generator.generate(profile);
    assertToken(profile, token);
}
Also used : JwtGenerator(org.pac4j.jwt.profile.JwtGenerator) SecretEncryptionConfiguration(org.pac4j.jwt.config.encryption.SecretEncryptionConfiguration) FacebookProfile(org.pac4j.oauth.profile.facebook.FacebookProfile) Test(org.junit.Test)

Example 18 with FacebookProfile

use of org.pac4j.oauth.profile.facebook.FacebookProfile in project pac4j by pac4j.

the class JwtTests method testGenerateAuthenticateDifferentSignatureConfiguration.

@Test
public void testGenerateAuthenticateDifferentSignatureConfiguration() throws NoSuchAlgorithmException {
    final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>(new SecretSignatureConfiguration(KEY2));
    final FacebookProfile profile = createProfile();
    final String token = generator.generate(profile);
    final JwtAuthenticator jwtAuthenticator = new JwtAuthenticator();
    jwtAuthenticator.addSignatureConfiguration(buildECSignatureConfiguration());
    final Exception e = TestsHelper.expectException(() -> assertToken(profile, token, jwtAuthenticator));
    assertTrue(e.getMessage().startsWith("No signature algorithm found for JWT:"));
}
Also used : JwtGenerator(org.pac4j.jwt.profile.JwtGenerator) JwtAuthenticator(org.pac4j.jwt.credentials.authenticator.JwtAuthenticator) FacebookProfile(org.pac4j.oauth.profile.facebook.FacebookProfile) SecretSignatureConfiguration(org.pac4j.jwt.config.signature.SecretSignatureConfiguration) TechnicalException(org.pac4j.core.exception.TechnicalException) CredentialsException(org.pac4j.core.exception.CredentialsException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Test(org.junit.Test)

Example 19 with FacebookProfile

use of org.pac4j.oauth.profile.facebook.FacebookProfile in project pac4j by pac4j.

the class JwtTests method testGenerateAuthenticateUselessSignatureConfiguration.

@Test
public void testGenerateAuthenticateUselessSignatureConfiguration() {
    final SignatureConfiguration signatureConfiguration = new SecretSignatureConfiguration(KEY2);
    final SignatureConfiguration signatureConfiguration2 = new SecretSignatureConfiguration(MAC_SECRET);
    final EncryptionConfiguration encryptionConfiguration = new SecretEncryptionConfiguration(MAC_SECRET);
    final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>(signatureConfiguration, encryptionConfiguration);
    final FacebookProfile profile = createProfile();
    final String token = generator.generate(profile);
    final JwtAuthenticator jwtAuthenticator = new JwtAuthenticator();
    jwtAuthenticator.addSignatureConfiguration(signatureConfiguration);
    jwtAuthenticator.addSignatureConfiguration(signatureConfiguration2);
    jwtAuthenticator.setEncryptionConfiguration(encryptionConfiguration);
    assertToken(profile, token, jwtAuthenticator);
}
Also used : JwtGenerator(org.pac4j.jwt.profile.JwtGenerator) SecretSignatureConfiguration(org.pac4j.jwt.config.signature.SecretSignatureConfiguration) SignatureConfiguration(org.pac4j.jwt.config.signature.SignatureConfiguration) ECSignatureConfiguration(org.pac4j.jwt.config.signature.ECSignatureConfiguration) SecretEncryptionConfiguration(org.pac4j.jwt.config.encryption.SecretEncryptionConfiguration) EncryptionConfiguration(org.pac4j.jwt.config.encryption.EncryptionConfiguration) JwtAuthenticator(org.pac4j.jwt.credentials.authenticator.JwtAuthenticator) SecretEncryptionConfiguration(org.pac4j.jwt.config.encryption.SecretEncryptionConfiguration) SecretSignatureConfiguration(org.pac4j.jwt.config.signature.SecretSignatureConfiguration) FacebookProfile(org.pac4j.oauth.profile.facebook.FacebookProfile) Test(org.junit.Test)

Example 20 with FacebookProfile

use of org.pac4j.oauth.profile.facebook.FacebookProfile in project pac4j by pac4j.

the class JwtTests method testGenerateAuthenticate.

@Test
public void testGenerateAuthenticate() {
    final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>(new SecretSignatureConfiguration(MAC_SECRET), new SecretEncryptionConfiguration(MAC_SECRET));
    final FacebookProfile profile = createProfile();
    final String token = generator.generate(profile);
    assertToken(profile, token);
}
Also used : JwtGenerator(org.pac4j.jwt.profile.JwtGenerator) SecretEncryptionConfiguration(org.pac4j.jwt.config.encryption.SecretEncryptionConfiguration) FacebookProfile(org.pac4j.oauth.profile.facebook.FacebookProfile) SecretSignatureConfiguration(org.pac4j.jwt.config.signature.SecretSignatureConfiguration) Test(org.junit.Test)

Aggregations

FacebookProfile (org.pac4j.oauth.profile.facebook.FacebookProfile)24 Test (org.junit.Test)19 JwtGenerator (org.pac4j.jwt.profile.JwtGenerator)17 JwtAuthenticator (org.pac4j.jwt.credentials.authenticator.JwtAuthenticator)11 SecretSignatureConfiguration (org.pac4j.jwt.config.signature.SecretSignatureConfiguration)9 SecretEncryptionConfiguration (org.pac4j.jwt.config.encryption.SecretEncryptionConfiguration)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 lombok.val (lombok.val)3 Test (org.junit.jupiter.api.Test)3 CredentialsException (org.pac4j.core.exception.CredentialsException)3 TechnicalException (org.pac4j.core.exception.TechnicalException)3 ECSignatureConfiguration (org.pac4j.jwt.config.signature.ECSignatureConfiguration)3 AuthenticationHandlerExecutionResult (org.apereo.cas.authentication.AuthenticationHandlerExecutionResult)2 Principal (org.apereo.cas.authentication.principal.Principal)2 TokenCredentials (org.pac4j.core.credentials.TokenCredentials)2 CommonProfile (org.pac4j.core.profile.CommonProfile)2 EncryptionConfiguration (org.pac4j.jwt.config.encryption.EncryptionConfiguration)2 SignatureConfiguration (org.pac4j.jwt.config.signature.SignatureConfiguration)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 ClientCredential (org.apereo.cas.authentication.principal.ClientCredential)1