Unable to authenticate with jax-ws on Glassfish

99封情书 提交于 2019-11-29 17:07:36

You need to add a <security-constraint> to your web.xml which describes who is allowed to access a certain URL. It's described in Securing Web Applications in the Java EE 6 Tutorial. In your case it should be something like this:

<security-constraint>  
<display-name>WebServiceSecurity</display-name>  

<web-resource-collection>  
    <web-resource-name>Authorized users only</web-resource-name>  
    <url-pattern>/yoururl</url-pattern>  
    <http-method>POST</http-method>
</web-resource-collection>  

<auth-constraint>       
    <role-name>user</role-name>
    <role-name>admin</role-name>
</auth-constraint>  

Edit: This should do the trick if you have make your stateless session bean a web service, by adding the @webservice annotation to the class and publishing the methods using @webmethod, as dma_k said in comments.

Edit 2: From the link above:

Specifying Security Constraints

A security constraint is used to define the access privileges to a collection of resources using their URL mapping.

Further on:

Specifying a Web Resource Collection

url-pattern is used to list the request URI to be protected. Many applications have both unprotected and protected resources. To provide unrestricted access to a resource, do not configure a security constraint for that particular request URI.

And:

Specifying an Authorization Constraint

An authorization constraint establishes a requirement for authentication and names the roles authorized to access the URL patterns and HTTP methods declared by this security constraint. If there is no authorization constraint, the container must accept the request without requiring user authentication.

So, no <security-constraint> => no authentication => no roles available.

Use auditing or read info (getUserPrincipal(), isUserInRole()) from WebServiceContext, to verify this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!