use of org.xipki.ca.server.mgmt.api.CaMgmtException in project xipki by xipki.
the class CaManagerQueryExecutor method addRequestor.
// method addCmpControl
void addRequestor(RequestorEntry dbEntry) throws CaMgmtException {
ParamUtil.requireNonNull("dbEntry", dbEntry);
try {
int id = (int) datasource.getMax(null, "REQUESTOR", "ID");
dbEntry.getIdent().setId(id + 1);
} catch (DataAccessException ex) {
throw new CaMgmtException(ex);
}
final String sql = "INSERT INTO REQUESTOR (ID,NAME,CERT) VALUES (?,?,?)";
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++, Base64.encodeToString(dbEntry.getCert().getEncoded()));
if (ps.executeUpdate() == 0) {
throw new CaMgmtException("could not add requestor " + dbEntry.getIdent());
}
if (LOG.isInfoEnabled()) {
LOG.info("added requestor '{}': {}", dbEntry.getIdent(), dbEntry.toString(false));
}
} catch (SQLException ex) {
throw new CaMgmtException(datasource, sql, ex);
} catch (CertificateEncodingException ex) {
throw new CaMgmtException(ex);
} finally {
datasource.releaseResources(ps, null);
}
}
use of org.xipki.ca.server.mgmt.api.CaMgmtException in project xipki by xipki.
the class CaManagerQueryExecutor method addResponder.
// method revokeCa
void addResponder(ResponderEntry dbEntry) throws CaMgmtException {
ParamUtil.requireNonNull("dbEntry", dbEntry);
final String sql = "INSERT INTO RESPONDER (NAME,TYPE,CERT,CONF) VALUES (?,?,?,?)";
PreparedStatement ps = null;
try {
ps = prepareStatement(sql);
int idx = 1;
ps.setString(idx++, dbEntry.getName());
ps.setString(idx++, dbEntry.getType());
ps.setString(idx++, dbEntry.getBase64Cert());
ps.setString(idx++, dbEntry.getConf());
if (ps.executeUpdate() == 0) {
throw new CaMgmtException("could not add responder " + dbEntry.getName());
}
LOG.info("added responder: {}", dbEntry.toString(false, true));
} catch (SQLException ex) {
throw new CaMgmtException(datasource, sql, ex);
} finally {
datasource.releaseResources(ps, null);
}
}
use of org.xipki.ca.server.mgmt.api.CaMgmtException in project xipki by xipki.
the class CaManagerQueryExecutor method addCertprofileToCa.
// method addCertprofile
void addCertprofileToCa(NameId profile, NameId ca) throws CaMgmtException {
ParamUtil.requireNonNull("profile", profile);
ParamUtil.requireNonNull("ca", ca);
final String sql = "INSERT INTO CA_HAS_PROFILE (CA_ID,PROFILE_ID) VALUES (?,?)";
PreparedStatement ps = null;
try {
ps = prepareStatement(sql);
ps.setInt(1, ca.getId());
ps.setInt(2, profile.getId());
if (ps.executeUpdate() == 0) {
throw new CaMgmtException("could not add profile " + profile + " to CA " + ca);
}
LOG.info("added profile '{}' to CA '{}'", profile, ca);
} catch (SQLException ex) {
throw new CaMgmtException(datasource, sql, ex);
} finally {
datasource.releaseResources(ps, null);
}
}
use of org.xipki.ca.server.mgmt.api.CaMgmtException in project xipki by xipki.
the class CaManagerQueryExecutor method createCaHasProfiles.
// method createCaHasRequestors
Set<Integer> createCaHasProfiles(NameId ca) throws CaMgmtException {
final String sql = "SELECT PROFILE_ID FROM CA_HAS_PROFILE WHERE CA_ID=?";
PreparedStatement stmt = null;
ResultSet rs = null;
try {
stmt = prepareStatement(sql);
stmt.setInt(1, ca.getId());
rs = stmt.executeQuery();
Set<Integer> ret = new HashSet<>();
while (rs.next()) {
int id = rs.getInt("PROFILE_ID");
ret.add(id);
}
return ret;
} catch (SQLException ex) {
throw new CaMgmtException(datasource, sql, ex);
} finally {
datasource.releaseResources(stmt, rs);
}
}
use of org.xipki.ca.server.mgmt.api.CaMgmtException 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);
}
}
Aggregations