2011-02-17 95 views
1

我使用Spring Secuirty 3與ACL模塊。我使用自定義PermissionEvaluator確保使用@PreAuthentication批註的方法。它的工作正常,但是每次PermissionEvaluator返回一個ACCESS_DENIEDAccessDeniedException被引發在某個點,這會停止應用程序執行。期望的行爲將是當PermissionEvaluator返回和ACCESS_DENIED,只有防止(跳過)安全的方法調用,並且應用程序的其餘部分保持正常運行。有沒有人有如何實現這個想法?Spring Security - 防止AccessDeniedException從停止應用程序正常流程

+0

[使用@PreAuthorize Annotation阻止方法調用無例外](http://stackoverflow.com/questions/4621394/prevent-method-call-without-exception-using-preauthorize-annotation) – Chepech 2011-09-26 23:10:37

回答

0

如果您將每個電話都打包在try...catch中,您可以獲得此行爲。基本上,因爲它是一個例外,任何正常的異常處理都將適用於它。如果您的應用程序可以處理該異常並繼續正常運行,那麼請執行該操作!


這裏是我的意思的例子:

// The 1st method that could be denied but you want to continue execution after 
try { 
    // Call method A that will throw the exception 
} catch (/*The exception you expect to be thrown and want to continue after*/){} 


// The 2nd method that could be denied but you want to continue execution after 
try { 
    // Call method B that will throw the exception 
} catch (/*The exception you expect to be thrown and want to continue after*/){} 

etc. 

是的,它大量的開銷增加調用這些方法,但它允許執行後的繼續的相當簡單的方式引發異常。

我也會爭辯說它也比較正確,因爲調用代碼的確知道知道如何處理這些例外。這也不需要額外的Spring配置,這意味着代碼行爲仍然接近默認值,並且不依賴外部配置來確定它的行爲。

+0

問題與也就是說,它允許方法調用,而不管PermissionEvaluator的結果如何,所以它的基本類似於禁用安全性 – Chepech 2011-09-26 23:08:44