Search in sources :

Example 1 with StaticValueGenerator

use of org.pac4j.core.util.generator.StaticValueGenerator in project pac4j by pac4j.

the class JwtTests method testPlainJwtNoSubjectButIdentifierGenerator.

@Test
public void testPlainJwtNoSubjectButIdentifierGenerator() {
    final var generator = new JwtGenerator();
    final var token = generator.generate(new HashMap<>());
    var authenticator = new JwtAuthenticator();
    authenticator.setIdentifierGenerator(new StaticValueGenerator(VALUE));
    final var profile = authenticator.validateToken(token);
    assertEquals(VALUE, profile.getId());
}
Also used : JwtGenerator(org.pac4j.jwt.profile.JwtGenerator) JwtAuthenticator(org.pac4j.jwt.credentials.authenticator.JwtAuthenticator) StaticValueGenerator(org.pac4j.core.util.generator.StaticValueGenerator) Test(org.junit.Test)

Example 2 with StaticValueGenerator

use of org.pac4j.core.util.generator.StaticValueGenerator in project pac4j by pac4j.

the class OAuth20ClientTests method testSetState.

@Test
public void testSetState() throws MalformedURLException {
    var client = new FacebookClient(KEY, SECRET);
    client.setCallbackUrl(CALLBACK_URL);
    client.getConfiguration().setStateGenerator(new StaticValueGenerator("oldstate"));
    final var mockWebContext = MockWebContext.create();
    var action = (FoundAction) client.getRedirectionAction(mockWebContext, new MockSessionStore()).get();
    var url = new URL(action.getLocation());
    final var stringMap = TestsHelper.splitQuery(url);
    assertEquals(stringMap.get("state"), "oldstate");
    action = (FoundAction) client.getRedirectionAction(mockWebContext, new MockSessionStore()).get();
    var url2 = new URL(action.getLocation());
    final var stringMap2 = TestsHelper.splitQuery(url2);
    assertEquals(stringMap2.get("state"), "oldstate");
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) FoundAction(org.pac4j.core.exception.http.FoundAction) URL(java.net.URL) StaticValueGenerator(org.pac4j.core.util.generator.StaticValueGenerator) Test(org.junit.Test)

Example 3 with StaticValueGenerator

use of org.pac4j.core.util.generator.StaticValueGenerator in project pac4j by pac4j.

the class OAuth20ClientTests method testState.

@Test
public void testState() throws MalformedURLException {
    var client = new FacebookClient(KEY, SECRET);
    client.setCallbackUrl(CALLBACK_URL);
    client.getConfiguration().setStateGenerator(new StaticValueGenerator("OK"));
    final var action = (FoundAction) client.getRedirectionAction(MockWebContext.create(), new MockSessionStore()).get();
    var url = new URL(action.getLocation());
    assertTrue(url.getQuery().contains("state=OK"));
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) FoundAction(org.pac4j.core.exception.http.FoundAction) URL(java.net.URL) StaticValueGenerator(org.pac4j.core.util.generator.StaticValueGenerator) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 StaticValueGenerator (org.pac4j.core.util.generator.StaticValueGenerator)3 URL (java.net.URL)2 MockSessionStore (org.pac4j.core.context.session.MockSessionStore)2 FoundAction (org.pac4j.core.exception.http.FoundAction)2 JwtAuthenticator (org.pac4j.jwt.credentials.authenticator.JwtAuthenticator)1 JwtGenerator (org.pac4j.jwt.profile.JwtGenerator)1