【问题标题】:The correct way of the authentication and authorization of a JAX-WS Web Service?JAX-WS Web Service 的认证和授权的正确方式?
【发布时间】:2012-09-25 15:24:44
【问题描述】:

我在实现 JAX-WS Web 服务的授权时遇到了麻烦。我正在开发一个可以通过 JAX-WS Web 服务连接到 Java EE 应用程序的 Swing 应用程序。用户可以使用 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();
}

我使用“文件”作为安全领域,并在 glassfish 3.1 中创建了一些测试用户。

有人知道怎么解决吗?

【问题讨论】:

标签: web-services glassfish authorization jax-ws


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-22
    • 2012-07-18
    • 1970-01-01
    • 1970-01-01
    • 2011-06-19
    • 1970-01-01
    • 2011-05-20
    相关资源
    最近更新 更多