Search in sources :

Example 1 with MockIndirectClient

use of org.pac4j.core.client.MockIndirectClient in project pac4j by pac4j.

the class DefaultLogoutLogicTests method testCentralLogoutWithRelativeUrl.

@Test
public void testCentralLogoutWithRelativeUrl() {
    final CommonProfile profile = new CommonProfile();
    profile.setClientName(NAME);
    final MockIndirectClient client = new MockIndirectClient(NAME);
    client.setCallbackUrl(PAC4J_BASE_URL);
    client.setLogoutActionBuilder((ctx, p, targetUrl) -> RedirectAction.redirect(CALLBACK_URL + "?p=" + targetUrl));
    config.setClients(new Clients(client));
    profiles.put(NAME, profile);
    addProfilesToContext();
    centralLogout = true;
    context.addRequestParameter(Pac4jConstants.URL, PATH);
    call();
    assertEquals(302, context.getResponseStatus());
    assertEquals(CALLBACK_URL + "?p=null", context.getResponseLocation());
    expectedNProfiles(0);
}
Also used : CommonProfile(org.pac4j.core.profile.CommonProfile) MockIndirectClient(org.pac4j.core.client.MockIndirectClient) Clients(org.pac4j.core.client.Clients) Test(org.junit.Test)

Example 2 with MockIndirectClient

use of org.pac4j.core.client.MockIndirectClient in project pac4j by pac4j.

the class DefaultSecurityClientFinderTests method testBlankClientRequested.

@Test
public void testBlankClientRequested() {
    final MockIndirectClient client1 = new MockIndirectClient(NAME, RedirectAction.redirect(LOGIN_URL), (Credentials) null, new CommonProfile());
    final Clients clients = new Clients(client1);
    final List<Client> result = finder.find(clients, MockWebContext.create(), "");
    assertEquals(0, result.size());
}
Also used : MockIndirectClient(org.pac4j.core.client.MockIndirectClient) CommonProfile(org.pac4j.core.profile.CommonProfile) Clients(org.pac4j.core.client.Clients) Client(org.pac4j.core.client.Client) MockIndirectClient(org.pac4j.core.client.MockIndirectClient) Test(org.junit.Test)

Example 3 with MockIndirectClient

use of org.pac4j.core.client.MockIndirectClient in project pac4j by pac4j.

the class DefaultSecurityClientFinderTests method testDefaultSecurityClients.

@Test
public void testDefaultSecurityClients() {
    final MockIndirectClient client1 = new MockIndirectClient(NAME, RedirectAction.redirect(LOGIN_URL), (Credentials) null, new CommonProfile());
    final MockIndirectClient client2 = new MockIndirectClient(CLIENT_NAME, RedirectAction.redirect(LOGIN_URL), (Credentials) null, new CommonProfile());
    final Clients clients = new Clients(client1, client2);
    clients.setDefaultSecurityClients(CLIENT_NAME);
    final List<Client> result = finder.find(clients, MockWebContext.create(), null);
    assertEquals(1, result.size());
    assertEquals(client2, result.get(0));
}
Also used : MockIndirectClient(org.pac4j.core.client.MockIndirectClient) CommonProfile(org.pac4j.core.profile.CommonProfile) Clients(org.pac4j.core.client.Clients) Client(org.pac4j.core.client.Client) MockIndirectClient(org.pac4j.core.client.MockIndirectClient) Test(org.junit.Test)

Example 4 with MockIndirectClient

use of org.pac4j.core.client.MockIndirectClient in project pac4j by pac4j.

the class DefaultSecurityClientFinderTests method testNoClientOnRequestBadDefaultClient.

@Test
public void testNoClientOnRequestBadDefaultClient() {
    final MockIndirectClient client1 = new MockIndirectClient(NAME, RedirectAction.redirect(LOGIN_URL), (Credentials) null, new CommonProfile());
    final MockIndirectClient client2 = new MockIndirectClient(CLIENT_NAME, RedirectAction.redirect(LOGIN_URL), (Credentials) null, new CommonProfile());
    final Clients clients = new Clients(client1, client2);
    final WebContext context = MockWebContext.create();
    TestsHelper.expectException(() -> finder.find(clients, context, FAKE_VALUE), TechnicalException.class, "No client found for name: " + FAKE_VALUE);
}
Also used : WebContext(org.pac4j.core.context.WebContext) MockWebContext(org.pac4j.core.context.MockWebContext) MockIndirectClient(org.pac4j.core.client.MockIndirectClient) CommonProfile(org.pac4j.core.profile.CommonProfile) Clients(org.pac4j.core.client.Clients) Test(org.junit.Test)

Example 5 with MockIndirectClient

use of org.pac4j.core.client.MockIndirectClient in project pac4j by pac4j.

the class DefaultSecurityClientFinderTests method testNoClientOnRequest.

@Test
public void testNoClientOnRequest() {
    final MockIndirectClient client1 = new MockIndirectClient(NAME, RedirectAction.redirect(LOGIN_URL), (Credentials) null, new CommonProfile());
    final MockIndirectClient client2 = new MockIndirectClient(CLIENT_NAME, RedirectAction.redirect(LOGIN_URL), (Credentials) null, new CommonProfile());
    final Clients clients = new Clients(client1, client2);
    final WebContext context = MockWebContext.create();
    final List<Client> currentClients = finder.find(clients, context, CLIENT_NAME);
    assertEquals(1, currentClients.size());
    assertEquals(client2, currentClients.get(0));
}
Also used : WebContext(org.pac4j.core.context.WebContext) MockWebContext(org.pac4j.core.context.MockWebContext) MockIndirectClient(org.pac4j.core.client.MockIndirectClient) CommonProfile(org.pac4j.core.profile.CommonProfile) Clients(org.pac4j.core.client.Clients) Client(org.pac4j.core.client.Client) MockIndirectClient(org.pac4j.core.client.MockIndirectClient) Test(org.junit.Test)

Aggregations

MockIndirectClient (org.pac4j.core.client.MockIndirectClient)16 CommonProfile (org.pac4j.core.profile.CommonProfile)16 Clients (org.pac4j.core.client.Clients)15 Test (org.junit.Test)14 MockWebContext (org.pac4j.core.context.MockWebContext)7 WebContext (org.pac4j.core.context.WebContext)7 Client (org.pac4j.core.client.Client)6 LinkedHashMap (java.util.LinkedHashMap)3 HttpSession (javax.servlet.http.HttpSession)3 IndirectClient (org.pac4j.core.client.IndirectClient)3 MockCredentials (org.pac4j.core.credentials.MockCredentials)3