2012-04-02 111 views
0

我目前有一個REST API,必須通過BasicAuth進行身份驗證,但稍後還有其他一些方法。Java web.xml中的動態安全約束配置

這是一個在Tomcat的6境界的設置和我在我的web.xml以下,

<security-constraint> 
    <web-resource-collection> 
     <web-resource-name>document</web-resource-name> 
     <url-pattern>/rest/document/*</url-pattern> 
    </web-resource-collection> 
    <auth-constraint> 
     <role-name>document</role-name> 
    </auth-constraint> 
</security-constraint> 

<login-config> 
    <auth-method>BASIC</auth-method> 
    <Realm-name>Tomcat-Advance-Authentication-Realm</Realm-name> 
</login-config> 

對於像/rest/document/*網址工作正常。

我的問題是,有誰知道是否有可能或如何動態定義其他網址,而無需構建和重新部署?

例如另一安全約束,

<security-constraint> 
    <web-resource-collection> 
     <web-resource-name>secure</web-resource-name> 
     <url-pattern>/rest/secure/*</url-pattern> 
    </web-resource-collection> 
    <auth-constraint> 
     <role-name>secure</role-name> 
    </auth-constraint> 
</security-constraint> 

感謝

回答

2

每當你做出改變的web.xml,Web應用程序需要重新啓動拿起這些變化。

如果您需要動態安全約束,請考慮構建自定義可配置篩選器和相關屬性文件,以便您可以定義受保護資源(例如)。

+0

謝謝盧卡,我想我們會走這條路。最終我們希望使用Spring 3 Security來處理這個問題。 – wsams 2012-04-03 17:11:26