如何解决SpringSecurity中的多个入口点不起作用
我的应用程序中有2个配置。第一个是
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable().cors()
.and()
.authorizeRequests()
.antMatchers("/api/project/projectIds","/api/project/**/involvement")
.permitAll()
.and()
.addFilter(new JwtAuthorizationFilter(authenticationManager(),secret,clientId,tokenVerificationUrl))
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
带有注释@Order(1)
第二个急需@Order(2)
,就像:
http
.addFilterBefore(new RedirectUrlFilter(projectDomainPath),OAuth2LoginAuthenticationFilter.class)
.csrf().disable().cors()
.and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED)
.and()
.authorizeRequests().antMatchers("/static/**","/logout").permitAll()
.anyRequest().authenticated()
.and()
.addFilter(new JwtAuthorizationFilter(authenticationManager(),tokenVerificationUrl))
.logout()
.logoutUrl("/logout")
.invalidateHttpSession(true)
.clearAuthentication(true)
.logoutSuccessUrl("/")
.deleteCookies("JSESSIONID")
.and()
.oauth2Login()
.loginPage(DEFAULT_AUTHORIZATION_REQUEST_BASE_URI + "/" + realm);
问题是,即使我转到例如登录页面,我仍然停留在第一个页面中。该程序从不使用第二个。
我认为antMatchers
在1个配置中将确保只有2个指定的APIS将使用这些配置,而其余的将转到配置编号2。
我做错了什么?
编辑 阅读建议的答案后,我将配置更改为
http
.csrf().disable().cors()
.and()
.antMatcher("/api/project/**")
.authorizeRequests()
.antMatchers("/api/project/projectIds","/api/project/**/involvement").permitAll()
.and()
.addFilter(new JwtAuthorizationFilter(authenticationManager(),tokenVerificationUrl))
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
,现在几乎可以了。问题出在/api/project
中,我的API比这2个更多,因此如果api/project/....
既不是/api/project/projectIds
也不是/api/project/**/involvement
,我想转到第二种配置。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。