This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LoginManager implements HttpSessionBindingListener{ | |
private static LoginManager loginManager = null; | |
// Users Hash Table | |
private static Hashtable<HttpSession, String> loginUsers = new Hashtable<HttpSession, String>(); | |
// single ton | |
public static synchronized LoginManager getInstance(){ | |
if(loginManager == null ){ | |
loginManager = new LoginManager(); | |
} | |
return loginManager; | |
} | |
/** | |
* session.setAttribute 시 호출. | |
* HashTable User Save | |
* **/ | |
@Override | |
public void valueBound(HttpSessionBindingEvent event) { | |
// TODO Auto-generated method stub | |
loginUsers.put(event.getSession(), event.getName()); | |
} | |
/** | |
* session invalidate | |
* hashTable user Delete | |
* **/ | |
@Override | |
public void valueUnbound(HttpSessionBindingEvent event) { | |
// TODO Auto-generated method stub | |
loginUsers.remove(event.getSession()); | |
} | |
@Autowired | |
public void removeSession(String userId){ | |
Enumeration e =loginUsers.keys(); | |
HttpSession session = null; | |
while(e.hasMoreElements()){ | |
session = (HttpSession)e.nextElement(); | |
if(loginUsers.get(session).equals(userId)){ | |
session.invalidate(); | |
} | |
} | |
} | |
/** | |
* 해당 사용자 사용중 체크. | |
* **/ | |
public boolean isUsing(String userId){ | |
return loginUsers.contains(userId); | |
} | |
/** | |
* 해당 사용자 사용중 체크. | |
* **/ | |
public void setSession(HttpSession session, String userId){ | |
session.setAttribute(userId, this); | |
} | |
/** | |
* 입력받은 세션의 정보 리턴 | |
* **/ | |
public String getUserId(HttpSession session){ | |
return (String)loginUsers.get(session); | |
} | |
} |
출처 : http://teck10.tistory.com/75
'Java' 카테고리의 다른 글
자바 컴파일(Compile) 과정 (0) | 2018.09.12 |
---|---|
pom.xml에서 환경별 주요 프로퍼티 분기. (0) | 2018.09.11 |
이클립스(Eclipse) - 톰켓(Tomcat) (0) | 2018.09.11 |
재귀적 호출 - 팩토리얼 (0) | 2018.09.04 |
JSTL Tag Custom Function (0) | 2018.09.04 |