1 package jsdsi.ldap;
2
3 import jsdsi.*;
4 import jsdsi.sexp.*;
5 import jsdsi.util.DigestAlgoEnum;
6
7 import java.security.cert.CertStoreException;
8
9 /***
10 * Jsdsi schema and CertSelectors filters
11 *
12 * Schema attributes: cn, canonicalSexp, subject, issuerName,
13 * subjectName and notAfter
14 *
15 * @author Lu�s Pedro
16 * @author Sean Radford
17 * @version $Revision: 1.6 $ $Date: 2004/11/08 12:08:08 $
18 *
19 **/
20
21 class LDAPAttributes {
22
23 /***
24 * cn attribute
25 */
26 private static String cn = "cn";
27
28 /***
29 * canonicalSexp attribute
30 */
31 private static String canonicalSexp = "canonicalSexp";
32
33 /***
34 * issuer attribute
35 */
36 private static String issuer = "issuer";
37
38 /***
39 * subject attribute
40 */
41 private static String subject = "subject";
42
43 /***
44 * issuerName attribute
45 */
46 private static String issuerName = "issuerName";
47
48 /***
49 * subjectName attribute
50 */
51 private static String subjectName = "subjectName";
52
53 /***
54 * notAfter attribute
55 */
56 private static String notAfter = "notAfter";
57
58 /***
59 * ampersand
60 */
61 private static String ampersand = "&";
62
63 /***
64 * comma
65 */
66 private static char comma = ',';
67
68 /***
69 * equals
70 */
71 private static char equals = '=';
72
73 /***
74 * left parenthensis
75 */
76 private static char leftpar = '(';
77
78 /***
79 * right parenthesis
80 */
81 private static char rightpar = ')';
82
83 /***
84 * Set a composed string with the cn attribute
85 *
86 * @param commonName cn ldap schema attribute that identifies the certificate
87 * @return String that represents composed commonName
88 */
89 static String setCn(String commonName) {
90 return(cn + equals + commonName + comma);
91 }
92
93 /***
94 * Set a composed string with issuerName attribute
95 *
96 * @param name issuerName ldap schema attribute that represents an issuer name
97 * @return String that represents composed issuer name
98 */
99 private static String setIssuerName(String name) {
100 return(issuerName + equals + name);
101 }
102
103 /***
104 * Set a composed string with subjectName attribute
105 *
106 * @param name subjectName ldap schema attribute that represents an subject name
107 * @return String that represents composed subject name
108 */
109 private static String setSubjectName(String name) {
110 return(subjectName + equals + name);
111 }
112
113 /***
114 * Create a filter with a specified attribute
115 *
116 * @param attribute ldap schema attribute defined on jsdsi schema
117 * @param obj sdsi object to be written
118 * @return String that represents a generic filter
119 */
120 private static String filter(String attribute, jsdsi.Obj obj) {
121 return(attribute + equals + Sexp.decodeString(obj.toTransport()));
122 }
123
124 /***
125 * Create a subject filter from subject issuer and an
126 * hash algorithm
127 *
128 * @param principal principal of a subject
129 * @param hashAlg hash algorithm
130 * @return String of a subject filter
131 */
132 static String setSubjectFilter(Subject principal, String hashAlg) {
133 if(principal instanceof PublicKeyHash)
134 return filter(subject, (PublicKeyHash)principal);
135 else {
136 Hash sHash = new Hash(DigestAlgoEnum.fromJdk(hashAlg),
137 (PublicKey)principal, null);
138 return filter(subject, sHash);
139 }
140 }
141
142 /***
143 * Create a auth filter from a principal issuer and an
144 * hash algorithm
145 *
146 * @param principal principal of a issuer
147 * @param hashAlg hash algorithm
148 * @return String representing an auth filter
149 */
150 static String setAuthFilter(Principal principal, String hashAlg) {
151 if(principal instanceof PublicKeyHash)
152 return filter(issuer, principal);
153 else {
154 Hash iHash = new Hash(DigestAlgoEnum.fromJdk(hashAlg),
155 principal, null);
156 return filter(issuer, iHash);
157 }
158 }
159
160 /***
161 * Create a name filter from a principal issuer a name and
162 * an hash algorithm
163 *
164 * @param principal principal of a issuer
165 * @param name issuer name
166 * @param hashAlg hash algorithm
167 * @return String representing a name filter
168 */
169 static String setNameFilter(Principal principal,
170 String name, String hashAlg) {
171 if(principal instanceof PublicKeyHash)
172 return(leftpar + ampersand + leftpar + filter(issuer,
173 principal) + rightpar + leftpar + setIssuerName(name) + rightpar + rightpar);
174 else {
175 Hash iHash = new Hash(DigestAlgoEnum.fromJdk(hashAlg),
176 principal, null);
177 return(leftpar + ampersand + leftpar + filter(issuer,
178 iHash) + rightpar + leftpar + setIssuerName(name) + rightpar + rightpar);
179 }
180 }
181
182 /***
183 * Create a compatible filter from a subject issuer a name and
184 * an hash algorithm
185 *
186 * @param principal principal of a subject
187 * @param name subject name
188 * @param hashAlg hash algorithm
189 * @return String representing a compatible filter
190 * @throws CertStoreException
191 */
192 static String setCompatibleFilter(Subject principal,
193 String name,
194 String hashAlg) throws CertStoreException {
195 if(principal instanceof PublicKeyHash)
196 return(leftpar + ampersand + leftpar + filter(subject,
197 (PublicKeyHash)principal) + rightpar + leftpar + setSubjectName(name) + rightpar + rightpar);
198 else {
199 Hash sHash = new Hash(DigestAlgoEnum.fromJdk(hashAlg),
200 (PublicKey)principal, null);
201 return(leftpar + ampersand + leftpar + filter(subject,
202 sHash) + rightpar + leftpar + setSubjectName(name) + rightpar + rightpar);
203 }
204 }
205
206 /***
207 * cn attribute
208 *
209 * @return cn attribute
210 */
211 static String getCn() {
212 return cn;
213 }
214
215 /***
216 * canonicalSexp attribute
217 *
218 * @return canonicalSexp attribute
219 */
220 static String getCanonicalSexp() {
221 return canonicalSexp;
222 }
223
224 /***
225 * issuer attribute
226 *
227 * @return issuer attribute
228 */
229 static String getIssuer() {
230 return issuer;
231 }
232
233 /***
234 * subject attribute
235 *
236 * @return subject attribute
237 */
238 static String getSubject() {
239 return subject;
240 }
241
242 /***
243 * issuerName attribute
244 *
245 * @return issuerName attribute
246 */
247 static String getIssuerName() {
248 return issuerName;
249 }
250
251 /***
252 * subjectName attribute
253 *
254 * @return subjectName attribute
255 */
256 static String getSubjectName() {
257 return subjectName;
258 }
259
260 /***
261 * notAfter attribute
262 *
263 * @return notAfter attribute
264 */
265 static String getNotAfter() {
266 return notAfter;
267 }
268 }
This page was automatically generated by Maven