Web services JAX-WS Web服务的正确身份验证和授权方式?

Web services JAX-WS Web服务的正确身份验证和授权方式?,web-services,glassfish,authorization,jax-ws,Web Services,Glassfish,Authorization,Jax Ws,我在实现JAX-WSWeb服务的授权时遇到了问题。我正在开发一个Swing应用程序,它可以通过JAX-WSWeb服务连接到JavaEE应用程序。用户可以使用Swing应用程序登录到服务器,并可以从服务器下载特定于用户的数据。登录用户不能下载属于其他用户的数据,这一点很重要 我的问题是jaxwsContext.getUserPrincipal().getName()返回“匿名”。我在这个门户网站上读到了类似的问题,但不幸的是它没有帮助 其实我有这个, 服务器端: @Stateless @Trans

我在实现JAX-WSWeb服务的授权时遇到了问题。我正在开发一个Swing应用程序,它可以通过JAX-WSWeb服务连接到JavaEE应用程序。用户可以使用Swing应用程序登录到服务器,并可以从服务器下载特定于用户的数据。登录用户不能下载属于其他用户的数据,这一点很重要

我的问题是
jaxwsContext.getUserPrincipal().getName()
返回“匿名”。我在这个门户网站上读到了类似的问题,但不幸的是它没有帮助

其实我有这个,

服务器端:

@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
@SOAPBinding(style = SOAPBinding.Style.RPC)
@WebService
public class SampleWSEJB extends AbstractSampleEJB implements ISampleWSLocal, ISampleWSRemote {

    @Resource
    private WebServiceContext jaxwsContext;

    public String getUsername() {
        return username = jaxwsContext.getUserPrincipal().getName();
    }

    @Override
    @WebMethod
    public UserDataVO logInUser() {
        return SampleServerServices.getInstance().logInUser(getEm(), this.getUsername());
    }

...
...

}
客户端:

我使用wsimport工具生成的一些类(ImportedSampleWSEJB、UserDataVO等)

相关客户代码:

private static ImportedSampleWSEJB importedEJB;

public UserDataVO logInUser(String username, String password) {
    Map<String, Object> requestContext = ((BindingProvider)ImportedSampleWSEJB.importedEJB).getRequestContext();
    requestContext.put(BindingProvider.USERNAME_PROPERTY, username);
    requestContext.put(BindingProvider.PASSWORD_PROPERTY, password);
    return importedEJB.logInUser();
}
private static ImportedSampleWSEJB importedEJB;
public UserDataVO登录用户(字符串用户名、字符串密码){
Map requestContext=((BindingProvider)ImportedSampleWSEJB.importedEJB.getRequestContext();
put(BindingProvider.USERNAME\u属性,USERNAME);
requestContext.put(BindingProvider.PASSWORD_属性,PASSWORD);
返回importedEJB.logInUser();
}
我使用“文件”作为安全域,并在glassfish 3.1中创建了一些测试用户


有人知道如何修复吗?

您可以使用基本身份验证(http头)或用户名令牌(WS-Security的一部分)。用户名令牌将放在SOAP头中,而不是http头中

这可能与:。还可以查看Spring安全性