| @Override | |
| protected String obtainValueFromCompoundCookie(final String cookieValue, final HttpServletRequest request) { | |
| val cookieParts = Splitter.on(String.valueOf(COOKIE_FIELD_SEPARATOR)).splitToList(cookieValue); | |
| if (cookieParts.isEmpty()) { | |
| throw new IllegalStateException("Invalid empty cookie"); | |
| } | |
| val value = cookieParts.get(0); | |
| if (!cookieProperties.isPinToSession()) { | |
| LOGGER.trace("Cookie session-pinning is disabled. Returning cookie value as it was provided"); | |
| return value; | |
| } | |
| if (cookieParts.size() != COOKIE_FIELDS_LENGTH) { | |
| throw new IllegalStateException("Invalid cookie. Required fields are missing"); | |
| } | |
| val remoteAddr = cookieParts.get(1); | |
| val userAgent = cookieParts.get(2); | |
| if (Stream.of(value, remoteAddr, userAgent).anyMatch(StringUtils::isBlank)) { | |
| throw new IllegalStateException("Invalid cookie. Required fields are empty"); | |
| } | |
| val clientInfo = ClientInfoHolder.getClientInfo(); | |
| if (!remoteAddr.equals(clientInfo.getClientIpAddress())) { | |
| throw new IllegalStateException("Invalid cookie. Required remote address " | |
| + remoteAddr + " does not match " + clientInfo.getClientIpAddress()); | |
| } | |
| val agent = HttpRequestUtils.getHttpServletRequestUserAgent(request); | |
| if (!userAgent.equals(agent)) { | |
| throw new IllegalStateException("Invalid cookie. Required user-agent " + userAgent + " does not match " + agent); | |
| } | |
| return value; | |
| } |