use of org.pac4j.core.credentials.MockCredentials in project pac4j by pac4j.
the class DefaultSecurityLogicTests method testDoubleIndirectClientOneChosen.
@Test
public void testDoubleIndirectClientOneChosen() {
final IndirectClient indirectClient = new MockIndirectClient(NAME, RedirectAction.redirect(PAC4J_URL), new MockCredentials(), new CommonProfile());
final IndirectClient indirectClient2 = new MockIndirectClient(VALUE, RedirectAction.redirect(PAC4J_BASE_URL), new MockCredentials(), new CommonProfile());
config.setClients(new Clients(CALLBACK_URL, indirectClient, indirectClient2));
clients = NAME + "," + VALUE;
context.addRequestParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, VALUE);
call();
assertEquals(302, context.getResponseStatus());
assertEquals(PAC4J_BASE_URL, context.getResponseLocation());
}
use of org.pac4j.core.credentials.MockCredentials 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.credentials.MockCredentials in project pac4j by pac4j.
the class DefaultCallbackLogicTests method testDirectClient.
@Test
public void testDirectClient() {
request.addParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, NAME);
final MockDirectClient directClient = new MockDirectClient(NAME, new MockCredentials(), new CommonProfile());
config.setClients(new Clients(directClient));
TestsHelper.expectException(() -> call(), TechnicalException.class, "unable to find one indirect client for the callback: check the callback URL for a client name parameter or" + " suffix path or ensure that your configuration defaults to one indirect client");
}
use of org.pac4j.core.credentials.MockCredentials in project pac4j by pac4j.
the class DefaultSecurityLogicTests method testAuthorizerThrowsRequiresHttpAction.
@Test
public void testAuthorizerThrowsRequiresHttpAction() {
final CommonProfile profile = new CommonProfile();
final LinkedHashMap<String, CommonProfile> profiles = new LinkedHashMap<>();
profiles.put(NAME, profile);
context.getSessionStore().set(context, Pac4jConstants.USER_PROFILES, profiles);
final IndirectClient indirectClient = new MockIndirectClient(NAME, null, new MockCredentials(), new CommonProfile());
authorizers = NAME;
config.setClients(new Clients(CALLBACK_URL, indirectClient));
config.addAuthorizer(NAME, (context, prof) -> {
throw HttpAction.status(400, context);
});
call();
assertEquals(400, context.getResponseStatus());
assertEquals(0, nbCall);
}
use of org.pac4j.core.credentials.MockCredentials in project pac4j by pac4j.
the class DefaultSecurityLogicTests method testAlreadyAuthenticatedAndAuthorized.
@Test
public void testAlreadyAuthenticatedAndAuthorized() {
final CommonProfile profile = new CommonProfile();
profile.setId(ID);
final LinkedHashMap<String, CommonProfile> profiles = new LinkedHashMap<>();
profiles.put(NAME, profile);
context.getSessionStore().set(context, Pac4jConstants.USER_PROFILES, profiles);
final IndirectClient indirectClient = new MockIndirectClient(NAME, null, new MockCredentials(), new CommonProfile());
authorizers = NAME;
config.setClients(new Clients(CALLBACK_URL, indirectClient));
config.addAuthorizer(NAME, (context, prof) -> ID.equals(((CommonProfile) prof.get(0)).getId()));
call();
assertEquals(-1, context.getResponseStatus());
assertEquals(1, nbCall);
}
Aggregations