Search in sources :

Example 21 with JEEContext

use of org.pac4j.core.context.JEEContext in project cas by apereo.

the class OidcConsentApprovalViewResolverTests method verifyBypassedBySession.

@Test
public void verifyBypassedBySession() throws Exception {
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val context = new JEEContext(request, response);
    JEESessionStore.INSTANCE.set(context, OAuth20Constants.BYPASS_APPROVAL_PROMPT, "true");
    val service = getOAuthRegisteredService(UUID.randomUUID().toString(), "https://google.com");
    assertFalse(consentApprovalViewResolver.resolve(context, service).hasView());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) JEEContext(org.pac4j.core.context.JEEContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 22 with JEEContext

use of org.pac4j.core.context.JEEContext in project cas by apereo.

the class OidcConsentApprovalViewResolverTests method verifyBypassedByPrompt.

@Test
public void verifyBypassedByPrompt() throws Exception {
    val request = new MockHttpServletRequest();
    request.setRequestURI("https://cas.org/something");
    request.setQueryString(OidcConstants.PROMPT + '=' + OidcConstants.PROMPT_CONSENT);
    val response = new MockHttpServletResponse();
    val context = new JEEContext(request, response);
    val service = getOidcRegisteredService(UUID.randomUUID().toString());
    val mv = consentApprovalViewResolver.resolve(context, service);
    assertTrue(mv.hasView());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) JEEContext(org.pac4j.core.context.JEEContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 23 with JEEContext

use of org.pac4j.core.context.JEEContext in project cas by apereo.

the class OidcPushedAuthorizationRequestValidatorTests method verifyOperation.

@Test
public void verifyOperation() throws Exception {
    val registeredService = getOidcRegisteredService();
    val profile = new CommonProfile();
    profile.setId("casTest");
    val holder = AccessTokenRequestContext.builder().clientId(registeredService.getClientId()).service(RegisteredServiceTestUtils.getService()).authentication(RegisteredServiceTestUtils.getAuthentication()).registeredService(registeredService).grantType(OAuth20GrantTypes.AUTHORIZATION_CODE).responseType(OAuth20ResponseTypes.CODE).userProfile(profile).build();
    val factory = (OidcPushedAuthorizationRequestFactory) defaultTicketFactory.get(OidcPushedAuthorizationRequest.class);
    val ticket = factory.create(holder);
    assertNotNull(ticket);
    ticketRegistry.addTicket(ticket);
    val request = new MockHttpServletRequest();
    request.addParameter(OAuth20Constants.CLIENT_ID, holder.getClientId());
    request.addParameter(OidcConstants.REQUEST_URI, ticket.getId());
    val context = new JEEContext(request, new MockHttpServletResponse());
    assertTrue(oidcPushedAuthorizationRequestValidator.supports(context));
    assertTrue(oidcPushedAuthorizationRequestValidator.validate(context));
    assertEquals(0, oidcPushedAuthorizationRequestValidator.getOrder());
}
Also used : lombok.val(lombok.val) CommonProfile(org.pac4j.core.profile.CommonProfile) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) JEEContext(org.pac4j.core.context.JEEContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 24 with JEEContext

use of org.pac4j.core.context.JEEContext in project cas by apereo.

the class OidcRequestSupportTests method verifyAuthnProfile.

@Test
public void verifyAuthnProfile() {
    val request = new MockHttpServletRequest();
    request.setRequestURI("https://www.example.org");
    request.setQueryString("param=value");
    val context = new JEEContext(request, new MockHttpServletResponse());
    val profile = new CommonProfile();
    context.setRequestAttribute(Pac4jConstants.USER_PROFILES, CollectionUtils.wrapLinkedHashMap(profile.getClientName(), profile));
    assertTrue(OidcRequestSupport.isAuthenticationProfileAvailable(context, JEESessionStore.INSTANCE).isPresent());
}
Also used : lombok.val(lombok.val) CommonProfile(org.pac4j.core.profile.CommonProfile) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) JEEContext(org.pac4j.core.context.JEEContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 25 with JEEContext

use of org.pac4j.core.context.JEEContext in project cas by apereo.

the class OidcRequestSupportTests method getContextForEndpoint.

protected static JEEContext getContextForEndpoint(final String endpoint) {
    val request = new MockHttpServletRequest();
    request.setScheme("https");
    request.setServerName("sso.example.org");
    request.setServerPort(8443);
    request.setRequestURI("/cas/oidc/" + endpoint);
    val response = new MockHttpServletResponse();
    return new JEEContext(request, response);
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) JEEContext(org.pac4j.core.context.JEEContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Aggregations

JEEContext (org.pac4j.core.context.JEEContext)224 lombok.val (lombok.val)215 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)158 Test (org.junit.jupiter.api.Test)157 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)155 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)34 ProfileManager (org.pac4j.core.profile.ProfileManager)28 UsernamePasswordCredentials (org.pac4j.core.credentials.UsernamePasswordCredentials)24 CommonProfile (org.pac4j.core.profile.CommonProfile)22 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)16 HashMap (java.util.HashMap)15 HttpServletRequest (javax.servlet.http.HttpServletRequest)14 HttpServletResponse (javax.servlet.http.HttpServletResponse)14 RedirectView (org.springframework.web.servlet.view.RedirectView)14 CasProfile (org.pac4j.cas.profile.CasProfile)13 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)13 MockRequestContext (org.springframework.webflow.test.MockRequestContext)13 GetMapping (org.springframework.web.bind.annotation.GetMapping)11 Map (java.util.Map)10 Slf4j (lombok.extern.slf4j.Slf4j)10