2012-10-04 42 views
3

我在实现JAX-WS Web服务的授权时遇到了问题。我正在开发一个Swing应用程序,该应用程序可以通过JAX-WS Web服务连接到Java EE应用程序。用户可以使用Swing应用程序登录到服务器,并可以从服务器下载用户特定的数据。记录的用户不能下载属于其他用户的数据是非常重要的。JAX-WS Web Service的身份验证和授权的正确方法是什么?

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

其实我有这样的:

服务器端:

@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中创建了一些测试用户。

任何人有任何想法如何解决它?

+0

这可能是相关的:http://stackoverflow.com/questions/10975070/how-to-enable-spring-security-for-apache-cxf-jax-ws。也看看Spring Security – amphibient

回答

0

您可以使用基本身份验证(http头),也可以使用UserName令牌(WS-安全性的一部分)。用户名令牌将进入SOAP Header而不是http头。