Search in sources :

Example 76 with MockSessionStore

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

the class RedirectSAML2ClientTests method testSetComparisonTypeWithRedirectBinding.

@Test
public void testSetComparisonTypeWithRedirectBinding() {
    final var client = getClient();
    client.getConfiguration().setComparisonType(AuthnContextComparisonTypeEnumeration.EXACT.toString());
    final var action = (FoundAction) client.getRedirectionAction(MockWebContext.create(), new MockSessionStore()).get();
    assertTrue(getInflatedAuthnRequest(action.getLocation()).contains("Comparison=\"exact\""));
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) FoundAction(org.pac4j.core.exception.http.FoundAction) Test(org.junit.Test)

Example 77 with MockSessionStore

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

the class RedirectSAML2ClientTests method testCustomSpEntityIdForRedirectBinding.

@Test
public void testCustomSpEntityIdForRedirectBinding() {
    final var client = getClient();
    client.getConfiguration().setServiceProviderEntityId("http://localhost:8080/callback");
    client.getConfiguration().setUseNameQualifier(true);
    final var action = (FoundAction) client.getRedirectionAction(MockWebContext.create(), new MockSessionStore()).get();
    final var inflated = getInflatedAuthnRequest(action.getLocation());
    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/callback\">http://localhost:8080/callback</saml2:Issuer>";
    assertTrue(inflated.contains(issuerJdk11));
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) FoundAction(org.pac4j.core.exception.http.FoundAction) Test(org.junit.Test)

Example 78 with MockSessionStore

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

the class RedirectSAML2ClientTests method testStandardSpEntityIdForRedirectBinding.

@Test
public void testStandardSpEntityIdForRedirectBinding() {
    final var client = getClient();
    client.getConfiguration().setServiceProviderEntityId("http://localhost:8080/callback");
    final var action = (FoundAction) client.getRedirectionAction(MockWebContext.create(), new MockSessionStore()).get();
    final var inflated = getInflatedAuthnRequest(action.getLocation());
    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\">http://localhost:8080/callback</saml2:Issuer>";
    assertTrue(inflated.contains(issuerJdk11));
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) FoundAction(org.pac4j.core.exception.http.FoundAction) Test(org.junit.Test)

Example 79 with MockSessionStore

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

the class SAML2LogoutValidatorTests method getSaml2MessageContext.

private static SAML2MessageContext getSaml2MessageContext(final MockWebContext webContext, final String xml) {
    final var context = new SAML2MessageContext();
    context.setSaml2Configuration(getSaml2Configuration());
    final var samlMessage = new MessageContext();
    final var samlResponse = (LogoutResponse) Configuration.deserializeSamlObject(xml).get();
    samlMessage.setMessage(samlResponse);
    context.setMessageContext(samlMessage);
    final var entityDescriptor = new EntityDescriptorBuilder().buildObject();
    context.getSAMLPeerMetadataContext().setEntityDescriptor(entityDescriptor);
    context.setWebContext(webContext);
    context.setSessionStore(new MockSessionStore());
    final var spDescriptor = new SPSSODescriptorBuilder().buildObject();
    final var logoutService = new SingleLogoutServiceBuilder().buildObject();
    logoutService.setLocation("http://sp.example.com/demo1/logout");
    spDescriptor.getSingleLogoutServices().add(logoutService);
    context.getSAMLSelfMetadataContext().setRoleDescriptor(spDescriptor);
    return context;
}
Also used : SAML2MessageContext(org.pac4j.saml.context.SAML2MessageContext) MockSessionStore(org.pac4j.core.context.session.MockSessionStore) LogoutResponse(org.opensaml.saml.saml2.core.LogoutResponse) SPSSODescriptorBuilder(org.opensaml.saml.saml2.metadata.impl.SPSSODescriptorBuilder) SingleLogoutServiceBuilder(org.opensaml.saml.saml2.metadata.impl.SingleLogoutServiceBuilder) MessageContext(org.opensaml.messaging.context.MessageContext) SAML2MessageContext(org.pac4j.saml.context.SAML2MessageContext) EntityDescriptorBuilder(org.opensaml.saml.saml2.metadata.impl.EntityDescriptorBuilder)

Example 80 with MockSessionStore

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

the class IpClientTests method testAuthentication.

@Test
public void testAuthentication() {
    final var client = new IpClient(new SimpleTestTokenAuthenticator());
    final var context = MockWebContext.create();
    context.setRemoteAddress(IP);
    final var credentials = (TokenCredentials) client.getCredentials(context, new MockSessionStore()).get();
    final var profile = (CommonProfile) client.getUserProfile(credentials, context, new MockSessionStore()).get();
    assertEquals(IP, profile.getId());
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) CommonProfile(org.pac4j.core.profile.CommonProfile) SimpleTestTokenAuthenticator(org.pac4j.http.credentials.authenticator.test.SimpleTestTokenAuthenticator) TokenCredentials(org.pac4j.core.credentials.TokenCredentials) 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