Search in sources :

Example 6 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 userId user id
 */
public static List<HostSystem> getAllSystemStatus(Long userId) throws SQLException, GeneralSecurityException {
    Connection con = DBUtils.getConn();
    List<HostSystem> hostSystemList = getAllSystemStatus(con, userId);
    DBUtils.closeConn(con);
    return hostSystemList;
}
Also used : Connection(java.sql.Connection) HostSystem(io.bastillion.manage.model.HostSystem)

Example 7 with HostSystem

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

the class SystemStatusDB method getSystemStatus.

/**
 * returns key placement status of system
 *
 * @param systemId system id
 * @param userId   user id
 */
public static HostSystem getSystemStatus(Long systemId, Long userId) throws SQLException, GeneralSecurityException {
    HostSystem hostSystem = null;
    Connection con = DBUtils.getConn();
    PreparedStatement stmt = con.prepareStatement("select * from status where id=? and user_id=?");
    stmt.setLong(1, systemId);
    stmt.setLong(2, userId);
    ResultSet rs = stmt.executeQuery();
    while (rs.next()) {
        hostSystem = SystemDB.getSystem(con, rs.getLong("id"));
        hostSystem.setStatusCd(rs.getString(STATUS_CD));
    }
    DBUtils.closeRs(rs);
    DBUtils.closeStmt(stmt);
    DBUtils.closeConn(con);
    return hostSystem;
}
Also used : HostSystem(io.bastillion.manage.model.HostSystem) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 8 with HostSystem

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

the class SystemStatusDB method getNextPendingSystem.

/**
 * returns the first system that authorized keys has not been tried
 *
 * @param userId user id
 * @return hostSystem systems for authorized_keys replacement
 */
public static HostSystem getNextPendingSystem(Long userId) throws SQLException, GeneralSecurityException {
    HostSystem hostSystem = null;
    Connection con = DBUtils.getConn();
    PreparedStatement stmt = con.prepareStatement("select * from status where (status_cd like ? or status_cd like ? or status_cd like ?) and user_id=? order by id asc");
    stmt.setString(1, HostSystem.INITIAL_STATUS);
    stmt.setString(2, HostSystem.AUTH_FAIL_STATUS);
    stmt.setString(3, HostSystem.PUBLIC_KEY_FAIL_STATUS);
    stmt.setLong(4, userId);
    ResultSet rs = stmt.executeQuery();
    if (rs.next()) {
        hostSystem = SystemDB.getSystem(con, rs.getLong("id"));
        hostSystem.setStatusCd(rs.getString(STATUS_CD));
    }
    DBUtils.closeRs(rs);
    DBUtils.closeStmt(stmt);
    DBUtils.closeConn(con);
    return hostSystem;
}
Also used : HostSystem(io.bastillion.manage.model.HostSystem) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 9 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 profileId profile id
 * @return list of host systems
 */
public static List<HostSystem> getSystemsByProfile(Long profileId) throws SQLException, GeneralSecurityException {
    Connection con = DBUtils.getConn();
    List<HostSystem> hostSystemList = getSystemsByProfile(con, profileId);
    DBUtils.closeConn(con);
    return hostSystemList;
}
Also used : Connection(java.sql.Connection) HostSystem(io.bastillion.manage.model.HostSystem)

Example 10 with HostSystem

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

the class SSHUtil method distributePubKeysToProfile.

/**
 * distributes public keys to all systems under profile
 *
 * @param profileId profile id
 */
public static void distributePubKeysToProfile(Long profileId) throws SQLException, GeneralSecurityException {
    if (keyManagementEnabled) {
        List<HostSystem> hostSystemList = ProfileSystemsDB.getSystemsByProfile(profileId);
        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