【发布时间】: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 中创建了一些测试用户。
有人知道怎么解决吗?
【问题讨论】:
-
这可能是相关的:stackoverflow.com/questions/10975070/…。还要研究 Spring Security
标签: web-services glassfish authorization jax-ws