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());
}
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);
}
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());
}
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());
}
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");
}
Aggregations