use of org.wso2.carbon.identity.application.authentication.framework.model.UserSession in project carbon-identity-framework by wso2.
the class UserSessionDAOImpl method getSession.
public UserSession getSession(String sessionId) throws SessionManagementServerException {
HashMap<String, String> propertiesMap = new HashMap<>();
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate(JdbcUtils.Database.SESSION);
try {
List<Application> applicationList = getApplicationsForSessionID(sessionId);
generateApplicationFromAppID(applicationList);
String sqlStmt = isH2DB() ? SQLQueries.SQL_GET_PROPERTIES_FROM_SESSION_META_DATA_H2 : SQLQueries.SQL_GET_PROPERTIES_FROM_SESSION_META_DATA;
jdbcTemplate.executeQuery(sqlStmt, ((resultSet, rowNumber) -> propertiesMap.put(resultSet.getString(1), resultSet.getString(2))), preparedStatement -> preparedStatement.setString(1, sessionId));
UserSession userSession = new UserSession();
userSession.setSessionId(sessionId);
propertiesMap.forEach((key, value) -> {
switch(key) {
case SessionMgtConstants.USER_AGENT:
userSession.setUserAgent(value);
break;
case SessionMgtConstants.IP_ADDRESS:
userSession.setIp(value);
break;
case SessionMgtConstants.LAST_ACCESS_TIME:
userSession.setLastAccessTime(value);
break;
case SessionMgtConstants.LOGIN_TIME:
userSession.setLoginTime(value);
break;
}
});
if (!applicationList.isEmpty()) {
userSession.setApplications(applicationList);
return userSession;
}
} catch (DataAccessException e) {
throw new SessionManagementServerException(SessionMgtConstants.ErrorMessages.ERROR_CODE_UNABLE_TO_GET_SESSION, SessionMgtConstants.ErrorMessages.ERROR_CODE_UNABLE_TO_GET_SESSION.getDescription(), e);
}
return null;
}
use of org.wso2.carbon.identity.application.authentication.framework.model.UserSession in project carbon-identity-framework by wso2.
the class UserSessionManagementServiceImpl method getActiveSessionList.
/**
* Returns the active sessions from given list of session IDs.
*
* @param sessionIdList list of sessionIds
* @return list of user sessions
* @throws SessionManagementServerException if an error occurs when retrieving the UserSessions.
*/
private List<UserSession> getActiveSessionList(List<String> sessionIdList) throws SessionManagementServerException {
List<UserSession> sessionsList = new ArrayList<>();
for (String sessionId : sessionIdList) {
if (sessionId != null) {
SessionContext sessionContext = FrameworkUtils.getSessionContextFromCache(sessionId, FrameworkUtils.getLoginTenantDomainFromContext());
if (sessionContext != null) {
UserSessionDAO userSessionDTO = new UserSessionDAOImpl();
UserSession userSession = userSessionDTO.getSession(sessionId);
if (userSession != null) {
sessionsList.add(userSession);
}
}
}
}
return sessionsList;
}
Aggregations