@Override protected Object execute0() throws Exception { if (caManager.getCa(caName) == null) { throw new CmdFailure("could not find CA '" + caName + "'"); } List<MgmtEntry.Publisher> entries = caManager.getPublishersForCa(caName); if (isNotEmpty(entries)) { StringBuilder sb = new StringBuilder(); sb.append("publishers for CA ").append(caName).append("\n"); for (MgmtEntry.Publisher entry : entries) { sb.append("\t").append(entry.getIdent().getName()).append("\n"); } println(sb.toString()); } else { println(StringUtil.concat("no publisher for CA ", caName," is configured")); } return null; }
idNameMap.addPublisher(dbEntry.getIdent()); dbEntry.setFaulty(true); publisherDbEntries.put(name, dbEntry);
public void addPublisher(MgmtEntry.Publisher publisher) { Args.notNull(publisher, "publisher"); this.publishers.put(publisher.getIdent().getName(), publisher); }
void addPublisher(MgmtEntry.Publisher dbEntry) throws CaMgmtException { Args.notNull(dbEntry, "dbEntry"); final String sql = "INSERT INTO PUBLISHER (ID,NAME,TYPE,CONF) VALUES (?,?,?,?)"; try { int id = (int) datasource.getMax(null, "PUBLISHER", "ID"); dbEntry.getIdent().setId(id + 1); } catch (DataAccessException ex) { throw new CaMgmtException(ex); } String name = dbEntry.getIdent().getName(); PreparedStatement ps = null; try { ps = prepareStatement(sql); int idx = 1; ps.setInt(idx++, dbEntry.getIdent().getId()); ps.setString(idx++, name); ps.setString(idx++, dbEntry.getType()); String conf = dbEntry.getConf(); ps.setString(idx++, conf); if (ps.executeUpdate() == 0) { throw new CaMgmtException("could not add publisher " + dbEntry.getIdent()); } LOG.info("added publisher '{}': {}", dbEntry.getIdent(), dbEntry); } catch (SQLException ex) { throw new CaMgmtException(datasource.translate(sql, ex)); } finally { datasource.releaseResources(ps, null); } } // method addPublisher
IdentifiedCertPublisher createPublisher(MgmtEntry.Publisher entry) throws CaMgmtException { Args.notNull(entry, "entry"); String type = entry.getType(); CertPublisher publisher; IdentifiedCertPublisher ret; try { if (certPublisherFactoryRegister.canCreatePublisher(type)) { publisher = certPublisherFactoryRegister.newPublisher(type); } else { throw new CaMgmtException("unsupported publisher type " + type); } ret = new IdentifiedCertPublisher(entry, publisher); ret.initialize(securityFactory.getPasswordResolver(), datasourceNameConfFileMap); return ret; } catch (ObjectCreationException | CertPublisherException | RuntimeException ex) { String msg = "invalid configuration for the publisher " + entry.getIdent(); LogUtil.error(LOG, ex, msg); throw new CaMgmtException(msg, ex); } } // method createPublisher
@Override public void addPublisher(MgmtEntry.Publisher entry) throws CaMgmtException { Args.notNull(entry, "entry"); asssertMasterMode(); String name = entry.getIdent().getName(); if (publisherDbEntries.containsKey(name)) { throw new CaMgmtException(concat("Publisher named ", name, " exists")); } entry.setFaulty(true); IdentifiedCertPublisher publisher = createPublisher(entry); entry.setFaulty(false); queryExecutor.addPublisher(entry); publishers.put(name, publisher); idNameMap.addPublisher(entry.getIdent()); publisherDbEntries.put(name, entry); } // method addPublisher
public NameId getIdent() { return entry.getIdent(); }
IdentifiedCertPublisher changePublisher(String name, String type, String conf, CaManagerImpl caManager) throws CaMgmtException { Args.notBlank(name, "name"); Args.notNull(caManager, "caManager"); MgmtEntry.Publisher currentDbEntry = createPublisher(name); MgmtEntry.Publisher dbEntry = new MgmtEntry.Publisher(currentDbEntry.getIdent(), (type == null ? currentDbEntry.getType() : type), (conf == null ? currentDbEntry.getConf() : conf)); IdentifiedCertPublisher publisher = caManager.createPublisher(dbEntry); changeIfNotNull("PUBLISHER", col(STRING, "NAME", name), col(STRING, "TYPE", type), col(STRING, "CONF", conf)); return publisher; } // method changePublisher