DEV Community

Discussion on: Spring Security with JWT

Collapse
 
petros0 profile image
Petros Stergioulas • Edited

Great Article! Good job!

A quick question: Why here are you checking the header and not the authentication object?

I mean, you already checked the header in getAuthentication()

        var authentication = getAuthentication(request);
        var header = request.getHeader(SecurityConstants.TOKEN_HEADER);

        if (StringUtils.isEmpty(header) || !header.startsWith(SecurityConstants.TOKEN_PREFIX)) {
            filterChain.doFilter(request, response);
            return;
        }
Enter fullscreen mode Exit fullscreen mode

Like this, should also work, or not? :D

        var authentication = getAuthentication(request);

        if (authentication == null) {
            filterChain.doFilter(request, response);
            return;
        }
Enter fullscreen mode Exit fullscreen mode

Again, great article!

Collapse
 
kubadlo profile image
Jakub Leško

Well, you're right. My bad 😀
I'll update the code. Thanks for your attention 🙂