use of org.springframework.security.web.csrf.DefaultCsrfToken in project gravitee-access-management by gravitee-io.
the class CookieCsrfSignedTokenRepository method loadToken.
@Override
public CsrfToken loadToken(HttpServletRequest request) {
Cookie cookie = WebUtils.getCookie(request, DEFAULT_CSRF_COOKIE_NAME);
if (cookie == null) {
return null;
}
String cookieValue = cookie.getValue();
if (!StringUtils.hasLength(cookieValue)) {
return null;
}
try {
JWT jwt = jwtParser.parse(cookieValue);
String token = jwt.get(TOKEN_CLAIM).toString();
if (!StringUtils.hasLength(token)) {
return null;
}
return new DefaultCsrfToken(DEFAULT_CSRF_HEADER_NAME, DEFAULT_CSRF_PARAMETER_NAME, token);
} catch (Exception ex) {
LOGGER.error("Unable to verify CSRF token", ex);
}
return null;
}
use of org.springframework.security.web.csrf.DefaultCsrfToken in project gravitee-access-management by gravitee-io.
the class CookieCsrfSignedTokenRepository method generateToken.
@Override
public CsrfToken generateToken(HttpServletRequest request) {
CsrfToken csrfToken = loadToken(request);
if (csrfToken != null) {
return csrfToken;
}
UUID token = UUID.randomUUID();
return new DefaultCsrfToken(DEFAULT_CSRF_HEADER_NAME, DEFAULT_CSRF_PARAMETER_NAME, token.toString());
}
Aggregations