Source code: jsdsi/CompatibleCertSelector.java
1 /*
2 * Copyright 2002 Massachusetts Institute of Technology
3 *
4 * Permission to use, copy, modify, and distribute this program for any
5 * purpose and without fee is hereby granted, provided that this
6 * copyright and permission notice appear on all copies and supporting
7 * documentation, the name of M.I.T. not be used in advertising or
8 * publicity pertaining to distribution of the program without specific
9 * prior permission, and notice be given in supporting documentation that
10 * copying and distribution is by permission of M.I.T. M.I.T. makes no
11 * representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
13 */
14 package jsdsi;
15
16 /**
17 * Selects all certificates whose subject is a name that starts with the
18 * specified issuer and string. That is, if the issuer is <code>K</code> and
19 * the string is <code>S</code>, this selects all certificates of the form
20 * <code>(LHS -> "K S ...")</code>, where <code>LHS</code> is the
21 * left-hand-side of the certificate and <code>"K S ..."</code> is a
22 * name.
23 *
24 * @author Sameer Ajmani
25 * @version $Revision: 1.2 $ $Date: 2003/04/22 21:37:46 $
26 */
27 public class CompatibleCertSelector extends CertSelector {
28 /**
29 * Issuer the searched certificat's subject starts with.
30 */
31 Principal issuer;
32
33 /**
34 * String the searched certificat's subject starts with.
35 */
36 String name;
37
38 /**
39 * Creates a new <code>CompatibleCertSelector</code> from a given principal
40 * and name.
41 *
42 * @param i issuer for the searched subject.
43 * @param n name string for the searched subject left-hand-side.
44 */
45 public CompatibleCertSelector(Principal i, String n) {
46 issuer = i;
47 name = n;
48 }
49
50 /**
51 * @see java.lang.Object#clone()
52 */
53 public Object clone() {
54 return new CompatibleCertSelector(issuer, name);
55 }
56
57 /**
58 * @see java.security.cert.CertSelector#match(Certificate)
59 */
60 public boolean match(jsdsi.Certificate cert) {
61 return (cert.getCert().getSubject() instanceof Name)
62 && ((Name) cert.getCert().getSubject()).getIssuer().samePrincipalAs(
63 issuer)
64 && ((Name) cert.getCert().getSubject()).getNames()[0].equals(name);
65 }
66
67 /**
68 * Returns the issuer of this <code>CompatibleCertSelector</code>.
69 *
70 * @return the issuer of this <code>CompatibleCertSelector</code>.
71 */
72 public Principal getIssuer() {
73 return issuer;
74 }
75
76 /**
77 * Returns the name of this <code>CompatibleCertSelector</code>.
78 *
79 * @return the name of this <code>CompatibleCertSelector</code>.
80 */
81 public String getName() {
82 return name;
83 }
84
85 /**
86 * Returns the full name that consist of the name constructed of the
87 * issuer and the name of this <code>CompatibleCertSelector</code>.
88 *
89 * @return the <code>Name</code> of this <code>CompatibleCertSelector</code>.
90 */
91 public Name getFullName() {
92 return new Name(issuer, name);
93 }
94 }