我的項目是使用JSF2.0,煤層2.3和Spring 3.0如何縫
登錄過程將被Seam安全發展。
我的問題是要控制重複的用戶登錄如下:
時間1:用戶A @ PC1 >>>>>>登錄系統的用戶ID:11111 >>>>>>>>>>(狀態:OK)
時間2:用戶B @ PC2 >>>>>>登錄系統的用戶ID:11111 >>>>>>>>>>(狀態:OK)
在這個時候,我喜歡無效和註銷自動User A
從系統
我該怎麼做,任何建議,歡迎
我的項目是使用JSF2.0,煤層2.3和Spring 3.0如何縫
登錄過程將被Seam安全發展。
我的問題是要控制重複的用戶登錄如下:
時間1:用戶A @ PC1 >>>>>>登錄系統的用戶ID:11111 >>>>>>>>>>(狀態:OK)
時間2:用戶B @ PC2 >>>>>>登錄系統的用戶ID:11111 >>>>>>>>>>(狀態:OK)
在這個時候,我喜歡無效和註銷自動User A
從系統
我該怎麼做,任何建議,歡迎
創建一個javax.servlet.http.HttpSessionListener並將其添加到您的Web XML中。
將所有會話保存在列表中。
public class SessionListener implements HttpSessionListener, java.io.Serializable{
private static final Logger log = Logger.getLogger(SessionListener.class);
public void sessionCreated(HttpSessionEvent event) {
listsession.add(event.getSession());
}
public void sessionDestroyed(HttpSessionEvent event) {
listsession.remove(event.getSession());
}
}
當一個新的會話被註冊康普艾,如果有一個現有的與列表中相同的用戶。並在其上使用invalidateSession。可以使用這樣的事情,從我有這個想法之後解決了這個問題的會議
for(HttpSession session:listsession){
if (session!=null)
{
Identity identity = null;
Credentials credentials = null;
Object attribute = session.getAttribute("org.jboss.seam.security.identity");
if (attribute instanceof Identity)
{
identity = (Identity) attribute;
}
Object cred = session.getAttribute("org.jboss.seam.security.credentials");
if (attribute instanceof Credentials)
{
credentials = (Credentials) cred;
}
}
}
得到接縫部分:
拳outject LoginUserMap
和LoginUserKeyMap
會話範圍時,用戶登錄。
LoginUserKeyMap
是存儲userId與系統知識密鑰。
例如:[鍵:用戶1,值:user120131010154566]
LoginUserMap
是在用戶信息列表可以存儲記錄。
如:關鍵:user120131010154566,值:對象]
/**
* Bijection Login User Map.
*/
@In(required = false, scope = ScopeType.APPLICATION, value = "loginUserMap")
@Out(required = false, scope = ScopeType.APPLICATION, value = "loginUserMap")
private Map<String, UserInfoBean> loginUserMap;
/**
* Bijection Login User Key Map.
*/
@In(required = false, scope = ScopeType.APPLICATION, value = "loginUserKeyMap")
@Out(required = false, scope = ScopeType.APPLICATION, value = "loginUserKeyMap")
private Map<String, String> loginUserKeyMap;
public void doLogin() {
// Generate User ID Key for duplicate user control.
String key = CommonUtil.convertDateToString(new Date(), KEY_PATTERN);
String userId = getCredentials().getUsername();
String userIdKey = userId + key;
if (getLoginUserMap() == null || getLoginUserKeyMap() == null) {
// Initialize the Login User Map.
setLoginUserMap(new HashMap());
// Initialize the Login User Key Map.
setLoginUserKeyMap(new HashMap());
}
// Check login User id is already login or not.
if (getLoginUserKeyMap().containsKey(userId)) {
log.info("Duplicate Login");
// Get Current logged in User's Key.
String CurrentUserKey = getLoginUserKeyMap().get(userId);
// Get Current logged in User Information.
UserInfoBean currentUserInfoBean = getLoginUserMap().get(CurrentUserKey);
if (currentUserInfoBean != null) {
// Set Duplicate flag true to Current logged User.
currentUserInfoBean.setDuplicate(true);
// Overwrite Current logged User Information.
getLoginUserMap().put(CurrentUserKey, currentUserInfoBean);
}
}
// Set New Login User Information.
getUserInfoBean().setUserId(userId);
getUserInfoBean().setUserIdKey(userIdKey);
getUserInfoBean().setDuplicate(false);
getUserInfoBean().setServiceStop(false);
// Set New Login User Information and Key to Application Scope.
getLoginUserKeyMap().put(userId, userIdKey);
getLoginUserMap().put(userIdKey, getUserInfoBean());
}
,然後創建checkStatus()
方法
public void checkStatus() throws DuplicateLoginException, UserServiceStopException {
if (getUserInfoBean() != null && getLoginUserMap() != null) {
UserInfoBean currentUser = getLoginUserMap().get(getUserInfoBean().getUserIdKey());
if (currentUser != null) {
if (currentUser.isServiceStop()) {
log.error("throw new UserServiceStopException()");
throw new UserServiceStopException();
} else if (currentUser.isDuplicate()) {
log.error("throw new DuplicateLoginException()");
throw new DuplicateLoginException();
}
}
}
}
而且從每一個頁面中調用該方法checkStatus()
。
<page view-id="/view/*">
<action execute="#{UserStatusChecker.checkStatus()}" />
現在問題被克服了!!!!!
如何在使用戶會話失效之前找到'User A'或'User B'是擁有'Original userID'的合法用戶? – SRy
我的awnser沒有工作? – Trind
@對於我遲到的答案Trind抱歉。非常感謝您的解決方案,它的工作。但我們必須控制其他解決方案,所以我用自定義方法解決了這個問題。請親切看到我的答案 – AKZap