use of io.bastillion.manage.model.Profile in project KeyBox by skavanagh.
the class UserProfileDB method getProfilesByUser.
/**
* return a list of profiles for user
*
* @param userId user id
* @return profile list
*/
public static List<Profile> getProfilesByUser(Long userId) throws SQLException, GeneralSecurityException {
Connection con = DBUtils.getConn();
List<Profile> profileList = getProfilesByUser(con, userId);
DBUtils.closeConn(con);
return profileList;
}
use of io.bastillion.manage.model.Profile in project KeyBox by skavanagh.
the class ProfileDB method getProfile.
/**
* returns profile based on id
*
* @param profileId profile id
* @return profile
*/
public static Profile getProfile(Long profileId) throws SQLException, GeneralSecurityException {
Connection con = DBUtils.getConn();
Profile profile = getProfile(con, profileId);
DBUtils.closeConn(con);
return profile;
}
use of io.bastillion.manage.model.Profile in project KeyBox by skavanagh.
the class ProfileDB method getProfileSet.
/**
* method to do order by based on the sorted set object for profiles
*
* @return list of profiles
*/
public static SortedSet getProfileSet(SortedSet sortedSet) throws SQLException, GeneralSecurityException {
ArrayList<Profile> profileList = new ArrayList<>();
String orderBy = "";
if (sortedSet.getOrderByField() != null && !sortedSet.getOrderByField().trim().equals("")) {
orderBy = " order by " + sortedSet.getOrderByField() + " " + sortedSet.getOrderByDirection();
}
String sql = "select distinct p.* from profiles p ";
if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_SYSTEM))) {
sql = sql + ", system_map m, system s where m.profile_id = p.id and m.system_id = s.id" + " and (lower(s.display_nm) like ? or lower(s.host) like ?)";
} else if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_USER))) {
sql = sql + ", user_map m, users u where m.profile_id = p.id and m.user_id = u.id" + " and (lower(u.first_nm) like ? or lower(u.last_nm) like ?" + " or lower(u.email) like ? or lower(u.username) like ?)";
}
sql = sql + orderBy;
Connection con = DBUtils.getConn();
PreparedStatement stmt = con.prepareStatement(sql);
if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_SYSTEM))) {
stmt.setString(1, "%" + sortedSet.getFilterMap().get(FILTER_BY_SYSTEM).toLowerCase() + "%");
stmt.setString(2, "%" + sortedSet.getFilterMap().get(FILTER_BY_SYSTEM).toLowerCase() + "%");
} else if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_USER))) {
stmt.setString(1, "%" + sortedSet.getFilterMap().get(FILTER_BY_USER).toLowerCase() + "%");
stmt.setString(2, "%" + sortedSet.getFilterMap().get(FILTER_BY_USER).toLowerCase() + "%");
stmt.setString(3, "%" + sortedSet.getFilterMap().get(FILTER_BY_USER).toLowerCase() + "%");
stmt.setString(4, "%" + sortedSet.getFilterMap().get(FILTER_BY_USER).toLowerCase() + "%");
}
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
Profile profile = new Profile();
profile.setId(rs.getLong("id"));
profile.setNm(rs.getString("nm"));
profile.setDesc(rs.getString("desc"));
profileList.add(profile);
}
DBUtils.closeRs(rs);
DBUtils.closeStmt(stmt);
DBUtils.closeConn(con);
sortedSet.setItemList(profileList);
return sortedSet;
}
use of io.bastillion.manage.model.Profile 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);
}
}
}
}
use of io.bastillion.manage.model.Profile in project KeyBox by skavanagh.
the class ProfileDB method getProfile.
/**
* returns profile based on id
*
* @param con db connection object
* @param profileId profile id
* @return profile
*/
public static Profile getProfile(Connection con, Long profileId) throws SQLException {
Profile profile = null;
PreparedStatement stmt = con.prepareStatement("select * from profiles where id=?");
stmt.setLong(1, profileId);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
profile = new Profile();
profile.setId(rs.getLong("id"));
profile.setNm(rs.getString("nm"));
profile.setDesc(rs.getString("desc"));
profile.setHostSystemList(ProfileSystemsDB.getSystemsByProfile(con, profileId));
}
DBUtils.closeRs(rs);
DBUtils.closeStmt(stmt);
return profile;
}
Aggregations