List of usage examples for java.lang Exception toString
public String toString()
From source file:com.keybox.manage.db.UserDB.java
/** * deletes user//from www. ja v a 2 s . c om * @param userId user id */ public static void disableUser(Long userId) { Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement("update users set enabled=false where id=?"); stmt.setLong(1, userId); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); }
From source file:com.keybox.manage.db.UserDB.java
/** * resets shared secret for user/* w ww . j a v a2s . co m*/ * @param userId user id */ public static void resetSharedSecret(Long userId) { Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement("update users set otp_secret=null where id=?"); stmt.setLong(1, userId); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); }
From source file:com.tethrnet.manage.db.SessionAuditDB.java
/** * returns terminal logs for user session for host system * * @param con DB connection//from w ww. jav a2s . c om * @param sessionId session id * @return session output for session */ public static List<HostSystem> getHostSystemsForSession(Connection con, Long sessionId) { List<HostSystem> hostSystemList = new ArrayList<HostSystem>(); try { PreparedStatement stmt = con.prepareStatement( "select distinct instance_id, system_id from terminal_log where session_id=?"); stmt.setLong(1, sessionId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { HostSystem hostSystem = SystemDB.getSystem(con, rs.getLong("system_id")); hostSystem.setInstanceId(rs.getInt("instance_id")); hostSystemList.add(hostSystem); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception ex) { log.error(ex.toString(), ex); } return hostSystemList; }
From source file:com.keybox.manage.db.AuthDB.java
/** * updates the admin table based on auth id * * @param con DB connection/*w w w. jav a 2s. c o m*/ * @param auth username and password object */ public static void updateLogin(Connection con, Auth auth) { try { PreparedStatement stmt = con.prepareStatement( "update users set username=?, auth_type=?, auth_token=?, password=?, salt=? where id=?"); stmt.setString(1, auth.getUsername()); stmt.setString(2, auth.getAuthType()); stmt.setString(3, auth.getAuthToken()); if (StringUtils.isNotEmpty(auth.getPassword())) { String salt = EncryptionUtil.generateSalt(); stmt.setString(4, EncryptionUtil.hash(auth.getPassword() + salt)); stmt.setString(5, salt); } else { stmt.setString(4, null); stmt.setString(5, null); } stmt.setLong(6, auth.getId()); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } }
From source file:com.tethrnet.manage.db.AuthDB.java
/** * returns user base on username/*from w w w . ja v a 2 s. c o m*/ * * @param con DB connection * @param uid username id * @return user object */ public static User getUserByUID(Connection con, String uid) { User user = null; try { PreparedStatement stmt = con .prepareStatement("select * from users where lower(username) like lower(?) and enabled=true"); stmt.setString(1, uid); ResultSet rs = stmt.executeQuery(); while (rs.next()) { user = new User(); user.setId(rs.getLong("id")); user.setEmail(rs.getString("email")); user.setUsername(rs.getString("username")); user.setUserType(rs.getString("user_type")); user.setProfileList(UserProfileDB.getProfilesByUser(con, user.getId())); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return user; }
From source file:com.vmware.identity.idm.IdmDataCreator.java
private static KeyPair readKeyStore(CredentialDescriptor cd) throws IOException { KeyPair kp = null;/*from w ww. j a v a 2s . c om*/ InputStream is = null; try { KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); char[] stsKeystorePassword = cd.getPassword().toCharArray(); is = getInputStream(cd.getFilename()); ks.load(is, stsKeystorePassword); kp = new KeyPair(); kp.setCertificateChain(Arrays.asList(ks.getCertificateChain(cd.getAlias()))); kp.setPrivateKey((PrivateKey) ks.getKey(cd.getAlias(), stsKeystorePassword)); } catch (Exception e) { logger.debug("Caught exception while reading keystore {}", e.toString()); } finally { if (is != null) { is.close(); } } return kp; }
From source file:com.tethrnet.manage.db.UserDB.java
/** * inserts new user/* ww w. jav a 2 s . c om*/ * * @param con DB connection * @param user user object */ public static Long insertUser(Connection con, User user) { Long userId = null; try { PreparedStatement stmt = con.prepareStatement( "insert into users (email, username, auth_type, user_type, password, salt) values (?,?,?,?,?,?)", Statement.RETURN_GENERATED_KEYS); stmt.setString(1, user.getEmail()); stmt.setString(2, user.getUsername()); stmt.setString(3, user.getAuthType()); stmt.setString(4, user.getUserType()); if (StringUtils.isNotEmpty(user.getPassword())) { String salt = EncryptionUtil.generateSalt(); stmt.setString(5, EncryptionUtil.hash(user.getPassword() + salt)); stmt.setString(6, salt); } else { stmt.setString(5, null); stmt.setString(6, null); } stmt.execute(); ResultSet rs = stmt.getGeneratedKeys(); if (rs != null && rs.next()) { userId = rs.getLong(1); } DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return userId; }
From source file:com.keybox.manage.db.AuthDB.java
/** * returns user base on username//from w w w . j a va 2s. c o m * * @param con DB connection * @param uid username id * @return user object */ public static User getUserByUID(Connection con, String uid) { User user = null; try { PreparedStatement stmt = con .prepareStatement("select * from users where lower(username) like lower(?) and enabled=true"); stmt.setString(1, uid); ResultSet rs = stmt.executeQuery(); while (rs.next()) { user = new User(); user.setId(rs.getLong("id")); user.setFirstNm(rs.getString("first_nm")); user.setLastNm(rs.getString("last_nm")); user.setEmail(rs.getString("email")); user.setUsername(rs.getString("username")); user.setUserType(rs.getString("user_type")); user.setProfileList(UserProfileDB.getProfilesByUser(con, user.getId())); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return user; }
From source file:com.keybox.manage.db.SessionAuditDB.java
/** * insert new session record for user//www . j a va 2s . com * * @param con DB connection * @param userId user id * @return session id */ public static Long createSessionLog(Connection con, Long userId) { Long sessionId = null; try { //insert PreparedStatement stmt = con.prepareStatement("insert into session_log (user_id) values(?)", Statement.RETURN_GENERATED_KEYS); stmt.setLong(1, userId); stmt.execute(); ResultSet rs = stmt.getGeneratedKeys(); if (rs != null && rs.next()) { sessionId = rs.getLong(1); } DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return sessionId; }
From source file:com.keybox.manage.db.SessionAuditDB.java
/** * insert new terminal history for user//from ww w.j a va 2s . co m * * @param con DB connection * @param sessionOutput output from session terminals * @return session id */ public static void insertTerminalLog(Connection con, SessionOutput sessionOutput) { try { if (sessionOutput != null && sessionOutput.getSessionId() != null && sessionOutput.getInstanceId() != null && sessionOutput.getOutput() != null && !sessionOutput.getOutput().toString().equals("")) { //insert PreparedStatement stmt = con.prepareStatement( "insert into terminal_log (session_id, instance_id, system_id, output) values(?,?,?,?)"); stmt.setLong(1, sessionOutput.getSessionId()); stmt.setLong(2, sessionOutput.getInstanceId()); stmt.setLong(3, sessionOutput.getId()); stmt.setString(4, sessionOutput.getOutput().toString()); stmt.execute(); DBUtils.closeStmt(stmt); } } catch (Exception e) { log.error(e.toString(), e); } }