Search in sources :

Example 11 with ClientInfo

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

the class AdaptiveMultifactorAuthenticationPolicyEventResolverTests method verifyOperationNeedsMfa.

@Test
public void verifyOperationNeedsMfa() {
    request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "MSIE");
    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 12 with ClientInfo

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

the class GroovyScriptMultifactorAuthenticationPolicyEventResolverTests 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 13 with ClientInfo

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

the class DefaultCaptchaActivationStrategyTests method verifyByIpPattern.

@Test
public void verifyByIpPattern() {
    val strategy = new DefaultCaptchaActivationStrategy(mock(ServicesManager.class));
    val request = new MockHttpServletRequest();
    val context = getRequestContext(request);
    val properties = new GoogleRecaptchaProperties().setEnabled(true).setActivateForIpAddressPattern("127.+");
    request.setRemoteAddr("185.86.151.11");
    request.setLocalAddr("195.88.151.11");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    assertFalse(strategy.shouldActivate(context, properties).isPresent());
}
Also used : lombok.val(lombok.val) ServicesManager(org.apereo.cas.services.ServicesManager) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) GoogleRecaptchaProperties(org.apereo.cas.configuration.model.support.captcha.GoogleRecaptchaProperties) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) Test(org.junit.jupiter.api.Test)

Example 14 with ClientInfo

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

the class JdbcThrottledSubmissionHandlerInterceptorAdapterTests method verifyRecords.

@Test
public void verifyRecords() {
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("1.2.3.4");
    request.setLocalAddr("4.5.6.7");
    request.setRemoteUser("cas");
    request.addHeader("User-Agent", "Firefox");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    throttle.recordSubmissionFailure(request);
    assertFalse(throttle.getRecords().isEmpty());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 15 with ClientInfo

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

the class BaseThrottledSubmissionHandlerInterceptorAdapterTests method loginUnsuccessfully.

@SneakyThrows
protected MockHttpServletResponse loginUnsuccessfully(final String username, final String fromAddress) {
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    request.setMethod("POST");
    request.setParameter("username", username);
    request.setRemoteAddr(fromAddress);
    request.setRequestURI("/cas/login");
    val context = new MockRequestContext();
    context.setCurrentEvent(new Event(StringUtils.EMPTY, "error"));
    request.setAttribute("flowRequestContext", context);
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    getThrottle().preHandle(request, response, null);
    try {
        val transaction = new DefaultAuthenticationTransactionFactory().newTransaction(CoreAuthenticationTestUtils.getService(), badCredentials(username));
        authenticationManager.authenticate(transaction);
    } catch (final AuthenticationException e) {
        getThrottle().postHandle(request, response, null, null);
        return response;
    } finally {
        getThrottle().afterCompletion(request, response, null, null);
    }
    throw new AssertionError("Expected AbstractAuthenticationException");
}
Also used : lombok.val(lombok.val) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Event(org.springframework.webflow.execution.Event) MockRequestContext(org.springframework.webflow.test.MockRequestContext) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) DefaultAuthenticationTransactionFactory(org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) SneakyThrows(lombok.SneakyThrows)

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