The following endpoint:
@RequestMapping(value = "/activated",method = RequestMethod.GET)
public GameHolder getAllGames(){
return gameService.getActivatedGames();
}
gets me some games and this path can be requested without token (WebSecurityConifugurerAdapter):
@Override
public void configure(WebSecurity web) throws Exception {
//Add Paths which should be ignored by authentication
web.ignoring().antMatchers("/games/activated");
}
But i call the userService and load some extra data if a user is logged in, but the problem now is, because of the ignoring() it ignores completely the authentication, how can I enter authentication when a token is provided?
I hope you understand what I mean
Edit1
My "doFilterInternal" looks like:
@Override
protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
final String authorization = httpServletRequest.getHeader("Authorization");
try{
if(authorization != null && !authorization.isEmpty() && authorization.toLowerCase().startsWith(tokenType.toLowerCase() + " ")){
String[] tokenTypeAndToken = authorization.split(" ");
final UserAuthentication tokenAuthentication = new UserAuthentication();
tokenAuthentication.setCredentials(tokenTypeAndToken[1]);
SecurityContextHolder.getContext().setAuthentication(authenticationManager.authenticate(tokenAuthentication));
}
else{
throw new HttpClientErrorException(HttpStatus.UNAUTHORIZED,"No token provided!");
}
filterChain.doFilter(httpServletRequest,httpServletResponse);
}