Apache Tomee SessionContext返回'guest'Principal

时间:2013-09-23 14:25:19

标签: jsf-2 ejb-3.0 tomee

我在apache中部署了EJB,但context.getCallerPrincipal().getName();始终返回“guest”用户,无论谁在Web模块中进行了身份验证。正确的用户在我的JSF托管bean中正确捕获。

EJB

@Stateless()
@DeclareRoles(value = {"ROLE_USER"})
public class StudentFacade extends AbstractFacade<Student> {

    @Resource
    private SessionContext context;
    @PersistenceContext(unitName = "tomeePU")
    private EntityManager em;

    public StudentFacade() {
        super(Student.class);
    }

    @TransactionAttribute(TransactionAttributeType.REQUIRED)

    public void save(Student student) {

        System.out.println("Username in EJB "+context.getCallerPrincipal().getName());
        //prints 'guest' user
        em.persist(student);
    }

    @TransactionAttribute(TransactionAttributeType.SUPPORTS)
    public Student getById(Integer id) {
        return em.find(Student.class, id);
    }

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }
}

jsf托管bean中的方法

 public void save(AjaxBehaviorEvent ajaxBehaviorEvent) {
        try {
            studentFacade.save(student);
            Principal p = JsfUtil.getCurrentHttpRequest().getUserPrincipal();
            System.out.println("UserName Is " + p.getName());//Works fine
            setStudent(new Student());
        } catch (Exception e) {
            JsfUtil.addErrorMessage(e.getMessage());
        }

有哪些额外的tomee配置可以将正确的Principal传播到ejb? 谢谢。

0 个答案:

没有答案