Esempio n. 1
0
 public synchronized TrustedAuthority getTrustedAuthority(String name)
     throws GTSInternalFault, InvalidTrustedAuthorityFault {
   Connection c = null;
   try {
     c = db.getConnection();
     PreparedStatement s =
         c.prepareStatement(
             "select * from "
                 + TrustedAuthorityTable.TABLE_NAME
                 + " where "
                 + TrustedAuthorityTable.NAME
                 + "= ?");
     s.setString(1, name);
     ResultSet rs = s.executeQuery();
     if (rs.next()) {
       TrustedAuthority ta = new TrustedAuthority();
       ta.setName(rs.getString(TrustedAuthorityTable.NAME));
       ta.setTrustLevels(getTrustLevels(name));
       ta.setStatus(Status.fromValue(rs.getString(TrustedAuthorityTable.STATUS)));
       ta.setIsAuthority(Boolean.valueOf(rs.getBoolean(TrustedAuthorityTable.IS_AUTHORITY)));
       ta.setAuthorityGTS(rs.getString(TrustedAuthorityTable.AUTHORITY_GTS));
       ta.setSourceGTS(rs.getString(TrustedAuthorityTable.SOURCE_GTS));
       ta.setExpires(rs.getLong(TrustedAuthorityTable.EXPIRES));
       ta.setLastUpdated(rs.getLong(TrustedAuthorityTable.LAST_UPDATED));
       ta.setCertificate(
           new gov.nih.nci.cagrid.gts.bean.X509Certificate(
               rs.getString(TrustedAuthorityTable.CERTIFICATE)));
       String crl = rs.getString(TrustedAuthorityTable.CRL);
       if ((crl != null) && (crl.trim().length() > 0)) {
         ta.setCRL(new gov.nih.nci.cagrid.gts.bean.X509CRL(crl));
       }
       return ta;
     }
     rs.close();
     s.close();
   } catch (Exception e) {
     this.log.error(
         "Unexpected database error incurred in obtaining the Trusted Authority, " + name + ":\n",
         e);
     GTSInternalFault fault = new GTSInternalFault();
     fault.setFaultString("Unexpected error obtaining the TrustedAuthority " + name);
     throw fault;
   } finally {
     db.releaseConnection(c);
   }
   InvalidTrustedAuthorityFault fault = new InvalidTrustedAuthorityFault();
   fault.setFaultString("The TrustedAuthority " + name + " does not exist.");
   throw fault;
 }
Esempio n. 2
0
  public synchronized void removeTrustedAuthority(String name)
      throws GTSInternalFault, InvalidTrustedAuthorityFault {
    if (doesTrustedAuthorityExist(name)) {
      Connection c = null;
      try {
        this.removeTrustedAuthoritysTrustLevels(name);
        c = db.getConnection();
        PreparedStatement s =
            c.prepareStatement(
                "delete FROM "
                    + TrustedAuthorityTable.TABLE_NAME
                    + " where "
                    + TrustedAuthorityTable.NAME
                    + "= ?");
        s.setString(1, name);
        s.execute();
        s.close();

      } catch (Exception e) {
        this.log.error(
            "Unexpected database error incurred in removing the Trusted Authority, "
                + name
                + ", the following statement generated the error: \n",
            e);
        GTSInternalFault fault = new GTSInternalFault();
        fault.setFaultString("Unexpected error removing the TrustedAuthority " + name);
        throw fault;
      } finally {
        db.releaseConnection(c);
      }
    } else {
      InvalidTrustedAuthorityFault fault = new InvalidTrustedAuthorityFault();
      fault.setFaultString("The TrustedAuthority " + name + " does not exist.");
      throw fault;
    }
  }