⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 localcertificatestoresessionbean.java

📁 一个免费的CA,基于EJB平台的,老师叫我们测试,现把之共享出来让大家参考
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        debug(">getLastCRL(" + issuerdn + ")");        try {            int maxnumber = getLastCRLNumber(admin, issuerdn);            X509CRL crl = null;            try {                CRLDataLocal data = crlHome.findByIssuerDNAndCRLNumber(issuerdn, maxnumber);                crl = data.getCRL();            } catch (FinderException e) {                crl = null;            }            debug("<getLastCRL()");            if (crl == null)                return null;        	String msg = intres.getLocalizedMessage("store.getcrl", issuerdn, new Integer(maxnumber));            	            getLogSession().log(admin, crl.getIssuerDN().toString().hashCode(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_INFO_GETLASTCRL, msg);            return crl.getEncoded();        } catch (Exception e) {        	String msg = intres.getLocalizedMessage("store.errorgetcrl", issuerdn);            	            getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_GETLASTCRL, msg);            throw new EJBException(e);        }    } //getLastCRL    /**     * Retrieves the information about the lastest CRL issued by this CA.     *     * @param admin Administrator performing the operation     * @param issuerdn the CRL issuers DN (CAs subject DN)     * @return CRLInfo of last CRL by CA.     * @ejb.interface-method     */    public CRLInfo getLastCRLInfo(Admin admin, String issuerdn) {        debug(">getLastCRLInfo(" + issuerdn + ")");        try {            int maxnumber = getLastCRLNumber(admin, issuerdn);            CRLInfo crlinfo = null;            try {                CRLDataLocal data = crlHome.findByIssuerDNAndCRLNumber(issuerdn, maxnumber);                crlinfo = new CRLInfo(data.getIssuerDN(), maxnumber, data.getThisUpdate(), data.getNextUpdate());            } catch (FinderException e) {            	String msg = intres.getLocalizedMessage("store.errorgetcrl", issuerdn, new Integer(maxnumber));            	                log.error(msg, e);                crlinfo = null;            }            debug("<getLastCRLInfo()");            return crlinfo;        } catch (Exception e) {        	String msg = intres.getLocalizedMessage("store.errorgetcrlinfo", issuerdn);            	            getLogSession().log(admin, issuerdn.hashCode(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_GETLASTCRL, msg);            throw new EJBException(e);        }    } //getLastCRL    /**     * Retrieves the highest CRLNumber issued by the CA.     *     * @param admin    Administrator performing the operation     * @param issuerdn the subjectDN of a CA certificate     * @ejb.interface-method     */    public int getLastCRLNumber(Admin admin, String issuerdn) {        debug(">getLastCRLNumber(" + issuerdn + ")");        Connection con = null;        PreparedStatement ps = null;        ResultSet result = null;        try {            con = JDBCUtil.getDBConnection(JNDINames.DATASOURCE);            ps = con.prepareStatement("select MAX(CRLNumber) from CRLData where issuerDN=?");            ps.setString(1, issuerdn);            result = ps.executeQuery();            int maxnumber = 0;            if (result.next())                maxnumber = result.getInt(1);            debug("<getLastCRLNumber(" + maxnumber + ")");            return maxnumber;        } catch (Exception e) {            throw new EJBException(e);        } finally {            JDBCUtil.close(con, ps, result);        }    } //getLastCRLNumber    /**     * Method used to add a CertReqHistory to database     *      * @param admin calling the methods     * @param certificate the certificate to store (Only X509Certificate used for now)     * @param useradmindata the user information used when issuing the certificate.     * @ejb.transaction type="Required"     * @ejb.interface-method          */    public void addCertReqHistoryData(Admin admin, Certificate certificate, UserDataVO useradmindata){    	X509Certificate cert = (X509Certificate) certificate;        debug(">addCertReqHistData(" + cert.getSerialNumber() + ", " + cert.getIssuerDN() + ", " + useradmindata.getUsername() + ")");        try {            CertReqHistoryDataPK pk = new CertReqHistoryDataPK();            pk.fingerprint = CertTools.getFingerprintAsString(cert);            certReqHistoryHome.create(cert,useradmindata);        	String msg = intres.getLocalizedMessage("store.storehistory", useradmindata.getUsername());            	            getLogSession().log(admin, cert, LogEntry.MODULE_CA, new java.util.Date(), useradmindata.getUsername(), cert, LogEntry.EVENT_INFO_STORECERTIFICATE, msg);                    } catch (Exception e) {        	String msg = intres.getLocalizedMessage("store.errorstorehistory", useradmindata.getUsername());            	            getLogSession().log(admin, cert, LogEntry.MODULE_CA, new java.util.Date(), useradmindata.getUsername(), cert, LogEntry.EVENT_ERROR_STORECERTIFICATE, msg);            throw new EJBException(e);        }        debug("<addCertReqHistData()");    	    }        /**     * Method to remove CertReqHistory data.     * @param admin     * @param certFingerprint the primary key.     * @ejb.transaction type="Required"         * @ejb.interface-method       */    public void removeCertReqHistoryData(Admin admin, String certFingerprint){    	debug(">removeCertReqHistData(" + certFingerprint + ")");        try {                      CertReqHistoryDataPK pk = new CertReqHistoryDataPK();            pk.fingerprint = certFingerprint;        	String msg = intres.getLocalizedMessage("store.removehistory", certFingerprint);            	            getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_INFO_STORECERTIFICATE, msg);            this.certReqHistoryHome.remove(pk);        } catch (Exception e) {        	String msg = intres.getLocalizedMessage("store.errorremovehistory", certFingerprint);            	            getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_STORECERTIFICATE, msg);            throw new EJBException(e);        }        debug("<removeCertReqHistData()");       	    }        /**     * Retrieves the certificate request data belonging to given certificate serialnumber and issuerdn     *      * @param admin     * @param certificateSN serial number of the certificate     * @param issuerDN     * @return the CertReqHistory or null if no data is stored with the certificate.     * @ejb.interface-method     */    public CertReqHistory getCertReqHistory(Admin admin, BigInteger certificateSN, String issuerDN){    	CertReqHistory retval = null;    	    	try{    	  Collection result = certReqHistoryHome.findByIssuerDNSerialNumber(issuerDN, certificateSN.toString());    	  if(result.iterator().hasNext())    	    retval = ((CertReqHistoryDataLocal) result.iterator().next()).getCertReqHistory();    	}catch(FinderException fe){    		// Do nothing but return null    	}    	    	return retval;    }            /**     * Retrieves all cert request datas belonging to a user.     * @param admin     * @param username     * @return a collection of CertReqHistory     * @ejb.interface-method     */    public List getCertReqHistory(Admin admin, String username){    	ArrayList retval = new ArrayList();    	    	try{    	  Collection result = certReqHistoryHome.findByUsername(username);    	  Iterator iter = result.iterator();    	  while(iter.hasNext()){    	    retval.add(((CertReqHistoryDataLocal) iter.next()).getCertReqHistory());    	  }    	}catch(FinderException fe){    		// Do nothing but return null    	}    	    	return retval;    }            /**     * Adds a certificate profile to the database.     *     * @param admin                  administrator performing the task     * @param certificateprofilename readable name of new certificate profile     * @param certificateprofile     the profile to be added     * @ejb.transaction type="Required"     * @ejb.interface-method     */    public void addCertificateProfile(Admin admin, String certificateprofilename,                                      CertificateProfile certificateprofile) throws CertificateProfileExistsException {        addCertificateProfile(admin, findFreeCertificateProfileId(), certificateprofilename, certificateprofile);    } // addCertificateProfile    /**     * Adds a certificate profile to the database.     *     * @param admin                  administrator performing the task     * @param certificateprofileid   internal ID of new certificate profile, use only if you know it's right.     * @param certificateprofilename readable name of new certificate profile     * @param certificateprofile     the profile to be added     * @ejb.transaction type="Required"     * @ejb.interface-method     */    public void addCertificateProfile(Admin admin, int certificateprofileid, String certificateprofilename,                                      CertificateProfile certificateprofile) throws CertificateProfileExistsException {        if (isCertificateProfileNameFixed(certificateprofilename)) {        	String msg = intres.getLocalizedMessage("store.errorcertprofilefixed", certificateprofilename);            	            getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CERTPROFILE, msg);            throw new CertificateProfileExistsException(msg);        }        if (isFreeCertificateProfileId(certificateprofileid)) {            try {                certprofilehome.findByCertificateProfileName(certificateprofilename);            	String msg = intres.getLocalizedMessage("store.errorcertprofileexists", certificateprofilename);            	                throw new CertificateProfileExistsException(msg);            } catch (FinderException e) {                try {                    certprofilehome.create(new Integer(certificateprofileid), certificateprofilename,                            certificateprofile);                	String msg = intres.getLocalizedMessage("store.addedcertprofile", certificateprofilename);            	                    getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_INFO_CERTPROFILE, msg);                } catch (Exception f) {                	String msg = intres.getLocalizedMessage("store.errorcreatecertprofile", certificateprofilename);            	                    getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CERTPROFILE, msg);                }            }        }    } // addCertificateProfile    /**     * Adds a certificateprofile  with the same content as the original certificateprofile,     *     * @param admin                          Administrator performing the operation     * @param originalcertificateprofilename readable name of old certificate profile     * @param newcertificateprofilename      readable name of new certificate profile     * @ejb.transaction type="Required"     * @ejb.interface-method     */    public void cloneCertificateProfile(Admin admin, String originalcertificateprofilename, String newcertificateprofilename) throws CertificateProfileExistsException {        CertificateProfile certificateprofile = null;        if (isCertificateProfileNameFixed(newcertificateprofilename)) {        	String msg = intres.getLocalizedMessage("store.errorcertprofilefixed", newcertificateprofilename);            	            getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CERTPROFILE, msg);            throw new CertificateProfileExistsException(msg);        }        try {            certificateprofile = (CertificateProfile) getCertificateProfile(admin, originalcertificateprofilename).clone();            boolean issuperadministrator = false;            try {                issuperadministrator = getAuthorizationSession().isAuthorizedNoLog(admin, "/super_administrator");            } catch (AuthorizationDeniedException ade) {            }            if (!issuperadministrator && certificateprofile.isApplicableToAnyCA()) {                // Not superadministrator, do not use ANYCA;                Collection authcas = getAuthorizationSession().getAuthorizedCAIds(admin);                certificateprofile.setAvailableCAs(authcas);            }            try {                certprofilehome.findByCertificateProfileName(newcertificateprofilename);            	String msg = intres.getLocalizedMessage("store.erroraddprofilewithtempl", newcertificateprofilename, originalcertificateprofilename);            	                getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CERTPROFILE, msg);                throw new CertificateProfileExistsException();            } catch (FinderException e) {                try {                    certprofilehome.create(new Integer(findFreeCertificateProfileId()), newcertificateprofilename, certificateprofile);                	String msg = intres.getLocalizedMessage("store.addedprofilewithtempl", newcertificateprofilename, originalcertificateprofilename);            	                    getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_INFO_CERTPROFILE, msg);                } catch (CreateException f) {                }            }        } catch (CloneNotSupportedException f) {        }    } // cloneCertificateP

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -