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

📄 localcertificatestoresessionbean.java

📁 一个免费的CA,基于EJB平台的,老师叫我们测试,现把之共享出来让大家参考
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        if (publishersession == null) {            try {                IPublisherSessionLocalHome home = (IPublisherSessionLocalHome) getLocator().getLocalHome(IPublisherSessionLocalHome.COMP_NAME);                publishersession = home.create();            } 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.     * @ejb.transaction type="Required"     * @ejb.interface-method     */    public boolean storeCertificate(Admin admin, Certificate incert, String username, String cafp,                                    int status, int type) {        debug(">storeCertificate(" + cafp + ", " + status + ", " + type + ")");        try {            // Strip dangerous chars            username = StringTools.strip(username);            X509Certificate cert = (X509Certificate) 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, LogEntry.MODULE_CA, new java.util.Date(), username, (X509Certificate) incert, LogEntry.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);            	            }        } catch (Exception e) {        	String msg = intres.getLocalizedMessage("store.errorstorecert");            	            getLogSession().log(admin, (X509Certificate) incert, LogEntry.MODULE_CA, new java.util.Date(), username, (X509Certificate) incert, LogEntry.EVENT_ERROR_STORECERTIFICATE, msg);            throw new EJBException(e);        }        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.     * @return true if storage was successful.     * @ejb.transaction type="Required"     * @ejb.interface-method     */    public boolean storeCRL(Admin admin, byte[] incrl, String cafp, int number) {        debug(">storeCRL(" + cafp + ", " + number + ")");        try {            X509CRL crl = CertTools.getCRLfromByteArray(incrl);            CRLDataLocal data1 = crlHome.create(crl, number);            data1.setCaFingerprint(cafp);        	String msg = intres.getLocalizedMessage("store.storecrl", new Integer(number), CertTools.getFingerprintAsString(crl));            	            getLogSession().log(admin, crl.getIssuerDN().toString().hashCode(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_INFO_STORECRL, msg);        } catch (Exception e) {        	String msg = intres.getLocalizedMessage("store.storecrl");            	            getLogSession().log(admin, LogConstants.INTERNALCAID, LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.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 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 listRevokedCertificates(Admin admin, String issuerdn) {        debug(">listRevokedCertificates()");        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 thousend certificates at a time, in case there            // are really many revoked certificates after some time...            con = JDBCUtil.getDBConnection(JNDINames.DATASOURCE);            ps = con.prepareStatement("select fingerprint from CertificateData where status=? and issuerDN=? ORDER BY expireDate DESC");            ps.setInt(1, CertificateDataBean.CERT_REVOKED);            ps.setString(2, dn);            result = ps.executeQuery();            ArrayList vect = new ArrayList();            while (result.next()) {                vect.add(result.getString(1));            }            debug("<listRevokedCertificates()");            return vect;        } catch (Exception e) {            throw new EJBException(e);        } finally {            JDBCUtil.close(con, ps, result);        }    } // listRevokedCertificates    /**     * 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     */    public Collection findCertificatesByExpireTimeWithLimit(Admin admin, Date expiretime) {        debug(">findCertificatesByExpireTimeWithLimit");        Connection con = null;        PreparedStatement ps = null;        ResultSet result = null;        ArrayList returnval = new ArrayList();        long currentdate = new Date().getTime();        try {            con = JDBCUtil.getDBConnection(JNDINames.DATASOURCE);            ps = con.prepareStatement("SELECT DISTINCT username FROM CertificateData WHERE expireDate>=? AND expireDate<? AND status=?");            ps.setLong(1, currentdate);            ps.setLong(2, expiretime.getTime());            ps.setInt(3, CertificateDataBean.CERT_ACTIVE);            result = ps.executeQuery();            while (result.next() && returnval.size() <= SecConst.MAXIMUM_QUERY_ROWCOUNT + 1) {                if (result.getString(1) != null && !result.getString(1).equals(""))                    returnval.add(result.getString(1));            }            debug("<findCertificatesByExpireTimeWithLimit()");            return returnval;        } catch (Exception e) {            throw new EJBException(e);        } finally {            JDBCUtil.close(con, ps, result);        }

⌨️ 快捷键说明

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