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

📄 localcertificatestoresessionbean.java

📁 用来生成java证书
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            } catch (Exception e) {                throw new EJBException(e);            }        }        return publishersession;    } //getPublisherSession    /**     * Stores a certificate.     *     * @param incert   The certificate to be stored.     * @param cafp     Fingerprint (hex) of the CAs certificate.     * @param username username of end entity owning the certificate.     * @param status   Status of the certificate (from CertificateData).     * @param type     Type of certificate (CERTTYPE_ENDENTITY etc from CertificateDataBean).     * @return true if storage was successful.     * @throws CreateException if the certificate can not be stored in the database     * @ejb.transaction type="Required"     * @ejb.interface-method     */    public boolean storeCertificate(Admin admin, Certificate incert, String username, String cafp,                                    int status, int type) throws CreateException {        debug(">storeCertificate(" + cafp + ", " + status + ", " + type + ")");        // Strip dangerous chars        username = StringTools.strip(username);        Certificate cert = incert;        CertificateDataPK pk = new CertificateDataPK();        pk.fingerprint = CertTools.getFingerprintAsString(cert);                    CertificateDataLocal data1 = null;        data1 = certHome.create(cert);        data1.setUsername(username);        data1.setCaFingerprint(cafp);        data1.setStatus(status);        data1.setType(type);        String msg = intres.getLocalizedMessage("store.storecert");            	        getLogSession().log(admin, cert, LogConstants.MODULE_CA, new java.util.Date(), username, incert, LogConstants.EVENT_INFO_STORECERTIFICATE, msg);        if (protect) {        	CertificateInfo entry = new CertificateInfo(data1.getFingerprint(), data1.getCaFingerprint(), data1.getSerialNumber(), data1.getIssuerDN(), data1.getSubjectDN(), data1.getStatus(), data1.getType(), data1.getExpireDate(), data1.getRevocationDate(), data1.getRevocationReason());        	TableProtectSessionLocal protect = protecthome.create();        	protect.protect(admin, entry);            	        }        debug("<storeCertificate()");        return true;    } // storeCertificate    /**     * Stores a CRL     *     * @param incrl  The DER coded CRL to be stored.     * @param cafp   Fingerprint (hex) of the CAs certificate.     * @param number CRL number.     * @param issuerDN the issuer of the CRL     * @param thisUpdate when this CRL was created     * @param nextUpdate when this CRL expires     * @param deltaCRLIndicator -1 for a normal CRL and 1 for a deltaCRL     * @return true if storage was successful.     * @ejb.transaction type="Required"     * @ejb.interface-method     */    public boolean storeCRL(Admin admin, byte[] incrl, String cafp, int number, String issuerDN, Date thisUpdate, Date nextUpdate, int deltaCRLIndicator) {        debug(">storeCRL(" + cafp + ", " + number + ")");        try {        	boolean deltaCRL = deltaCRLIndicator > 0;        	int lastNo = getLastCRLNumber(admin, issuerDN, deltaCRL);        	if (number <= lastNo) {        		// There is already a CRL with this number, or a later one stored. Don't create duplicates            	String msg = intres.getLocalizedMessage("store.storecrlwrongnumber", number, lastNo);            	                getLogSession().log(admin, LogConstants.INTERNALCAID, LogConstants.MODULE_CA, new java.util.Date(), null, null, LogConstants.EVENT_ERROR_STORECRL, msg);        		        	}            crlHome.create(incrl, number, issuerDN, thisUpdate, nextUpdate, cafp, deltaCRLIndicator);        	String msg = intres.getLocalizedMessage("store.storecrl", new Integer(number), null);            	            getLogSession().log(admin, issuerDN.toString().hashCode(), LogConstants.MODULE_CA, new java.util.Date(), null, null, LogConstants.EVENT_INFO_STORECRL, msg);        } catch (Exception e) {        	String msg = intres.getLocalizedMessage("store.storecrl");            	            getLogSession().log(admin, LogConstants.INTERNALCAID, LogConstants.MODULE_CA, new java.util.Date(), null, null, LogConstants.EVENT_ERROR_STORECRL, msg);            throw new EJBException(e);        }        debug("<storeCRL()");        return true;    } // storeCRL    /**     * Lists fingerprint (primary key) of ALL certificates in the database.     * NOTE: Caution should be taken with this method as execution may be very     * heavy indeed if many certificates exist in the database (imagine what happens if     * there are millinos of certificates in the DB!).     * Should only be used for testing purposes.     *     * @param admin    Administrator performing the operation     * @param issuerdn the dn of the certificates issuer.     * @return Collection of fingerprints, i.e. Strings, reverse ordered by expireDate where last expireDate is first in array.     * @ejb.interface-method     */    public Collection listAllCertificates(Admin admin, String issuerdn) {        debug(">listAllCertificates()");        Connection con = null;        PreparedStatement ps = null;        ResultSet result = null;        String dn = CertTools.stringToBCDNString(issuerdn);        dn = StringTools.strip(dn);        try {            con = JDBCUtil.getDBConnection(JNDINames.DATASOURCE);            ps = con.prepareStatement("select fingerprint, expireDate from CertificateData where issuerDN=? ORDER BY expireDate DESC");            ps.setString(1, dn);            result = ps.executeQuery();            ArrayList vect = new ArrayList();            while (result.next()) {                vect.add(result.getString(1));            }            debug("<listAllCertificates()");            return vect;        } catch (Exception e) {            throw new EJBException(e);        } finally {            JDBCUtil.close(con, ps, result);        }    } // listAllCertificates    /**     * Lists RevokedCertInfo of ALL revoked certificates (status = CertificateDataBean.CERT_REVOKED) in the database from a certain issuer.      * NOTE: Caution should be taken with this method as execution may be very heavy indeed if many certificates exist in the database (imagine what happens if there are millinos of certificates in the DB!).      * Should only be used for testing purposes.     * @param admin Administrator performing the operation     * @param issuerdn the dn of the certificates issuer.     * @param lastbasecrldate a date (Date.getTime()) of last base CRL or -1 for a complete CRL     * @return Collection of RevokedCertInfo, reverse ordered by expireDate where last expireDate is first in array.     *     * @ejb.interface-method     */    public Collection listRevokedCertInfo(Admin admin, String issuerdn, long lastbasecrldate) {    	debug(">listRevokedCertInfo()");    	Connection con = null;    	PreparedStatement ps = null;    	ResultSet result = null;    	String dn = CertTools.stringToBCDNString(issuerdn);    	dn = StringTools.strip(dn);    	try {    		// TODO:    		// This should only list a few thousand certificates at a time, in case there    		// are really many revoked certificates after some time...    		con = JDBCUtil.getDBConnection(JNDINames.DATASOURCE);    		String sql = "select fingerprint, issuerDN, serialNumber, expireDate, revocationDate, revocationReason from CertificateData where issuerDN=? and status=?";    		// For delta CRLs we must select both revoked certificates, and certificates that are active because they have been un-revoked    		String deltaCRLSql = "select fingerprint, issuerDN, serialNumber, expireDate, revocationDate, revocationReason from CertificateData where issuerDN=? and revocationDate>? and (status=? or (status=? and revocationReason=?))";    		if (lastbasecrldate > 0) {    			sql = deltaCRLSql;    		}    		if (log.isDebugEnabled()) {        		log.debug("Executing SQL: "+sql);    			    		}    		ps = con.prepareStatement(sql);    		ps.setString(1, dn);    		if (lastbasecrldate > 0) {    			ps.setLong(2, lastbasecrldate);    			ps.setInt(3, CertificateDataBean.CERT_REVOKED);    			ps.setInt(4, CertificateDataBean.CERT_ACTIVE);    			ps.setInt(5, RevokedCertInfo.REVOKATION_REASON_REMOVEFROMCRL);    		} else {    			ps.setInt(2, CertificateDataBean.CERT_REVOKED);            	    		}    		result = ps.executeQuery();    		ArrayList vect = new ArrayList();    		while (result.next()) {    			String fp = result.getString(1);    			String issuerDN = result.getString(2);    			BigInteger serNo = new BigInteger(result.getString(3));    			long exptime = result.getLong(4);    			Date expDate = null;    			if (exptime > 0) {    				expDate = new Date(exptime);    			}    			long revtime = result.getLong(5);    			Date revDate = null;    			if (revtime > 0) {    				revDate = new Date(revtime);            	    			}    			int revReason = result.getInt(6);    			RevokedCertInfo certinfo = new RevokedCertInfo(fp, serNo, revDate, revReason, expDate);    			// Add to the result    			vect.add(certinfo);    		}    		debug("<listRevokedCertInfo()");    		return vect;    	} catch (Exception e) {    		throw new EJBException(e);    	} finally {    		JDBCUtil.close(con, ps, result);    	}    } // listRevokedCertInfo    /**     * Lists certificates for a given subject signed by the given issuer.     *     * @param admin     Administrator performing the operation     * @param subjectDN the DN of the subject whos certificates will be retrieved.     * @param issuerDN  the dn of the certificates issuer.     * @return Collection of Certificates (java.security.cert.Certificate) in no specified order or an empty Collection.     * @throws EJBException if a communication or other error occurs.     * @ejb.interface-method     */    public Collection findCertificatesBySubjectAndIssuer(Admin admin, String subjectDN, String issuerDN) {        debug(">findCertificatesBySubjectAndIssuer(), dn='" + subjectDN + "' and issuer='" + issuerDN + "'");        // First make a DN in our well-known format        String dn = CertTools.stringToBCDNString(subjectDN);        dn = StringTools.strip(dn);        String issuerdn = CertTools.stringToBCDNString(issuerDN);        issuerdn = StringTools.strip(issuerdn);        debug("Looking for cert with (transformed)DN: " + dn);        try {            Collection coll = certHome.findBySubjectDNAndIssuerDN(dn, issuerdn);            Collection ret = new ArrayList();            if (coll != null) {                Iterator iter = coll.iterator();                while (iter.hasNext()) {                    ret.add(((CertificateDataLocal) iter.next()).getCertificate());                }            }            debug("<findCertificatesBySubjectAndIssuer(), dn='" + subjectDN + "' and issuer='" + issuerDN + "'");            return ret;        } catch (javax.ejb.FinderException fe) {            throw new EJBException(fe);        }    } //findCertificatesBySubjectAndIssuer    /**     * Lists certificates for a given subject.     *     * @param admin     Administrator performing the operation     * @param subjectDN the DN of the subject whos certificates will be retrieved.     * @return Collection of Certificates (java.security.cert.Certificate) in no specified order or an empty Collection.     * @ejb.interface-method     */    public Collection findCertificatesBySubject(Admin admin, String subjectDN) {        debug(">findCertificatesBySubjectAndIssuer(), dn='" + subjectDN + "'");        // First make a DN in our well-known format        String dn = CertTools.stringToBCDNString(subjectDN);        dn = StringTools.strip(dn);        debug("Looking for cert with (transformed)DN: " + dn);        try {            Collection coll = certHome.findBySubjectDN(dn);            Collection ret = new ArrayList();            if (coll != null) {                Iterator iter = coll.iterator();                while (iter.hasNext()) {                    ret.add(((CertificateDataLocal) iter.next()).getCertificate());                }            }            debug("<findCertificatesBySubject(), dn='" + subjectDN + "'");            return ret;        } catch (javax.ejb.FinderException fe) {            throw new EJBException(fe);        }    } //findCertificatesBySubject    /**     * @ejb.interface-method     */    public Collection findCertificatesByExpireTime(Admin admin, Date expireTime) {        debug(">findCertificatesByExpireTime(), time=" + expireTime);        // First make expiretime in well know format        debug("Looking for certs that expire before: " + expireTime);        try {            Collection coll = certHome.findByExpireDate(expireTime.getTime());            Collection ret = new ArrayList();            if (coll != null) {                Iterator iter = coll.iterator();                while (iter.hasNext()) {                    ret.add(((CertificateDataLocal) iter.next()).getCertificate());                }            }            debug("<findCertificatesByExpireTime(), time=" + expireTime);            return ret;        } catch (javax.ejb.FinderException fe) {            throw new EJBException(fe);        }    }    //findCertificatesByExpireTime    /**     * Finds usernames of users having certificate(s) expiring within a specified time and that has     * status active.     *     * @ejb.interface-method

⌨️ 快捷键说明

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