class HttpUtils {

    public static boolean validateSessionKey(final HttpSession session, final Map<String, Object[]> params, final Cookie[] cookies, final String sessionKeyString) {
        if (session == null || sessionKeyString == null) {
            return false;
        }
        final String sessionKey = (String) session.getAttribute(sessionKeyString);
        final String sessionKeyFromCookie = HttpUtils.findCookie(cookies, sessionKeyString);
        String[] sessionKeyFromParams = null;
        if (params != null) {
            sessionKeyFromParams = (String[]) params.get(sessionKeyString);
        }
        if ((sessionKey == null)
                || (sessionKeyFromParams == null && sessionKeyFromCookie == null)
                || (sessionKeyFromParams != null && !sessionKey.equals(sessionKeyFromParams[0]))
                || (sessionKeyFromCookie != null && !sessionKey.equals(sessionKeyFromCookie))) {
            return false;
        }
        return true;
    }

}