use of org.pac4j.core.context.WebContext in project pac4j by pac4j.
the class RedirectSAML2ClientTests method testNameIdPolicyFormat.
@Test
public void testNameIdPolicyFormat() {
final SAML2Client client = getClient();
client.getConfiguration().setNameIdPolicyFormat("urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress");
final WebContext context = new J2EContext(new MockHttpServletRequest(), new MockHttpServletResponse());
final RedirectAction action = client.getRedirectAction(context);
final String loc = action.getLocation();
assertTrue(getInflatedAuthnRequest(loc).contains("<saml2p:NameIDPolicy AllowCreate=\"true\" " + "Format=\"urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress\"/></saml2p:AuthnRequest>"));
}
use of org.pac4j.core.context.WebContext in project pac4j by pac4j.
the class RedirectSAML2ClientTests method testAuthnContextClassRef.
@Test
public void testAuthnContextClassRef() {
final SAML2Client client = getClient();
client.getConfiguration().setComparisonType(AuthnContextComparisonTypeEnumeration.EXACT.toString());
client.getConfiguration().setAuthnContextClassRef("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport");
final WebContext context = new J2EContext(new MockHttpServletRequest(), new MockHttpServletResponse());
final RedirectAction action = client.getRedirectAction(context);
final String checkClass = "<saml2p:RequestedAuthnContext Comparison=\"exact\"><saml2:AuthnContextClassRef " + "xmlns:saml2=\"urn:oasis:names:tc:SAML:2.0:assertion\">" + "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml2:AuthnContextClassRef>" + "</saml2p:RequestedAuthnContext>";
assertTrue(getInflatedAuthnRequest(action.getLocation()).contains(checkClass));
}
use of org.pac4j.core.context.WebContext 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.context.WebContext 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));
}
use of org.pac4j.core.context.WebContext in project pac4j by pac4j.
the class DefaultSecurityClientFinderTests method internalTestClientOnRequestAllowedList.
private void internalTestClientOnRequestAllowedList(final String parameterName, final String names) {
final MockIndirectClient client = new MockIndirectClient(NAME, RedirectAction.redirect(LOGIN_URL), (Credentials) null, new CommonProfile());
final Clients clients = new Clients(client);
final WebContext context = MockWebContext.create().addRequestParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, parameterName);
final List<Client> currentClients = finder.find(clients, context, names);
assertEquals(1, currentClients.size());
assertEquals(client, currentClients.get(0));
}
Aggregations