📄 ejbcawsrabasecommand.java
字号:
package org.ejbca.core.protocol.ws.client;import java.io.BufferedReader;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStreamReader;import java.io.PrintStream;import java.net.URL;import java.util.Properties;import javax.xml.namespace.QName;import org.ejbca.core.model.ca.crl.RevokedCertInfo;import org.ejbca.core.protocol.ws.client.gen.EjbcaWSService;import org.ejbca.util.CertTools;/** * Base class inherited by all EJBCA RA WS cli commands. * Checks the property file and creates a webservice connection. * * @author Philip Vendil * $Id: EJBCAWSRABaseCommand.java,v 1.2 2006/10/08 22:53:26 herrvendil Exp $ */public abstract class EJBCAWSRABaseCommand { protected String[] args = null; private org.ejbca.core.protocol.ws.client.gen.EjbcaWS ejbcaraws = null; private Properties props = null; private String password = null; protected static final String[] REASON_TEXTS ={"NOT REVOKED","UNSPECIFIED","KEYCOMPROMISE","CACOMPROMISE", "AFFILIATIONCHANGED","SUPERSEDED","CESSATIONOFOPERATION", "CERTIFICATEHOLD","REMOVEFROMCRL","PRIVILEGESWITHDRAWN", "AACOMPROMISE"}; public static final int NOT_REVOKED = RevokedCertInfo.NOT_REVOKED; public static final int REVOKATION_REASON_UNSPECIFIED = RevokedCertInfo.REVOKATION_REASON_UNSPECIFIED; public static final int REVOKATION_REASON_KEYCOMPROMISE = RevokedCertInfo.REVOKATION_REASON_KEYCOMPROMISE; public static final int REVOKATION_REASON_CACOMPROMISE = RevokedCertInfo.REVOKATION_REASON_CACOMPROMISE; public static final int REVOKATION_REASON_AFFILIATIONCHANGED = RevokedCertInfo.REVOKATION_REASON_AFFILIATIONCHANGED; public static final int REVOKATION_REASON_SUPERSEDED = RevokedCertInfo.REVOKATION_REASON_SUPERSEDED; public static final int REVOKATION_REASON_CESSATIONOFOPERATION = RevokedCertInfo.REVOKATION_REASON_CESSATIONOFOPERATION; public static final int REVOKATION_REASON_CERTIFICATEHOLD = RevokedCertInfo.REVOKATION_REASON_CERTIFICATEHOLD; public static final int REVOKATION_REASON_REMOVEFROMCRL = RevokedCertInfo.REVOKATION_REASON_REMOVEFROMCRL; public static final int REVOKATION_REASON_PRIVILEGESWITHDRAWN = RevokedCertInfo.REVOKATION_REASON_PRIVILEGESWITHDRAWN; public static final int REVOKATION_REASON_AACOMPROMISE = RevokedCertInfo.REVOKATION_REASON_AACOMPROMISE; protected static final int[] REASON_VALUES = {NOT_REVOKED,REVOKATION_REASON_UNSPECIFIED, REVOKATION_REASON_KEYCOMPROMISE, REVOKATION_REASON_CACOMPROMISE, REVOKATION_REASON_AFFILIATIONCHANGED, REVOKATION_REASON_SUPERSEDED, REVOKATION_REASON_CESSATIONOFOPERATION, REVOKATION_REASON_CERTIFICATEHOLD, REVOKATION_REASON_REMOVEFROMCRL, REVOKATION_REASON_PRIVILEGESWITHDRAWN, REVOKATION_REASON_AACOMPROMISE}; EJBCAWSRABaseCommand(String[] args){ this.args = args; } /** * Method creating a connection to the webservice * using the information stored in the property files. * @throws ServiceException * @throws IOException * @throws FileNotFoundException */ protected org.ejbca.core.protocol.ws.client.gen.EjbcaWS getEjbcaRAWS() throws FileNotFoundException, IOException{ if(ejbcaraws == null){ CertTools.installBCProvider(); System.setProperty("javax.net.ssl.trustStore",getKeyStorePath()); System.setProperty("javax.net.ssl.trustStorePassword",getKeyStorePassword()); System.setProperty("javax.net.ssl.keyStore",getKeyStorePath()); System.setProperty("javax.net.ssl.keyStorePassword",getKeyStorePassword()); QName qname = new QName("http://ws.protocol.core.ejbca.org/", "EjbcaWSService"); EjbcaWSService service = new EjbcaWSService(new URL(getWebServiceURL()),qname); ejbcaraws = service.getEjbcaWSPort(); } return ejbcaraws; } private String getKeyStorePassword() throws FileNotFoundException, IOException { if(password == null){ if(getProperties().getProperty("ejbcawsracli.keystore.password") == null){ BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter keystore password :"); password = reader.readLine(); }else{ password = getProperties().getProperty("ejbcawsracli.keystore.password"); } } return password; } private String getKeyStorePath() throws FileNotFoundException, IOException { return getProperties().getProperty("ejbcawsracli.keystore.path", "keystore.jks"); } private String getWebServiceURL() throws FileNotFoundException, IOException { return getProperties().getProperty("ejbcawsracli.url", "https://localhost:8443/ejbca/ejbcaws/ejbcaws") + "?wsdl"; } private Properties getProperties() throws FileNotFoundException, IOException { if(props == null){ props = new Properties(); try { props.load(new FileInputStream("ejbcawsracli.properties")); } catch (FileNotFoundException e) { // Try in parent directory props.load(new FileInputStream("../ejbcawsracli.properties")); } } return props; } protected PrintStream getPrintStream(){ return System.out; } protected int getRevokeReason(String reason) throws Exception{ for(int i=0;i<REASON_TEXTS.length;i++){ if(REASON_TEXTS[i].equalsIgnoreCase(reason)){ return REASON_VALUES[i]; } } getPrintStream().println("Error : Unsupported reason " + reason); usage(); System.exit(-1); return 0; } protected String getRevokeReason(int reason) { for(int i=0;i<REASON_VALUES.length;i++){ if(REASON_VALUES[i]==reason){ return REASON_TEXTS[i]; } } getPrintStream().println("Error : Unsupported reason " + reason); usage(); System.exit(-1); return null; } protected abstract void usage();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -