2011-09-06 83 views
4

我有一個在Tomcat 6下部署的webservice,它可以很好地工作。 現在我想authentificate任何客戶端,而是通過URL保持WSDL公開存取像 http://localhost:8080/services/MyService?wsdl如何限制訪問除wsdl以外的所有內容?

我試圖解決這個問題這樣(Web應用程序的web.xml中),但它不工作:

<security-constraint> 
    <web-resource-collection> 
     <web-resource-name>WSDL access - to anybody</web-resource-name> 
     <url-pattern>/services/MyService?wsdl</url-pattern> 
    </web-resource-collection> 

    <auth-constraint><role-name>*</role-name></auth-constraint>  
</security-constraint> 

<security-constraint> 
    <web-resource-collection> 
     <web-resource-name>Some authentification required</web-resource-name> 
     <url-pattern>/services/MyService</url-pattern> 
    </web-resource-collection> 

    <auth-constraint><role-name>somebody</role-name></auth-constraint>   
</security-constraint> 

我現在看到的唯一解決方案是創建附加的servlet並授予訪問WSDL的權限。無論是否驗證,servlet都會將所需的wsdl傳遞給客戶端。在這種情況下,WSDL URL不會被忽略,所以我不喜歡這個解決方案。請提供其他建議嗎?

+0

只是好奇,但如果你扭轉秩序會發生什麼? – cwallenpoole

+0

沒有什麼變化。手冊指出將使用第一個匹配模式,因此順序是正確的。 –

回答

7

我有類似的問題,我找到了解決方案。通過POST調用WebServices方法,而通過GET獲取WSDL。所以解決方案是隻限制POST訪問。

security-constraint> 
    <web-resource-collection> 
     <web-resource-name>Some authentification required</web-resource-name> 
     <url-pattern>/services/MyService</url-pattern> 
     <http-method>POST</http-method> 
    </web-resource-collection> 
    <auth-constraint><role-name>somebody</role-name></auth-constraint>   
</security-constraint> 

我使用WebSphere 7 JAXWS,但web.xml配置是所有容器和appservers相同。

+0

這篇文章也可以是有用的:http://stackoverflow.com/questions/8069640/whitelist-security-constraint-in-web-xml –

1

你想有傳輸層安全性。如果您嘗試使用的WS-Security保護您的個人服務 - 你可以保持WSDL開放而被固定服務...

+0

-1:錯誤,與提問者需要相反。 – bdares

+2

沒有它不相反。他希望保持wsdl的開放並保護所有其他服務。 –

+0

這不是相反的。這就是你如何保護服務,但仍然保持wsdl打開。 –

0

我有一個應用程序設置這種方式。我有一個登錄頁面,用戶名和密碼對用戶進行身份驗證。只有當有效的用戶登錄時,他們纔有權訪問數據和頁面。任何與WSDL的連接都不會受到影響,因爲它將由WSDL函數調用進行處理。

相關問題