Estou chamando o UsernamePasswordAuthenticationToken.clss nesse trecho de codigo:
Build output:
java: incompatible types: java.lang.Class<org.springframework.security.authentication.UsernamePasswordAuthenticationToken> cannot be converted to java.lang.Class<? extends javax.servlet.Filter>
Código:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers(HttpMethod.GET, "/api/costumer").permitAll()
.antMatchers(HttpMethod.GET, "/api/costumers/*").permitAll()
.antMatchers(HttpMethod.POST, "/auth").permitAll()
.anyRequest().authenticated()
.and().csrf().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and().addFilterBefore(new AuthenticationViaTokenFilter(), UsernamePasswordAuthenticationToken.class);
}
public class AuthenticationViaTokenFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
String token = retrieveToken(request);
filterChain.doFilter(request, response);
}
private String retrieveToken(HttpServletRequest request) {
String token = request.getHeader("Authorization");
if(token == null || token == "" || !token.startsWith("Bearer ")){
return null;
}
return token.substring(7, token.length());
}
}
Tenho meus endpoints diferentes, porém não estou entendendo o motivo desse erro.. Alguém pode me ajudar?