Search in sources :

Example 96 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class IndirectBasicAuthClientTests method testRedirectionUrl.

@Test
public void testRedirectionUrl() {
    final var basicAuthClient = getBasicAuthClient();
    var context = MockWebContext.create();
    final var action = (FoundAction) basicAuthClient.getRedirectionAction(context, new MockSessionStore()).get();
    assertEquals(CALLBACK_URL + "?" + Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER + "=" + basicAuthClient.getName(), action.getLocation());
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) FoundAction(org.pac4j.core.exception.http.FoundAction) Test(org.junit.Test)

Example 97 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class RestAuthenticatorIT method testProfileOk.

@Test
public void testProfileOk() {
    final var authenticator = new RestAuthenticator("http://localhost:" + PORT + "?r=ok");
    final var credentials = new UsernamePasswordCredentials(GOOD_USERNAME, PASSWORD);
    authenticator.validate(credentials, MockWebContext.create(), new MockSessionStore());
    final var profile = (RestProfile) credentials.getUserProfile();
    assertNotNull(profile);
    assertEquals(ID, profile.getId());
    assertEquals(1, profile.getRoles().size());
    assertEquals(ROLE, profile.getRoles().iterator().next());
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) RestProfile(org.pac4j.http.profile.RestProfile) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) Test(org.junit.Test)

Example 98 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class RestAuthenticatorIT method testHttps.

@Test
public void testHttps() {
    final var authenticator = new RestAuthenticator("https://www.google.com");
    final var credentials = new UsernamePasswordCredentials(GOOD_USERNAME, PASSWORD);
    authenticator.validate(credentials, MockWebContext.create(), new MockSessionStore());
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) Test(org.junit.Test)

Example 99 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class RestAuthenticatorIT method testNotFound.

@Test
public void testNotFound() {
    final var authenticator = new RestAuthenticator("http://localhost:" + PORT + "?r=notfound");
    final var credentials = new UsernamePasswordCredentials(GOOD_USERNAME, PASSWORD);
    authenticator.validate(credentials, MockWebContext.create(), new MockSessionStore());
    final var profile = (RestProfile) credentials.getUserProfile();
    assertNull(profile);
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) RestProfile(org.pac4j.http.profile.RestProfile) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) Test(org.junit.Test)

Example 100 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class IpExtractorTests method testRetrieveIpFromHeaderWithProxyIpCheck.

@Test
public void testRetrieveIpFromHeaderWithProxyIpCheck() {
    final var context = MockWebContext.create().addRequestHeader(HEADER_NAME, GOOD_IP).setRemoteAddress(LOCALHOST);
    final var ipExtractor = new IpExtractor();
    ipExtractor.setProxyIp(LOCALHOST);
    // test for varargs
    ipExtractor.setAlternateIpHeaders("fooBar", HEADER_NAME, "barFoo");
    final var credentials = (TokenCredentials) ipExtractor.extract(context, new MockSessionStore()).get();
    assertEquals(GOOD_IP, credentials.getToken());
    // test for edge case of 1 header
    ipExtractor.setAlternateIpHeaders(HEADER_NAME);
    final var credentials2 = (TokenCredentials) ipExtractor.extract(context, new MockSessionStore()).get();
    assertEquals(GOOD_IP, credentials2.getToken());
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) TokenCredentials(org.pac4j.core.credentials.TokenCredentials) Test(org.junit.Test)

Aggregations

MockSessionStore (org.pac4j.core.context.session.MockSessionStore)164 Test (org.junit.Test)151 FoundAction (org.pac4j.core.exception.http.FoundAction)29 SessionStore (org.pac4j.core.context.session.SessionStore)22 CommonProfile (org.pac4j.core.profile.CommonProfile)20 TokenCredentials (org.pac4j.core.credentials.TokenCredentials)19 UsernamePasswordCredentials (org.pac4j.core.credentials.UsernamePasswordCredentials)17 MockWebContext (org.pac4j.core.context.MockWebContext)15 WebContext (org.pac4j.core.context.WebContext)15 CasConfiguration (org.pac4j.cas.config.CasConfiguration)14 HttpAction (org.pac4j.core.exception.http.HttpAction)12 SimpleTestTokenAuthenticator (org.pac4j.http.credentials.authenticator.test.SimpleTestTokenAuthenticator)11 AnonymousProfile (org.pac4j.core.profile.AnonymousProfile)9 SimpleTestUsernamePasswordAuthenticator (org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator)7 CasProfile (org.pac4j.cas.profile.CasProfile)6 HashMap (java.util.HashMap)5 Authorizer (org.pac4j.core.authorization.authorizer.Authorizer)5 RequireAnyRoleAuthorizer (org.pac4j.core.authorization.authorizer.RequireAnyRoleAuthorizer)5 OkAction (org.pac4j.core.exception.http.OkAction)5 URL (java.net.URL)4