< prev index next >

src/java.base/share/classes/javax/security/auth/login/LoginContext.java

Print this page




 287         });
 288     }
 289 
 290     private void loadDefaultCallbackHandler() throws LoginException {
 291 
 292         // get the default handler class
 293         try {
 294 
 295             final ClassLoader finalLoader = contextClassLoader;
 296 
 297             this.callbackHandler = java.security.AccessController.doPrivileged(
 298                 new java.security.PrivilegedExceptionAction<CallbackHandler>() {
 299                 public CallbackHandler run() throws Exception {
 300                     String defaultHandler = java.security.Security.getProperty
 301                         (DEFAULT_HANDLER);
 302                     if (defaultHandler == null || defaultHandler.length() == 0)
 303                         return null;
 304                     Class<? extends CallbackHandler> c = Class.forName(
 305                             defaultHandler, true,
 306                             finalLoader).asSubclass(CallbackHandler.class);
 307                     return c.newInstance();


 308                 }
 309             });
 310         } catch (java.security.PrivilegedActionException pae) {
 311             throw new LoginException(pae.getException().toString());
 312         }
 313 
 314         // secure it with the caller's ACC
 315         if (this.callbackHandler != null && creatorAcc == null) {
 316             this.callbackHandler = new SecureCallbackHandler
 317                                 (java.security.AccessController.getContext(),
 318                                 this.callbackHandler);
 319         }
 320     }
 321 
 322     /**
 323      * Instantiate a new {@code LoginContext} object with a name.
 324      *
 325      * @param name the name used as the index into the
 326      *          {@code Configuration}.
 327      *


 680 
 681                     // locate and instantiate the LoginModule
 682                     //
 683                     String name = moduleStack[i].entry.getLoginModuleName();
 684                     ServiceLoader<LoginModule> sc = AccessController.doPrivileged(
 685                             (PrivilegedAction<ServiceLoader<LoginModule>>)
 686                                     () -> ServiceLoader.load(
 687                                         LoginModule.class, contextClassLoader));
 688                     for (LoginModule m: sc) {
 689                         if (m.getClass().getName().equals(name)) {
 690                             moduleStack[i].module = m;
 691                             if (debug != null) {
 692                                 debug.println(name + " loaded as a service");
 693                             }
 694                             break;
 695                         }
 696                     }
 697 
 698                     if (moduleStack[i].module == null) {
 699                         try {
 700                             moduleStack[i].module = (LoginModule) Class.forName(
 701                                     name, false, contextClassLoader).newInstance();

 702                             if (debug != null) {
 703                                 debug.println(name + " loaded via reflection");
 704                             }
 705                         } catch (ClassNotFoundException e) {
 706                             throw new LoginException("No LoginModule found for "
 707                                     + name);
 708                         }
 709                     }
 710 
 711                     // invoke the LoginModule initialize method
 712                     moduleStack[i].module.initialize(subject,
 713                             callbackHandler,
 714                             state,
 715                             moduleStack[i].entry.getOptions());
 716                 }
 717 
 718                 // find the requested method in the LoginModule
 719                 boolean status;
 720                 switch (methodName) {
 721                     case LOGIN_METHOD:




 287         });
 288     }
 289 
 290     private void loadDefaultCallbackHandler() throws LoginException {
 291 
 292         // get the default handler class
 293         try {
 294 
 295             final ClassLoader finalLoader = contextClassLoader;
 296 
 297             this.callbackHandler = java.security.AccessController.doPrivileged(
 298                 new java.security.PrivilegedExceptionAction<CallbackHandler>() {
 299                 public CallbackHandler run() throws Exception {
 300                     String defaultHandler = java.security.Security.getProperty
 301                         (DEFAULT_HANDLER);
 302                     if (defaultHandler == null || defaultHandler.length() == 0)
 303                         return null;
 304                     Class<? extends CallbackHandler> c = Class.forName(
 305                             defaultHandler, true,
 306                             finalLoader).asSubclass(CallbackHandler.class);
 307                     @SuppressWarnings("deprecation")
 308                     CallbackHandler result = c.newInstance();
 309                     return result;
 310                 }
 311             });
 312         } catch (java.security.PrivilegedActionException pae) {
 313             throw new LoginException(pae.getException().toString());
 314         }
 315 
 316         // secure it with the caller's ACC
 317         if (this.callbackHandler != null && creatorAcc == null) {
 318             this.callbackHandler = new SecureCallbackHandler
 319                                 (java.security.AccessController.getContext(),
 320                                 this.callbackHandler);
 321         }
 322     }
 323 
 324     /**
 325      * Instantiate a new {@code LoginContext} object with a name.
 326      *
 327      * @param name the name used as the index into the
 328      *          {@code Configuration}.
 329      *


 682 
 683                     // locate and instantiate the LoginModule
 684                     //
 685                     String name = moduleStack[i].entry.getLoginModuleName();
 686                     ServiceLoader<LoginModule> sc = AccessController.doPrivileged(
 687                             (PrivilegedAction<ServiceLoader<LoginModule>>)
 688                                     () -> ServiceLoader.load(
 689                                         LoginModule.class, contextClassLoader));
 690                     for (LoginModule m: sc) {
 691                         if (m.getClass().getName().equals(name)) {
 692                             moduleStack[i].module = m;
 693                             if (debug != null) {
 694                                 debug.println(name + " loaded as a service");
 695                             }
 696                             break;
 697                         }
 698                     }
 699 
 700                     if (moduleStack[i].module == null) {
 701                         try {
 702                             @SuppressWarnings("deprecation")
 703                             Object tmp = Class.forName(name, false, contextClassLoader).newInstance();
 704                             moduleStack[i].module = (LoginModule) tmp;
 705                             if (debug != null) {
 706                                 debug.println(name + " loaded via reflection");
 707                             }
 708                         } catch (ClassNotFoundException e) {
 709                             throw new LoginException("No LoginModule found for "
 710                                     + name);
 711                         }
 712                     }
 713 
 714                     // invoke the LoginModule initialize method
 715                     moduleStack[i].module.initialize(subject,
 716                             callbackHandler,
 717                             state,
 718                             moduleStack[i].entry.getOptions());
 719                 }
 720 
 721                 // find the requested method in the LoginModule
 722                 boolean status;
 723                 switch (methodName) {
 724                     case LOGIN_METHOD:


< prev index next >