Возможно, есть более простой способ:
Cookie cookies[] = request.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals("_id")) {
boolean bool_1 = isIdCookieValid(cookie, auth);
}
else if (cookie.getName().equals("XSRF-TOKEN")) {
boolean bool_2 = isXSRFTokenValid(cookie, request);
}
}
if (bool_1 && bool_2) {
System.out.println("Ok");
}
// else if they are not both true do nothing
}
Cookie[] cookies = request.getCookies();
if (cookies != null) {
boolean bool = Arrays.stream(cookies)
.filter(cookie ->
(cookie.getName().equals("_id") ?
isIdCookieValid(cookie, auth) :
cookie.getName().equals("XSRF-TOKEN") &&
isXSRFTokenValid(cookie, request)))
.count() == 2;
System.out.println(bool ? "Ok" : "")
}