通过RESTeasy webservice对EJB进行身份验证

时间:2013-05-22 11:41:18

标签: authentication jboss resteasy

我正在尝试使用RESTeasy设置REST-webservice,以访问部署在JBoss 7.1.1上的EJB。 我成功了:

  • 设置通过REST访问的Bean

  • 为连接配置SSL

  • 设置PreProcessInterceptor,使用HTTP Basic Auth向用户询问其凭据。

目前我基本上只是检查拦截器中硬编码的凭证。 这可以确保用户通过身份验证,但我们的Beans查询某些BeanCalls当前登录的Principal的名称,如下所示:

@Resource
private SessionContext context = null;
[...]

String userName = context.getCallerPrincipal().getName();

目前,userName现在始终是匿名的。设置调用者主体的正确方法是什么?我是否在拦截器中执行此操作?还是在Bean本身?我的目标是基本上能够调用一个方法loginUserWithEJBOnJboss(String user,String pass),该方法使用在jboss中配置的登录方法并正确设置主体。

我在这里不知所措,谷歌没有找到任何东西。也许我只是在寻找错误的词语。

1 个答案:

答案 0 :(得分:0)

所以是的,就像我一直问我自己找到解决方案后不久。我想有时我只会问,因为我知道这会发生。

所以解决方案就是这些方法:

    SecurityContextAssociation.setPrincipal(new SimplePrincipal(username));
    SecurityContextAssociation.setCredential(password.toCharArray());

他们几乎所有我想做的事情:)