#secure my auth with being able to acces swagger
1 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @spark lake! Please use
/closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Please format your code to make it more readable.
For java, it should look like this:
````java
public void foo() {
}
````
don t want that and don t wanna enter pws
@Component ```java
public class JWTFilter extends OncePerRequestFilter {
private static final String BEARER_PREFIX = "Bearer ";
private final UserRepository userRepository;
private final UserService userService;
private final JWTUtil jwtTokenUtil;
private static final List<RequestMatcher> PUBLIC_URLS =
Arrays.stream(SecurityConfig.PUBLIC_URL_PATTERNS)
.map(p -> (RequestMatcher) new AntPathRequestMatcher(p))
.toList();
@Autowired
public JWTFilter(
UserService userService,
JWTUtil jwtTokenUtil,
UserRepository userRepository
) {
this.userService = userService;
this.jwtTokenUtil = jwtTokenUtil;
this.userRepository = userRepository;
}
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
final Optional<String> authHeader = Optional.ofNullable(request.getHeader("Authorization"));
if(authHeader.isPresent()) {
authHeader
.map(header -> header.substring(BEARER_PREFIX.length()))
.map(jwtTokenUtil::validateTokenAndRetrieveSubject)
.map(email -> userRepository
.findByEmail(email)
.orElseThrow(() -> new IllegalArgumentException("Invalid bearer token")))
.ifPresent(user -> {
UserDetails userDetails = userService.loadUserByUsername(user.getEmail());
UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(user, userDetails.getPassword(), userDetails.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(authToken);
});
}
filterChain.doFilter(request, response);
}
} ```
This message has been formatted automatically. You can disable this using /preferences.
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use/help ping.
Warning: abusing this will result in moderative actions taken against you.

@Override
protected boolean shouldNotFilter(HttpServletRequest request) {
PUBLIC_URLS.forEach(m -> {
System.out.println("url " + m.getPattern() + " request " + request.getRequestURI());
});
return true;
}
try this i wanna see what it prints
Will check when ik home going to work rn
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use/help ping.
Warning: abusing this will result in moderative actions taken against you.
Thank you
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.