Example #1
0
  private void loadDefaultCallbackHandler() throws LoginException {

    // get the default handler class
    try {

      final ClassLoader finalLoader = contextClassLoader;

      this.callbackHandler =
          java.security.AccessController.doPrivileged(
              new java.security.PrivilegedExceptionAction<CallbackHandler>() {
                public CallbackHandler run() throws Exception {
                  String defaultHandler = java.security.Security.getProperty(DEFAULT_HANDLER);
                  if (defaultHandler == null || defaultHandler.length() == 0) return null;
                  Class<? extends CallbackHandler> c =
                      Class.forName(defaultHandler, true, finalLoader)
                          .asSubclass(CallbackHandler.class);
                  return c.newInstance();
                }
              });
    } catch (java.security.PrivilegedActionException pae) {
      throw new LoginException(pae.getException().toString());
    }

    // secure it with the caller's ACC
    if (this.callbackHandler != null && creatorAcc == null) {
      this.callbackHandler =
          new SecureCallbackHandler(
              java.security.AccessController.getContext(), this.callbackHandler);
    }
  }
Example #2
0
 /**
  * Invokes the login, commit, and logout methods from a LoginModule inside a doPrivileged block
  * restricted by creatorAcc (may be null).
  *
  * <p>This version is called if the caller did not instantiate the LoginContext with a
  * Configuration object.
  */
 private void invokePriv(final String methodName) throws LoginException {
   try {
     java.security.AccessController.doPrivileged(
         new java.security.PrivilegedExceptionAction<Void>() {
           public Void run() throws LoginException {
             invoke(methodName);
             return null;
           }
         },
         creatorAcc);
   } catch (java.security.PrivilegedActionException pae) {
     throw (LoginException) pae.getException();
   }
 }
Example #3
0
 public void handle(final Callback[] callbacks)
     throws java.io.IOException, UnsupportedCallbackException {
   try {
     java.security.AccessController.doPrivileged(
         new java.security.PrivilegedExceptionAction<Void>() {
           public Void run() throws java.io.IOException, UnsupportedCallbackException {
             ch.handle(callbacks);
             return null;
           }
         },
         acc);
   } catch (java.security.PrivilegedActionException pae) {
     if (pae.getException() instanceof java.io.IOException) {
       throw (java.io.IOException) pae.getException();
     } else {
       throw (UnsupportedCallbackException) pae.getException();
     }
   }
 }