private void asssertMasterMode() throws CaMgmtException { if (!masterMode) { throw new CaMgmtException("operation not allowed in slave mode"); } }
public X509Ca getCa() { try { return caManager.getX509Ca(caName); } catch (CaMgmtException ex) { throw new IllegalStateException(ex.getMessage(), ex); } }
public void commitNextCrlNo(NameId ca, long nextCrlNo) throws OperationException { try { queryExecutor.commitNextCrlNoIfLess(ca, nextCrlNo); } catch (CaMgmtException ex) { if (ex.getCause() instanceof DataAccessException) { throw new OperationException(ErrorCode.DATABASE_FAILURE, ex.getMessage()); } else { throw new OperationException(ErrorCode.SYSTEM_FAILURE, ex.getMessage()); } } catch (RuntimeException ex) { throw new OperationException(ErrorCode.SYSTEM_FAILURE, ex.getMessage()); } }
private static <T extends MgmtResponse> T parse(byte[] bytes, Class<?> clazz) throws CaMgmtException { try { return JSON.parseObject(bytes, clazz); } catch (RuntimeException ex) { throw new CaMgmtException("cannot parse response " + clazz + " from byte[]", ex); } }
@Override protected Object execute0() throws Exception { if (publisherNames == null) { throw new IllegalStateException("should not reach here"); } boolean allPublishers = false; for (String publisherName : publisherNames) { if ("all".equalsIgnoreCase(publisherName)) { allPublishers = true; break; } } if (allPublishers) { publisherNames = null; } if ("all".equalsIgnoreCase(caName)) { caName = null; } String msg = "certificates"; try { caManager.republishCertificates(caName, publisherNames, numThreads); println("republished " + msg); return null; } catch (CaMgmtException ex) { throw new CmdFailure("could not republish " + msg + ", error: " + ex.getMessage(), ex); } }
private static CaMgmtException logAndCreateException(String msg) { LOG.error(msg); return new CaMgmtException(msg); }
@Override protected Object execute0() throws Exception { String msg = "CA alias " + caAlias + " associated with CA " + caName; try { caManager.addCaAlias(caAlias, caName); println("added " + msg); return null; } catch (CaMgmtException ex) { throw new CmdFailure("could not add " + msg + ", error: " + ex.getMessage(), ex); } }
private Statement createStatement() throws CaMgmtException { try { return datasource.createStatement(); } catch (DataAccessException ex) { throw new CaMgmtException(ex); } } // method createStatement
@Override protected Object execute0() throws Exception { String msg = "the change of CA system"; try { caManager.notifyCaChange(); println("notified " + msg); return null; } catch (CaMgmtException ex) { throw new CmdFailure("could not notify " + msg + ", error: " + ex.getMessage(), ex); } }
private X509Certificate parseCert(byte[] certBytes) throws CaMgmtException { try { return X509Util.parseCert(certBytes); } catch (CertificateException ex) { throw new CaMgmtException("could not parse X.509 certificate", ex); } }
@Override protected Object execute0() throws Exception { BigInteger serialNo = getSerialNumber(); String msg = "certificate (serial number = 0x" + serialNo.toString(16) + ")"; try { caManager.unrevokeCertificate(caName, serialNo); println("unrevoked " + msg); return null; } catch (CaMgmtException ex) { throw new CmdFailure("could not unrevoke " + msg + ", error: " + ex.getMessage(), ex); } }
public X509Ca getX509Ca(String name) throws CaMgmtException { name = Args.toNonBlankLower(name, "name"); X509Ca ca = x509cas.get(name); if (ca == null) { throw new CaMgmtException("unknown CA " + name); } return ca; }
@Override protected Object execute0() throws Exception { try { caManager.unlockCa(); println("unlocked CA system, calling ca:restart to restart CA system"); return null; } catch (CaMgmtException ex) { throw new CmdFailure("could not unlock CA system, error: " + ex.getMessage(), ex); } }
private PreparedStatement prepareStatement(String sql) throws CaMgmtException { try { return datasource.prepareStatement(sql); } catch (DataAccessException ex) { throw new CaMgmtException(ex); } } // method prepareStatement
@Override protected Object execute0() throws Exception { for (String publisherName : publisherNames) { String msg = "publisher " + publisherName + " to CA " + caName; try { caManager.addPublisherToCa(publisherName, caName); println("added " + msg); } catch (CaMgmtException ex) { throw new CmdFailure("could not add " + msg + ", error: " + ex.getMessage(), ex); } } return null; }
void unlockCa() throws CaMgmtException { final String sql = "DELETE FROM SYSTEM_EVENT WHERE NAME='LOCK'"; Statement stmt = null; try { stmt = createStatement(); stmt.execute(sql); if (stmt.getUpdateCount() == 0) { throw new CaMgmtException("could not unlock CA"); } } catch (SQLException ex) { throw new CaMgmtException(datasource.translate(sql, ex)); } finally { datasource.releaseResources(stmt, null); } } // method unlockCa
@Override protected Object execute0() throws Exception { if (publisherNames == null) { throw new IllegalStateException("should not reach here"); } boolean allPublishers = false; for (String publisherName : publisherNames) { if ("all".equalsIgnoreCase(publisherName)) { allPublishers = true; break; } } if (allPublishers) { publisherNames = null; } if ("all".equalsIgnoreCase(caName)) { caName = null; } String msg = "publish queue of CA " + caName + " for publishers " + toString(publisherNames); try { caManager.clearPublishQueue(caName, publisherNames); println("cleared " + msg); return null; } catch (CaMgmtException ex) { throw new CmdFailure("could not clear " + msg + ", error: " + ex.getMessage(), ex); } }
public X509Ca getX509Ca(NameId ident) throws CaMgmtException { Args.notNull(ident, "ident"); X509Ca ca = x509cas.get(ident.getName()); if (ca == null) { throw new CaMgmtException("unknown CA " + ident); } return ca; }
@Override protected Object execute0() throws Exception { String msg = "configuration to file " + confFile; try { InputStream is = caManager.exportConf(caNames); save(new File(confFile), IoUtil.read(is)); println("exported " + msg); return null; } catch (CaMgmtException ex) { throw new CmdFailure("could not export " + msg + ", error: " + ex.getMessage(), ex); } }
private int getNonNullIdForName(String sql, String name) throws CaMgmtException { Integer id = getIdForName(sql, name); if (id != null) { return id.intValue(); } throw new CaMgmtException(concat("Found no entry named ",name)); }