【发布时间】:2020-04-30 10:47:57
【问题描述】:
我想对我的 Spring Boot 应用程序上的 2 个 URL 应用特定的安全规则。
我想使用 AccessDecisionVoter 功能来管理它。
一切都很好......事件太好了。
我的新规则适用于我的 2 个特定网址,但不幸的是适用于 我的所有网址。
我的 AccessDecisionManager 声明:
@Bean
public AccessDecisionManager playerResourceDecisionManager() {
List<AccessDecisionVoter<? extends Object>> decisionVoters = Arrays.asList(
new AuthenticatedVoter(),
hashSerialSecurityVoter
);
return new UnanimousBased(decisionVoters);
}
这是我的 SecurityConfig 主要代码
http.csrf()
.disable().cors().and().exceptionHandling()
// All Login Stuff
.authenticationEntryPoint(new Http403ForbiddenEntryPoint() {})
.and().authenticationProvider(getProvider())
.formLogin().loginProcessingUrl("/login")
.successHandler(new AuthentificationLoginSuccessHandler())
.failureHandler(new SimpleUrlAuthenticationFailureHandler())
.and().logout().logoutUrl("/logout")
.logoutSuccessHandler(new AuthentificationLogoutSuccessHandler())
.invalidateHttpSession(true).and().authorizeRequests()
...
// Spring boot actuator - App Status
.antMatchers("/actuator/*").permitAll()
// Static Token end points
.antMatchers("/my-filtered-url1", "/sub/my-filtered-url2/*")
.permitAll()
.accessDecisionManager(playerResourceDecisionManager())
/* Here is the problem :
* I want this accessDescisionManager apply only on my antMatchers
* (2 specific URLs),
* But it runs on every app calls.
*/
.antMatchers(HttpMethod.POST, "/log/*").permitAll()
/* Login */
.antMatchers("/login").permitAll()
.antMatchers("/auth/**").permitAll()
.antMatchers(HttpMethod.POST,"/user/lost-password").permitAll()
.antMatchers("/user").hasAuthority("ADMIN")
.anyRequest().authenticated();
我宁愿不在我的 hashSerialSecurityVoter 类中放入带有 URL 声明的特定代码。 我该怎么做?
问候。
【问题讨论】:
标签: java spring spring-security