我在jboss eap 6.1應用服務器中開發了一個基於Ejb的web服務。 如果沒有驗證,此服務按預期工作。 現在,我添加了一個基本autentication機制,這個Web服務,下面我執行的步驟:Jboss AS 7,web服務基本http認證中的錯誤
我批註我的EJB(至極實現了WS)以下列方式:
import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed;
import javax.ejb.Stateless;
import javax.jws.WebService;
import org.jboss.ejb3.annotation.SecurityDomain;
import org.jboss.ws.api.annotation.WebContext;
@Stateless
@WebService(name = "HelloWorldWS", targetNamespace="http://my-company/ws/")
@WebContext(authMethod = "BASIC", contextRoot = "helloWS", urlPattern ="/*")
@SecurityDomain("helloworld-webservice-login")
public class HelloWorldWebService implements HelloWorldWebServiceRemote {
@RolesAllowed({"mioruolo"})
public String sayHello() {
return "Hello World";
}
}
,並根據這一點,我已經添加了HelloWorld Web網頁登錄的安全域在我standalone.xml文件,內容如下:
<security-domain name="helloworld-webservice-login">
<authentication>
<login-module code="Database" flag="required">
<module-option name="dsJndiName" value="java:jboss/datasources/ExampleDS"/>
<module-option name="principalsQuery" value="select password from s_principals where principal_id=?"/>
<module-option name="rolesQuery" value="select role, 'Roles' from s_roles where principal_id=?"/>
</login-module>
</authentication>
</security-domain>
所以,我想的是,只有一個叫角色的用戶「mioruolo」可以訪問web服務。 我在Oracle 10g數據庫中添加了表s_roles和s_principals,並且我已經執行了Toad窗口中xml文件中的兩個查詢,並且兩者都按預期工作。
我用生成的客戶端調用這個Web服務的JAX-WS,和我通過憑據以下列方式HTTP頭,在客戶端:
bindingProvider.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "federico");
bindingProvider.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "passwd");
我得到的迴應總是一個403-禁止的狀態碼。 我檢查JBoss的日誌文件,我播下以下行:
14:50:40,693 DEBUG [org.apache.catalina.authenticator] (http-/127.0.0.1:8080-1) Security checking request POST /helloWS
14:50:40,694 DEBUG [org.apache.catalina.realm] (http-/127.0.0.1:8080-1) Checking constraint 'SecurityConstraint[HelloWorldWebService]' against POST/--> true
14:50:40,709 DEBUG [org.apache.catalina.realm] (http-/127.0.0.1:8080-1) Checking constraint 'SecurityConstraint[HelloWorldWebService]' against POST/--> true
14:50:40,709 DEBUG [org.apache.catalina.authenticator] (http-/127.0.0.1:8080-1) Calling hasUserDataPermission()
14:50:40,709 DEBUG [org.apache.catalina.realm] (http-/127.0.0.1:8080-1) User data constraint has no restrictions
14:50:40,710 DEBUG [org.apache.catalina.authenticator] (http-/127.0.0.1:8080-1) Calling authenticate()
14:50:41,287 DEBUG [org.apache.catalina.authenticator] (http-/127.0.0.1:8080-1) Authenticated 'federico' with type 'BASIC'
14:50:41,288 DEBUG [org.apache.catalina.authenticator] (http-/127.0.0.1:8080-1) Calling accessControl()
14:50:41,288 DEBUG [org.apache.catalina.realm] (http-/127.0.0.1:8080-1) Checking roles GenericPrincipal[federico(mioruolo,)]
14:50:41,321 DEBUG [org.apache.catalina.authenticator] (http-/127.0.0.1:8080-1) Failed accessControl() test
所以,autentication去確定,但授權(我想檢查一下「費德里科·」用戶「mioruolo」的角色),失敗,我無法找出原因,因爲在Toad客戶端中執行的查詢執行沒有問題。
有關此錯誤的任何想法? 任何幫助將不勝感激。
非常感謝您
問候
'選擇角色, '角色' 從s_roles其中principal_id ='。該查詢不應該因爲逗號而起作用 – kolossus