Search in sources :

Example 76 with ClientInfo

use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.

the class TimedMultifactorAuthenticationPolicyEventResolverTests method initialize.

@BeforeEach
public void initialize() {
    this.context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("185.86.151.11");
    request.setLocalAddr("195.88.151.11");
    request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "MSIE");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val targetResolver = new DefaultTargetStateResolver(TestMultifactorAuthenticationProvider.ID);
    val transition = new Transition(new DefaultTransitionCriteria(new LiteralExpression(TestMultifactorAuthenticationProvider.ID)), targetResolver);
    context.getRootFlow().getGlobalTransitionSet().add(transition);
    WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService());
    TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
    WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(), context);
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DefaultTransitionCriteria(org.springframework.webflow.engine.support.DefaultTransitionCriteria) LiteralExpression(org.springframework.binding.expression.support.LiteralExpression) Transition(org.springframework.webflow.engine.Transition) DefaultTargetStateResolver(org.springframework.webflow.engine.support.DefaultTargetStateResolver) MockRequestContext(org.springframework.webflow.test.MockRequestContext) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 77 with ClientInfo

use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.

the class AdaptiveMultifactorAuthenticationPolicyEventResolverTests method verifyOperationNeedsMfaByGeo.

@Test
public void verifyOperationNeedsMfaByGeo() {
    request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "FIREFOX");
    request.addParameter("geolocation", "1000,1000,1000,1000");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    val event = resolver.resolve(context);
    assertEquals(1, event.size());
    assertEquals(TestMultifactorAuthenticationProvider.ID, event.iterator().next().getId());
}
Also used : lombok.val(lombok.val) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) Test(org.junit.jupiter.api.Test)

Example 78 with ClientInfo

use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.

the class DefaultCasCookieValueManagerTests method verifySessionPinning.

@Test
public void verifySessionPinning() {
    val request = new MockHttpServletRequest();
    request.setRemoteAddr(CLIENT_IP);
    request.setLocalAddr(CLIENT_IP);
    request.removeHeader("User-Agent");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    val props = new TicketGrantingCookieProperties();
    assertThrows(IllegalStateException.class, () -> new DefaultCasCookieValueManager(CipherExecutor.noOp(), props).buildCookieValue(VALUE, request));
    props.setPinToSession(false);
    assertNotNull(new DefaultCasCookieValueManager(CipherExecutor.noOp(), props).buildCookieValue(VALUE, request));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) TicketGrantingCookieProperties(org.apereo.cas.configuration.model.support.cookie.TicketGrantingCookieProperties) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) DefaultCasCookieValueManager(org.apereo.cas.web.support.mgmr.DefaultCasCookieValueManager) Test(org.junit.jupiter.api.Test)

Example 79 with ClientInfo

use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.

the class DefaultCasCookieValueManagerTests method verifySessionPinningAuthorizedOnFailure.

@Test
public void verifySessionPinningAuthorizedOnFailure() {
    val request = new MockHttpServletRequest();
    request.setRemoteAddr(CLIENT_IP);
    request.setLocalAddr(CLIENT_IP);
    request.addHeader("User-Agent", USER_AGENT);
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    val props = new TicketGrantingCookieProperties();
    props.setAllowedIpAddressesPattern("^19.*.3.1\\d\\d");
    val mgr = new DefaultCasCookieValueManager(CipherExecutor.noOp(), props);
    var value = mgr.buildCookieValue(VALUE, request);
    assertNotNull(value);
    request.setRemoteAddr("198.127.3.155");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    value = mgr.obtainCookieValue(value, request);
    assertNotNull(value);
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) TicketGrantingCookieProperties(org.apereo.cas.configuration.model.support.cookie.TicketGrantingCookieProperties) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) DefaultCasCookieValueManager(org.apereo.cas.web.support.mgmr.DefaultCasCookieValueManager) Test(org.junit.jupiter.api.Test)

Example 80 with ClientInfo

use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.

the class DefaultCasCookieValueManagerTests method initialize.

@BeforeEach
public void initialize() {
    MockitoAnnotations.openMocks(this);
    val request = new MockHttpServletRequest();
    request.setRemoteAddr(CLIENT_IP);
    request.setLocalAddr(CLIENT_IP);
    request.addHeader("User-Agent", USER_AGENT);
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    cookieValueManager = new DefaultCasCookieValueManager(CipherExecutor.noOp(), new TicketGrantingCookieProperties());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) TicketGrantingCookieProperties(org.apereo.cas.configuration.model.support.cookie.TicketGrantingCookieProperties) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) DefaultCasCookieValueManager(org.apereo.cas.web.support.mgmr.DefaultCasCookieValueManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ClientInfo (org.apereo.inspektr.common.web.ClientInfo)82 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)69 lombok.val (lombok.val)65 Test (org.junit.jupiter.api.Test)42 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)36 MockRequestContext (org.springframework.webflow.test.MockRequestContext)35 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)31 MockServletContext (org.springframework.mock.web.MockServletContext)29 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)14 MockWebServer (org.apereo.cas.util.MockWebServer)13 ByteArrayResource (org.springframework.core.io.ByteArrayResource)13 BeforeEach (org.junit.jupiter.api.BeforeEach)12 BeforeAll (org.junit.jupiter.api.BeforeAll)6 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)5 GeoLocationRequest (org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest)5 ClassPathResource (org.springframework.core.io.ClassPathResource)5 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)4 Cookie (javax.servlet.http.Cookie)4 GeoLocationResponse (org.apereo.cas.authentication.adaptive.geo.GeoLocationResponse)4 AdaptiveAuthenticationProperties (org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties)4