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");
}
}
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<>();
}
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);
}
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);
}
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));
}
Aggregations