Java Spring boot 1.5.2.Release-DefaultRolesPrefixPostProcessor不删除默认值;角色“uquot;前缀
在Spring Boot中,应用程序定义了参考手册第8.3节中提到的DefaultRolesPrefixPostProcessor。摘录如下:Java Spring boot 1.5.2.Release-DefaultRolesPrefixPostProcessor不删除默认值;角色“uquot;前缀,java,spring-boot,spring-security,Java,Spring Boot,Spring Security,在Spring Boot中,应用程序定义了参考手册第8.3节中提到的DefaultRolesPrefixPostProcessor。摘录如下: public class DefaultRolesPrefixPostProcessor implements BeanPostProcessor, PriorityOrdered { @Override public Object postProcessAfterInitialization(final Object bean, fi
public class DefaultRolesPrefixPostProcessor implements BeanPostProcessor, PriorityOrdered {
@Override
public Object postProcessAfterInitialization(final Object bean, final String beanName) {
if (bean instanceof DefaultMethodSecurityExpressionHandler) {
((DefaultMethodSecurityExpressionHandler) bean).setDefaultRolePrefix(null);
}
.... // if statement for DefaultWebSecurityExpressionHandler
.... // if statement for SecurityContextHolderAwareRequestFilter
return bean;
}
SecurityConfig类重写配置(HttpSecurity)方法:
但是,任何@Secured方法仍然需要“ROLE_u3;”前缀,否则会收到403,这主要是因为默认的AccessDecisionManager的roleNoter返回0
@RestController
public class MyController {
@Secured("ROLE_XXX")
public String hello() {
return "hello";
}
}
是否有任何方法可以解决此问题,或者使用“hasAuthority”是避免此问题的唯一方法?您应该从类中删除
@EnableWebSecurity
SecurityConfig
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
// your config
}
}
如果使用@EnableWebSecurity
,则默认配置将完全关闭
关闭默认web应用程序安全配置的步骤
完全可以用
你的情况不需要。但是,如果要像以前一样使用方法安全性,则必须启用该方法安全性
所以我认为你的后处理器根本没有被使用,如果你没有在你还没有发布的地方手动完成的话
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
// your config
}
}