use of org.pac4j.core.credentials.MockCredentials in project pac4j by pac4j.
the class DefaultSecurityLogicTests method testDoubleDirectClientChooseDirectClient.
@Test
public void testDoubleDirectClientChooseDirectClient() {
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;
context.addRequestParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, 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(1, profiles.size());
assertTrue(profiles.containsValue(profile2));
}
use of org.pac4j.core.credentials.MockCredentials in project pac4j by pac4j.
the class DefaultSecurityLogicTests method testDoubleIndirectClientBadOneChosen.
@Test
public void testDoubleIndirectClientBadOneChosen() {
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;
context.addRequestParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, VALUE);
TestsHelper.expectException(() -> call(), TechnicalException.class, "Client not allowed: " + VALUE);
}
use of org.pac4j.core.credentials.MockCredentials in project pac4j by pac4j.
the class DefaultSecurityLogicTests method testNotAuthenticated.
@Test
public void testNotAuthenticated() {
final IndirectClient indirectClient = new MockIndirectClient(NAME, null, new MockCredentials(), new CommonProfile());
config.setClients(new Clients(CALLBACK_URL, indirectClient));
clients = "";
call();
assertEquals(401, context.getResponseStatus());
}
use of org.pac4j.core.credentials.MockCredentials in project pac4j by pac4j.
the class DefaultSecurityLogicTests method testDoubleDirectClientChooseBadDirectClient.
@Test
public void testDoubleDirectClientChooseBadDirectClient() {
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;
context.addRequestParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, VALUE);
multiProfile = true;
TestsHelper.expectException(() -> call(), TechnicalException.class, "Client not allowed: " + VALUE);
}
use of org.pac4j.core.credentials.MockCredentials in project pac4j by pac4j.
the class DefaultSecurityLogicTests method testNotAuthenticatedButMatcher.
@Test
public void testNotAuthenticatedButMatcher() {
final IndirectClient indirectClient = new MockIndirectClient(NAME, null, new MockCredentials(), new CommonProfile());
config.setClients(new Clients(CALLBACK_URL, indirectClient));
config.addMatcher(NAME, context -> false);
matchers = NAME;
call();
assertEquals(-1, context.getResponseStatus());
assertEquals(1, nbCall);
}
Aggregations