use of org.xipki.ca.server.mgmt.api.PublisherEntry in project xipki by xipki.
the class CaManagerQueryExecutor method createPublisher.
// method getNamesFromTable
PublisherEntry createPublisher(String name) throws CaMgmtException {
final String sql = sqls.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);
}
int id = rs.getInt("ID");
String type = rs.getString("TYPE");
String conf = rs.getString("CONF");
return new PublisherEntry(new NameId(id, name), type, conf);
} catch (SQLException ex) {
throw new CaMgmtException(datasource, sql, ex);
} finally {
datasource.releaseResources(stmt, rs);
}
}
use of org.xipki.ca.server.mgmt.api.PublisherEntry in project xipki by xipki.
the class CaManagerQueryExecutor method changePublisher.
// method changeEnvParam
IdentifiedX509CertPublisher changePublisher(String name, String type, String conf, CaManagerImpl caManager) throws CaMgmtException {
ParamUtil.requireNonBlank("name", name);
ParamUtil.requireNonNull("caManager", caManager);
StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.append("UPDATE PUBLISHER SET ");
String tmpType = type;
String tmpConf = conf;
AtomicInteger index = new AtomicInteger(1);
Integer idxType = addToSqlIfNotNull(sqlBuilder, index, tmpType, "TYPE");
Integer idxConf = addToSqlIfNotNull(sqlBuilder, index, tmpConf, "CONF");
sqlBuilder.deleteCharAt(sqlBuilder.length() - 1);
sqlBuilder.append(" WHERE NAME=?");
if (index.get() == 1) {
throw new IllegalArgumentException("nothing to change");
}
PublisherEntry currentDbEntry = createPublisher(name);
if (tmpType == null) {
tmpType = currentDbEntry.getType();
}
if (tmpConf == null) {
tmpConf = currentDbEntry.getConf();
}
PublisherEntry dbEntry = new PublisherEntry(currentDbEntry.getIdent(), tmpType, tmpConf);
IdentifiedX509CertPublisher publisher = caManager.createPublisher(dbEntry);
if (publisher == null) {
throw new CaMgmtException("could not create publisher object");
}
final String sql = sqlBuilder.toString();
PreparedStatement ps = null;
try {
StringBuilder sb = new StringBuilder();
ps = prepareStatement(sql);
if (idxType != null) {
sb.append("type: '").append(tmpType).append("'; ");
ps.setString(idxType, tmpType);
}
if (idxConf != null) {
String txt = getRealString(tmpConf);
sb.append("conf: '").append(txt).append("'; ");
ps.setString(idxConf, getRealString(tmpConf));
}
ps.setString(index.get(), name);
if (ps.executeUpdate() == 0) {
throw new CaMgmtException("could not change publisher " + name);
}
if (sb.length() > 0) {
sb.deleteCharAt(sb.length() - 1).deleteCharAt(sb.length() - 1);
}
LOG.info("changed publisher '{}': {}", name, sb);
return publisher;
} catch (SQLException ex) {
throw new CaMgmtException(datasource, sql, ex);
} finally {
datasource.releaseResources(ps, null);
}
}
use of org.xipki.ca.server.mgmt.api.PublisherEntry in project xipki by xipki.
the class PublisherInfoCmd method execute0.
@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 {
PublisherEntry entry = caManager.getPublisher(name);
if (entry == null) {
throw new CmdFailure("\tno publisher named '" + name + "' is configured");
} else {
println(entry.toString());
}
}
return null;
}
use of org.xipki.ca.server.mgmt.api.PublisherEntry in project xipki by xipki.
the class PublisherCheckCmd method execute0.
@Override
protected Object execute0() throws Exception {
println("checking publisher " + name);
PublisherEntry cp = caManager.getPublisher(name);
if (cp == null) {
throw new CmdFailure("publisher named '" + name + "' is not configured");
}
if (cp.getType() != null) {
MgmtQaShellUtil.assertEquals("type", type, cp.getType());
}
if (cp.getConf() != null) {
MgmtQaShellUtil.assertEquals("signer conf", conf, cp.getConf());
}
println(" checked publisher " + name);
return null;
}
use of org.xipki.ca.server.mgmt.api.PublisherEntry in project xipki by xipki.
the class CaPublisherCheckCmd method execute0.
@Override
protected Object execute0() throws Exception {
println("checking CA publisher CA='" + caName + "', publisher='" + publisherName + "'");
if (caManager.getCa(caName) == null) {
throw new CmdFailure("could not find CA '" + caName + "'");
}
List<PublisherEntry> entries = caManager.getPublishersForCa(caName);
String upPublisherName = publisherName.toLowerCase();
for (PublisherEntry m : entries) {
if (m.getIdent().getName().equals(upPublisherName)) {
println(" checked CA publisher CA='" + caName + "', publisher='" + publisherName + "'");
return null;
}
}
throw new CmdFailure("CA is not associated with publisher '" + publisherName + "'");
}
Aggregations