Search in sources :

Example 6 with MockIndirectClient

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

the class DefaultSecurityClientFinderTests method testClientOnRequestNotAllowedList.

@Test
public void testClientOnRequestNotAllowedList() {
    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().addRequestParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, NAME);
    TestsHelper.expectException(() -> finder.find(clients, context, CLIENT_NAME + "," + FAKE_VALUE), TechnicalException.class, "Client not allowed: " + NAME);
}
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 7 with MockIndirectClient

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

the class DefaultCallbackLogicTests method testCallbackNoRenew.

@Test
public void testCallbackNoRenew() {
    final String originalSessionId = request.getSession().getId();
    request.setParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, NAME);
    final CommonProfile profile = new CommonProfile();
    final IndirectClient indirectClient = new MockIndirectClient(NAME, null, new MockCredentials(), profile);
    config.setClients(new Clients(CALLBACK_URL, indirectClient));
    renewSession = false;
    config.getClients().init();
    call();
    final HttpSession session = request.getSession();
    final String newSessionId = session.getId();
    final LinkedHashMap<String, CommonProfile> profiles = (LinkedHashMap<String, CommonProfile>) session.getAttribute(Pac4jConstants.USER_PROFILES);
    assertTrue(profiles.containsValue(profile));
    assertEquals(1, profiles.size());
    assertEquals(newSessionId, originalSessionId);
    assertEquals(302, response.getStatus());
    assertEquals(Pac4jConstants.DEFAULT_URL_VALUE, response.getRedirectedUrl());
}
Also used : CommonProfile(org.pac4j.core.profile.CommonProfile) MockIndirectClient(org.pac4j.core.client.MockIndirectClient) MockCredentials(org.pac4j.core.credentials.MockCredentials) HttpSession(javax.servlet.http.HttpSession) MockIndirectClient(org.pac4j.core.client.MockIndirectClient) IndirectClient(org.pac4j.core.client.IndirectClient) Clients(org.pac4j.core.client.Clients) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 8 with MockIndirectClient

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

the class DefaultLogoutLogicTests method testCentralLogout.

@Test
public void testCentralLogout() {
    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, CALLBACK_URL);
    logoutUrlPattern = ".*";
    call();
    assertEquals(302, context.getResponseStatus());
    assertEquals(CALLBACK_URL + "?p=" + CALLBACK_URL, 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 9 with MockIndirectClient

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

the class DefaultSecurityClientFinderTests method testClientOnRequestNotAllowed.

@Test
public void testClientOnRequestNotAllowed() {
    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().addRequestParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, NAME);
    TestsHelper.expectException(() -> finder.find(clients, context, CLIENT_NAME), TechnicalException.class, "Client not allowed: " + NAME);
}
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 10 with MockIndirectClient

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

the class DefaultSecurityClientFinderTests method internalTestNoClientOnRequestList.

private void internalTestNoClientOnRequestList(final String names) {
    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, names);
    assertEquals(2, currentClients.size());
    assertEquals(client2, currentClients.get(0));
    assertEquals(client1, currentClients.get(1));
}
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)

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