public void RemoveAuditAccess(String u, String url) throws Exception { Connection con = Utility.getConfigurationDBConnection(); try { PreparedStatement cmd = con.prepareStatement("delete from userpermissions where username=? and objecturi=?; "); cmd.setString(1, u); cmd.setString(2, url); cmd.execute(); cmd.close(); // System.out.println("attempting config connection close"); con.close(); // System.out.println("config connection closed"); } catch (Exception x) { x.printStackTrace(); } finally { try { if (!con.isClosed()) { // System.out.println("attempting config connection close"); con.close(); // System.out.println("config connection closed"); } } catch (Exception e) { } } }
public void resetClassLevel() throws SQLException { Connection con = Utility.getConfigurationDBConnection(); try { PreparedStatement ps = con.prepareStatement("UPDATE globalpolicies SET classification=?, caveat=?"); ps.setString(1, ClassificationType.U.value()); ps.setString(2, ""); ps.execute(); } catch (Exception x) { x.printStackTrace(); } finally { try { if (!con.isClosed()) { //System.out.println("attempting config connection close"); con.close(); // System.out.println("config connection closed"); } } catch (Exception e) { } } }
public void adduser(String bobusername) throws SQLException { Connection con = Utility.getConfigurationDBConnection(); try { PreparedStatement ps = con.prepareStatement("delete from userpermissions where username=?; delete from slasub where username=?; delete from users where username=?;" + "INSERT INTO users( username , displayname , email ) VALUES( ?, ?, ?); "); ps.setString(1, bobusername); ps.setString(2, bobusername); ps.setString(3, bobusername); ps.setString(4, bobusername); ps.setString(5, "junit"); ps.setString(6, bobusername + "@localhost.localdomain"); ps.execute(); } catch (Exception x) { x.printStackTrace(); } finally { try { if (!con.isClosed()) { // System.out.println("attempting config connection close"); con.close(); // System.out.println("config connection closed"); } } catch (Exception e) { } } }
/** * returns all of the mail settings, use from pooled connections with jndi * * @return */ public static Properties LoadSLAPropertiesPooled() { Connection con = Utility.getConfigurationDBConnection(); Properties p = loadSLAProperties(con); DBUtils.safeClose(con); return p; }
private List<String> getProcessListByHostname(String hostname, String domainName) { List<String> r = new ArrayList<String>(); Connection con = Utility.getConfigurationDBConnection(); PreparedStatement com = null; ResultSet rs = null; try { com = con.prepareStatement("select uri from servicepolicies where hostname=? and domaincol=? and policytype=?;"); com.setString(1, hostname); com.setString(2, domainName); com.setInt(3, PolicyType.PROCESS.ordinal()); rs = com.executeQuery(); while (rs.next()) { r.add(rs.getString(1)); } } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(com); DBUtils.safeClose(con); } return r; }
/** * Loads a policy using a caching mechanism, used by DCS and DAS if the * policy does not exist, it will NOT be created * * @param uRI * @return */ public static ServicePolicy LoadPolicyPooled(String uRI) { SetupBundle(); Connection con = Utility.getConfigurationDBConnection(); ServicePolicy sp = loadPolicy(con, uRI); try { con.close(); } catch (SQLException ex) { log.log(Level.WARN, bundle.getString("ErrorClosingDB"), ex); } return sp; }
private static void validatePluginRegistered(String type) throws Exception { Connection configurationDBConnection = Utility.getConfigurationDBConnection(); PreparedStatement cmd = null; ResultSet rs = null; try { cmd = configurationDBConnection.prepareStatement("select * from plugins where classname=? and appliesto='REPORTING'"); cmd.setString(1, type); ResultSet executeQuery = cmd.executeQuery(); if (executeQuery.next()) { //we are ok } else { throw new IllegalArgumentException("Plugin '" + type + "' not registered"); } } catch (Exception ex) { log.log(Level.WARN, null, ex); throw ex; } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); DBUtils.safeClose(configurationDBConnection); } }
@Override public void run() { UUID random = UUID.randomUUID(); MessageProcessor.getSingletonObject().processMessageInput(SERVICE_NAME, 0, myUrl, "machine/process", "system", random.toString(), new HashMap(), "", this.getClass().getCanonicalName(), "", ""); Connection ConfigCon = Utility.getConfigurationDBConnection(); Connection PerfCon = Utility.getPerformanceDBConnection(); try { doWorkBrokers(ConfigCon, PerfCon, periods); MessageProcessor.getSingletonObject().processMessageOutput(random.toString(), "success", 0, false, System.currentTimeMillis(), new HashMap()); } catch (Exception ex) { MessageProcessor.getSingletonObject().processMessageOutput(random.toString(), "error " + ex.getMessage(), 0, true, System.currentTimeMillis(), new HashMap()); } finally { DBUtils.safeClose(PerfCon); DBUtils.safeClose(ConfigCon); } }
@Override public void run() { UUID random = UUID.randomUUID(); MessageProcessor.getSingletonObject().processMessageInput(SERVICE_NAME, 0, myUrl, "machine/process", "system", random.toString(), new HashMap(), "", this.getClass().getCanonicalName(), "", ""); Connection ConfigCon = Utility.getConfigurationDBConnection(); Connection PerfCon = Utility.getPerformanceDBConnection(); try { doWorkMachinesProcesses(ConfigCon, PerfCon, periods); MessageProcessor.getSingletonObject().processMessageOutput(random.toString(), "success", 0, false, System.currentTimeMillis(), new HashMap()); } catch (Exception ex) { MessageProcessor.getSingletonObject().processMessageOutput(random.toString(), "error " + ex.getMessage(), 0, true, System.currentTimeMillis(), new HashMap()); } finally { DBUtils.safeClose(PerfCon); DBUtils.safeClose(ConfigCon); } }
private Pair translateURItoPair(String policyURI) { Connection con = Utility.getConfigurationDBConnection(); Pair p = null; PreparedStatement com = null; ResultSet rs = null; try { com = con.prepareStatement("select hostname, domaincol from servicepolicies where uri=?;"); com.setString(1, policyURI); rs = com.executeQuery(); if (rs.next()) { p = new Pair(); p.hostname = rs.getString("hostname"); p.domainname = rs.getString("domaincol"); } } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(com); DBUtils.safeClose(con); } return p; }
@Override public void run() { UUID random = UUID.randomUUID(); MessageProcessor.getSingletonObject().processMessageInput(SERVICE_NAME, 0, myUrl, "status", "system", random.toString(), new HashMap(), "", this.getClass().getCanonicalName(), "", ""); Connection ConfigCon = Utility.getConfigurationDBConnection(); Connection PerfCon = Utility.getPerformanceDBConnection(); try { doWorkForStatusItemsOnly(ConfigCon, PerfCon, periods); MessageProcessor.getSingletonObject().processMessageOutput(random.toString(), "success", 0, false, System.currentTimeMillis(), new HashMap()); } catch (Exception ex) { MessageProcessor.getSingletonObject().processMessageOutput(random.toString(), "error " + ex.getMessage(), 0, true, System.currentTimeMillis(), new HashMap()); log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(PerfCon); DBUtils.safeClose(ConfigCon); } }
public static InternetAddress[] GetAllfgsmsAdminsEmailAddressPooled() { SetupBundle(); Connection con = Utility.getConfigurationDBConnection(); InternetAddress[] sp = getAllfgsmsAdminsEmailAddress(con); DBUtils.safeClose(con); return sp; }
@Override public void run() { UUID random = UUID.randomUUID(); MessageProcessor.getSingletonObject().processMessageInput(SERVICE_NAME + " for " + uri, 0, myUrl, "transactional", "system", random.toString(), new HashMap(), "", this.getClass().getCanonicalName(), "", ""); Connection ConfigCon = Utility.getConfigurationDBConnection(); Connection PerfCon = Utility.getPerformanceDBConnection(); try { doWorkTransactional(ConfigCon, PerfCon, periods, uri); MessageProcessor.getSingletonObject().processMessageOutput(random.toString(), "success", 0, false, System.currentTimeMillis(), new HashMap()); } catch (Exception ex) { MessageProcessor.getSingletonObject().processMessageOutput(random.toString(), "error " + ex.getMessage(), 0, true, System.currentTimeMillis(), new HashMap()); log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(PerfCon); DBUtils.safeClose(ConfigCon); } }
protected static boolean isPolicyTypeOf(String uri, PolicyType p) { Connection con = Utility.getConfigurationDBConnection(); PreparedStatement com = null; ResultSet rs = null; try { com = con.prepareStatement("select policytype from servicepolicies where uri=?"); com.setString(1, uri); rs = com.executeQuery(); if (rs.next()) { int x = rs.getInt(1); if (PolicyType.values()[x].equals(p)) { return true; } } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(com); DBUtils.safeClose(con); } return false; }
/** * Returns a list of user's email addresses that are subscribed to a * specific SLA with email actions * * @param guid * @return */ public static InternetAddress[] GetSubscribersPooled(String guid) { SetupBundle(); Connection con = Utility.getConfigurationDBConnection(); InternetAddress[] sp = getSubscribers(con, guid); DBUtils.safeClose(con); return sp; }
public static boolean isPolicyTypeOf(String uri, PolicyType p) { Connection con = Utility.getConfigurationDBConnection(); PreparedStatement com = null; ResultSet rs = null; try { com = con.prepareStatement("select policytype from servicepolicies where uri=?"); com.setString(1, uri); rs = com.executeQuery(); if (rs.next()) { int x = rs.getInt(1); if (PolicyType.values()[x].equals(p)) { return true; } } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(com); DBUtils.safeClose(con); } return false; }
/** * used by Federation Scheduler for publication * * @return either an empty list, or a list containing service policies that * contain SLA's */ public static List<ServicePolicy> LoadFederationServicePoliciesPooled() { SetupBundle(); Connection con = Utility.getConfigurationDBConnection(); List<ServicePolicy> r = null; try { r = loadServicePoliciesWithFederation(con); } catch (Exception ex) { log.log(Level.ERROR, bundle.getString("ErrorLoadingPolicy"), ex); } finally { DBUtils.safeClose(con); } if (r == null) { r = new ArrayList<ServicePolicy>(); } return r; }
/** * used by NT SLA for web services * * @return either an empty list, or a list containing service policies that * contain SLA's */ public static List<ServicePolicy> LoadServicePoliciesPooled() { SetupBundle(); Connection con = Utility.getConfigurationDBConnection(); List<ServicePolicy> r = null; try { r = loadServicePolicies(con); } catch (Exception ex) { log.log(Level.ERROR, bundle.getString("ErrorLoadingPolicy"), ex); } finally { DBUtils.safeClose(con); } if (r == null) { r = new ArrayList<ServicePolicy>(); } return r; }
public static SecurityWrapper GetClassLevel(boolean pooled) { Connection con = null; SecurityWrapper c = new SecurityWrapper(); if (pooled) { con = Utility.getConfigurationDBConnection(); } else { con = Utility.getConfigurationDB_NONPOOLED_Connection(); } PreparedStatement cmd =null; ResultSet rs = null; try { cmd = con.prepareStatement("select classification,caveat from globalpolicies;"); rs = cmd.executeQuery(); if (rs.next()) { c.setCaveats(rs.getString("caveat")); c.setClassification(ClassificationType.fromValue(rs.getString("classification"))); } } catch (Exception ex) { log.log(Level.WARN,null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); DBUtils.safeClose(con); } return c; }
protected SecurityWrapper getClassLevelFromDB() { Connection con = Utility.getConfigurationDBConnection(); PreparedStatement com = null; ResultSet rs = null; try { com = con.prepareStatement("select classification, caveat from globalpolicies;"); rs = com.executeQuery(); if (rs.next()) { ClassificationType t = ClassificationType.fromValue(rs.getString(1)); String cav = rs.getString(2); return new SecurityWrapper(t, cav); } else { log.log(Level.ERROR, "unable to determine current classification level, defaulting to UNCLASSIFIED"); return new SecurityWrapper(ClassificationType.U, "None"); } } catch (SQLException ex) { log.log(Level.ERROR, "error determining classification level from config db", ex); log.log(Level.ERROR, "unable to determine current classification level, defaulting to UNCLASSIFIED"); return new SecurityWrapper(ClassificationType.U, "None"); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(com); DBUtils.safeClose(con); } }