MgmtEntry.Publisher createPublisher(String name) throws CaMgmtException { final String sql = sqlSelectPublisher; PreparedStatement stmt = null; ResultSet rs = null; try { stmt = prepareStatement(sql); stmt.setString(1, name); rs = stmt.executeQuery(); if (!rs.next()) { throw new CaMgmtException("unkown Publisher " + name); } return new MgmtEntry.Publisher(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 createPublisher
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
MgmtEntry.Publisher entryB = publisherDbEntries.get(name); if (entryB != null) { if (entry.equals(entryB, ignoreId)) { LOG.info("ignore existed publisher {}", name); continue;
MgmtEntry.Publisher en = new MgmtEntry.Publisher(new NameId(null, m.getName()), expandConf(m.getType()), getValue(m.getConf(), zipEntries)); addPublisher(en);
@Override protected Object execute0() throws Exception { if (name == null) { Set<String> names = caManager.getPublisherNames(); int size = names.size(); StringBuilder sb = new StringBuilder(); if (size == 0 || size == 1) { sb.append((size == 0) ? "no" : "1"); sb.append(" publisher is configured\n"); } else { sb.append(size).append(" publishers are configured:\n"); } List<String> sorted = new ArrayList<>(names); Collections.sort(sorted); for (String entry : sorted) { sb.append("\t").append(entry).append("\n"); } println(sb.toString()); } else { MgmtEntry.Publisher entry = caManager.getPublisher(name); if (entry == null) { throw new CmdFailure("\tno publisher named '" + name + "' is configured"); } else { println(entry.toString()); } } return null; } // method execute0
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 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; }
@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
@Override protected Object execute0() throws Exception { if (conf == null && confFile != null) { conf = new String(IoUtil.read(confFile)); } MgmtEntry.Publisher entry = new MgmtEntry.Publisher(new NameId(null, name), type, conf); String msg = "publisher " + name; try { caManager.addPublisher(entry); println("added " + msg); return null; } catch (CaMgmtException ex) { throw new CmdFailure("could not add " + msg + ", error: " + ex.getMessage(), ex); } }
public NameId getIdent() { return entry.getIdent(); }
@Override protected Object execute0() throws Exception { MgmtEntry.Publisher entry = caManager.getPublisher(name); if (entry == null) { throw new IllegalCmdParamException("no publisher named " + name + " is defined"); } if (StringUtil.isBlank(entry.getConf())) { println("publisher does not have conf"); } else { saveVerbose("saved publisher configuration to", confFile, entry.getConf().getBytes("UTF-8")); } return null; }
public void addPublisher(MgmtEntry.Publisher publisher) { Args.notNull(publisher, "publisher"); this.publishers.put(publisher.getIdent().getName(), publisher); }
public void initialize(PasswordResolver passwordResolver, Map<String, String> datasourceConfFiles) throws CertPublisherException { certPublisher.initialize(entry.getConf(), passwordResolver, datasourceConfFiles); }
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
@Override public boolean equals(Object obj) { if (this == obj) { return true; } else if (!(obj instanceof Publisher)) { return false; } return equals((Publisher) obj, false); }