Example usage for java.security PrivilegedActionException getException

List of usage examples for java.security PrivilegedActionException getException

Introduction

In this page you can find the example usage for java.security PrivilegedActionException getException.

Prototype

public Exception getException() 

Source Link

Document

Returns the exception thrown by the privileged computation that resulted in this PrivilegedActionException .

Usage

From source file:org.apache.axiom.om.util.StAXUtils.java

public static XMLStreamWriter createXMLStreamWriter(StAXWriterConfiguration configuration,
        final OutputStream out) throws XMLStreamException {
    final XMLOutputFactory outputFactory = getXMLOutputFactory(configuration);
    try {/* w  ww .  j a v  a  2s. co m*/
        XMLStreamWriter writer = (XMLStreamWriter) AccessController
                .doPrivileged(new PrivilegedExceptionAction() {
                    public Object run() throws XMLStreamException {
                        return outputFactory.createXMLStreamWriter(out, OMConstants.DEFAULT_CHAR_SET_ENCODING);
                    }
                });

        if (isDebugEnabled) {
            log.debug("XMLStreamWriter is " + writer.getClass().getName());
        }
        return writer;
    } catch (PrivilegedActionException pae) {
        throw (XMLStreamException) pae.getException();
    }
}

From source file:org.apache.axiom.om.util.StAXUtils.java

public static XMLStreamWriter createXMLStreamWriter(StAXWriterConfiguration configuration,
        final OutputStream out, final String encoding) throws XMLStreamException {
    final XMLOutputFactory outputFactory = getXMLOutputFactory(configuration);
    try {//  ww  w.ja va  2 s .com
        XMLStreamWriter writer = (XMLStreamWriter) AccessController
                .doPrivileged(new PrivilegedExceptionAction() {
                    public Object run() throws XMLStreamException {
                        return outputFactory.createXMLStreamWriter(out, encoding);
                    }
                });

        if (isDebugEnabled) {
            log.debug("XMLStreamWriter is " + writer.getClass().getName());
        }
        return writer;
    } catch (PrivilegedActionException pae) {
        throw (XMLStreamException) pae.getException();
    }
}

From source file:org.apache.axiom.om.util.StAXUtils.java

public static XMLStreamReader createXMLStreamReader(StAXParserConfiguration configuration, final InputStream in)
        throws XMLStreamException {

    final XMLInputFactory inputFactory = getXMLInputFactory(configuration);
    try {//from   w  ww .j a v  a 2  s  .c  om
        XMLStreamReader reader = (XMLStreamReader) AccessController
                .doPrivileged(new PrivilegedExceptionAction() {
                    public Object run() throws XMLStreamException {
                        return inputFactory.createXMLStreamReader(in);
                    }
                });

        if (isDebugEnabled) {
            log.debug("XMLStreamReader is " + reader.getClass().getName());
        }
        return reader;
    } catch (PrivilegedActionException pae) {
        throw (XMLStreamException) pae.getException();
    }
}

From source file:org.apache.axis2.jaxws.runtime.description.marshal.impl.AnnotationBuilder.java

/**
 * Return the class for this name/*from   w  ww .  j a va2 s  .co m*/
 *
 * @return Class
 */
static Class forName(final String className, final boolean initialize, final ClassLoader classloader)
        throws ClassNotFoundException {
    // NOTE: This method must remain protected because it uses AccessController
    Class cl = null;
    try {
        cl = (Class) AccessController.doPrivileged(new PrivilegedExceptionAction() {
            public Object run() throws ClassNotFoundException {
                // Class.forName does not support primitives
                Class cls = ClassUtils.getPrimitiveClass(className);
                if (cls == null) {
                    cls = Class.forName(className, initialize, classloader);
                }
                return cls;
            }
        });
    } catch (PrivilegedActionException e) {
        /* An exception should NOT be logged.  Depending on the JAXWS scenario, certain classes 
         * may or may not exist.  Putting an exception in the log will confuse programmers who
         * are servicing the product
         * 
                 
        if (log.isDebugEnabled()) {
        log.debug("Exception thrown from AccessController: " + e);
        }
        */
        throw (ClassNotFoundException) e.getException();
    }

    return cl;
}

From source file:org.apache.axis2.jaxws.server.EndpointController.java

/**
 * Return the class for this name/*w  w  w  . ja  v  a 2 s .c om*/
 *
 * @return Class
 */
private static Class forName(final String className, final boolean initialize, final ClassLoader classloader)
        throws ClassNotFoundException {
    // NOTE: This method must remain private because it uses AccessController
    Class cl = null;
    try {
        cl = (Class) AccessController.doPrivileged(new PrivilegedExceptionAction() {
            public Object run() throws ClassNotFoundException {
                return Class.forName(className, initialize, classloader);
            }
        });
    } catch (PrivilegedActionException e) {
        if (log.isDebugEnabled()) {
            log.debug("PrivilegedActionException thrown from AccessController: " + e);
            log.debug("Real Cause is " + e.getException().getCause());
        }
        throw (ClassNotFoundException) e.getException();
    }

    return cl;
}

From source file:org.apache.axis2.jaxws.runtime.description.marshal.impl.ArtifactProcessor.java

/** @return ClassLoader */
private static ClassLoader getContextClassLoader() {
    // NOTE: This method must remain private because it uses AccessController
    ClassLoader cl = null;/*from  www  . j a v a2  s.c o m*/
    try {
        cl = (ClassLoader) AccessController.doPrivileged(new PrivilegedExceptionAction() {
            public Object run() throws ClassNotFoundException {
                return Thread.currentThread().getContextClassLoader();
            }
        });
    } catch (PrivilegedActionException e) {
        if (log.isDebugEnabled()) {
            log.debug("Exception thrown from AccessController: " + e);
        }
        throw (RuntimeException) e.getException();
    }

    return cl;
}

From source file:org.apache.struts2.jasper.runtime.PageContextImpl.java

/**
 * Proprietary method to evaluate EL expressions.
 * XXX - This method should go away once the EL interpreter moves
 * out of JSTL and into its own project.  For now, this is necessary
 * because the standard machinery is too slow.
 *
 * @param expression   The expression to be evaluated
 * @param expectedType The expected resulting type
 * @param pageContext  The page context//  w w  w .j  a v a  2  s.  c  om
 * @param functionMap  Maps prefix and name to Method
 * @return The result of the evaluation
 */
public static Object proprietaryEvaluate(final String expression, final Class expectedType,
        final PageContext pageContext, final ProtectedFunctionMapper functionMap, final boolean escape)
        throws ELException {
    Object retValue;
    if (SecurityUtil.isPackageProtectionEnabled()) {
        try {
            retValue = AccessController.doPrivileged(new PrivilegedExceptionAction() {

                public Object run() throws Exception {
                    return elExprEval.evaluate(expression, expectedType, pageContext.getVariableResolver(),
                            functionMap);
                }
            });
        } catch (PrivilegedActionException ex) {
            Exception realEx = ex.getException();
            if (realEx instanceof ELException) {
                throw (ELException) realEx;
            } else {
                throw new ELException(realEx);
            }
        }
    } else {
        retValue = elExprEval.evaluate(expression, expectedType, pageContext.getVariableResolver(),
                functionMap);
    }
    if (escape) {
        retValue = XmlEscape(retValue.toString());
    }

    return retValue;
}

From source file:org.apache.hadoop.security.token.delegation.web.TestWebDelegationToken.java

public static <T> T doAsKerberosUser(String principal, String keytab, final Callable<T> callable)
        throws Exception {
    LoginContext loginContext = null;
    try {/*w w w .java2  s . co  m*/
        Set<Principal> principals = new HashSet<Principal>();
        principals.add(new KerberosPrincipal(principal));
        Subject subject = new Subject(false, principals, new HashSet<Object>(), new HashSet<Object>());
        loginContext = new LoginContext("", subject, null, new KerberosConfiguration(principal, keytab));
        loginContext.login();
        subject = loginContext.getSubject();
        return Subject.doAs(subject, new PrivilegedExceptionAction<T>() {
            @Override
            public T run() throws Exception {
                return callable.call();
            }
        });
    } catch (PrivilegedActionException ex) {
        throw ex.getException();
    } finally {
        if (loginContext != null) {
            loginContext.logout();
        }
    }
}

From source file:org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.java

private static ClassLoader getContextClassLoader() {
    // NOTE: This method must remain private because it uses AccessController
    ClassLoader cl = null;//from   w w w . j  a v  a  2  s.  c o m
    try {
        cl = (ClassLoader) AccessController.doPrivileged(new PrivilegedExceptionAction() {
            public Object run() throws ClassNotFoundException {
                return Thread.currentThread().getContextClassLoader();
            }
        });
    } catch (PrivilegedActionException e) {
        if (log.isDebugEnabled()) {
            log.debug("Exception thrown from AccessController: " + e);
        }
        throw ExceptionFactory.makeWebServiceException(e.getException());
    }

    return cl;
}

From source file:org.apache.jasper.runtime.PageContextImpl.java

/**
 * Proprietary method to evaluate EL expressions.
 * XXX - This method should go away once the EL interpreter moves
 * out of JSTL and into its own project.  For now, this is necessary
 * because the standard machinery is too slow.
 *
 * @param expression The expression to be evaluated
 * @param expectedType The expected resulting type
 * @param pageContext The page context//from  w  ww .  j a v a2 s. c  o m
 * @param functionMap Maps prefix and name to Method
 * @return The result of the evaluation
 */
public static Object proprietaryEvaluate(final String expression, final Class expectedType,
        final PageContext pageContext, final ProtectedFunctionMapper functionMap, final boolean escape)
        throws ELException {
    Object retValue;
    if (System.getSecurityManager() != null) {
        try {
            retValue = AccessController.doPrivileged(new PrivilegedExceptionAction() {

                public Object run() throws Exception {
                    return elExprEval.evaluate(expression, expectedType, pageContext.getVariableResolver(),
                            functionMap);
                }
            });
        } catch (PrivilegedActionException ex) {
            Exception realEx = ex.getException();
            if (realEx instanceof ELException) {
                throw (ELException) realEx;
            } else {
                throw new ELException(realEx);
            }
        }
    } else {
        retValue = elExprEval.evaluate(expression, expectedType, pageContext.getVariableResolver(),
                functionMap);
    }
    if (escape) {
        retValue = XmlEscape(retValue.toString());
    }

    return retValue;
}