use of org.pac4j.core.credentials.MockCredentials in project pac4j by pac4j.
the class DefaultSecurityLogicTests method testAlreadyAuthenticatedNotAuthorized.
@Test
public void testAlreadyAuthenticatedNotAuthorized() {
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) -> ID.equals(((CommonProfile) prof.get(0)).getId()));
call();
assertEquals(403, context.getResponseStatus());
}
use of org.pac4j.core.credentials.MockCredentials in project pac4j by pac4j.
the class DefaultSecurityLogicTests method testRedirectByIndirectClient.
@Test
public void testRedirectByIndirectClient() {
final IndirectClient indirectClient = new MockIndirectClient(NAME, RedirectAction.redirect(PAC4J_URL), new MockCredentials(), new CommonProfile());
config.setClients(new Clients(CALLBACK_URL, indirectClient));
clients = NAME;
call();
assertEquals(302, context.getResponseStatus());
assertEquals(PAC4J_URL, context.getResponseLocation());
}
use of org.pac4j.core.credentials.MockCredentials in project pac4j by pac4j.
the class DefaultSecurityLogicTests method testDoubleDirectClientSupportingMultiProfile.
@Test
public void testDoubleDirectClientSupportingMultiProfile() {
final CommonProfile profile = new CommonProfile();
profile.setId(NAME);
final CommonProfile profile2 = new CommonProfile();
profile2.setId(VALUE);
final DirectClient directClient = new MockDirectClient(NAME, new MockCredentials(), profile);
final DirectClient directClient2 = new MockDirectClient(VALUE, new MockCredentials(), profile2);
config.setClients(new Clients(CALLBACK_URL, directClient, directClient2));
clients = NAME + "," + VALUE;
multiProfile = true;
call();
assertEquals(-1, context.getResponseStatus());
assertEquals(1, nbCall);
final LinkedHashMap<String, CommonProfile> profiles = (LinkedHashMap<String, CommonProfile>) context.getRequestAttribute(Pac4jConstants.USER_PROFILES);
assertEquals(2, profiles.size());
assertTrue(profiles.containsValue(profile));
assertTrue(profiles.containsValue(profile2));
}
use of org.pac4j.core.credentials.MockCredentials in project pac4j by pac4j.
the class DefaultSecurityLogicTests method testDoubleDirectClient.
@Test
public void testDoubleDirectClient() {
final CommonProfile profile = new CommonProfile();
profile.setId(NAME);
final CommonProfile profile2 = new CommonProfile();
profile2.setId(VALUE);
final DirectClient directClient = new MockDirectClient(NAME, new MockCredentials(), profile);
final DirectClient directClient2 = new MockDirectClient(VALUE, new MockCredentials(), profile2);
config.setClients(new Clients(CALLBACK_URL, directClient, directClient2));
clients = NAME + "," + VALUE;
call();
assertEquals(-1, context.getResponseStatus());
assertEquals(1, nbCall);
final LinkedHashMap<String, CommonProfile> profiles = (LinkedHashMap<String, CommonProfile>) context.getRequestAttribute(Pac4jConstants.USER_PROFILES);
assertEquals(1, profiles.size());
assertTrue(profiles.containsValue(profile));
}
use of org.pac4j.core.credentials.MockCredentials 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());
}
Aggregations