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.atricore.idbus.kernel.main.databinding.JAXBUtils.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 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 new RuntimeException(e.getException());
    }

    return cl;
}

From source file:org.apache.axis2.deployment.DescriptionBuilder.java

/**
 * Processes default message receivers specified either in axis2.xml or
 * services.xml./*from w  w  w  .  j  a  va  2s .c o m*/
 *
 */
protected HashMap<String, MessageReceiver> processMessageReceivers(OMElement messageReceivers)
        throws DeploymentException {
    HashMap<String, MessageReceiver> mr_mep = new HashMap<String, MessageReceiver>();
    Iterator msgReceivers = messageReceivers.getChildrenWithName(new QName(TAG_MESSAGE_RECEIVER));
    while (msgReceivers.hasNext()) {
        OMElement msgReceiver = (OMElement) msgReceivers.next();
        final OMElement tempMsgReceiver = msgReceiver;
        MessageReceiver receiver = null;
        try {
            receiver = org.apache.axis2.java.security.AccessController
                    .doPrivileged(new PrivilegedExceptionAction<MessageReceiver>() {
                        public MessageReceiver run() throws org.apache.axis2.deployment.DeploymentException {
                            return loadMessageReceiver(Thread.currentThread().getContextClassLoader(),
                                    tempMsgReceiver);
                        }
                    });
        } catch (PrivilegedActionException e) {
            throw (DeploymentException) e.getException();
        }
        OMAttribute mepAtt = msgReceiver.getAttribute(new QName(TAG_MEP));
        mr_mep.put(mepAtt.getAttributeValue(), receiver);
    }
    return mr_mep;
}

From source file:org.apache.openjpa.lib.util.Options.java

/**
 * Converts the given string into an object of the given type, or its
 * wrapper type if it is primitive./*from   www  .  j av  a2s.  c om*/
 */
private Object stringToObject(String str, Class<?> type) throws Exception {
    // special case for null and for strings
    if (str == null || type == String.class)
        return str;

    // special case for creating Class instances
    if (type == Class.class)
        return Class.forName(str, false, getClass().getClassLoader());

    // special case for numeric types that end in .0; strip the decimal
    // places because it can kill int, short, long parsing
    if (type.isPrimitive() || Number.class.isAssignableFrom(type))
        if (str.length() > 2 && str.endsWith(".0"))
            str = str.substring(0, str.length() - 2);

    // for primitives, recurse on wrapper type
    if (type.isPrimitive())
        for (int i = 0; i < _primWrappers.length; i++)
            if (type == _primWrappers[i][0])
                return stringToObject(str, (Class<?>) _primWrappers[i][1]);

    // look for a string constructor
    Exception err = null;
    try {
        Constructor<?> cons = type.getConstructor(new Class[] { String.class });
        if (type == Boolean.class && "t".equalsIgnoreCase(str))
            str = "true";
        return cons.newInstance(new Object[] { str });
    } catch (Exception e) {
        err = new ParseException(_loc.get("conf-no-constructor", str, type), e);
    }

    // special case: the argument value is a subtype name and a new instance
    // of that type should be set as the object
    Class<?> subType = null;
    try {
        subType = Class.forName(str);
    } catch (Exception e) {
        err = e;
        throw new ParseException(_loc.get("conf-no-type", str, type), e);
    }
    if (!type.isAssignableFrom(subType))
        throw err;
    try {
        return AccessController.doPrivileged(J2DoPrivHelper.newInstanceAction(subType));
    } catch (PrivilegedActionException pae) {
        throw pae.getException();
    }
}

From source file:org.apache.axis2.jaxws.message.databinding.JAXBUtils.java

/**
 * Create JAXBContext from context String and ClassLoader
 *
 * @param context/* w w w  . j  a va2s.co  m*/
 * @param classloader
 * @return
 * @throws Exception
 */
private static JAXBContext JAXBContext_newInstance(final String context, final ClassLoader classloader)
        throws Exception {
    // NOTE: This method must remain private because it uses AccessController
    JAXBContext jaxbContext = null;
    try {
        if (log.isDebugEnabled()) {
            if (context == null || context.length() == 0) {
                log.debug("JAXBContext is constructed without a context String.");
            } else {
                log.debug("JAXBContext is constructed with a context of:" + context);
            }
        }
        jaxbContext = (JAXBContext) AccessController.doPrivileged(new PrivilegedExceptionAction() {
            public Object run() throws JAXBException {
                return JAXBContext.newInstance(context, classloader);
            }
        });
    } catch (PrivilegedActionException e) {
        if (log.isDebugEnabled()) {
            log.debug("Exception thrown from AccessController: " + e);
        }
        throw e.getException();
    }

    return jaxbContext;
}

From source file:org.apache.axis2.deployment.DescriptionBuilder.java

/**
 * Processes the message builders specified in axis2.xml or services.xml.
 *
 * @param messageBuildersElement/*from   www .  j  a  va2  s  . co m*/
 */
protected HashMap processMessageBuilders(OMElement messageBuildersElement) throws DeploymentException {
    HashMap builderSelector = new HashMap();
    Iterator msgBuilders = messageBuildersElement.getChildrenWithName(new QName(TAG_MESSAGE_BUILDER));
    while (msgBuilders.hasNext()) {
        OMElement msgBuilderElement = (OMElement) msgBuilders.next();
        OMAttribute builderName = msgBuilderElement.getAttribute(new QName(TAG_CLASS_NAME));
        String className = builderName.getAttributeValue();
        Class builderClass = null;
        Builder builderObject;
        try {
            builderClass = findAndValidateSelectorClass(className,
                    DeploymentErrorMsgs.ERROR_LOADING_MESSAGE_BUILDER);
            builderObject = (Builder) builderClass.newInstance();
        } catch (PrivilegedActionException e) {
            throw (DeploymentException) e.getException();
        } catch (InstantiationException e) {
            throw new DeploymentException(
                    "Cannot instantiate the specified Builder Class  : " + builderClass.getName() + ".", e);
        } catch (IllegalAccessException e) {
            throw new DeploymentException(
                    "Cannot instantiate the specified Builder Class : " + builderClass.getName() + ".", e);
        }
        OMAttribute contentTypeAtt = msgBuilderElement.getAttribute(new QName(TAG_CONTENT_TYPE));
        builderSelector.put(contentTypeAtt.getAttributeValue(), builderObject);
    }
    return builderSelector;
}

From source file:org.apache.axis2.deployment.DescriptionBuilder.java

/**
 * Processes the message builders specified in axis2.xml or services.xml.
 */// w w  w. j  a v  a2  s . c o  m
protected HashMap processMessageFormatters(OMElement messageFormattersElement) throws DeploymentException {
    HashMap messageFormatters = new HashMap();
    Iterator msgFormatters = messageFormattersElement.getChildrenWithName(new QName(TAG_MESSAGE_FORMATTER));
    while (msgFormatters.hasNext()) {
        OMElement msgFormatterElement = (OMElement) msgFormatters.next();
        OMElement tempMsgFormatter = msgFormatterElement;
        OMAttribute formatterName = tempMsgFormatter.getAttribute(new QName(TAG_CLASS_NAME));
        String className = formatterName.getAttributeValue();
        MessageFormatter formatterObject;
        Class formatterClass = null;
        try {
            formatterClass = findAndValidateSelectorClass(className,
                    DeploymentErrorMsgs.ERROR_LOADING_MESSAGE_FORMATTER);
            formatterObject = (MessageFormatter) formatterClass.newInstance();
        } catch (PrivilegedActionException e) {
            throw (DeploymentException) e.getException();
        } catch (InstantiationException e) {
            throw new DeploymentException(
                    "Cannot instantiate the specified Formatter Class  : " + formatterClass.getName() + ".", e);
        } catch (IllegalAccessException e) {
            throw new DeploymentException(
                    "Cannot instantiate the specified Formatter Class : " + formatterClass.getName() + ".", e);
        }
        OMAttribute contentTypeAtt = msgFormatterElement.getAttribute(new QName(TAG_CONTENT_TYPE));
        messageFormatters.put(contentTypeAtt.getAttributeValue(), formatterObject);
    }
    return messageFormatters;
}

From source file:org.apache.stanbol.commons.opennlp.OpenNLP.java

/**
 * Lookup an openNLP data file via the {@link #dataFileProvider}
 * @param modelName the name of the model
 * @return the stream or <code>null</code> if not found
 * @throws IOException an any error while opening the model file
 *//* w ww . j  a  v a 2s  .c o m*/
protected InputStream lookupModelStream(final String modelName, final Map<String, String> properties)
        throws IOException {
    try {
        return AccessController.doPrivileged(new PrivilegedExceptionAction<InputStream>() {
            public InputStream run() throws IOException {
                return dataFileProvider.getInputStream(null, modelName, properties);
            }
        });
    } catch (PrivilegedActionException pae) {
        Exception e = pae.getException();
        if (e instanceof IOException) {
            throw (IOException) e;
        } else {
            throw RuntimeException.class.cast(e);
        }
    }
}

From source file:org.apache.axis2.jaxws.message.databinding.JAXBUtils.java

/**
 * Return the class for this name/*  w  w w.  j  ava 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 {
                // 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) {
        if (log.isDebugEnabled()) {
            log.debug("Exception thrown from AccessController: " + e);
        }
        throw (ClassNotFoundException) e.getException();
    }

    return cl;
}

From source file:org.eclipse.gemini.blueprint.io.OsgiBundleResourcePatternResolver.java

/**
 * Special classpath method. Will try to detect the imported bundles (which are part of the classpath) and look for
 * resources in all of them. This implementation will try to determine the bundles that compose the current bundle
 * classpath and then it will inspect the bundle space of each of them individually.
 * /*from  www .  j  a v a 2  s. c o m*/
 * <p/> Since the bundle space is considered, runtime classpath entries such as dynamic imports are not supported
 * (yet).
 * 
 * @param locationPattern
 * @param type
 * @return classpath resources
 */
@SuppressWarnings("unchecked")
private Resource[] findClassPathMatchingResources(String locationPattern, int type) throws IOException {

    if (resolver == null)
        throw new IllegalArgumentException(
                "PackageAdmin service/a started bundle is required for classpath matching");

    final ImportedBundle[] importedBundles = resolver.getImportedBundles(bundle);

    // eliminate classpath path
    final String path = OsgiResourceUtils.stripPrefix(locationPattern);

    final Collection<String> foundPaths = new LinkedHashSet<String>();

    // 1. search the imported packages

    // find folder path matching
    final String rootDirPath = determineFolderPattern(path);

    if (System.getSecurityManager() != null) {
        try {
            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {

                public Object run() throws IOException {
                    for (int i = 0; i < importedBundles.length; i++) {
                        final ImportedBundle importedBundle = importedBundles[i];
                        if (!bundle.equals(importedBundle.getBundle())) {
                            findImportedBundleMatchingResource(importedBundle, rootDirPath, path, foundPaths);
                        }
                    }
                    return null;
                }
            });
        } catch (PrivilegedActionException pe) {
            throw (IOException) pe.getException();
        }
    } else {
        for (int i = 0; i < importedBundles.length; i++) {
            final ImportedBundle importedBundle = importedBundles[i];
            if (!bundle.equals(importedBundle.getBundle())) {
                findImportedBundleMatchingResource(importedBundle, rootDirPath, path, foundPaths);
            }
        }
    }

    // 2. search the target bundle
    findSyntheticClassPathMatchingResource(bundle, path, foundPaths);

    // 3. resolve the entries using the official class-path method (as some of them might be hidden)
    List<Resource> resources = new ArrayList<Resource>(foundPaths.size());

    for (String resourcePath : foundPaths) {
        // classpath*: -> getResources()
        if (OsgiResourceUtils.PREFIX_TYPE_CLASS_ALL_SPACE == type) {
            CollectionUtils.mergeArrayIntoCollection(
                    convertURLEnumerationToResourceArray(bundle.getResources(resourcePath), resourcePath),
                    resources);
        }
        // classpath -> getResource()
        else {
            URL url = bundle.getResource(resourcePath);
            if (url != null)
                resources.add(new UrlContextResource(url, resourcePath));
        }
    }

    if (logger.isTraceEnabled()) {
        logger.trace("Fitered " + foundPaths + " to " + resources);
    }

    return (Resource[]) resources.toArray(new Resource[resources.size()]);
}

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

public void include(final String relativeUrlPath, final boolean flush) throws ServletException, IOException {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        try {//  ww w  .ja v a 2  s  .c om
            AccessController.doPrivileged(new PrivilegedExceptionAction() {
                public Object run() throws Exception {
                    doInclude(relativeUrlPath, flush);
                    return null;
                }
            });
        } catch (PrivilegedActionException e) {
            Exception ex = e.getException();
            if (ex instanceof IOException) {
                throw (IOException) ex;
            } else {
                throw (ServletException) ex;
            }
        }
    } else {
        doInclude(relativeUrlPath, flush);
    }
}