Search in sources :

Example 16 with HostSystem

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

the class SystemDB method getSystem.

/**
 * returns system by id
 *
 * @param id system id
 * @return system
 */
public static HostSystem getSystem(Long id) throws SQLException, GeneralSecurityException {
    Connection con = DBUtils.getConn();
    HostSystem hostSystem = getSystem(con, id);
    DBUtils.closeConn(con);
    return hostSystem;
}
Also used : Connection(java.sql.Connection) HostSystem(io.bastillion.manage.model.HostSystem)

Example 17 with HostSystem

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
 */
public static SortedSet getSystemSet(SortedSet sortedSet) 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 s ";
    // if profile id exists add to statement
    sql += StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_PROFILE_ID)) ? ",system_map m where s.id=m.system_id and m.profile_id=? " : "";
    sql += orderBy;
    Connection con = DBUtils.getConn();
    PreparedStatement stmt = con.prepareStatement(sql);
    if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_PROFILE_ID))) {
        stmt.setLong(1, 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;
}
Also used : HostSystem(io.bastillion.manage.model.HostSystem) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 18 with HostSystem

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

the class SystemDB method getSystem.

/**
 * returns system by id
 *
 * @param con DB connection
 * @param id  system id
 * @return system
 */
public static HostSystem getSystem(Connection con, Long id) throws SQLException {
    HostSystem hostSystem = null;
    PreparedStatement stmt = con.prepareStatement("select * from  system where id=?");
    stmt.setLong(1, id);
    ResultSet rs = stmt.executeQuery();
    while (rs.next()) {
        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));
    }
    DBUtils.closeRs(rs);
    DBUtils.closeStmt(stmt);
    return hostSystem;
}
Also used : HostSystem(io.bastillion.manage.model.HostSystem) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 19 with HostSystem

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

the class SSHUtil method distributePubKeysToAllSystems.

/**
 * distributes public keys to all systems
 */
public static void distributePubKeysToAllSystems() throws SQLException, GeneralSecurityException {
    if (keyManagementEnabled) {
        List<HostSystem> hostSystemList = SystemDB.getAllSystems();
        for (HostSystem hostSystem : hostSystemList) {
            hostSystem = SSHUtil.authAndAddPubKey(hostSystem, null, null);
            SystemDB.updateSystem(hostSystem);
        }
    }
}
Also used : HostSystem(io.bastillion.manage.model.HostSystem)

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