【发布时间】:2015-05-15 15:38:50
【问题描述】:
我正在尝试了解 JAX-WS 中的身份验证,因此我制作了一个带有 JAX-WS 网络服务的小型 Netbeans8.0.2/Glassfish4.1 Web 应用程序,并且我试图使其不公开,但可供授权仅限用户。
此网络服务的 web.xml 文件包含:
<security-constraint>
<web-resource-collection>
<web-resource-name>Fib Web Service</web-resource-name>
<url-pattern>/FibServiceWithAuth/*</url-pattern>
<http-method>*</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>user</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>file</realm-name>
</login-config>
但是,当我制作另一个使用此服务的简单网络应用程序时, 它无需任何身份验证即可工作,请参见此处:
http://kempelen.ii.fmph.uniba.sk:8080/FibApp/
我知道我应该从处理这个 JSF 页面的 JSF 托管 bean 连接到服务,如下所示:
package fibapp;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.WebServiceRef;
@ManagedBean
@RequestScoped
public class FibBean
{
public FibBean() { }
int n;
String result;
public int getN() { return n; }
public void setN(int newN) { n = newN; }
public String getResult() { return result; }
public void setResult(String newResult) { result = newResult; }
@WebServiceRef(wsdlLocation = "http://kempelen.ii.fmph.uniba.sk:8080/FibServiceWithAuth/FibWithAuth?wsdl")
private FibWithAuth_Service fibService;
public void compute()
{
FibWithAuth fib = fibService.getFibWithAuthPort();
// ((BindingProvider) fib).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "someuser");
// ((BindingProvider) fib).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "somepass");
result = fib.fib(n).toString();
}
}
但即使这些用户/密码行被注释掉,bean 仍然从 web 服务中获取结果。
请问缺少什么?
【问题讨论】:
标签: web-services jsf glassfish jax-ws java-ee-7