【问题标题】:In Restful web services how to get username or password programmatically (basic authentication)在 Restful Web 服务中如何以编程方式获取用户名或密码(基本身份验证)
【发布时间】:2011-06-28 04:35:21
【问题描述】:

我在一个运行在 jboss 上的 Java EE 应用程序 (ejb3) 中有一个安静的 Web 服务。并且不知道如何以编程方式获取用户名或密码,例如在调用服务方法时我希望能够让这个用户主体与 jaxws 类似

webServiceContext.getUserPrincipal().getName() 

(httpServletRequest) <-- request.getUserPrincipal()

我很高兴听到解决方案,谢谢。

【问题讨论】:

    标签: rest ejb-3.0 restful-authentication basic-authentication


    【解决方案1】:

    [已解决] 我已经找到了解决办法,就在这里;

    使用

    @Context
     protected SecurityContext sc;
    

    或者

    Public TestResponse test(@Context SecurityContext sc){
       ..
       sc.getUserPrincipal.getName() //will return username
    }
    

    【讨论】:

    • 您是否也通过注入的上下文获得了密码??
    • 实际上是很久以前的事了,但我记得,是的,我能够同时获得用户名和密码!也许是 sc.getUserPrincipal.getPassword()?
    猜你喜欢
    • 2013-06-11
    • 1970-01-01
    • 2018-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 2020-11-13
    相关资源
    最近更新 更多