Search in sources :

Example 6 with FacebookProfile

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

the class JwtTests method testPlainJwtExpired.

@Test
public void testPlainJwtExpired() {
    final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>();
    Map<String, Object> claims = new HashMap<>();
    claims.put(JwtClaims.SUBJECT, ID);
    claims.put(JwtClaims.EXPIRATION_TIME, yesterday());
    final String token = generator.generate(claims);
    JwtAuthenticator authenticator = new JwtAuthenticator();
    assertNull(authenticator.validateToken(token));
}
Also used : JwtGenerator(org.pac4j.jwt.profile.JwtGenerator) JwtAuthenticator(org.pac4j.jwt.credentials.authenticator.JwtAuthenticator) FacebookProfile(org.pac4j.oauth.profile.facebook.FacebookProfile) Test(org.junit.Test)

Example 7 with FacebookProfile

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

the class JwtTests method testPlainJwtWithSignatureConfigurations.

@Test(expected = CredentialsException.class)
public void testPlainJwtWithSignatureConfigurations() {
    final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>();
    final FacebookProfile profile = createProfile();
    final String token = generator.generate(profile);
    assertToken(profile, token);
}
Also used : JwtGenerator(org.pac4j.jwt.profile.JwtGenerator) FacebookProfile(org.pac4j.oauth.profile.facebook.FacebookProfile) Test(org.junit.Test)

Example 8 with FacebookProfile

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

the class JwtTests method testGenerateAuthenticateAndEncryptedWithRolesPermissions.

@Test
public void testGenerateAuthenticateAndEncryptedWithRolesPermissions() {
    final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>(new SecretSignatureConfiguration(MAC_SECRET));
    final FacebookProfile profile = createProfile();
    profile.addRoles(ROLES);
    profile.addPermissions(PERMISSIONS);
    final String token = generator.generate(profile);
    final CommonProfile profile2 = assertToken(profile, token);
    assertEquals(ROLES, profile2.getRoles());
    assertEquals(PERMISSIONS, profile2.getPermissions());
}
Also used : JwtGenerator(org.pac4j.jwt.profile.JwtGenerator) CommonProfile(org.pac4j.core.profile.CommonProfile) FacebookProfile(org.pac4j.oauth.profile.facebook.FacebookProfile) SecretSignatureConfiguration(org.pac4j.jwt.config.signature.SecretSignatureConfiguration) Test(org.junit.Test)

Example 9 with FacebookProfile

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

the class JwtTests method testGenerateAuthenticateNotEncrypted.

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

Example 10 with FacebookProfile

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

the class JwtTests method testGenerateAuthenticateSlightlyDifferentSignatureConfiguration.

@Test
public void testGenerateAuthenticateSlightlyDifferentSignatureConfiguration() {
    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(new SecretSignatureConfiguration(MAC_SECRET));
    final Exception e = TestsHelper.expectException(() -> assertToken(profile, token, jwtAuthenticator));
    assertTrue(e.getMessage().startsWith("JWT verification failed"));
}
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)

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