Search in sources :

Example 26 with Clients

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

the class DefaultSecurityClientFinderTests method testBlankClientName.

@Test
public void testBlankClientName() {
    final List<Client> currentClients = finder.find(new Clients(), MockWebContext.create(), "  ");
    assertEquals(0, currentClients.size());
}
Also used : Client(org.pac4j.core.client.Client) MockIndirectClient(org.pac4j.core.client.MockIndirectClient) Clients(org.pac4j.core.client.Clients) Test(org.junit.Test)

Example 27 with Clients

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

the class DefaultSecurityClientFinderTests method testOneClientAsDefault.

@Test
public void testOneClientAsDefault() {
    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(), null);
    assertEquals(1, result.size());
    assertEquals(client1, 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 28 with Clients

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

the class DefaultSecurityClientFinderTests method internalTestClientOnRequestAllowedList.

private void internalTestClientOnRequestAllowedList(final String parameterName, final String names) {
    final MockIndirectClient client = new MockIndirectClient(NAME, RedirectAction.redirect(LOGIN_URL), (Credentials) null, new CommonProfile());
    final Clients clients = new Clients(client);
    final WebContext context = MockWebContext.create().addRequestParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, parameterName);
    final List<Client> currentClients = finder.find(clients, context, names);
    assertEquals(1, currentClients.size());
    assertEquals(client, 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)

Example 29 with Clients

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

the class DefaultSecurityClientFinderTests method testBadClientOnRequest.

@Test
public void testBadClientOnRequest() {
    final MockIndirectClient client = new MockIndirectClient(NAME, RedirectAction.redirect(LOGIN_URL), (Credentials) null, new CommonProfile());
    final Clients clients = new Clients(client);
    final WebContext context = MockWebContext.create().addRequestParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, FAKE_VALUE);
    TestsHelper.expectException(() -> finder.find(clients, context, NAME), 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 30 with Clients

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

the class DefaultCallbackLogicTests method testCallbackWithOriginallyRequestedUrl.

@Test
public void testCallbackWithOriginallyRequestedUrl() {
    HttpSession session = request.getSession();
    final String originalSessionId = session.getId();
    session.setAttribute(Pac4jConstants.REQUESTED_URL, PAC4J_URL);
    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));
    config.getClients().init();
    call();
    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());
    assertNotEquals(newSessionId, originalSessionId);
    assertEquals(302, response.getStatus());
    assertEquals(PAC4J_URL, 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)

Aggregations

Clients (org.pac4j.core.client.Clients)33 Test (org.junit.Test)19 CommonProfile (org.pac4j.core.profile.CommonProfile)19 MockIndirectClient (org.pac4j.core.client.MockIndirectClient)16 Client (org.pac4j.core.client.Client)13 WebContext (org.pac4j.core.context.WebContext)10 MockWebContext (org.pac4j.core.context.MockWebContext)7 FacebookClient (org.pac4j.oauth.client.FacebookClient)6 Credentials (org.pac4j.core.credentials.Credentials)5 IndirectClient (org.pac4j.core.client.IndirectClient)4 MockCredentials (org.pac4j.core.credentials.MockCredentials)4 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)4 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)4 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 HttpSession (javax.servlet.http.HttpSession)3 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)3 BaseClient (org.pac4j.core.client.BaseClient)3 Config (org.pac4j.core.config.Config)3