use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.
the class BasePasswordManagementService method createToken.
@Override
public String createToken(final String to) {
try {
final String token = UUID.randomUUID().toString();
final JwtClaims claims = new JwtClaims();
claims.setJwtId(token);
claims.setIssuer(issuer);
claims.setAudience(issuer);
claims.setExpirationTimeMinutesInTheFuture(properties.getReset().getExpirationMinutes());
claims.setIssuedAtToNow();
final ClientInfo holder = ClientInfoHolder.getClientInfo();
claims.setStringClaim("origin", holder.getServerIpAddress());
claims.setStringClaim("client", holder.getClientIpAddress());
claims.setSubject(to);
final String json = claims.toJson();
return this.cipherExecutor.encode(json);
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return null;
}
use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.
the class JdbcThrottledSubmissionHandlerInterceptorAdapterTests method loginUnsuccessfully.
@Override
protected MockHttpServletResponse loginUnsuccessfully(final String username, final String fromAddress) throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
request.setMethod("POST");
request.setParameter("username", username);
request.setRemoteAddr(fromAddress);
request.setRequestURI("/cas/login");
final MockRequestContext context = new MockRequestContext();
context.setCurrentEvent(new Event(StringUtils.EMPTY, "error"));
request.setAttribute("flowRequestContext", context);
ClientInfoHolder.setClientInfo(new ClientInfo(request));
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
throttle.preHandle(request, response, null);
try {
authenticationManager.authenticate(AuthenticationTransaction.of(CoreAuthenticationTestUtils.getService(), badCredentials(username)));
} catch (final AuthenticationException e) {
throttle.postHandle(request, response, null, null);
return response;
}
throw new AssertionError("Expected AbstractAuthenticationException");
}
use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.
the class AbstractThrottledSubmissionHandlerInterceptorAdapterTests method setUp.
@Before
public void setUp() {
final MockHttpServletRequest request = new MockHttpServletRequest();
request.setRemoteAddr(IP_ADDRESS);
request.setLocalAddr(IP_ADDRESS);
ClientInfoHolder.setClientInfo(new ClientInfo(request));
}
use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.
the class DefaultCaptchaActivationStrategyTests method verifyByIpPatternPerService.
@Test
public void verifyByIpPatternPerService() {
val servicesManager = mock(ServicesManager.class);
val strategy = new DefaultCaptchaActivationStrategy(servicesManager);
val request = new MockHttpServletRequest();
val context = getRequestContext(request);
request.setRemoteAddr("185.86.151.99");
request.setLocalAddr("195.88.151.11");
ClientInfoHolder.setClientInfo(new ClientInfo(request));
val service = RegisteredServiceTestUtils.getService(UUID.randomUUID().toString());
val registeredService = RegisteredServiceTestUtils.getRegisteredService(service.getId());
registeredService.getProperties().put(RegisteredServiceProperty.RegisteredServiceProperties.CAPTCHA_ENABLED.getPropertyName(), new DefaultRegisteredServiceProperty("true"));
registeredService.getProperties().put(RegisteredServiceProperty.RegisteredServiceProperties.CAPTCHA_IP_ADDRESS_PATTERN.getPropertyName(), new DefaultRegisteredServiceProperty("no-match1", "no-match2", "\\d\\d\\.8.+\\.99"));
when(servicesManager.findServiceBy(any(Service.class))).thenReturn(registeredService);
WebUtils.putServiceIntoFlowScope(context, service);
val properties = new GoogleRecaptchaProperties().setEnabled(false);
assertTrue(strategy.shouldActivate(context, properties).isPresent());
}
use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.
the class DefaultCaptchaActivationStrategy method shouldActivate.
@Override
public Optional<GoogleRecaptchaProperties> shouldActivate(final RequestContext requestContext, final GoogleRecaptchaProperties properties) {
val service = WebUtils.getService(requestContext);
val registeredService = servicesManager.findServiceBy(service);
if (RegisteredServiceProperty.RegisteredServiceProperties.CAPTCHA_ENABLED.isAssignedTo(registeredService)) {
LOGGER.trace("Checking for activation of captcha defined for service [{}]", registeredService);
if (RegisteredServiceProperty.RegisteredServiceProperties.CAPTCHA_IP_ADDRESS_PATTERN.isAssignedTo(registeredService)) {
val ip = Optional.ofNullable(ClientInfoHolder.getClientInfo()).map(ClientInfo::getClientIpAddress).orElse(StringUtils.EMPTY).trim();
LOGGER.trace("Checking for activation of captcha defined for service [{}] based on IP address [{}]", registeredService, ip);
val ipPattern = RegisteredServiceProperty.RegisteredServiceProperties.CAPTCHA_IP_ADDRESS_PATTERN.getPropertyValues(registeredService, Set.class);
val result = ipPattern.stream().anyMatch(pattern -> RegexUtils.find(pattern.toString().trim(), ip));
return evaluateResult(result, properties);
}
val result = RegisteredServiceProperty.RegisteredServiceProperties.CAPTCHA_ENABLED.getPropertyBooleanValue(registeredService);
return evaluateResult(result, properties);
}
if (StringUtils.isNotBlank(properties.getActivateForIpAddressPattern())) {
val ip = Optional.ofNullable(ClientInfoHolder.getClientInfo()).map(ClientInfo::getClientIpAddress).orElse(StringUtils.EMPTY);
LOGGER.debug("Remote IP address [{}] will be checked against [{}]", ip, properties.getActivateForIpAddressPattern());
val activate = RegexUtils.find(properties.getActivateForIpAddressPattern(), ip);
return evaluateResult(activate, properties);
}
LOGGER.trace("Checking for activation of captcha defined under site key [{}]", properties.getSiteKey());
return evaluateResult(properties.isEnabled(), properties);
}
Aggregations