use of io.bastillion.manage.model.HostSystem in project KeyBox by skavanagh.
the class SystemDB method getAllSystems.
/**
* returns all systems
*
* @return system list
*/
public static List<HostSystem> getAllSystems() throws SQLException, GeneralSecurityException {
List<HostSystem> hostSystemList = new ArrayList<>();
Connection con = DBUtils.getConn();
PreparedStatement stmt = con.prepareStatement("select * from system");
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
HostSystem hostSystem = new HostSystem();
hostSystem.setId(rs.getLong("id"));
hostSystem.setDisplayNm(rs.getString(DISPLAY_NM));
hostSystem.setUser(rs.getString("username"));
hostSystem.setHost(rs.getString("host"));
hostSystem.setPort(rs.getInt("port"));
hostSystem.setAuthorizedKeys(rs.getString(AUTHORIZED_KEYS));
hostSystem.setStatusCd(rs.getString(STATUS_CD));
hostSystemList.add(hostSystem);
}
DBUtils.closeRs(rs);
DBUtils.closeStmt(stmt);
DBUtils.closeConn(con);
return hostSystemList;
}
use of io.bastillion.manage.model.HostSystem in project KeyBox by skavanagh.
the class SystemDB method getSystems.
/**
* returns the host systems
*
* @param systemIdList list of host system ids
* @return host system with array of public keys
*/
public static List<HostSystem> getSystems(List<Long> systemIdList) throws SQLException, GeneralSecurityException {
List<HostSystem> hostSystemListReturn = new ArrayList<>();
Connection con = DBUtils.getConn();
for (Long systemId : systemIdList) {
HostSystem hostSystem = getSystem(con, systemId);
hostSystemListReturn.add(hostSystem);
}
DBUtils.closeConn(con);
return hostSystemListReturn;
}
use of io.bastillion.manage.model.HostSystem in project KeyBox by skavanagh.
the class SystemDB method getSystemSet.
/**
* method to do order by based on the sorted set object for systems
*
* @param sortedSet sorted set object
* @return sortedSet with list of host systems
* @profileId check if system is apart of given profile
*/
public static SortedSet getSystemSet(SortedSet sortedSet, Long profileId) throws SQLException, GeneralSecurityException {
List<HostSystem> hostSystemList = new ArrayList<>();
String orderBy = "";
if (sortedSet.getOrderByField() != null && !sortedSet.getOrderByField().trim().equals("")) {
orderBy = "order by " + sortedSet.getOrderByField() + " " + sortedSet.getOrderByDirection();
}
String sql = "select s.*, m.profile_id from system s left join system_map m on m.system_id = s.id and m.profile_id = ? " + orderBy;
Connection con = DBUtils.getConn();
PreparedStatement stmt = con.prepareStatement(sql);
stmt.setLong(1, profileId);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
HostSystem hostSystem = new HostSystem();
hostSystem.setId(rs.getLong("id"));
hostSystem.setDisplayNm(rs.getString(DISPLAY_NM));
hostSystem.setUser(rs.getString("username"));
hostSystem.setHost(rs.getString("host"));
hostSystem.setPort(rs.getInt("port"));
hostSystem.setAuthorizedKeys(rs.getString(AUTHORIZED_KEYS));
hostSystem.setStatusCd(rs.getString(STATUS_CD));
hostSystem.setChecked(profileId != null && profileId.equals(rs.getLong(PROFILE_ID)));
hostSystemList.add(hostSystem);
}
DBUtils.closeRs(rs);
DBUtils.closeStmt(stmt);
DBUtils.closeConn(con);
sortedSet.setItemList(hostSystemList);
return sortedSet;
}
use of io.bastillion.manage.model.HostSystem in project KeyBox by skavanagh.
the class SystemDB method getUserSystemSet.
/**
* method to do order by based on the sorted set object for systems for user
*
* @param sortedSet sorted set object
* @param userId user id
* @return sortedSet with list of host systems
*/
public static SortedSet getUserSystemSet(SortedSet sortedSet, Long userId) throws SQLException, GeneralSecurityException {
List<HostSystem> hostSystemList = new ArrayList<>();
String orderBy = "";
if (sortedSet.getOrderByField() != null && !sortedSet.getOrderByField().trim().equals("")) {
orderBy = "order by " + sortedSet.getOrderByField() + " " + sortedSet.getOrderByDirection();
}
String sql = "select * from system where id in (select distinct system_id from system_map m, user_map um where m.profile_id=um.profile_id and um.user_id=? ";
// if profile id exists add to statement
sql += StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_PROFILE_ID)) ? " and um.profile_id=? " : "";
sql += ") " + orderBy;
// get user for auth token
Connection con = DBUtils.getConn();
PreparedStatement stmt = con.prepareStatement(sql);
stmt.setLong(1, userId);
// filter by profile id if exists
if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_PROFILE_ID))) {
stmt.setLong(2, Long.parseLong(sortedSet.getFilterMap().get(FILTER_BY_PROFILE_ID)));
}
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
HostSystem hostSystem = new HostSystem();
hostSystem.setId(rs.getLong("id"));
hostSystem.setDisplayNm(rs.getString(DISPLAY_NM));
hostSystem.setUser(rs.getString("username"));
hostSystem.setHost(rs.getString("host"));
hostSystem.setPort(rs.getInt("port"));
hostSystem.setAuthorizedKeys(rs.getString(AUTHORIZED_KEYS));
hostSystem.setStatusCd(rs.getString(STATUS_CD));
hostSystemList.add(hostSystem);
}
DBUtils.closeRs(rs);
DBUtils.closeStmt(stmt);
DBUtils.closeConn(con);
sortedSet.setItemList(hostSystemList);
return sortedSet;
}
use of io.bastillion.manage.model.HostSystem in project KeyBox by skavanagh.
the class SecureShellKtrl method createTerms.
/**
* creates composite terminals if there are errors or authentication issues.
*/
@Kontrol(path = "/admin/createTerms", method = MethodType.POST)
public String createTerms() throws ServletException {
try {
Long userId = AuthUtil.getUserId(getRequest().getSession());
Long sessionId = AuthUtil.getSessionId(getRequest().getSession());
if (pendingSystemStatus != null && pendingSystemStatus.getId() != null) {
// get status
currentSystemStatus = SystemStatusDB.getSystemStatus(pendingSystemStatus.getId(), userId);
// if initial status run script
if (currentSystemStatus != null && (HostSystem.INITIAL_STATUS.equals(currentSystemStatus.getStatusCd()) || HostSystem.AUTH_FAIL_STATUS.equals(currentSystemStatus.getStatusCd()) || HostSystem.PUBLIC_KEY_FAIL_STATUS.equals(currentSystemStatus.getStatusCd()))) {
// set current session
currentSystemStatus = SSHUtil.openSSHTermOnSystem(passphrase, password, userId, sessionId, currentSystemStatus, userSchSessionMap);
}
if (currentSystemStatus != null && (HostSystem.AUTH_FAIL_STATUS.equals(currentSystemStatus.getStatusCd()) || HostSystem.PUBLIC_KEY_FAIL_STATUS.equals(currentSystemStatus.getStatusCd()))) {
pendingSystemStatus = currentSystemStatus;
} else {
pendingSystemStatus = SystemStatusDB.getNextPendingSystem(userId);
// if success loop through systems until finished or need password
while (pendingSystemStatus != null && currentSystemStatus != null && HostSystem.SUCCESS_STATUS.equals(currentSystemStatus.getStatusCd())) {
currentSystemStatus = SSHUtil.openSSHTermOnSystem(passphrase, password, userId, sessionId, pendingSystemStatus, userSchSessionMap);
pendingSystemStatus = SystemStatusDB.getNextPendingSystem(userId);
}
}
}
// set system list if no pending systems
if (SystemStatusDB.getNextPendingSystem(userId) == null) {
setSystemList(userId, sessionId);
// set allocated systems for connect to
SortedSet sortedSet = new SortedSet();
sortedSet.setOrderByField(SystemDB.SORT_BY_NAME);
if (Auth.MANAGER.equals(AuthUtil.getUserType(getRequest().getSession()))) {
sortedSet = SystemDB.getSystemSet(sortedSet);
} else {
sortedSet = SystemDB.getUserSystemSet(sortedSet, userId);
}
if (sortedSet.getItemList() != null) {
allocatedSystemList = (List<HostSystem>) sortedSet.getItemList();
}
// set theme
this.userSettings = UserThemeDB.getTheme(userId);
}
} catch (SQLException | GeneralSecurityException ex) {
log.error(ex.toString(), ex);
throw new ServletException(ex.toString(), ex);
}
return "/admin/secure_shell.html";
}
Aggregations