I'm trying to implement a CSRF token, but all the info is programmed with Java 8+ version, so what I need is some help rewriting this line in Java 6/7:
tokenCookie = Arrays.stream(httpReq.getCookies()).filter(c -> c.getName().equals(csrfCookieExpectedName)).findFirst().orElse(null);
Actually from that line I'm only getting the error in:
c -> c.getName().equals(csrfCookieExpectedName)
In addition to @GIO's answer, you could try for-each loop like this:
public Cookie getExpectedCookieName(Cookie[] cookies) {
for (Cookie c : cookies) {
if (c.getName().equals(csrfCookiesExpectedName)) {
return c;
}
}
return null;
}
and call it like this :
tokenCookie = getExpectedCookieName(httpReq.getCookies());