1 7 8 package javax.naming.ldap; 9 10 import java.util.Iterator ; 11 import java.security.AccessController ; 12 import java.security.PrivilegedAction ; 13 import javax.naming.ConfigurationException ; 14 import javax.naming.NamingException ; 15 import com.sun.naming.internal.VersionHelper; 16 import sun.misc.Service; 17 18 60 public class StartTlsRequest implements ExtendedRequest { 61 62 64 68 public static final String OID = "1.3.6.1.4.1.1466.20037"; 69 70 71 73 76 public StartTlsRequest() { 77 } 78 79 80 82 87 public String getID() { 88 return OID; 89 } 90 91 98 public byte[] getEncodedValue() { 99 return null; 100 } 101 102 152 public ExtendedResponse createExtendedResponse(String id, byte[] berValue, 153 int offset, int length) throws NamingException { 154 155 if ((id != null) && (!id.equals(OID))) { 157 throw new ConfigurationException ( 158 "Start TLS received the following response instead of " + 159 OID + ": " + id); 160 } 161 162 StartTlsResponse resp = null; 163 164 Iterator ps = Service.providers(StartTlsResponse .class, 165 getContextClassLoader()); 166 167 while (resp == null && privilegedHasNext(ps)) { 168 resp = (StartTlsResponse )ps.next(); 169 } 170 171 if (resp != null) { 172 return resp; 173 } 174 175 try { 176 VersionHelper helper = VersionHelper.getVersionHelper(); 177 Class clas = helper.loadClass( 178 "com.sun.jndi.ldap.ext.StartTlsResponseImpl"); 179 180 resp = (StartTlsResponse ) clas.newInstance(); 181 182 } catch (IllegalAccessException e) { 183 throw wrapException(e); 184 185 } catch (InstantiationException e) { 186 throw wrapException(e); 187 188 } catch (ClassNotFoundException e) { 189 throw wrapException(e); 190 } 191 192 return resp; 193 } 194 195 199 private ConfigurationException wrapException(Exception e) { 200 ConfigurationException ce = new ConfigurationException ( 201 "Cannot load implementation of javax.naming.ldap.StartTlsResponse"); 202 203 ce.setRootCause(e); 204 return ce; 205 } 206 207 210 private final ClassLoader getContextClassLoader() { 211 return (ClassLoader ) AccessController.doPrivileged( 212 new PrivilegedAction () { 213 public Object run() { 214 return Thread.currentThread().getContextClassLoader(); 215 } 216 } 217 ); 218 } 219 220 private final static boolean privilegedHasNext(final Iterator iter) { 221 Boolean answer = (Boolean ) AccessController.doPrivileged( 222 new PrivilegedAction () { 223 public Object run() { 224 return new Boolean (iter.hasNext()); 225 } 226 }); 227 return answer.booleanValue(); 228 } 229 230 private static final long serialVersionUID = 4441679576360753397L; 231 } 232 | Popular Tags |