I recently switched to JHipster v8.1.0 but cannot figure out how to authenticate incoming requests by their cookies.
In version 7.x.x there was a JWTFilter class and inside of it there was a resolveToken(HttpServletRequest request) method and with that, I could easily resolve the token from cookie or header...
This was my version of the resolveToken function in older versions to resolve the JWT token from the cookie:
private String resolveToken(HttpServletRequest request) {
String bearerToken = request.getHeader(AUTHORIZATION_HEADER);
if (StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer ")) {
return bearerToken.substring(7);
}
final Cookie auth = WebUtils.getCookie(request, AUTHORIZATION_COOKIE);
if (auth != null && StringUtils.hasText(auth.getValue())) {
return auth.getValue();
}
return null;
}
But in the new version, I cannot find a way to do that. What can I try next?
Because of not finding any answer on the internet or here I tried to somehow do my own trick.
As much as the way I did it seems good I hope the Jhipster crew gives the developers some interface so that they could choose their own authorization method.
Ok so I implemented a filter to extract the possible token in the cookie then added it to headers and then added this filter before
UsernamePasswordAuthenticationFilter:And in
SecurityConfiguration:Hope this will help.