List of usage examples for java.lang Exception toString
public String toString()
From source file:com.keybox.manage.db.AuthDB.java
/** * checks to see if user is an admin based on auth token * * @param userId user id// ww w . j av a 2 s . com * @param authToken auth token string * @return user type if authorized, null if not authorized */ public static String isAuthorized(Long userId, String authToken) { String authorized = null; Connection con = null; if (authToken != null && !authToken.trim().equals("")) { try { con = DBUtils.getConn(); PreparedStatement stmt = con .prepareStatement("select * from users where enabled=true and id=? and auth_token=?"); stmt.setLong(1, userId); stmt.setString(2, authToken); ResultSet rs = stmt.executeQuery(); if (rs.next()) { authorized = rs.getString("user_type"); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } } DBUtils.closeConn(con); return authorized; }
From source file:com.keybox.manage.db.UserDB.java
/** * updates existing user//from w w w .jav a 2s. com * @param user user object */ public static void updateUserCredentials(User user) { Connection con = null; try { con = DBUtils.getConn(); String salt = EncryptionUtil.generateSalt(); PreparedStatement stmt = con.prepareStatement( "update users set first_nm=?, last_nm=?, email=?, username=?, user_type=?, password=?, salt=? where id=?"); stmt.setString(1, user.getFirstNm()); stmt.setString(2, user.getLastNm()); stmt.setString(3, user.getEmail()); stmt.setString(4, user.getUsername()); stmt.setString(5, user.getUserType()); stmt.setString(6, EncryptionUtil.hash(user.getPassword() + salt)); stmt.setString(7, salt); stmt.setLong(8, user.getId()); stmt.execute(); DBUtils.closeStmt(stmt); if (User.ADMINISTRATOR.equals(user.getUserType())) { PublicKeyDB.deleteUnassignedKeysByUser(con, user.getId()); } } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); }
From source file:com.keybox.manage.db.UserDB.java
/** * checks to see if username is unique while ignoring current user * * @param userId user id//from ww w . j ava2 s .c o m * @param username username * @return true false indicator */ public static boolean isUnique(Long userId, String username) { boolean isUnique = true; if (userId == null) { userId = -99L; } Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement( "select * from users where enabled=true and lower(username) like lower(?) and id != ?"); stmt.setString(1, username); stmt.setLong(2, userId); ResultSet rs = stmt.executeQuery(); if (rs.next()) { isUnique = false; } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception ex) { log.error(ex.toString(), ex); } DBUtils.closeConn(con); return isUnique; }
From source file:com.keybox.manage.db.SessionAuditDB.java
/** * returns a list of terminal sessions for session id * * @param sessionId session id/*from ww w. ja va2 s . com*/ * @return terminal sessions with host information */ public static SessionAudit getSessionsTerminals(Long sessionId) { //get db connection Connection con = null; SessionAudit sessionAudit = new SessionAudit(); String sql = "select * from session_log, users where users.id= session_log.user_id and session_log.id = ? "; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement(sql); stmt.setLong(1, sessionId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { sessionAudit.setId(rs.getLong("session_log.id")); sessionAudit.setSessionTm(rs.getTimestamp(SESSION_TM)); sessionAudit.setUser(UserDB.getUser(con, rs.getLong(USER_ID))); sessionAudit.setHostSystemList(getHostSystemsForSession(con, sessionId)); } DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } //close db connection DBUtils.closeConn(con); return sessionAudit; }
From source file:com.keybox.manage.db.UserDB.java
/** * returns user base on id// w w w . jav a2 s. com * @param con DB connection * @param userId user id * @return user object */ public static User getUser(Connection con, Long userId) { User user = null; try { PreparedStatement stmt = con.prepareStatement("select * from users where id=?"); stmt.setLong(1, userId); 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.setPassword(rs.getString(PASSWORD)); user.setAuthType(rs.getString(AUTH_TYPE)); user.setUserType(rs.getString(USER_TYPE)); user.setSalt(rs.getString("salt")); user.setProfileList(UserProfileDB.getProfilesByUser(con, userId)); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return user; }
From source file:com.tethrnet.manage.db.SessionAuditDB.java
/** * returns terminal logs for user session for host system * * @param sessionId session id//from w w w. jav a2 s. co m * @param instanceId instance id for terminal session * @return session output for session */ public static List<SessionOutput> getTerminalLogsForSession(Connection con, Long sessionId, Integer instanceId) { List<SessionOutput> outputList = new LinkedList<SessionOutput>(); try { PreparedStatement stmt = con.prepareStatement( "select * from terminal_log where instance_id=? and session_id=? order by log_tm asc"); stmt.setLong(1, instanceId); stmt.setLong(2, sessionId); ResultSet rs = stmt.executeQuery(); String output = ""; while (rs.next()) { output = output + rs.getString("output"); } output = output.replaceAll("\\u0007|\u001B\\[K|\\]0;|\\[\\d\\d;\\d\\dm|\\[\\dm", ""); while (output.contains("\b")) { output = output.replaceFirst(".\b", ""); } DBUtils.closeRs(rs); SessionOutput sessionOutput = new SessionOutput(); sessionOutput.setSessionId(sessionId); sessionOutput.setInstanceId(instanceId); sessionOutput.getOutput().append(output); outputList.add(sessionOutput); DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return outputList; }
From source file:com.vmware.identity.idm.IdmDataCreator.java
/** * Create data (ServerConfig loaded at this point) * * @param idmClient/*from w w w. j a v a 2s . co m*/ * @throws Exception */ public static void createData(CasIdmClient idmClient) throws Exception { logger.debug("IdmDataCreator.createData called"); Validate.notNull(idmClient); if (forceCleanup) { // delete tenants int i = 0; String tenantName = ServerConfig.getTenant(i); while (tenantName != null) { IdmDataRemover.addTenant(tenantName); i++; tenantName = ServerConfig.getTenant(i); } try { IdmDataRemover.removeData(idmClient); } catch (Exception e) { logger.debug("Caught exception while removing data {}", e.toString()); } forceCleanup = false; } // create tenants int i = 0; String tenantName = ServerConfig.getTenant(i); while (tenantName != null) { processTenant(idmClient, tenantName); i++; tenantName = ServerConfig.getTenant(i); } // process default tenant String defaultTenant = ServerConfig.getDefaultTenant(); idmClient.setDefaultTenant(defaultTenant); }
From source file:com.etime.ETimeUtils.java
protected static String getHtmlPageWithProgress(DefaultHttpClient client, String url, ETimeAsyncTask asyncTask, int startProgress, int maxProgress, int estimatedPageSize) { HttpResponse response;/*from w ww .j av a 2s . c o m*/ HttpGet httpGet; BufferedReader in = null; String page = null; int runningSize = 0; int progress = startProgress; int tempProgress; String redirect = null; try { httpGet = new HttpGet(url); response = client.execute(httpGet); in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuilder sb = new StringBuilder(""); String line; String NL = System.getProperty("line.separator"); Header[] headers = response.getAllHeaders(); for (Header header : headers) { if (header.getName().equals("Content-Length")) { try { estimatedPageSize = Integer.parseInt(header.getValue()); } catch (Exception e) { Log.w(TAG, e.toString()); } } else if (header.getName().equals("Location")) { redirect = header.getValue(); } if (asyncTask != null) { progress += 5 / (maxProgress - startProgress); asyncTask.publishToProgressBar(progress); } } while ((line = in.readLine()) != null) { if (asyncTask != null) { runningSize += line.length(); tempProgress = startProgress + (int) (((double) runningSize / ((double) estimatedPageSize)) * (maxProgress - startProgress)); progress = (progress >= tempProgress ? progress : tempProgress); if (progress > maxProgress) { //happens when estimatedPageSize <= runningSize progress = maxProgress; } asyncTask.publishToProgressBar(progress); } sb.append(line).append(NL); } page = sb.toString(); } catch (Exception e) { Log.v(TAG, e.toString()); } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } if (redirect != null) { return redirect; } return page; }
From source file:com.keybox.manage.db.UserDB.java
/** * inserts new user//from www . java 2s .c o m * * @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 (first_nm, last_nm, email, username, auth_type, user_type, password, salt) values (?,?,?,?,?,?,?,?)", Statement.RETURN_GENERATED_KEYS); stmt.setString(1, user.getFirstNm()); stmt.setString(2, user.getLastNm()); stmt.setString(3, user.getEmail()); stmt.setString(4, user.getUsername()); stmt.setString(5, user.getAuthType()); stmt.setString(6, user.getUserType()); if (StringUtils.isNotEmpty(user.getPassword())) { String salt = EncryptionUtil.generateSalt(); stmt.setString(7, EncryptionUtil.hash(user.getPassword() + salt)); stmt.setString(8, salt); } else { stmt.setString(7, null); stmt.setString(8, 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.SessionAuditDB.java
/** * returns terminal logs for user session for host system * * @param sessionId session id//from w w w . j ava 2 s . c o m * @param instanceId instance id for terminal session * @return session output for session */ public static List<SessionOutput> getTerminalLogsForSession(Connection con, Long sessionId, Integer instanceId) { List<SessionOutput> outputList = new LinkedList<>(); try { PreparedStatement stmt = con.prepareStatement( "select * from terminal_log where instance_id=? and session_id=? order by log_tm asc"); stmt.setLong(1, instanceId); stmt.setLong(2, sessionId); ResultSet rs = stmt.executeQuery(); StringBuilder outputBuilder = new StringBuilder(""); while (rs.next()) { outputBuilder.append(rs.getString("output")); } String output = outputBuilder.toString(); output = output.replaceAll("\\u0007|\u001B\\[K|\\]0;|\\[\\d\\d;\\d\\dm|\\[\\dm", ""); while (output.contains("\b")) { output = output.replaceFirst(".\b", ""); } DBUtils.closeRs(rs); SessionOutput sessionOutput = new SessionOutput(); sessionOutput.setSessionId(sessionId); sessionOutput.setInstanceId(instanceId); sessionOutput.getOutput().append(output); outputList.add(sessionOutput); DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return outputList; }