01: /*
02: * IssuerNameAndSerialCertSelector.java
03: *
04: * Created on February 28, 2007, 11:09 AM
05: *
06: * To change this template, choose Tools | Template Manager
07: * and open the template in the editor.
08: */
09:
10: package com.sun.xml.wss.impl.misc;
11:
12: import java.math.BigInteger;
13: import java.security.cert.CertSelector;
14: import java.security.cert.Certificate;
15:
16: import java.util.logging.Level;
17: import java.util.logging.Logger;
18: import com.sun.xml.wss.logging.LogDomainConstants;
19: import java.security.cert.X509Certificate;
20: import java.util.Arrays;
21:
22: import com.sun.xml.wss.XWSSecurityException;
23:
24: import java.security.cert.CertificateEncodingException;
25:
26: /**
27: *
28: * @author kumar jayanti
29: */
30: public class IssuerNameAndSerialCertSelector implements CertSelector {
31:
32: private final BigInteger serialNumber;
33: private final String issuerName;
34:
35: /** logger */
36: protected static final Logger log = Logger.getLogger(
37: LogDomainConstants.WSS_API_DOMAIN,
38: LogDomainConstants.WSS_API_DOMAIN_BUNDLE);
39:
40: /** Creates a new instance of IssuerNameAndSerialCertSelector */
41: public IssuerNameAndSerialCertSelector(BigInteger serialNum,
42: String issuer) {
43: this .serialNumber = serialNum;
44: this .issuerName = issuer;
45: }
46:
47: public boolean match(Certificate cert) {
48: if (cert instanceof X509Certificate) {
49: if (this .matchesIssuerSerialAndName(this .serialNumber,
50: this .issuerName, (X509Certificate) cert)) {
51: return true;
52: }
53: }
54: return false;
55: }
56:
57: public Object clone() {
58: return new IssuerNameAndSerialCertSelector(this .serialNumber,
59: this .issuerName);
60: }
61:
62: private boolean matchesIssuerSerialAndName(
63: BigInteger serialNumberMatch, String issuerNameMatch,
64: X509Certificate x509Cert) {
65:
66: BigInteger serialNumber = x509Cert.getSerialNumber();
67: String issuerName = com.sun.org.apache.xml.internal.security.utils.RFC2253Parser
68: .normalize(x509Cert.getIssuerDN().getName());
69:
70: if (serialNumber.equals(serialNumberMatch)
71: && issuerName.equals(issuerNameMatch)) {
72: return true;
73: }
74: return false;
75: }
76: }
|