Search in sources :

Example 21 with Clients

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

the class DefaultCallbackLogic method renewSession.

protected void renewSession(final C context, final Config config) {
    final SessionStore<C> sessionStore = context.getSessionStore();
    if (sessionStore != null) {
        final String oldSessionId = sessionStore.getOrCreateSessionId(context);
        final boolean renewed = sessionStore.renewSession(context);
        if (renewed) {
            final String newSessionId = sessionStore.getOrCreateSessionId(context);
            logger.debug("Renewing session: {} -> {}", oldSessionId, newSessionId);
            final Clients clients = config.getClients();
            if (clients != null) {
                final List<Client> clientList = clients.getClients();
                for (final Client client : clientList) {
                    final BaseClient baseClient = (BaseClient) client;
                    baseClient.notifySessionRenewal(oldSessionId, context);
                }
            }
        } else {
            logger.error("Unable to renew the session. The session store may not support this feature");
        }
    } else {
        logger.error("No session store available for this web context");
    }
}
Also used : Clients(org.pac4j.core.client.Clients) BaseClient(org.pac4j.core.client.BaseClient) Client(org.pac4j.core.client.Client) BaseClient(org.pac4j.core.client.BaseClient)

Example 22 with Clients

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

the class DefaultLogoutLogicTests method setUp.

@Before
public void setUp() {
    logic = new DefaultLogoutLogic<>();
    context = MockWebContext.create();
    config = new Config();
    config.setClients(new Clients());
    httpActionAdapter = (code, ctx) -> null;
    defaultUrl = null;
    logoutUrlPattern = null;
    localLogout = null;
    centralLogout = null;
    profiles = new LinkedHashMap<>();
}
Also used : Config(org.pac4j.core.config.Config) Clients(org.pac4j.core.client.Clients) Before(org.junit.Before)

Example 23 with Clients

use of org.pac4j.core.client.Clients 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 24 with Clients

use of org.pac4j.core.client.Clients 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 25 with Clients

use of org.pac4j.core.client.Clients 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

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