📄 localcertificatestoresessionbean.java
字号:
try { X509CRL crl = CertTools.getCRLfromByteArray(incrl); CRLDataLocal data1 = crlHome.create(crl, number); data1.setCAFingerprint(cafp); getLogSession().log(admin, crl.getIssuerDN().toString().hashCode(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_INFO_STORECRL, "Number : " + number + " Fingerprint : " + CertTools.getFingerprintAsString(crl) + "."); } catch (Exception e) { getLogSession().log(admin, LogConstants.INTERNALCAID, LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_STORECRL, "Number : " + number + "."); 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 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 /** * @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); } } //findCertificatesByExpireTimeWithLimit /** * Finds a certificate specified by issuer DN and serial number. * * @param admin Administrator performing the operation * @param issuerDN issuer DN of the desired certificate. * @param serno serial number of the desired certificate! * @return Certificate if found or null * @ejb.interface-method */ public Certificate findCertificateByIssuerAndSerno(Admin admin, String issuerDN, BigInteger serno) { debug(">findCertificateByIssuerAndSerno(), dn:" + issuerDN + ", serno=" + serno); // First make a DN in our well-known format String dn = CertTools.stringToBCDNString(issuerDN); dn = StringTools.strip(dn); debug("Looking for cert with (transformed)DN: " + dn); try { Collection coll = certHome.findByIssuerDNSerialNumber(dn, serno.toString()); Certificate ret = null; if (coll != null) { if (coll.size() > 1) getLogSession().log(admin, issuerDN.hashCode(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_DATABASE, "Error in database, more than one certificate has the same Issuer : " + issuerDN + " and serialnumber " + serno.toString(16) + "."); Iterator iter = coll.iterator(); if (iter.hasNext()) { ret = ((CertificateDataLocal) iter.next()).getCertificate(); } } debug("<findCertificateByIssuerAndSerno(), dn:" + issuerDN + ", serno=" + serno); return ret; } catch (Exception fe) { throw new EJBException(fe); } } //findCertificateByIssuerAndSerno /** * Implements ICertificateStoreSession::findCertificatesByIssuerAndSernos. * <p/> * The method retrives all certificates from a specific issuer * which are identified by list of serial numbers. The collection * will be empty if the issuerDN is <tt>null</tt>/empty * or the collection of serial numbers is empty. * * @param admin * @param issuerDN the subjectDN of a CA certificate * @param sernos a collection of certificate serialnumbers * @return Collection a list of certificates; never <tt>null</tt> * @ejb.interface-method */ public Collection findCertificatesByIssuerAndSernos(Admin admin, String issuerDN, Collection sernos) { debug(">findCertificateByIssuerAndSernos()"); Connection con = null; PreparedStatement ps = null; ResultSet result = null; ArrayList vect = null; if (null == admin) { throw new IllegalArgumentException(); } if (null == issuerDN || issuerDN.length() <= 0 || null == sernos || sernos.isEmpty()) { return new ArrayList(); } String dn = CertTools.stringToBCDNString(issuerDN); debug("Looking for cert with (transformed)DN: " + dn); try { final StringBuffer sb = new StringBuffer(); /* * tmeckel: * JBoss seems to have problems loading anoymous classes :( * i always get an java.lang.NoClassDefFound exception when * i try to use the following code snipped * * the code in the following block is only a dingy * replacement as long as the problem with anonymous * classes are solved :) CollectionUtils.forAllDo(sernos, new Closure() { public void execute(Object input) { if (null != input) { sb.append(", "); sb.append(input.toString()); } }} ); */ { Iterator iter = sernos.iterator(); while (iter.hasNext()) { sb.append(", '");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -