src/java.naming/share/classes/sun/security/provider/certpath/ldap/LDAPCertStoreImpl.java
equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
60 */ |
60 */ |
61 final class LDAPCertStoreImpl { |
61 final class LDAPCertStoreImpl { |
62 |
62 |
63 private static final Debug debug = Debug.getInstance("certpath"); |
63 private static final Debug debug = Debug.getInstance("certpath"); |
64 |
64 |
65 private final static boolean DEBUG = false; |
|
66 |
|
67 /** |
65 /** |
68 * LDAP attribute identifiers. |
66 * LDAP attribute identifiers. |
69 */ |
67 */ |
70 private static final String USER_CERT = "userCertificate;binary"; |
68 private static final String USER_CERT = "userCertificate;binary"; |
71 private static final String CA_CERT = "cACertificate;binary"; |
69 private static final String CA_CERT = "cACertificate;binary"; |
72 private static final String CROSS_CERT = "crossCertificatePair;binary"; |
70 private static final String CROSS_CERT = "crossCertificatePair;binary"; |
73 private static final String CRL = "certificateRevocationList;binary"; |
71 private static final String CRL = "certificateRevocationList;binary"; |
74 private static final String ARL = "authorityRevocationList;binary"; |
72 private static final String ARL = "authorityRevocationList;binary"; |
75 private static final String DELTA_CRL = "deltaRevocationList;binary"; |
|
76 |
73 |
77 // Constants for various empty values |
74 // Constants for various empty values |
78 private final static String[] STRING0 = new String[0]; |
75 private final static String[] STRING0 = new String[0]; |
79 |
76 |
80 private final static byte[][] BB0 = new byte[0][]; |
77 private final static byte[][] BB0 = new byte[0][]; |
111 /** |
108 /** |
112 * The CertificateFactory used to decode certificates from |
109 * The CertificateFactory used to decode certificates from |
113 * their binary stored form. |
110 * their binary stored form. |
114 */ |
111 */ |
115 private CertificateFactory cf; |
112 private CertificateFactory cf; |
|
113 |
116 /** |
114 /** |
117 * The JNDI directory context. |
115 * The JNDI directory context. |
118 */ |
116 */ |
119 private LdapContext ctx; |
117 private LdapContext ctx; |
120 |
118 |
239 throw new CertStoreException("Invalid name: " + name, ine); |
237 throw new CertStoreException("Invalid name: " + name, ine); |
240 } |
238 } |
241 return name; |
239 return name; |
242 } |
240 } |
243 |
241 |
244 String getName() { |
|
245 return name; |
|
246 } |
|
247 |
|
248 void addRequestedAttribute(String attrId) { |
242 void addRequestedAttribute(String attrId) { |
249 if (valueMap != null) { |
243 if (valueMap != null) { |
250 throw new IllegalStateException("Request already sent"); |
244 throw new IllegalStateException("Request already sent"); |
251 } |
245 } |
252 requestedAttributes.add(attrId); |
246 requestedAttributes.add(attrId); |
258 * @param attrId the attribute identifier |
252 * @param attrId the attribute identifier |
259 * @return an array of binary values (byte arrays) |
253 * @return an array of binary values (byte arrays) |
260 * @throws NamingException if a naming exception occurs |
254 * @throws NamingException if a naming exception occurs |
261 */ |
255 */ |
262 byte[][] getValues(String attrId) throws NamingException { |
256 byte[][] getValues(String attrId) throws NamingException { |
263 if (DEBUG && ((cacheHits + cacheMisses) % 50 == 0)) { |
257 if (debug != null && Debug.isVerbose() && ((cacheHits + cacheMisses) % 50 == 0)) { |
264 System.out.println("Cache hits: " + cacheHits + "; misses: " |
258 debug.println("LDAPRequest Cache hits: " + cacheHits + |
265 + cacheMisses); |
259 "; misses: " + cacheMisses); |
266 } |
260 } |
267 String cacheKey = name + "|" + attrId; |
261 String cacheKey = name + "|" + attrId; |
268 byte[][] values = valueCache.get(cacheKey); |
262 byte[][] values = valueCache.get(cacheKey); |
269 if (values != null) { |
263 if (values != null) { |
270 cacheHits++; |
264 cacheHits++; |
292 */ |
286 */ |
293 private Map<String, byte[][]> getValueMap() throws NamingException { |
287 private Map<String, byte[][]> getValueMap() throws NamingException { |
294 if (valueMap != null) { |
288 if (valueMap != null) { |
295 return valueMap; |
289 return valueMap; |
296 } |
290 } |
297 if (DEBUG) { |
291 if (debug != null && Debug.isVerbose()) { |
298 System.out.println("Request: " + name + ":" + requestedAttributes); |
292 debug.println("LDAPRequest: " + name + ":" + requestedAttributes); |
299 requests++; |
293 requests++; |
300 if (requests % 5 == 0) { |
294 if (requests % 5 == 0) { |
301 System.out.println("LDAP requests: " + requests); |
295 debug.println("LDAP requests: " + requests); |
302 } |
296 } |
303 } |
297 } |
304 valueMap = new HashMap<>(8); |
298 valueMap = new HashMap<>(8); |
305 String[] attrIds = requestedAttributes.toArray(STRING0); |
299 String[] attrIds = requestedAttributes.toArray(STRING0); |
306 Attributes attrs; |
300 Attributes attrs; |