use of org.xipki.ca.dbtool.jaxb.ca.CaHasPublisherType in project xipki by xipki.
the class CaConfigurationDbImporter method importCaHasPublisher.
// method importCaHasRequestor
private void importCaHasPublisher(CaHasPublishers caHasPublishers) throws Exception {
System.out.println("importing table CA_HAS_PUBLISHER");
final String sql = "INSERT INTO CA_HAS_PUBLISHER (CA_ID,PUBLISHER_ID) VALUES (?,?)";
PreparedStatement ps = prepareStatement(sql);
try {
for (CaHasPublisherType entry : caHasPublishers.getCaHasPublisher()) {
try {
ps.setInt(1, entry.getCaId());
ps.setInt(2, entry.getPublisherId());
ps.executeUpdate();
} catch (SQLException ex) {
System.err.println("could not import CA_HAS_PUBLISHER with CA_ID=" + entry.getCaId() + " and PUBLISHER_ID=" + entry.getPublisherId());
throw translate(sql, ex);
}
}
} finally {
releaseResources(ps, null);
}
System.out.println(" imported table CA_HAS_PUBLISHER");
}
use of org.xipki.ca.dbtool.jaxb.ca.CaHasPublisherType in project xipki by xipki.
the class CaConfigurationDbExporter method exportCaHasPublisher.
// method exportCaHasRequestor
private void exportCaHasPublisher(CAConfigurationType caconf) throws DataAccessException {
System.out.println("exporting table CA_HAS_PUBLISHER");
CaHasPublishers caHasPublishers = new CaHasPublishers();
final String sql = "SELECT CA_ID,PUBLISHER_ID FROM CA_HAS_PUBLISHER";
Statement stmt = null;
ResultSet rs = null;
try {
stmt = createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
CaHasPublisherType caHasPublisher = new CaHasPublisherType();
caHasPublisher.setCaId(rs.getInt("CA_ID"));
caHasPublisher.setPublisherId(rs.getInt("PUBLISHER_ID"));
caHasPublishers.getCaHasPublisher().add(caHasPublisher);
}
} catch (SQLException ex) {
throw translate(sql, ex);
} finally {
releaseResources(stmt, rs);
}
caconf.setCaHasPublishers(caHasPublishers);
System.out.println(" exported table CA_HAS_PUBLISHER");
}
use of org.xipki.ca.dbtool.jaxb.ca.CaHasPublisherType in project xipki by xipki.
the class OcspCertStoreFromCaDbImporter method importToDb.
public void importToDb() throws Exception {
CertStoreType certstore;
try {
@SuppressWarnings("unchecked") JAXBElement<CertStoreType> root = (JAXBElement<CertStoreType>) unmarshaller.unmarshal(new File(baseDir, FILENAME_CA_CERTSTORE));
certstore = root.getValue();
} catch (JAXBException ex) {
throw XmlUtil.convert(ex);
}
if (certstore.getVersion() > VERSION) {
throw new InvalidInputException("could not import CertStore greater than " + VERSION + ": " + certstore.getVersion());
}
CAConfigurationType caConf;
try {
File file = new File(baseDir + File.separator + FILENAME_CA_CONFIGURATION);
@SuppressWarnings("unchecked") JAXBElement<CAConfigurationType> rootCaConf = (JAXBElement<CAConfigurationType>) unmarshaller.unmarshal(file);
caConf = rootCaConf.getValue();
} catch (JAXBException ex) {
throw XmlUtil.convert(ex);
}
if (caConf.getVersion() > VERSION) {
throw new InvalidInputException("could not import CA Configuration greater than " + VERSION + ": " + certstore.getVersion());
}
System.out.println("importing CA certstore to OCSP database");
try {
if (!resume) {
dropIndexes();
}
PublisherType publisherType = null;
for (PublisherType type : caConf.getPublishers().getPublisher()) {
if (publisherName.equals(type.getName())) {
publisherType = type;
break;
}
}
if (publisherType == null) {
throw new InvalidInputException("unknown publisher " + publisherName);
}
String type = publisherType.getType();
if (!"ocsp".equalsIgnoreCase(type)) {
throw new InvalidInputException("Unkwown publisher type " + type);
}
ConfPairs confPairs = new ConfPairs(value(publisherType.getConf()));
String str = confPairs.value("publish.goodcerts");
boolean revokedOnly = false;
if (str != null) {
revokedOnly = !Boolean.parseBoolean(str);
}
Set<Integer> relatedCaIds = new HashSet<>();
for (CaHasPublisherType ctype : caConf.getCaHasPublishers().getCaHasPublisher()) {
if (ctype.getPublisherId() == publisherType.getId()) {
relatedCaIds.add(ctype.getCaId());
}
}
List<CaType> relatedCas = new LinkedList<>();
for (CaType m : caConf.getCas().getCa()) {
if (relatedCaIds.contains(m.getId())) {
relatedCas.add(m);
}
}
if (relatedCas.isEmpty()) {
System.out.println("No CA has publisher " + publisherName);
return;
}
Map<Integer, String> profileMap = new HashMap<Integer, String>();
for (ProfileType ni : caConf.getProfiles().getProfile()) {
profileMap.put(ni.getId(), ni.getName());
}
List<Integer> relatedCertStoreCaIds = resume ? getIssuerIds(relatedCas) : importIssuer(relatedCas);
File processLogFile = new File(baseDir, DbPorter.IMPORT_TO_OCSP_PROCESS_LOG_FILENAME);
importCert(certstore, profileMap, revokedOnly, relatedCertStoreCaIds, processLogFile);
recoverIndexes();
processLogFile.delete();
} catch (Exception ex) {
System.err.println("could not import OCSP certstore to database");
throw ex;
}
System.out.println(" imported OCSP certstore to database");
}
Aggregations