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