Search in sources :

Example 41 with WebContext

use of org.pac4j.core.context.WebContext in project pac4j by pac4j.

the class DefaultSecurityClientFinderTests method testBadClientOnRequest.

@Test
public void testBadClientOnRequest() {
    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, FAKE_VALUE);
    TestsHelper.expectException(() -> finder.find(clients, context, NAME), TechnicalException.class, "No client found for name: " + FAKE_VALUE);
}
Also used : WebContext(org.pac4j.core.context.WebContext) MockWebContext(org.pac4j.core.context.MockWebContext) MockIndirectClient(org.pac4j.core.client.MockIndirectClient) CommonProfile(org.pac4j.core.profile.CommonProfile) Clients(org.pac4j.core.client.Clients) Test(org.junit.Test)

Example 42 with WebContext

use of org.pac4j.core.context.WebContext in project pac4j by pac4j.

the class CsrfAuthorizerTests method testParameterOkNewName.

@Test
public void testParameterOkNewName() {
    final WebContext context = MockWebContext.create().addRequestParameter(NAME, VALUE).addSessionAttribute(Pac4jConstants.CSRF_TOKEN, VALUE);
    authorizer.setParameterName(NAME);
    Assert.assertTrue(authorizer.isAuthorized(context, null));
}
Also used : WebContext(org.pac4j.core.context.WebContext) MockWebContext(org.pac4j.core.context.MockWebContext) Test(org.junit.Test)

Example 43 with WebContext

use of org.pac4j.core.context.WebContext in project pac4j by pac4j.

the class CsrfAuthorizerTests method testParameterOk.

@Test
public void testParameterOk() {
    final WebContext context = MockWebContext.create().addRequestParameter(Pac4jConstants.CSRF_TOKEN, VALUE).addSessionAttribute(Pac4jConstants.CSRF_TOKEN, VALUE);
    Assert.assertTrue(authorizer.isAuthorized(context, null));
}
Also used : WebContext(org.pac4j.core.context.WebContext) MockWebContext(org.pac4j.core.context.MockWebContext) Test(org.junit.Test)

Example 44 with WebContext

use of org.pac4j.core.context.WebContext in project pac4j by pac4j.

the class CsrfAuthorizerTests method testHeaderOk.

@Test
public void testHeaderOk() {
    final WebContext context = MockWebContext.create().addRequestHeader(Pac4jConstants.CSRF_TOKEN, VALUE).addSessionAttribute(Pac4jConstants.CSRF_TOKEN, VALUE);
    Assert.assertTrue(authorizer.isAuthorized(context, null));
}
Also used : WebContext(org.pac4j.core.context.WebContext) MockWebContext(org.pac4j.core.context.MockWebContext) Test(org.junit.Test)

Example 45 with WebContext

use of org.pac4j.core.context.WebContext in project ddf by codice.

the class OidcTokenValidatorTest method testValidateIdTokensNoNonce.

@Test(expected = OidcValidationException.class)
public void testValidateIdTokensNoNonce() throws Exception {
    WebContext context = getWebContext();
    String stringJwt = getIdTokenBuilder().sign(validAlgorithm);
    JWT jwt = SignedJWT.parse(stringJwt);
    OidcTokenValidator.validateIdTokens(jwt, context, configuration, oidcClient);
}
Also used : WebContext(org.pac4j.core.context.WebContext) PlainJWT(com.nimbusds.jwt.PlainJWT) JWT(com.nimbusds.jwt.JWT) SignedJWT(com.nimbusds.jwt.SignedJWT) Test(org.junit.Test)

Aggregations

WebContext (org.pac4j.core.context.WebContext)58 Test (org.junit.Test)31 MockWebContext (org.pac4j.core.context.MockWebContext)15 Slf4j (lombok.extern.slf4j.Slf4j)11 J2EContext (org.pac4j.core.context.J2EContext)11 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)11 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)11 lombok.val (lombok.val)10 CommonProfile (org.pac4j.core.profile.CommonProfile)10 RedirectAction (org.pac4j.core.redirect.RedirectAction)10 Optional (java.util.Optional)9 Clients (org.pac4j.core.client.Clients)9 SessionStore (org.pac4j.core.context.session.SessionStore)8 JWT (com.nimbusds.jwt.JWT)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 Client (org.pac4j.core.client.Client)7 MockIndirectClient (org.pac4j.core.client.MockIndirectClient)7 UserProfile (org.pac4j.core.profile.UserProfile)7 SignedJWT (com.nimbusds.jwt.SignedJWT)6 StringUtils (org.apache.commons.lang3.StringUtils)6