use of org.xipki.ca.server.mgmt.api.ResponderEntry in project xipki by xipki.
the class CaManagerImpl method initResponders.
// method initRequestors
private void initResponders() throws CaMgmtException {
if (responderInitialized) {
return;
}
responderDbEntries.clear();
responders.clear();
List<String> names = queryExecutor.namesFromTable("RESPONDER");
for (String name : names) {
ResponderEntry dbEntry = queryExecutor.createResponder(name);
if (dbEntry == null) {
LOG.error("could not initialize Responder '{}'", name);
continue;
}
dbEntry.setConfFaulty(true);
responderDbEntries.put(name, dbEntry);
ResponderEntryWrapper responder = createResponder(dbEntry);
if (responder != null) {
dbEntry.setConfFaulty(false);
responders.put(name, responder);
}
}
responderInitialized = true;
}
use of org.xipki.ca.server.mgmt.api.ResponderEntry in project xipki by xipki.
the class CaManagerQueryExecutor method changeResponder.
// method changeRequestor
ResponderEntryWrapper changeResponder(String name, String type, String conf, String base64Cert, CaManagerImpl caManager, SecurityFactory securityFactory) throws CaMgmtException {
ParamUtil.requireNonBlank("name", name);
ParamUtil.requireNonNull("caManager", caManager);
StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.append("UPDATE RESPONDER SET ");
AtomicInteger index = new AtomicInteger(1);
Integer idxType = addToSqlIfNotNull(sqlBuilder, index, type, "TYPE");
Integer idxCert = addToSqlIfNotNull(sqlBuilder, index, base64Cert, "CERT");
Integer idxConf = addToSqlIfNotNull(sqlBuilder, index, conf, "CONF");
sqlBuilder.deleteCharAt(sqlBuilder.length() - 1);
sqlBuilder.append(" WHERE NAME=?");
if (index.get() == 1) {
throw new IllegalArgumentException("nothing to change");
}
ResponderEntry dbEntry = createResponder(name);
String tmpType = (type != null) ? type : dbEntry.getType();
String tmpConf;
if (conf == null) {
tmpConf = dbEntry.getConf();
} else {
tmpConf = CaManagerImpl.canonicalizeSignerConf(tmpType, conf, null, securityFactory);
}
String tmpBase64Cert;
if (base64Cert == null) {
tmpBase64Cert = dbEntry.getBase64Cert();
} else {
tmpBase64Cert = base64Cert;
}
ResponderEntry newDbEntry = new ResponderEntry(name, tmpType, tmpConf, tmpBase64Cert);
ResponderEntryWrapper responder = caManager.createResponder(newDbEntry);
final String sql = sqlBuilder.toString();
StringBuilder sb = new StringBuilder();
PreparedStatement ps = null;
try {
ps = prepareStatement(sql);
if (idxType != null) {
String txt = tmpType;
ps.setString(idxType, txt);
sb.append("type: '").append(txt).append("'; ");
}
if (idxConf != null) {
String txt = getRealString(tmpConf);
sb.append("conf: '").append(SignerConf.toString(txt, false, true));
ps.setString(idxConf, txt);
}
if (idxCert != null) {
String txt = getRealString(tmpBase64Cert);
sb.append("cert: '");
if (txt == null) {
sb.append("null");
} else {
try {
String subject = canonicalizName(X509Util.parseBase64EncodedCert(txt).getSubjectX500Principal());
sb.append(subject);
} catch (CertificateException ex) {
sb.append("ERROR");
}
}
sb.append("'; ");
ps.setString(idxCert, txt);
}
ps.setString(index.get(), name);
if (ps.executeUpdate() == 0) {
throw new CaMgmtException("could not change responder " + name);
}
if (sb.length() > 0) {
sb.deleteCharAt(sb.length() - 1).deleteCharAt(sb.length() - 1);
}
LOG.info("changed responder: {}", sb);
return responder;
} catch (SQLException ex) {
throw new CaMgmtException(datasource, sql, ex);
} finally {
datasource.releaseResources(ps, null);
}
}
use of org.xipki.ca.server.mgmt.api.ResponderEntry in project xipki by xipki.
the class CaManagerQueryExecutor method createResponder.
// method createCmpControl
ResponderEntry createResponder(String name) throws CaMgmtException {
final String sql = sqls.sqlSelectResponder;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
stmt = prepareStatement(sql);
stmt.setString(1, name);
rs = stmt.executeQuery();
if (!rs.next()) {
throw new CaMgmtException("unknown responder " + name);
}
String type = rs.getString("TYPE");
String conf = rs.getString("CONF");
String b64Cert = rs.getString("CERT");
return new ResponderEntry(name, type, conf, b64Cert);
} catch (SQLException ex) {
throw new CaMgmtException(datasource, sql, ex);
} finally {
datasource.releaseResources(stmt, rs);
}
}
use of org.xipki.ca.server.mgmt.api.ResponderEntry in project xipki by xipki.
the class ResponderUpdateCmd method getSignerConf.
protected String getSignerConf() throws Exception {
if (signerConf == null) {
return signerConf;
}
String tmpSignerType = signerType;
if (tmpSignerType == null) {
ResponderEntry entry = caManager.getResponder(name);
if (entry == null) {
throw new IllegalCmdParamException("please specify the signerType");
}
tmpSignerType = entry.getType();
}
return ShellUtil.canonicalizeSignerConf(tmpSignerType, signerConf, passwordResolver, securityFactory);
}
use of org.xipki.ca.server.mgmt.api.ResponderEntry in project xipki by xipki.
the class ResponderAddCmd method execute0.
@Override
protected Object execute0() throws Exception {
String base64Cert = null;
X509Certificate signerCert = null;
if (certFile != null) {
signerCert = X509Util.parseCert(certFile);
base64Cert = IoUtil.base64Encode(signerCert.getEncoded(), false);
}
if ("PKCS12".equalsIgnoreCase(signerType) || "JKS".equalsIgnoreCase(signerType)) {
signerConf = ShellUtil.canonicalizeSignerConf(signerType, signerConf, passwordResolver, securityFactory);
}
ResponderEntry entry = new ResponderEntry(name, signerType, signerConf, base64Cert);
String msg = "CMP responder " + name;
try {
caManager.addResponder(entry);
println("added " + msg);
return null;
} catch (CaMgmtException ex) {
throw new CmdFailure("could not add " + msg + ", error: " + ex.getMessage(), ex);
}
}
Aggregations