Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 2 ApacheTomee SessionContext返回';客人';校长_Jsf 2_Ejb 3.0_Apache Tomee - Fatal编程技术网

Jsf 2 ApacheTomee SessionContext返回';客人';校长

Jsf 2 ApacheTomee SessionContext返回';客人';校长,jsf-2,ejb-3.0,apache-tomee,Jsf 2,Ejb 3.0,Apache Tomee,我在ApacheTomee中部署了一个EJB,但是context.getCallerPrincipal().getName()始终返回“guest”用户,无论谁已在web模块中通过身份验证。在我的JSF托管bean中正确捕获了正确的用户 EJB @Stateless() @DeclareRoles(value = {"ROLE_USER"}) public class StudentFacade extends AbstractFacade<Student> { @Reso

我在ApacheTomee中部署了一个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;
    }
}
为了使传播正确的主体到ejb,还有哪些额外的TOME配置? 谢谢

 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());
        }