Search in sources :

Example 11 with HostSystem

use of io.bastillion.manage.model.HostSystem in project KeyBox by skavanagh.

the class SSHUtil method distributePubKeysToUser.

/**
 * distributes public keys to all systems under all user profiles
 *
 * @param userId user id
 */
public static void distributePubKeysToUser(Long userId) throws SQLException, GeneralSecurityException {
    if (keyManagementEnabled) {
        for (Profile profile : UserProfileDB.getProfilesByUser(userId)) {
            List<HostSystem> hostSystemList = ProfileSystemsDB.getSystemsByProfile(profile.getId());
            for (HostSystem hostSystem : hostSystemList) {
                hostSystem = SSHUtil.authAndAddPubKey(hostSystem, null, null);
                SystemDB.updateSystem(hostSystem);
            }
        }
    }
}
Also used : HostSystem(io.bastillion.manage.model.HostSystem) Profile(io.bastillion.manage.model.Profile)

Example 12 with HostSystem

use of io.bastillion.manage.model.HostSystem in project KeyBox by skavanagh.

the class SessionAuditDB method getHostSystemsForSession.

/**
 * returns terminal logs for user session for host system
 *
 * @param con       DB connection
 * @param sessionId session id
 * @return session output for session
 */
public static List<HostSystem> getHostSystemsForSession(Connection con, Long sessionId) throws SQLException {
    List<HostSystem> hostSystemList = new ArrayList<>();
    PreparedStatement stmt = con.prepareStatement("select distinct instance_id, display_nm, username, host, port from terminal_log where session_id=?");
    stmt.setLong(1, sessionId);
    ResultSet rs = stmt.executeQuery();
    while (rs.next()) {
        HostSystem hostSystem = new HostSystem();
        hostSystem.setDisplayNm(rs.getString("display_nm"));
        hostSystem.setUser(rs.getString("username"));
        hostSystem.setHost(rs.getString("host"));
        hostSystem.setPort(rs.getInt("port"));
        hostSystem.setInstanceId(rs.getInt("instance_id"));
        hostSystemList.add(hostSystem);
    }
    DBUtils.closeRs(rs);
    DBUtils.closeStmt(stmt);
    return hostSystemList;
}
Also used : HostSystem(io.bastillion.manage.model.HostSystem) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 13 with HostSystem

use of io.bastillion.manage.model.HostSystem in project KeyBox by skavanagh.

the class SystemStatusDB method getAllSystemStatus.

/**
 * returns all key placement statuses
 *
 * @param con    DB connection object
 * @param userId user id
 */
private static List<HostSystem> getAllSystemStatus(Connection con, Long userId) throws SQLException {
    List<HostSystem> hostSystemList = new ArrayList<>();
    PreparedStatement stmt = con.prepareStatement("select * from status where user_id=? order by id asc");
    stmt.setLong(1, userId);
    ResultSet rs = stmt.executeQuery();
    while (rs.next()) {
        HostSystem hostSystem = SystemDB.getSystem(con, rs.getLong("id"));
        hostSystem.setStatusCd(rs.getString(STATUS_CD));
        hostSystemList.add(hostSystem);
    }
    DBUtils.closeRs(rs);
    DBUtils.closeStmt(stmt);
    return hostSystemList;
}
Also used : HostSystem(io.bastillion.manage.model.HostSystem) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 14 with HostSystem

use of io.bastillion.manage.model.HostSystem in project KeyBox by skavanagh.

the class SystemStatusDB method setInitialSystemStatus.

/**
 * set the initial status for selected systems
 *
 * @param systemSelectIds systems ids to set initial status
 * @param userId          user id
 * @param userType        user type
 */
public static void setInitialSystemStatus(List<Long> systemSelectIds, Long userId, String userType) throws SQLException, GeneralSecurityException {
    Connection con = DBUtils.getConn();
    // checks perms if to see if in assigned profiles
    if (!Auth.MANAGER.equals(userType)) {
        systemSelectIds = SystemDB.checkSystemPerms(con, systemSelectIds, userId);
    }
    // deletes all old systems
    deleteAllSystemStatus(con, userId);
    for (Long hostSystemId : systemSelectIds) {
        HostSystem hostSystem = new HostSystem();
        hostSystem.setId(hostSystemId);
        hostSystem.setStatusCd(HostSystem.INITIAL_STATUS);
        // insert new status
        insertSystemStatus(con, hostSystem, userId);
    }
    DBUtils.closeConn(con);
}
Also used : Connection(java.sql.Connection) HostSystem(io.bastillion.manage.model.HostSystem)

Example 15 with HostSystem

use of io.bastillion.manage.model.HostSystem in project KeyBox by skavanagh.

the class ProfileSystemsDB method getSystemsByProfile.

/**
 * returns a list of systems for a given profile
 *
 * @param con       DB connection
 * @param profileId profile id
 * @return list of host systems
 */
public static List<HostSystem> getSystemsByProfile(Connection con, Long profileId) throws SQLException {
    List<HostSystem> hostSystemList = new ArrayList<>();
    PreparedStatement stmt = con.prepareStatement("select * from  system s, system_map m where s.id=m.system_id and m.profile_id=? order by display_nm asc");
    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"));
        hostSystemList.add(hostSystem);
    }
    DBUtils.closeRs(rs);
    DBUtils.closeStmt(stmt);
    return hostSystemList;
}
Also used : HostSystem(io.bastillion.manage.model.HostSystem) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Aggregations

HostSystem (io.bastillion.manage.model.HostSystem)19 Connection (java.sql.Connection)11 PreparedStatement (java.sql.PreparedStatement)10 ResultSet (java.sql.ResultSet)10 ArrayList (java.util.ArrayList)8 Profile (io.bastillion.manage.model.Profile)1 SortedSet (io.bastillion.manage.model.SortedSet)1 GeneralSecurityException (java.security.GeneralSecurityException)1 SQLException (java.sql.SQLException)1 ServletException (javax.servlet.ServletException)1 Kontrol (loophole.mvc.annotation.Kontrol)1