Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/304.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
Java jsf sessionscope和jaas登录模块的会话混合_Java_Jsf_Session_Jboss_Jaas - Fatal编程技术网

Java jsf sessionscope和jaas登录模块的会话混合

Java jsf sessionscope和jaas登录模块的会话混合,java,jsf,session,jboss,jaas,Java,Jsf,Session,Jboss,Jaas,我们有一个CustomLoginModule(扩展了一个UsernamePasswordLoginModule),它在登录时将所有用户和会话引用放在一个映射中。它们存储在@javax.enterprise.context.ApplicationScopedbean中 注销时,这些引用将被删除。为了捕获意外的注销,删除这些引用的方法也从javax.enterprise.context.SessionScopedbean的@PreDestroy方法中调用 当用户在两个位置登录时,第一个位置的会话将无

我们有一个
CustomLoginModule
(扩展了一个
UsernamePasswordLoginModule
),它在登录时将所有用户和会话引用放在一个映射中。它们存储在
@javax.enterprise.context.ApplicationScoped
bean中

注销时,这些引用将被删除。为了捕获意外的注销,删除这些引用的方法也从
javax.enterprise.context.SessionScoped
bean的
@PreDestroy
方法中调用

当用户在两个位置登录时,第一个位置的会话将无效,其引用将从映射中删除。 这意味着当用户在第二个位置登录时,相应的记录将从映射中删除,然后
@PreDestroy
方法将再次尝试删除它

您可能会说,这不是什么大问题,我们只需通过
@PreDestroy
方法传递currect session引用,并将其与映射中的会话进行比较,然后删除会话,前提是两者相等。 然而,我的问题就在这里,显然新实例的
@PreDestroy
方法是在会话注销时调用的。在调用
@Predestroy
方法之后,相同的会话bean将继续运行

我对替代品不太感兴趣,因为有很多。我只是想知道这怎么可能

所讨论的类太复杂,无法粘贴到这里,但我试图表达它们的意图:

登录模块:

public class CustomLoginModule extends UsernamePasswordLoginModule {
    login(){
        SessionMap.addToMap(username, currentSession);
    }
}
适用范围:

@ApplicationScoped
public class SessionMap{
    addToMap(String username, HttpSession currentSession){
         // get previously present session
         previousSession.invalidate(); // this triggers the predestroy of the sessionscoped
         // remove previous session from map
         // put new session in map
    }
}
@SessionScoped
public MySessionBean{
    @PreDestroy
    public void removeSession(){
        // this predestroy is called after the session is invalidated in the addtomap method
        // however, if you log the hash of this class, you will see that the second
        // class's predestroy is called, not the first
        SessionMap.removeFromMap(username, currentSession);
    }
}
会议范围:

@ApplicationScoped
public class SessionMap{
    addToMap(String username, HttpSession currentSession){
         // get previously present session
         previousSession.invalidate(); // this triggers the predestroy of the sessionscoped
         // remove previous session from map
         // put new session in map
    }
}
@SessionScoped
public MySessionBean{
    @PreDestroy
    public void removeSession(){
        // this predestroy is called after the session is invalidated in the addtomap method
        // however, if you log the hash of this class, you will see that the second
        // class's predestroy is called, not the first
        SessionMap.removeFromMap(username, currentSession);
    }
}