Java Code Examples for java.security.PrivilegedActionException#printStackTrace()

The following examples show how to use java.security.PrivilegedActionException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NotesNativeAPI.java    From domino-jna with Apache License 2.0 6 votes vote down vote up
/**
 * Wraps the specified API object to dump caller stacktraces right before invoking
 * native methods
 * 
 * @param api API
 * @return wrapped API
 */
static <T> T wrapWithCrashStackLogging(final Class<T> apiClazz, final T api) {

	try {
		return AccessController.doPrivileged(new PrivilegedExceptionAction<T>() {

			@Override
			public T run() throws Exception {
				MethodInterceptor handler = new MethodInterceptorWithStacktraceLogging<T>(api);
				T wrapperWithStacktraceLogging = (T) Enhancer.create(apiClazz, handler);
				return wrapperWithStacktraceLogging;
			}
		});
	} catch (PrivilegedActionException e) {
		e.printStackTrace();
		return api;
	}
}
 
Example 2
Source File: SaslNettyClient.java    From herddb with Apache License 2.0 6 votes vote down vote up
public byte[] evaluateChallenge(final byte[] saslToken) throws SaslException {
    if (saslToken == null) {
        throw new SaslException("saslToken is null.");
    }

    if (clientSubject != null) {
        try {
            final byte[] retval =
                    Subject.doAs(clientSubject, new PrivilegedExceptionAction<byte[]>() {
                        public byte[] run() throws SaslException {
                            return saslClient.evaluateChallenge(saslToken);
                        }
                    });
            return retval;
        } catch (PrivilegedActionException e) {
            e.printStackTrace();
            throw new SaslException("SASL/JAAS error", e);
        }
    } else {
        return saslClient.evaluateChallenge(saslToken);
    }
}
 
Example 3
Source File: ExecutableInputMethodManager.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void initializeInputMethodLocatorList() {
    synchronized (javaInputMethodLocatorList) {
        javaInputMethodLocatorList.clear();
        try {
            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
                public Object run() {
                    for (InputMethodDescriptor descriptor :
                        ServiceLoader.loadInstalled(InputMethodDescriptor.class)) {
                        ClassLoader cl = descriptor.getClass().getClassLoader();
                        javaInputMethodLocatorList.add(new InputMethodLocator(descriptor, cl, null));
                    }
                    return null;
                }
            });
        }  catch (PrivilegedActionException e) {
            e.printStackTrace();
        }
        javaInputMethodCount = javaInputMethodLocatorList.size();
    }

    if (hasMultipleInputMethods()) {
        // initialize preferences
        if (userRoot == null) {
            userRoot = getUserRoot();
        }
    } else {
        // indicate to clients not to offer the menu
        triggerMenuString = null;
    }
}
 
Example 4
Source File: ExecutableInputMethodManager.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void initializeInputMethodLocatorList() {
    synchronized (javaInputMethodLocatorList) {
        javaInputMethodLocatorList.clear();
        try {
            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
                public Object run() {
                    for (InputMethodDescriptor descriptor :
                        ServiceLoader.loadInstalled(InputMethodDescriptor.class)) {
                        ClassLoader cl = descriptor.getClass().getClassLoader();
                        javaInputMethodLocatorList.add(new InputMethodLocator(descriptor, cl, null));
                    }
                    return null;
                }
            });
        }  catch (PrivilegedActionException e) {
            e.printStackTrace();
        }
        javaInputMethodCount = javaInputMethodLocatorList.size();
    }

    if (hasMultipleInputMethods()) {
        // initialize preferences
        if (userRoot == null) {
            userRoot = getUserRoot();
        }
    } else {
        // indicate to clients not to offer the menu
        triggerMenuString = null;
    }
}
 
Example 5
Source File: ExecutableInputMethodManager.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void initializeInputMethodLocatorList() {
    synchronized (javaInputMethodLocatorList) {
        javaInputMethodLocatorList.clear();
        try {
            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
                public Object run() {
                    for (InputMethodDescriptor descriptor :
                        ServiceLoader.load(InputMethodDescriptor.class,
                                           ClassLoader.getSystemClassLoader())) {
                        ClassLoader cl = descriptor.getClass().getClassLoader();
                        javaInputMethodLocatorList.add(new InputMethodLocator(descriptor, cl, null));
                    }
                    return null;
                }
            });
        }  catch (PrivilegedActionException e) {
            e.printStackTrace();
        }
        javaInputMethodCount = javaInputMethodLocatorList.size();
    }

    if (hasMultipleInputMethods()) {
        // initialize preferences
        if (userRoot == null) {
            userRoot = getUserRoot();
        }
    } else {
        // indicate to clients not to offer the menu
        triggerMenuString = null;
    }
}
 
Example 6
Source File: ExecutableInputMethodManager.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void initializeInputMethodLocatorList() {
    synchronized (javaInputMethodLocatorList) {
        javaInputMethodLocatorList.clear();
        try {
            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
                public Object run() {
                    for (InputMethodDescriptor descriptor :
                        ServiceLoader.loadInstalled(InputMethodDescriptor.class)) {
                        ClassLoader cl = descriptor.getClass().getClassLoader();
                        javaInputMethodLocatorList.add(new InputMethodLocator(descriptor, cl, null));
                    }
                    return null;
                }
            });
        }  catch (PrivilegedActionException e) {
            e.printStackTrace();
        }
        javaInputMethodCount = javaInputMethodLocatorList.size();
    }

    if (hasMultipleInputMethods()) {
        // initialize preferences
        if (userRoot == null) {
            userRoot = getUserRoot();
        }
    } else {
        // indicate to clients not to offer the menu
        triggerMenuString = null;
    }
}
 
Example 7
Source File: ExecutableInputMethodManager.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void initializeInputMethodLocatorList() {
    synchronized (javaInputMethodLocatorList) {
        javaInputMethodLocatorList.clear();
        try {
            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
                public Object run() {
                    for (InputMethodDescriptor descriptor :
                        ServiceLoader.loadInstalled(InputMethodDescriptor.class)) {
                        ClassLoader cl = descriptor.getClass().getClassLoader();
                        javaInputMethodLocatorList.add(new InputMethodLocator(descriptor, cl, null));
                    }
                    return null;
                }
            });
        }  catch (PrivilegedActionException e) {
            e.printStackTrace();
        }
        javaInputMethodCount = javaInputMethodLocatorList.size();
    }

    if (hasMultipleInputMethods()) {
        // initialize preferences
        if (userRoot == null) {
            userRoot = getUserRoot();
        }
    } else {
        // indicate to clients not to offer the menu
        triggerMenuString = null;
    }
}
 
Example 8
Source File: ExecutableInputMethodManager.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void initializeInputMethodLocatorList() {
    synchronized (javaInputMethodLocatorList) {
        javaInputMethodLocatorList.clear();
        try {
            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
                public Object run() {
                    for (InputMethodDescriptor descriptor :
                        ServiceLoader.loadInstalled(InputMethodDescriptor.class)) {
                        ClassLoader cl = descriptor.getClass().getClassLoader();
                        javaInputMethodLocatorList.add(new InputMethodLocator(descriptor, cl, null));
                    }
                    return null;
                }
            });
        }  catch (PrivilegedActionException e) {
            e.printStackTrace();
        }
        javaInputMethodCount = javaInputMethodLocatorList.size();
    }

    if (hasMultipleInputMethods()) {
        // initialize preferences
        if (userRoot == null) {
            userRoot = getUserRoot();
        }
    } else {
        // indicate to clients not to offer the menu
        triggerMenuString = null;
    }
}
 
Example 9
Source File: JAXBWrapperAccessor.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
static protected Field[] getDeclaredFields(final Class<?> clz) {
    try {
        return (System.getSecurityManager() == null) ? clz .getDeclaredFields() :
            AccessController.doPrivileged(new PrivilegedExceptionAction<Field[]>() {
                    @Override
                    public Field[] run() throws IllegalAccessException {
                        return clz.getDeclaredFields();
                    }
                });
    } catch (PrivilegedActionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    }
}
 
Example 10
Source File: ExecutableInputMethodManager.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void initializeInputMethodLocatorList() {
    synchronized (javaInputMethodLocatorList) {
        javaInputMethodLocatorList.clear();
        try {
            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
                public Object run() {
                    for (InputMethodDescriptor descriptor :
                        ServiceLoader.loadInstalled(InputMethodDescriptor.class)) {
                        ClassLoader cl = descriptor.getClass().getClassLoader();
                        javaInputMethodLocatorList.add(new InputMethodLocator(descriptor, cl, null));
                    }
                    return null;
                }
            });
        }  catch (PrivilegedActionException e) {
            e.printStackTrace();
        }
        javaInputMethodCount = javaInputMethodLocatorList.size();
    }

    if (hasMultipleInputMethods()) {
        // initialize preferences
        if (userRoot == null) {
            userRoot = getUserRoot();
        }
    } else {
        // indicate to clients not to offer the menu
        triggerMenuString = null;
    }
}
 
Example 11
Source File: JAXBWrapperAccessor.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
static protected Field[] getDeclaredFields(final Class<?> clz) {
    try {
        return (System.getSecurityManager() == null) ? clz .getDeclaredFields() :
            AccessController.doPrivileged(new PrivilegedExceptionAction<Field[]>() {
                    @Override
                    public Field[] run() throws IllegalAccessException {
                        return clz.getDeclaredFields();
                    }
                });
    } catch (PrivilegedActionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    }
}
 
Example 12
Source File: JAXBWrapperAccessor.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
static protected Field[] getDeclaredFields(final Class<?> clz) {
    try {
        return (System.getSecurityManager() == null) ? clz .getDeclaredFields() :
            AccessController.doPrivileged(new PrivilegedExceptionAction<Field[]>() {
                    @Override
                    public Field[] run() throws IllegalAccessException {
                        return clz.getDeclaredFields();
                    }
                });
    } catch (PrivilegedActionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    }
}
 
Example 13
Source File: ExecutableInputMethodManager.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void initializeInputMethodLocatorList() {
    synchronized (javaInputMethodLocatorList) {
        javaInputMethodLocatorList.clear();
        try {
            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
                public Object run() {
                    for (InputMethodDescriptor descriptor :
                        ServiceLoader.loadInstalled(InputMethodDescriptor.class)) {
                        ClassLoader cl = descriptor.getClass().getClassLoader();
                        javaInputMethodLocatorList.add(new InputMethodLocator(descriptor, cl, null));
                    }
                    return null;
                }
            });
        }  catch (PrivilegedActionException e) {
            e.printStackTrace();
        }
        javaInputMethodCount = javaInputMethodLocatorList.size();
    }

    if (hasMultipleInputMethods()) {
        // initialize preferences
        if (userRoot == null) {
            userRoot = getUserRoot();
        }
    } else {
        // indicate to clients not to offer the menu
        triggerMenuString = null;
    }
}
 
Example 14
Source File: GSSUtil.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Searches the private credentials of current Subject with the
 * specified criteria and returns the matching GSSCredentialSpi
 * object out of Sun's impl of GSSCredential. Returns null if
 * no Subject present or a Vector which contains 0 or more
 * matching GSSCredentialSpi objects.
 */
public static <T extends GSSCredentialSpi> Vector<T>
        searchSubject(final GSSNameSpi name,
                      final Oid mech,
                      final boolean initiate,
                      final Class<? extends T> credCls) {
    debug("Search Subject for " + getMechStr(mech) +
          (initiate? " INIT" : " ACCEPT") + " cred (" +
          (name == null? "<<DEF>>" : name.toString()) + ", " +
          credCls.getName() + ")");
    final AccessControlContext acc = AccessController.getContext();
    try {
        Vector<T> creds =
            AccessController.doPrivileged
            (new PrivilegedExceptionAction<Vector<T>>() {
                public Vector<T> run() throws Exception {
                    Subject accSubj = Subject.getSubject(acc);
                    Vector<T> result = null;
                    if (accSubj != null) {
                        result = new Vector<T>();
                        Iterator<GSSCredentialImpl> iterator =
                            accSubj.getPrivateCredentials
                            (GSSCredentialImpl.class).iterator();
                        while (iterator.hasNext()) {
                            GSSCredentialImpl cred = iterator.next();
                            debug("...Found cred" + cred);
                            try {
                                GSSCredentialSpi ce =
                                    cred.getElement(mech, initiate);
                                debug("......Found element: " + ce);
                                if (ce.getClass().equals(credCls) &&
                                    (name == null ||
                                     name.equals((Object) ce.getName()))) {
                                    result.add(credCls.cast(ce));
                                } else {
                                    debug("......Discard element");
                                }
                            } catch (GSSException ge) {
                                debug("...Discard cred (" + ge + ")");
                            }
                        }
                    } else debug("No Subject");
                    return result;
                }
            });
        return creds;
    } catch (PrivilegedActionException pae) {
        debug("Unexpected exception when searching Subject:");
        if (DEBUG) pae.printStackTrace();
        return null;
    }
}
 
Example 15
Source File: GSSUtil.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Searches the private credentials of current Subject with the
 * specified criteria and returns the matching GSSCredentialSpi
 * object out of Sun's impl of GSSCredential. Returns null if
 * no Subject present or a Vector which contains 0 or more
 * matching GSSCredentialSpi objects.
 */
public static <T extends GSSCredentialSpi> Vector<T>
        searchSubject(final GSSNameSpi name,
                      final Oid mech,
                      final boolean initiate,
                      final Class<? extends T> credCls) {
    debug("Search Subject for " + getMechStr(mech) +
          (initiate? " INIT" : " ACCEPT") + " cred (" +
          (name == null? "<<DEF>>" : name.toString()) + ", " +
          credCls.getName() + ")");
    final AccessControlContext acc = AccessController.getContext();
    try {
        Vector<T> creds =
            AccessController.doPrivileged
            (new PrivilegedExceptionAction<Vector<T>>() {
                public Vector<T> run() throws Exception {
                    Subject accSubj = Subject.getSubject(acc);
                    Vector<T> result = null;
                    if (accSubj != null) {
                        result = new Vector<T>();
                        Iterator<GSSCredentialImpl> iterator =
                            accSubj.getPrivateCredentials
                            (GSSCredentialImpl.class).iterator();
                        while (iterator.hasNext()) {
                            GSSCredentialImpl cred = iterator.next();
                            debug("...Found cred" + cred);
                            try {
                                GSSCredentialSpi ce =
                                    cred.getElement(mech, initiate);
                                debug("......Found element: " + ce);
                                if (ce.getClass().equals(credCls) &&
                                    (name == null ||
                                     name.equals((Object) ce.getName()))) {
                                    result.add(credCls.cast(ce));
                                } else {
                                    debug("......Discard element");
                                }
                            } catch (GSSException ge) {
                                debug("...Discard cred (" + ge + ")");
                            }
                        }
                    } else debug("No Subject");
                    return result;
                }
            });
        return creds;
    } catch (PrivilegedActionException pae) {
        debug("Unexpected exception when searching Subject:");
        if (DEBUG) pae.printStackTrace();
        return null;
    }
}
 
Example 16
Source File: GSSUtil.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Searches the private credentials of current Subject with the
 * specified criteria and returns the matching GSSCredentialSpi
 * object out of Sun's impl of GSSCredential. Returns null if
 * no Subject present or a Vector which contains 0 or more
 * matching GSSCredentialSpi objects.
 */
public static <T extends GSSCredentialSpi> Vector<T>
        searchSubject(final GSSNameSpi name,
                      final Oid mech,
                      final boolean initiate,
                      final Class<? extends T> credCls) {
    debug("Search Subject for " + getMechStr(mech) +
          (initiate? " INIT" : " ACCEPT") + " cred (" +
          (name == null? "<<DEF>>" : name.toString()) + ", " +
          credCls.getName() + ")");
    final AccessControlContext acc = AccessController.getContext();
    try {
        Vector<T> creds =
            AccessController.doPrivileged
            (new PrivilegedExceptionAction<Vector<T>>() {
                public Vector<T> run() throws Exception {
                    Subject accSubj = Subject.getSubject(acc);
                    Vector<T> result = null;
                    if (accSubj != null) {
                        result = new Vector<T>();
                        Iterator<GSSCredentialImpl> iterator =
                            accSubj.getPrivateCredentials
                            (GSSCredentialImpl.class).iterator();
                        while (iterator.hasNext()) {
                            GSSCredentialImpl cred = iterator.next();
                            debug("...Found cred" + cred);
                            try {
                                GSSCredentialSpi ce =
                                    cred.getElement(mech, initiate);
                                debug("......Found element: " + ce);
                                if (ce.getClass().equals(credCls) &&
                                    (name == null ||
                                     name.equals((Object) ce.getName()))) {
                                    result.add(credCls.cast(ce));
                                } else {
                                    debug("......Discard element");
                                }
                            } catch (GSSException ge) {
                                debug("...Discard cred (" + ge + ")");
                            }
                        }
                    } else debug("No Subject");
                    return result;
                }
            });
        return creds;
    } catch (PrivilegedActionException pae) {
        debug("Unexpected exception when searching Subject:");
        if (DEBUG) pae.printStackTrace();
        return null;
    }
}
 
Example 17
Source File: GSSUtil.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Searches the private credentials of current Subject with the
 * specified criteria and returns the matching GSSCredentialSpi
 * object out of Sun's impl of GSSCredential. Returns null if
 * no Subject present or a Vector which contains 0 or more
 * matching GSSCredentialSpi objects.
 */
public static <T extends GSSCredentialSpi> Vector<T>
        searchSubject(final GSSNameSpi name,
                      final Oid mech,
                      final boolean initiate,
                      final Class<? extends T> credCls) {
    debug("Search Subject for " + getMechStr(mech) +
          (initiate? " INIT" : " ACCEPT") + " cred (" +
          (name == null? "<<DEF>>" : name.toString()) + ", " +
          credCls.getName() + ")");
    final AccessControlContext acc = AccessController.getContext();
    try {
        Vector<T> creds =
            AccessController.doPrivileged
            (new PrivilegedExceptionAction<Vector<T>>() {
                public Vector<T> run() throws Exception {
                    Subject accSubj = Subject.getSubject(acc);
                    Vector<T> result = null;
                    if (accSubj != null) {
                        result = new Vector<T>();
                        Iterator<GSSCredentialImpl> iterator =
                            accSubj.getPrivateCredentials
                            (GSSCredentialImpl.class).iterator();
                        while (iterator.hasNext()) {
                            GSSCredentialImpl cred = iterator.next();
                            debug("...Found cred" + cred);
                            try {
                                GSSCredentialSpi ce =
                                    cred.getElement(mech, initiate);
                                debug("......Found element: " + ce);
                                if (ce.getClass().equals(credCls) &&
                                    (name == null ||
                                     name.equals((Object) ce.getName()))) {
                                    result.add(credCls.cast(ce));
                                } else {
                                    debug("......Discard element");
                                }
                            } catch (GSSException ge) {
                                debug("...Discard cred (" + ge + ")");
                            }
                        }
                    } else debug("No Subject");
                    return result;
                }
            });
        return creds;
    } catch (PrivilegedActionException pae) {
        debug("Unexpected exception when searching Subject:");
        if (DEBUG) pae.printStackTrace();
        return null;
    }
}
 
Example 18
Source File: GSSUtil.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Searches the private credentials of current Subject with the
 * specified criteria and returns the matching GSSCredentialSpi
 * object out of Sun's impl of GSSCredential. Returns null if
 * no Subject present or a Vector which contains 0 or more
 * matching GSSCredentialSpi objects.
 */
public static <T extends GSSCredentialSpi> Vector<T>
        searchSubject(final GSSNameSpi name,
                      final Oid mech,
                      final boolean initiate,
                      final Class<? extends T> credCls) {
    debug("Search Subject for " + getMechStr(mech) +
          (initiate? " INIT" : " ACCEPT") + " cred (" +
          (name == null? "<<DEF>>" : name.toString()) + ", " +
          credCls.getName() + ")");
    final AccessControlContext acc = AccessController.getContext();
    try {
        Vector<T> creds =
            AccessController.doPrivileged
            (new PrivilegedExceptionAction<Vector<T>>() {
                public Vector<T> run() throws Exception {
                    Subject accSubj = Subject.getSubject(acc);
                    Vector<T> result = null;
                    if (accSubj != null) {
                        result = new Vector<T>();
                        Iterator<GSSCredentialImpl> iterator =
                            accSubj.getPrivateCredentials
                            (GSSCredentialImpl.class).iterator();
                        while (iterator.hasNext()) {
                            GSSCredentialImpl cred = iterator.next();
                            debug("...Found cred" + cred);
                            try {
                                GSSCredentialSpi ce =
                                    cred.getElement(mech, initiate);
                                debug("......Found element: " + ce);
                                if (ce.getClass().equals(credCls) &&
                                    (name == null ||
                                     name.equals((Object) ce.getName()))) {
                                    result.add(credCls.cast(ce));
                                } else {
                                    debug("......Discard element");
                                }
                            } catch (GSSException ge) {
                                debug("...Discard cred (" + ge + ")");
                            }
                        }
                    } else debug("No Subject");
                    return result;
                }
            });
        return creds;
    } catch (PrivilegedActionException pae) {
        debug("Unexpected exception when searching Subject:");
        if (DEBUG) pae.printStackTrace();
        return null;
    }
}
 
Example 19
Source File: GSSUtil.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Searches the private credentials of current Subject with the
 * specified criteria and returns the matching GSSCredentialSpi
 * object out of Sun's impl of GSSCredential. Returns null if
 * no Subject present or a Vector which contains 0 or more
 * matching GSSCredentialSpi objects.
 */
public static <T extends GSSCredentialSpi> Vector<T>
        searchSubject(final GSSNameSpi name,
                      final Oid mech,
                      final boolean initiate,
                      final Class<? extends T> credCls) {
    debug("Search Subject for " + getMechStr(mech) +
          (initiate? " INIT" : " ACCEPT") + " cred (" +
          (name == null? "<<DEF>>" : name.toString()) + ", " +
          credCls.getName() + ")");
    final AccessControlContext acc = AccessController.getContext();
    try {
        Vector<T> creds =
            AccessController.doPrivileged
            (new PrivilegedExceptionAction<Vector<T>>() {
                public Vector<T> run() throws Exception {
                    Subject accSubj = Subject.getSubject(acc);
                    Vector<T> result = null;
                    if (accSubj != null) {
                        result = new Vector<T>();
                        Iterator<GSSCredentialImpl> iterator =
                            accSubj.getPrivateCredentials
                            (GSSCredentialImpl.class).iterator();
                        while (iterator.hasNext()) {
                            GSSCredentialImpl cred = iterator.next();
                            debug("...Found cred" + cred);
                            try {
                                GSSCredentialSpi ce =
                                    cred.getElement(mech, initiate);
                                debug("......Found element: " + ce);
                                if (ce.getClass().equals(credCls) &&
                                    (name == null ||
                                     name.equals((Object) ce.getName()))) {
                                    result.add(credCls.cast(ce));
                                } else {
                                    debug("......Discard element");
                                }
                            } catch (GSSException ge) {
                                debug("...Discard cred (" + ge + ")");
                            }
                        }
                    } else debug("No Subject");
                    return result;
                }
            });
        return creds;
    } catch (PrivilegedActionException pae) {
        debug("Unexpected exception when searching Subject:");
        if (DEBUG) pae.printStackTrace();
        return null;
    }
}
 
Example 20
Source File: GSSUtil.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Searches the private credentials of current Subject with the
 * specified criteria and returns the matching GSSCredentialSpi
 * object out of Sun's impl of GSSCredential. Returns null if
 * no Subject present or a Vector which contains 0 or more
 * matching GSSCredentialSpi objects.
 */
public static <T extends GSSCredentialSpi> Vector<T>
        searchSubject(final GSSNameSpi name,
                      final Oid mech,
                      final boolean initiate,
                      final Class<? extends T> credCls) {
    debug("Search Subject for " + getMechStr(mech) +
          (initiate? " INIT" : " ACCEPT") + " cred (" +
          (name == null? "<<DEF>>" : name.toString()) + ", " +
          credCls.getName() + ")");
    final AccessControlContext acc = AccessController.getContext();
    try {
        Vector<T> creds =
            AccessController.doPrivileged
            (new PrivilegedExceptionAction<Vector<T>>() {
                public Vector<T> run() throws Exception {
                    Subject accSubj = Subject.getSubject(acc);
                    Vector<T> result = null;
                    if (accSubj != null) {
                        result = new Vector<T>();
                        Iterator<GSSCredentialImpl> iterator =
                            accSubj.getPrivateCredentials
                            (GSSCredentialImpl.class).iterator();
                        while (iterator.hasNext()) {
                            GSSCredentialImpl cred = iterator.next();
                            debug("...Found cred" + cred);
                            try {
                                GSSCredentialSpi ce =
                                    cred.getElement(mech, initiate);
                                debug("......Found element: " + ce);
                                if (ce.getClass().equals(credCls) &&
                                    (name == null ||
                                     name.equals((Object) ce.getName()))) {
                                    result.add(credCls.cast(ce));
                                } else {
                                    debug("......Discard element");
                                }
                            } catch (GSSException ge) {
                                debug("...Discard cred (" + ge + ")");
                            }
                        }
                    } else debug("No Subject");
                    return result;
                }
            });
        return creds;
    } catch (PrivilegedActionException pae) {
        debug("Unexpected exception when searching Subject:");
        if (DEBUG) pae.printStackTrace();
        return null;
    }
}