use of org.apereo.cas.web.support.InvalidCookieException in project cas by apereo.
the class InvalidTicketExceptionTests method verifyCodeWithCause.
@Test
public void verifyCodeWithCause() {
val cause = new InvalidCookieException("forbidden");
val t = new InvalidTicketException(cause, "InvalidTicketId");
assertEquals(cause.getCode(), t.getCode());
}
use of org.apereo.cas.web.support.InvalidCookieException in project cas by apereo.
the class DefaultCasCookieValueManager method obtainValueFromCompoundCookie.
@Override
protected String obtainValueFromCompoundCookie(final String value, final HttpServletRequest request) {
val cookieParts = Splitter.on(String.valueOf(COOKIE_FIELD_SEPARATOR)).splitToList(value);
val cookieValue = cookieParts.get(0);
if (!cookieProperties.isPinToSession()) {
LOGGER.trace("Cookie session-pinning is disabled. Returning cookie value as it was provided");
return cookieValue;
}
if (cookieParts.size() != COOKIE_FIELDS_LENGTH) {
throw new InvalidCookieException("Invalid cookie. Required fields are missing");
}
val cookieIpAddress = cookieParts.get(1);
val cookieUserAgent = cookieParts.get(2);
if (Stream.of(cookieValue, cookieIpAddress, cookieUserAgent).anyMatch(StringUtils::isBlank)) {
throw new InvalidCookieException("Invalid cookie. Required fields are empty");
}
val clientInfo = ClientInfoHolder.getClientInfo();
if (clientInfo == null) {
throw new InvalidCookieException("Unable to match required remote address " + cookieIpAddress + " because client ip at time of cookie creation is unknown");
}
if (!cookieIpAddress.equals(clientInfo.getClientIpAddress())) {
if (StringUtils.isBlank(cookieProperties.getAllowedIpAddressesPattern()) || !RegexUtils.find(cookieProperties.getAllowedIpAddressesPattern(), clientInfo.getClientIpAddress())) {
throw new InvalidCookieException("Invalid cookie. Required remote address " + cookieIpAddress + " does not match " + clientInfo.getClientIpAddress());
}
LOGGER.debug("Required remote address [{}] does not match [{}], but it's authorized proceed", cookieIpAddress, clientInfo.getClientIpAddress());
}
val agent = HttpRequestUtils.getHttpServletRequestUserAgent(request);
if (!cookieUserAgent.equals(agent)) {
throw new InvalidCookieException("Invalid cookie. Required user-agent " + cookieUserAgent + " does not match " + agent);
}
return cookieValue;
}
use of org.apereo.cas.web.support.InvalidCookieException in project cas by apereo.
the class CookieRetrievingCookieGenerator method retrieveCookieValue.
@Override
public String retrieveCookieValue(final HttpServletRequest request) {
try {
if (StringUtils.isBlank(getCookieName())) {
throw new InvalidCookieException("Cookie name is undefined");
}
var cookie = org.springframework.web.util.WebUtils.getCookie(request, Objects.requireNonNull(getCookieName()));
if (cookie == null) {
val cookieValue = request.getHeader(getCookieName());
if (StringUtils.isNotBlank(cookieValue)) {
LOGGER.trace("Found cookie [{}] under header name [{}]", cookieValue, getCookieName());
cookie = createCookie(cookieValue);
}
}
if (cookie == null) {
val cookieValue = request.getParameter(getCookieName());
if (StringUtils.isNotBlank(cookieValue)) {
LOGGER.trace("Found cookie [{}] under request parameter name [{}]", cookieValue, getCookieName());
cookie = createCookie(cookieValue);
}
}
return Optional.ofNullable(cookie).map(ck -> this.casCookieValueManager.obtainCookieValue(ck, request)).orElse(null);
} catch (final Exception e) {
LoggingUtils.warn(LOGGER, e);
}
return null;
}
Aggregations