簡體   English   中英

在Spring Security中將XML配置轉換為Java配置以實現全局方法安全

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM