Search in sources :

Example 41 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class ParameterExtractorTests method testRetrievePostParameterOk.

@Test
public void testRetrievePostParameterOk() {
    final var context = MockWebContext.create().setRequestMethod(HttpConstants.HTTP_METHOD.POST.name()).addRequestParameter(GOOD_PARAMETER, VALUE);
    final var credentials = (TokenCredentials) postExtractor.extract(context, new MockSessionStore()).get();
    assertEquals(VALUE, credentials.getToken());
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) TokenCredentials(org.pac4j.core.credentials.TokenCredentials) Test(org.junit.Test)

Example 42 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class PostSAML2ClientTests method testRelayState.

@Test
public void testRelayState() {
    final var client = getClient();
    final WebContext context = MockWebContext.create();
    final SessionStore sessionStore = new MockSessionStore();
    sessionStore.set(context, SAML2StateGenerator.SAML_RELAY_STATE_ATTRIBUTE, "relayState");
    final var action = (OkAction) client.getRedirectionAction(context, sessionStore).get();
    assertTrue(action.getContent().contains("<input type=\"hidden\" name=\"RelayState\" value=\"relayState\"/>"));
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) SessionStore(org.pac4j.core.context.session.SessionStore) WebContext(org.pac4j.core.context.WebContext) MockWebContext(org.pac4j.core.context.MockWebContext) MockSessionStore(org.pac4j.core.context.session.MockSessionStore) OkAction(org.pac4j.core.exception.http.OkAction) Test(org.junit.Test)

Example 43 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class PostSAML2ClientTests method testForceAuthIsSetForPostBinding.

@Test
public void testForceAuthIsSetForPostBinding() {
    final var client = getClient();
    client.getConfiguration().setForceAuth(true);
    final var action = (OkAction) client.getRedirectionAction(MockWebContext.create(), new MockSessionStore()).get();
    assertTrue(getDecodedAuthnRequest(action.getContent()).contains("ForceAuthn=\"true\""));
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) OkAction(org.pac4j.core.exception.http.OkAction) Test(org.junit.Test)

Example 44 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class PostSAML2ClientTests method testCustomSpEntityIdForPostBinding.

@Test
public void testCustomSpEntityIdForPostBinding() {
    final var client = getClient();
    client.getConfiguration().setServiceProviderEntityId("http://localhost:8080/cb");
    client.getConfiguration().setUseNameQualifier(true);
    final var person = new SAML2MetadataContactPerson();
    person.setCompanyName("Pac4j");
    person.setGivenName("Bob");
    person.setSurname("Smith");
    person.setType("technical");
    person.setEmailAddresses(Collections.singletonList("test@example.org"));
    person.setTelephoneNumbers(Collections.singletonList("+13476547689"));
    client.getConfiguration().getContactPersons().add(person);
    final var uiInfo = new SAML2MetadataUIInfo();
    uiInfo.setDescriptions(Collections.singletonList("description1"));
    uiInfo.setDisplayNames(Collections.singletonList("displayName"));
    uiInfo.setPrivacyUrls(Collections.singletonList("https://pac4j.org"));
    uiInfo.setInformationUrls(Collections.singletonList("https://pac4j.org"));
    uiInfo.setKeywords(Collections.singletonList("keyword1,keyword2,keyword3"));
    uiInfo.setLogos(Collections.singletonList(new SAML2MetadataUIInfo.SAML2MetadataUILogo("https://pac4j.org/logo.png", 16, 16)));
    client.getConfiguration().getMetadataUIInfos().add(uiInfo);
    final var action = (OkAction) client.getRedirectionAction(MockWebContext.create(), new MockSessionStore()).get();
    final var issuerJdk11 = "<saml2:Issuer " + "xmlns:saml2=\"urn:oasis:names:tc:SAML:2.0:assertion\" " + "Format=\"urn:oasis:names:tc:SAML:2.0:nameid-format:entity\" " + "NameQualifier=\"http://localhost:8080/cb\">http://localhost:8080/cb</saml2:Issuer>";
    final var decodedAuthnRequest = getDecodedAuthnRequest(action.getContent());
    assertTrue(decodedAuthnRequest.contains(issuerJdk11));
}
Also used : SAML2MetadataContactPerson(org.pac4j.saml.metadata.SAML2MetadataContactPerson) MockSessionStore(org.pac4j.core.context.session.MockSessionStore) SAML2MetadataUIInfo(org.pac4j.saml.metadata.SAML2MetadataUIInfo) OkAction(org.pac4j.core.exception.http.OkAction) Test(org.junit.Test)

Example 45 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class SAML2AuthenticatorTests method verifyAttributeMapping.

@Test
public void verifyAttributeMapping() {
    final var credentials = createCredentialsForTest(true, true);
    final Map<String, String> mappedAttributes = createMappedAttributesForTest();
    final var authenticator = new SAML2Authenticator("username", mappedAttributes);
    authenticator.validate(credentials, MockWebContext.create(), new MockSessionStore());
    final var finalProfile = credentials.getUserProfile();
    assertTrue(finalProfile.containsAttribute("mapped-display-name"));
    assertTrue(finalProfile.containsAttribute("mapped-given-name"));
    assertTrue(finalProfile.containsAttribute("mapped-surname"));
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) Test(org.junit.Test)

Aggregations

MockSessionStore (org.pac4j.core.context.session.MockSessionStore)164 Test (org.junit.Test)151 FoundAction (org.pac4j.core.exception.http.FoundAction)29 SessionStore (org.pac4j.core.context.session.SessionStore)22 CommonProfile (org.pac4j.core.profile.CommonProfile)20 TokenCredentials (org.pac4j.core.credentials.TokenCredentials)19 UsernamePasswordCredentials (org.pac4j.core.credentials.UsernamePasswordCredentials)17 MockWebContext (org.pac4j.core.context.MockWebContext)15 WebContext (org.pac4j.core.context.WebContext)15 CasConfiguration (org.pac4j.cas.config.CasConfiguration)14 HttpAction (org.pac4j.core.exception.http.HttpAction)12 SimpleTestTokenAuthenticator (org.pac4j.http.credentials.authenticator.test.SimpleTestTokenAuthenticator)11 AnonymousProfile (org.pac4j.core.profile.AnonymousProfile)9 SimpleTestUsernamePasswordAuthenticator (org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator)7 CasProfile (org.pac4j.cas.profile.CasProfile)6 HashMap (java.util.HashMap)5 Authorizer (org.pac4j.core.authorization.authorizer.Authorizer)5 RequireAnyRoleAuthorizer (org.pac4j.core.authorization.authorizer.RequireAnyRoleAuthorizer)5 OkAction (org.pac4j.core.exception.http.OkAction)5 URL (java.net.URL)4