use of org.xipki.ca.server.impl.cmp.RequestorEntryWrapper in project xipki by xipki.
the class CaManagerImpl method addRequestor.
@Override
public void addRequestor(RequestorEntry dbEntry) throws CaMgmtException {
ParamUtil.requireNonNull("dbEntry", dbEntry);
asssertMasterMode();
String name = dbEntry.getIdent().getName();
if (requestorDbEntries.containsKey(name)) {
throw new CaMgmtException(concat("Requestor named ", name, " exists"));
}
RequestorEntryWrapper requestor = new RequestorEntryWrapper();
requestor.setDbEntry(dbEntry);
queryExecutor.addRequestor(dbEntry);
idNameMap.addRequestor(dbEntry.getIdent());
requestorDbEntries.put(name, dbEntry);
requestors.put(name, requestor);
}
use of org.xipki.ca.server.impl.cmp.RequestorEntryWrapper in project xipki by xipki.
the class CaManagerImpl method changeRequestor.
// method removeRequestor
@Override
public void changeRequestor(String name, String base64Cert) throws CaMgmtException {
ParamUtil.requireNonNull("base64Cert", base64Cert);
name = ParamUtil.requireNonBlank("name", name).toLowerCase();
asssertMasterMode();
NameId ident = idNameMap.getRequestor(name);
if (ident == null) {
String msg = concat("unknown requestor ", name);
LOG.warn(msg);
throw new CaMgmtException(msg);
}
RequestorEntryWrapper requestor = queryExecutor.changeRequestor(ident, base64Cert);
requestorDbEntries.remove(name);
requestors.remove(name);
requestorDbEntries.put(name, requestor.getDbEntry());
requestors.put(name, requestor);
}
use of org.xipki.ca.server.impl.cmp.RequestorEntryWrapper in project xipki by xipki.
the class CaManagerImpl method initRequestors.
private void initRequestors() throws CaMgmtException {
if (requestorsInitialized) {
return;
}
idNameMap.clearRequestor();
requestorDbEntries.clear();
requestors.clear();
List<String> names = queryExecutor.namesFromTable("REQUESTOR");
for (String name : names) {
if (RequestorInfo.NAME_BY_CA.equals(name)) {
Integer id = queryExecutor.getRequestorId(name);
NameId ident = new NameId(id, name);
byCaRequestor = new ByCaRequestorInfo(ident);
idNameMap.addRequestor(ident);
} else if (RequestorInfo.NAME_BY_USER.equals(name)) {
Integer id = queryExecutor.getRequestorId(name);
byUserRequestorId = new NameId(id, name);
idNameMap.addRequestor(byUserRequestorId);
} else {
RequestorEntry requestorDbEntry = queryExecutor.createRequestor(name);
if (requestorDbEntry == null) {
continue;
}
idNameMap.addRequestor(requestorDbEntry.getIdent());
requestorDbEntries.put(name, requestorDbEntry);
RequestorEntryWrapper requestor = new RequestorEntryWrapper();
requestor.setDbEntry(requestorDbEntry);
requestors.put(name, requestor);
}
}
requestorsInitialized = true;
}
use of org.xipki.ca.server.impl.cmp.RequestorEntryWrapper in project xipki by xipki.
the class CaManagerQueryExecutor method changeRequestor.
// method changeCmpControl
RequestorEntryWrapper changeRequestor(NameId nameId, String base64Cert) throws CaMgmtException {
ParamUtil.requireNonNull("nameId", nameId);
RequestorEntry newDbEntry = new RequestorEntry(nameId, base64Cert);
RequestorEntryWrapper requestor = new RequestorEntryWrapper();
requestor.setDbEntry(newDbEntry);
final String sql = "UPDATE REQUESTOR SET CERT=? WHERE ID=?";
PreparedStatement ps = null;
try {
ps = prepareStatement(sql);
String b64Cert = getRealString(base64Cert);
ps.setString(1, b64Cert);
ps.setInt(2, nameId.getId());
if (ps.executeUpdate() == 0) {
throw new CaMgmtException("could not change requestor " + nameId);
}
String subject = null;
if (b64Cert != null) {
try {
subject = canonicalizName(X509Util.parseBase64EncodedCert(b64Cert).getSubjectX500Principal());
} catch (CertificateException ex) {
subject = "ERROR";
}
}
LOG.info("changed requestor '{}': {}", nameId, subject);
return requestor;
} catch (SQLException ex) {
throw new CaMgmtException(datasource, sql, ex);
} finally {
datasource.releaseResources(ps, null);
}
}
Aggregations