Java Spring Security-permitAll()不允许未经身份验证的访问
我只想允许未经身份验证的用户访问几个路径:/everyone1/something1、/everyone2/something2和/everyone3/**。 对于其余路径,我希望只允许经过身份验证的请求 目前,我有“类WebSecurityConfig扩展WebSecurityConfigureAdapter”,包括: 在“jwtAuthenticationFilter”中,我将身份验证设置为:Java Spring Security-permitAll()不允许未经身份验证的访问,java,spring,spring-mvc,websecurity,Java,Spring,Spring Mvc,Websecurity,我只想允许未经身份验证的用户访问几个路径:/everyone1/something1、/everyone2/something2和/everyone3/**。 对于其余路径,我希望只允许经过身份验证的请求 目前,我有“类WebSecurityConfig扩展WebSecurityConfigureAdapter”,包括: 在“jwtAuthenticationFilter”中,我将身份验证设置为: private void setAuthentication2(String username
private void setAuthentication2(String username, String someData, boolean authenticated) {
User user = new User(username, "", new ArrayList<>());
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(user, null, new ArrayList<>());
if (!authenticated) {
authentication.setAuthenticated(false);
}
AuthenticationDetails authenticationDetails = new AuthenticationDetails(someData);
authentication.setDetails(authenticationDetails);
SecurityContextHolder.getContext().setAuthentication(authentication);
}
private void setAuthentication2(字符串用户名、字符串someData、布尔认证){
User User=new User(用户名,“,new ArrayList());
UsernamePasswordAuthenticationToken authentication=新的UsernamePasswordAuthenticationToken(user,null,new ArrayList());
如果(!已验证){
authentication.setAuthenticated(false);
}
AuthenticationDetails AuthenticationDetails=新的AuthenticationDetails(someData);
authentication.setDetails(authenticationDetails);
SecurityContextHolder.getContext().setAuthentication(身份验证);
}
不幸的是,上面的配置阻止了每个请求,包括经过身份验证和未经身份验证的请求
任何帮助都将不胜感激
谢谢 此方法为经过身份验证的请求授权某些路径。您需要的是:
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/everyone1/something1", "/everyone2/something2", "/everyone3/**");
}
然后匿名请求可以访问此路径。谢谢您的评论。据我所知,这将使我的自定义筛选器JwtAuthenticationFilter忽略对上述路径的所有请求。这不是我想要的行为-我需要所有的请求都被这个过滤器过滤。
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/everyone1/something1", "/everyone2/something2", "/everyone3/**");
}