最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何創(chuàng)建用于spring安全表達(dá)式語言注釋的自定義方法

如何創(chuàng)建用于spring安全表達(dá)式語言注釋的自定義方法

尚方寶劍之說 2019-09-19 14:30:16
我想創(chuàng)建一個類,通過注釋添加自定義方法以用于spring安全表達(dá)式語言,以進(jìn)行基于方法的授權(quán)。例如,我想創(chuàng)建一個像'customMethodReturningBoolean'這樣的自定義方法,以某種方式使用:  @PreAuthorize("customMethodReturningBoolean()")  public void myMethodToSecure() {     // whatever  }我的問題是這個。如果有可能,我應(yīng)該創(chuàng)建自定義方法的子類,我將如何在spring xml配置文件中配置它,有人給我一個這樣使用的自定義方法的示例?
查看完整描述

3 回答

?
慕桂英3389331

TA貢獻(xiàn)2036條經(jīng)驗 獲得超8個贊

您需要子類化兩個類。


首先,設(shè)置一個新方法表達(dá)式處理程序


<global-method-security>

  <expression-handler ref="myMethodSecurityExpressionHandler"/>

</global-method-security>

myMethodSecurityExpressionHandler將是的一個子類DefaultMethodSecurityExpressionHandler,其覆蓋createEvaluationContext(),設(shè)置的一個子類MethodSecurityExpressionRoot的MethodSecurityEvaluationContext。


例如:


@Override

public EvaluationContext createEvaluationContext(Authentication auth, MethodInvocation mi) {

    MethodSecurityEvaluationContext ctx = new MethodSecurityEvaluationContext(auth, mi, parameterNameDiscoverer);

    MethodSecurityExpressionRoot root = new MyMethodSecurityExpressionRoot(auth);

    root.setTrustResolver(trustResolver);

    root.setPermissionEvaluator(permissionEvaluator);

    root.setRoleHierarchy(roleHierarchy);

    ctx.setRootObject(root);


    return ctx;

}


查看完整回答
反對 回復(fù) 2019-09-19
  • 3 回答
  • 0 關(guān)注
  • 1012 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號