[英]Converting XML configuration to java configuration in spring security for global method security
我正在尝试将xml配置转换为java config
我的XML配置是这样的
<security:global-method-security secured-annotations="enabled" pre-post-annotations="enabled" access-decision-manager-ref="methodAccessDecisionManager">
<security:expression-handler ref="methodExpressionHandler"/>
</security:global-method-security>
我尝试使用注释转换
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
但是我不知道如何转换和使用全局安全性方法access-decision-manager-ref="methodAccessDecisionManager"
和<security:expression-handler ref="methodExpressionHandler"/>
您可以编写自定义方法安全性配置,请参阅Spring Security Reference :
5.10.2 GlobalMethodSecurityConfiguration
有时您可能需要执行比
@EnableGlobalMethodSecurity
批注允许的操作更复杂的操作。 对于这些实例,可以扩展GlobalMethodSecurityConfiguration
,以确保@EnableGlobalMethodSecurity
批注出现在子类中。 例如,如果您想提供一个自定义的MethodSecurityExpressionHandler
,则可以使用以下配置:@EnableGlobalMethodSecurity(prePostEnabled = true) public class MethodSecurityConfig extends GlobalMethodSecurityConfiguration { @Override protected MethodSecurityExpressionHandler createExpressionHandler() { // ... create and return custom MethodSecurityExpressionHandler ... return expressionHandler; } }
有关可以覆盖的方法的其他信息,请参考
GlobalMethodSecurityConfiguration
Javadoc。
您修改的代码:
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
public class MethodSecurityConfig extends GlobalMethodSecurityConfiguration {
@Autowired
private AccessDecisionManager accessDecisionManager;
@Autowired
private MethodSecurityExpressionHandler methodSecurityExpressionHandler;
protected MethodSecurityExpressionHandler createExpressionHandler() {
return methodSecurityExpressionHandler;
}
protected AccessDecisionManager accessDecisionManager() {
return accessDecisionManager;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.