MgmtEntry.Certprofile createCertprofile(String name) throws CaMgmtException { PreparedStatement stmt = null; ResultSet rs = null; final String sql = sqlSelectProfile; try { stmt = prepareStatement(sql); stmt.setString(1, name); rs = stmt.executeQuery(); if (!rs.next()) { throw new CaMgmtException("unknown CA " + name); } return new MgmtEntry.Certprofile(new NameId(rs.getInt("ID"), name), rs.getString("TYPE"), rs.getString("CONF")); } catch (SQLException ex) { throw new CaMgmtException(datasource.translate(sql, ex)); } finally { datasource.releaseResources(stmt, rs); } } // method createCertprofile
MgmtEntry.Certprofile entryB = certprofileDbEntries.get(name); if (entryB != null) { if (entry.equals(entryB, ignoreId)) { LOG.info("ignore existed certprofile {}", name); continue;
MgmtEntry.Certprofile en = new MgmtEntry.Certprofile(new NameId(null, m.getName()), expandConf(m.getType()), getValue(m.getConf(), zipEntries)); addProfile(en);
void addCertprofile(MgmtEntry.Certprofile dbEntry) throws CaMgmtException { Args.notNull(dbEntry, "dbEntry"); final String sql = "INSERT INTO PROFILE (ID,NAME,TYPE,CONF) VALUES (?,?,?,?)"; try { int id = (int) datasource.getMax(null, "PROFILE", "ID"); dbEntry.getIdent().setId(id + 1); } catch (DataAccessException ex) { throw new CaMgmtException(ex); } PreparedStatement ps = null; try { ps = prepareStatement(sql); int idx = 1; ps.setInt(idx++, dbEntry.getIdent().getId()); ps.setString(idx++, dbEntry.getIdent().getName()); ps.setString(idx++, dbEntry.getType()); String conf = dbEntry.getConf(); ps.setString(idx++, conf); if (ps.executeUpdate() == 0) { throw new CaMgmtException("could not add certprofile " + dbEntry.getIdent()); } LOG.info("added profile '{}': {}", dbEntry.getIdent(), dbEntry); } catch (SQLException ex) { throw new CaMgmtException(datasource.translate(sql, ex)); } finally { datasource.releaseResources(ps, null); } } // method addCertprofile
@Override protected Object execute0() throws Exception { StringBuilder sb = new StringBuilder(); if (name == null) { Set<String> names = caManager.getCertprofileNames(); int size = names.size(); if (size == 0 || size == 1) { sb.append((size == 0) ? "no" : "1"); sb.append(" profile is configured\n"); } else { sb.append(size).append(" profiles are configured:\n"); } List<String> sorted = new ArrayList<>(names); Collections.sort(sorted); for (String entry : sorted) { sb.append("\t").append(entry).append("\n"); } } else { MgmtEntry.Certprofile entry = caManager.getCertprofile(name); if (entry == null) { throw new CmdFailure("\tno certificate profile named '" + name + "' is configured"); } else { sb.append(entry.toString(verbose)); } } println(sb.toString()); return null; } // method execute0
IdentifiedCertprofile changeCertprofile(NameId nameId, String type, String conf, CaManagerImpl caManager) throws CaMgmtException { MgmtEntry.Certprofile currentDbEntry = createCertprofile(nameId.getName()); MgmtEntry.Certprofile newDbEntry = new MgmtEntry.Certprofile(currentDbEntry.getIdent(), str(type, currentDbEntry.getType()), str(conf, currentDbEntry.getConf())); IdentifiedCertprofile profile = caManager.createCertprofile(newDbEntry); if (profile == null) { throw new CaMgmtException("could not create certprofile object"); } boolean failed = true; try { changeIfNotNull("PROFILE", col(INT, "ID", nameId.getId()), col(STRING, "TYPE", type), col(STRING, "CONF", conf)); failed = false; return profile; } finally { if (failed) { profile.close(); } } } // method changeCertprofile
@Override public void removeCertprofile(String name) throws CaMgmtException { name = Args.toNonBlankLower(name, "name"); asssertMasterMode(); for (String caName : caHasProfiles.keySet()) { if (caHasProfiles.get(caName).contains(name)) { removeCertprofileFromCa(name, caName); } } boolean bo = queryExecutor.deleteRowWithName(name, "PROFILE"); if (!bo) { throw new CaMgmtException("unknown profile " + name); } LOG.info("removed profile '{}'", name); idNameMap.removeCertprofile(certprofileDbEntries.get(name).getIdent().getId()); certprofileDbEntries.remove(name); IdentifiedCertprofile profile = certprofiles.remove(name); shutdownCertprofile(profile); } // method removeCertprofile
@Override public void addCertprofile(MgmtEntry.Certprofile certprofileEntry) throws CaMgmtException { Args.notNull(certprofileEntry, "certprofileEntry"); asssertMasterMode(); String name = certprofileEntry.getIdent().getName(); if (certprofileDbEntries.containsKey(name)) { throw new CaMgmtException(concat("Certprofile named ", name, " exists")); } certprofileEntry.setFaulty(true); IdentifiedCertprofile profile = createCertprofile(certprofileEntry); if (profile == null) { throw new CaMgmtException("could not create Certprofile object"); } certprofileEntry.setFaulty(false); certprofiles.put(name, profile); queryExecutor.addCertprofile(certprofileEntry); idNameMap.addCertprofile(certprofileEntry.getIdent()); certprofileDbEntries.put(name, certprofileEntry); } // method addCertprofile
IdentifiedCertprofile createCertprofile(MgmtEntry.Certprofile entry) throws CaMgmtException { Args.notNull(entry, "entry"); String type = entry.getType(); if (!certprofileFactoryRegister.canCreateProfile(type)) { throw new CaMgmtException("unsupported cert profile type " + type); } try { Certprofile profile = certprofileFactoryRegister.newCertprofile(type); IdentifiedCertprofile ret = new IdentifiedCertprofile(entry, profile); ret.validate(); return ret; } catch (ObjectCreationException | CertprofileException ex) { String msg = "could not initialize Certprofile " + entry.getIdent(); LogUtil.error(LOG, ex, msg); throw new CaMgmtException(msg, ex); } } // method createCertprofile
@Override protected Object execute0() throws Exception { if (conf == null && confFile != null) { conf = new String(IoUtil.read(confFile)); } MgmtEntry.Certprofile entry = new MgmtEntry.Certprofile(new NameId(null, name), type, conf); String msg = "certificate profile " + name; try { caManager.addCertprofile(entry); println("added " + msg); return null; } catch (CaMgmtException ex) { throw new CmdFailure("could not add " + msg + ", error: " + ex.getMessage(), ex); } }
public NameId getIdent() { return dbEntry.getIdent(); }
public void addProfile(MgmtEntry.Certprofile profile) { Args.notNull(profile, "profile"); this.certprofiles.put(profile.getIdent().getName(), profile); }
@Override protected Object execute0() throws Exception { MgmtEntry.Certprofile entry = caManager.getCertprofile(name); if (entry == null) { throw new IllegalCmdParamException("no certificate profile named " + name + " is defined"); } if (StringUtil.isBlank(entry.getConf())) { println("cert profile does not have conf"); } else { saveVerbose("saved cert profile configuration to", confFile, entry.getConf().getBytes("UTF-8")); } return null; }
@Override public String toString() { return toString(false); }
IdentifiedCertprofile(MgmtEntry.Certprofile dbEntry, Certprofile certprofile) throws CertprofileException { this.dbEntry = Args.notNull(dbEntry, "dbEntry"); this.certprofile = Args.notNull(certprofile, "certprofile"); this.certprofile.initialize(dbEntry.getConf()); } // constructor
@Override public boolean equals(Object obj) { if (this == obj) { return true; } else if (!(obj instanceof Certprofile)) { return false; } return equals((Certprofile) obj, false); }