Search in sources :

Example 56 with MockSessionStore

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

the class DefaultCasAuthorizationGeneratorTests method testNoAttribute.

@Test
public void testNoAttribute() {
    final AuthorizationGenerator generator = new DefaultCasAuthorizationGenerator();
    final Map<String, Object> attributes = new HashMap<>();
    final var profile = new CasProfile();
    profile.build(ID, attributes);
    generator.generate(null, new MockSessionStore(), profile);
    assertEquals(false, profile.isRemembered());
}
Also used : CasProfile(org.pac4j.cas.profile.CasProfile) MockSessionStore(org.pac4j.core.context.session.MockSessionStore) HashMap(java.util.HashMap) AuthorizationGenerator(org.pac4j.core.authorization.generator.AuthorizationGenerator) Test(org.junit.Test)

Example 57 with MockSessionStore

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

the class CasProxyReceptorTests method testMissingPgt.

@Test
public void testMissingPgt() {
    final var client = new CasProxyReceptor();
    client.setCallbackUrl(CALLBACK_URL);
    final var context = MockWebContext.create();
    final var action = (HttpAction) TestsHelper.expectException(() -> client.getCredentials(context.addRequestParameter(CasProxyReceptor.PARAM_PROXY_GRANTING_TICKET, VALUE), new MockSessionStore()));
    assertEquals(200, action.getCode());
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) HttpAction(org.pac4j.core.exception.http.HttpAction) Test(org.junit.Test)

Example 58 with MockSessionStore

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

the class DirectCasProxyClientTests method testNoTicket.

@Test
public void testNoTicket() {
    final var configuration = new CasConfiguration();
    configuration.setLoginUrl(LOGIN_URL);
    configuration.setProtocol(CasProtocol.CAS20_PROXY);
    final var client = new DirectCasProxyClient(configuration, CALLBACK_URL);
    assertFalse(client.getCredentials(MockWebContext.create(), new MockSessionStore()).isPresent());
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) CasConfiguration(org.pac4j.cas.config.CasConfiguration) Test(org.junit.Test)

Example 59 with MockSessionStore

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

the class X509ClientTests method testOk.

@Test
public void testOk() throws CertificateException {
    final var context = MockWebContext.create();
    final var certificateData = Base64.getDecoder().decode(CERTIFICATE);
    final var cert = (X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(new ByteArrayInputStream(certificateData));
    final var certs = new X509Certificate[1];
    certs[0] = cert;
    context.setRequestAttribute(X509CredentialsExtractor.CERTIFICATE_REQUEST_ATTRIBUTE, certs);
    final var credentials = (X509Credentials) client.getCredentials(context, new MockSessionStore()).get();
    final var profile = (X509Profile) client.getUserProfile(credentials, context, new MockSessionStore()).get();
    assertEquals("jerome", profile.getId());
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) X509Profile(org.pac4j.http.profile.X509Profile) ByteArrayInputStream(java.io.ByteArrayInputStream) X509Certificate(java.security.cert.X509Certificate) X509Credentials(org.pac4j.http.credentials.X509Credentials) Test(org.junit.Test)

Example 60 with MockSessionStore

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

the class IndirectBasicAuthClientTests method verifyGetCredentialsFailsWithAuthenticationRequired.

private void verifyGetCredentialsFailsWithAuthenticationRequired(IndirectBasicAuthClient basicAuthClient, MockWebContext context) {
    try {
        basicAuthClient.getCredentials(context, new MockSessionStore());
        fail("should throw HttpAction");
    } catch (final HttpAction e) {
        assertEquals(401, e.getCode());
        assertEquals("Basic realm=\"authentication required\"", context.getResponseHeaders().get(HttpConstants.AUTHENTICATE_HEADER));
    }
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) HttpAction(org.pac4j.core.exception.http.HttpAction)

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