Search in sources :

Example 16 with JEEContext

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

the class OidcAuthenticationAuthorizeSecurityLogicTests method verifyLoadNoProfileWhenNoTgtAvailable.

@Test
public void verifyLoadNoProfileWhenNoTgtAvailable() {
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val context = new JEEContext(request, response);
    val profileManager = new ProfileManager(context, JEESessionStore.INSTANCE);
    profileManager.save(true, new BasicUserProfile(), false);
    val logic = new OidcAuthenticationAuthorizeSecurityLogic(ticketGrantingTicketCookieGenerator, ticketRegistry, centralAuthenticationService);
    assertTrue(logic.loadProfiles(profileManager, context, JEESessionStore.INSTANCE, List.of()).isEmpty());
}
Also used : lombok.val(lombok.val) ProfileManager(org.pac4j.core.profile.ProfileManager) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) JEEContext(org.pac4j.core.context.JEEContext) BasicUserProfile(org.pac4j.core.profile.BasicUserProfile) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 17 with JEEContext

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

the class OidcCallbackAuthorizeViewResolverTests method verifyPromptNoneWithoutProfileWithRedirectParam.

@Test
public void verifyPromptNoneWithoutProfileWithRedirectParam() {
    val request = new MockHttpServletRequest();
    request.addParameter(OAuth20Constants.REDIRECT_URI, "https://google.com");
    val url = "https://cas.org/something?" + OidcConstants.PROMPT + "=none";
    val response = new MockHttpServletResponse();
    val context = new JEEContext(request, response);
    val manager = new ProfileManager(context, JEESessionStore.INSTANCE);
    val mv = callbackAuthorizeViewResolver.resolve(context, manager, url);
    assertNotNull(mv);
    assertEquals(mv.getModel().get(OAuth20Constants.ERROR), OidcConstants.LOGIN_REQUIRED);
}
Also used : lombok.val(lombok.val) ProfileManager(org.pac4j.core.profile.ProfileManager) 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 18 with JEEContext

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

the class OidcCallbackAuthorizeViewResolverTests method verifyPromptLogin.

@Test
public void verifyPromptLogin() {
    val request = new MockHttpServletRequest();
    val url = "https://cas.org/something?" + OidcConstants.PROMPT + "=login";
    val response = new MockHttpServletResponse();
    val context = new JEEContext(request, response);
    val manager = new ProfileManager(context, JEESessionStore.INSTANCE);
    val mv = callbackAuthorizeViewResolver.resolve(context, manager, url);
    assertNotNull(mv);
    assertTrue(mv.getView() instanceof RedirectView);
}
Also used : lombok.val(lombok.val) ProfileManager(org.pac4j.core.profile.ProfileManager) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) JEEContext(org.pac4j.core.context.JEEContext) RedirectView(org.springframework.web.servlet.view.RedirectView) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 19 with JEEContext

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

the class OidcCallbackAuthorizeViewResolverTests method verifyRedirect.

@Test
public void verifyRedirect() {
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val context = new JEEContext(request, response);
    val manager = new ProfileManager(context, JEESessionStore.INSTANCE);
    val profile = new CommonProfile();
    profile.setClientName(Authenticators.CAS_OAUTH_CLIENT_BASIC_AUTHN);
    profile.setId("casuser");
    manager.save(true, profile, false);
    val mv = callbackAuthorizeViewResolver.resolve(context, manager, "https://github.com");
    assertNotNull(mv);
    assertTrue(mv.getView() instanceof RedirectView);
}
Also used : lombok.val(lombok.val) ProfileManager(org.pac4j.core.profile.ProfileManager) CommonProfile(org.pac4j.core.profile.CommonProfile) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) JEEContext(org.pac4j.core.context.JEEContext) RedirectView(org.springframework.web.servlet.view.RedirectView) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 20 with JEEContext

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

the class OidcCasCallbackUrlResolverTests method verifyOperation.

@Test
public void verifyOperation() throws Exception {
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    request.addParameter(OAuth20Constants.CLIENT_ID, UUID.randomUUID().toString());
    request.addParameter(OAuth20Constants.STATE, UUID.randomUUID().toString());
    request.addParameter(OidcConstants.UI_LOCALES, "de");
    request.addParameter(OidcConstants.MAX_AGE, "100");
    request.addParameter(OidcConstants.REQUEST_URI, UUID.randomUUID().toString());
    val output = casCallbackUrlResolver.compute(OAuth20Utils.casOAuthCallbackUrl(casProperties.getServer().getPrefix()), new JEEContext(request, response));
    assertNotNull(output);
    val uri = new URIBuilder(output);
    assertTrue(uri.getQueryParams().stream().anyMatch(p -> p.getName().equalsIgnoreCase(OAuth20Constants.CLIENT_ID)));
    assertTrue(uri.getQueryParams().stream().anyMatch(p -> p.getName().equalsIgnoreCase(OAuth20Constants.STATE)));
    assertTrue(uri.getQueryParams().stream().anyMatch(p -> p.getName().equalsIgnoreCase(OidcConstants.UI_LOCALES)));
    assertTrue(uri.getQueryParams().stream().anyMatch(p -> p.getName().equalsIgnoreCase(OidcConstants.MAX_AGE)));
    assertTrue(uri.getQueryParams().stream().anyMatch(p -> p.getName().equalsIgnoreCase(OidcConstants.REQUEST_URI)));
}
Also used : lombok.val(lombok.val) OAuth20Constants(org.apereo.cas.support.oauth.OAuth20Constants) OAuth20Utils(org.apereo.cas.support.oauth.util.OAuth20Utils) URIBuilder(org.apache.http.client.utils.URIBuilder) OidcConstants(org.apereo.cas.oidc.OidcConstants) lombok.val(lombok.val) Autowired(org.springframework.beans.factory.annotation.Autowired) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) UUID(java.util.UUID) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test) UrlResolver(org.pac4j.core.http.url.UrlResolver) Qualifier(org.springframework.beans.factory.annotation.Qualifier) Assertions(org.junit.jupiter.api.Assertions) Tag(org.junit.jupiter.api.Tag) AbstractOidcTests(org.apereo.cas.oidc.AbstractOidcTests) JEEContext(org.pac4j.core.context.JEEContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) JEEContext(org.pac4j.core.context.JEEContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) URIBuilder(org.apache.http.client.utils.URIBuilder) Test(org.junit.jupiter.api.Test)

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