Search in sources :

Example 6 with BasicUserProfile

use of org.pac4j.core.profile.BasicUserProfile in project cas by apereo.

the class OAuth20TicketGrantingTicketAwareSecurityLogicTests 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 OAuth20TicketGrantingTicketAwareSecurityLogic(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 7 with BasicUserProfile

use of org.pac4j.core.profile.BasicUserProfile in project cas by apereo.

the class OAuth20TicketGrantingTicketAwareSecurityLogicTests method verifyLoadWithBadTicketInSession.

@Test
public void verifyLoadWithBadTicketInSession() {
    when(centralAuthenticationService.getTicket(anyString(), any())).thenThrow(new InvalidTicketException("bad ticket"));
    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);
    JEESessionStore.INSTANCE.set(context, WebUtils.PARAMETER_TICKET_GRANTING_TICKET_ID, UUID.randomUUID().toString());
    val logic = new OAuth20TicketGrantingTicketAwareSecurityLogic(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) InvalidTicketException(org.apereo.cas.ticket.InvalidTicketException) 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 8 with BasicUserProfile

use of org.pac4j.core.profile.BasicUserProfile in project cas by apereo.

the class OidcAuthenticationAuthorizeSecurityLogicTests method verifyOperation.

@Test
public void verifyOperation() {
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    when(ticketGrantingTicketCookieGenerator.retrieveCookieValue(request)).thenReturn(ticketGrantingTicket.getId());
    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);
    assertFalse(logic.loadProfiles(profileManager, context, JEESessionStore.INSTANCE, List.of()).isEmpty());
    request.setQueryString("prompt=login");
    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)

Aggregations

BasicUserProfile (org.pac4j.core.profile.BasicUserProfile)8 lombok.val (lombok.val)7 Test (org.junit.jupiter.api.Test)6 JEEContext (org.pac4j.core.context.JEEContext)6 ProfileManager (org.pac4j.core.profile.ProfileManager)6 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)6 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)6 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 DefaultAuthenticationHandlerExecutionResult (org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult)1 BasicIdentifiableCredential (org.apereo.cas.authentication.credential.BasicIdentifiableCredential)1 BasicCredentialMetaData (org.apereo.cas.authentication.metadata.BasicCredentialMetaData)1 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)1 InvalidTicketException (org.apereo.cas.ticket.InvalidTicketException)1 Before (org.junit.Before)1