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.wso2.carbon.user.core.common.DefaultRealmService.java

@Override
public org.wso2.carbon.user.api.UserRealm getTenantUserRealm(final int tenantId)
        throws org.wso2.carbon.user.api.UserStoreException {

    try {//from  ww  w.  j  av  a  2s  . c o  m
        return AccessController
                .doPrivileged(new PrivilegedExceptionAction<org.wso2.carbon.user.api.UserRealm>() {
                    @Override
                    public org.wso2.carbon.user.api.UserRealm run() throws Exception {
                        return getTenantUserRealmInternal(tenantId);
                    }
                });
    } catch (PrivilegedActionException e) {
        throw (org.wso2.carbon.user.api.UserStoreException) e.getException();
    }
}

From source file:com.stratuscom.harvester.classloading.VirtualFileSystemClassLoader.java

@Override
protected Class<?> findClass(final String name) throws ClassNotFoundException {
    try {/*from   ww  w .ja  v  a 2s. co  m*/
        return (Class) Security.doPrivileged(new PrivilegedExceptionAction<Class>() {

            public Class run() throws ClassNotFoundException {
                String resourceName = classToResourceName(name);
                FileObject resourceFileObject = findResourceFileObject(resourceName);
                if (resourceFileObject == null) {
                    if (log.isLoggable(Level.FINE)) {
                        log.fine(getDebugName() + " was asked for " + resourceName + " but couldn't find it.");
                    }
                    throw new ClassNotFoundException(name + "(" + resourceName + ")");
                }
                try {
                    byte[] bytes = FileUtil.getContent(resourceFileObject);
                    return defineClass(name, bytes, 0, bytes.length);
                } catch (IOException ioe) {
                    if (log.isLoggable(Level.FINE)) {
                        log.fine(getDebugName() + " was asked for " + resourceName
                                + " but got IOException while loading it.");
                    }
                    throw new ClassNotFoundException(name, ioe);
                }

            }
        });
    } catch (PrivilegedActionException ex) {
        throw (ClassNotFoundException) ex.getException();
    }
}

From source file:org.apache.axis2.wsdl.util.WSDLWrapperReloadImpl.java

/**
 * This method provides a Java2 Security compliant way to obtain the InputStream
 * for a given URLConnection object. This is needed as a given URLConnection object
 * may be an instance of a FileURLConnection object which would require access 
 * permissions if Java2 Security was enabled.
 *///from  ww  w . j a  va  2s.  co m
private static InputStream getInputStream(URLConnection urlCon) throws Exception {
    final URLConnection finalURLCon = urlCon;
    InputStream is = null;
    try {
        is = (InputStream) AccessController.doPrivileged(new PrivilegedExceptionAction() {
            public Object run() throws IOException {
                return finalURLCon.getInputStream();
            }
        });
    } catch (PrivilegedActionException e) {
        throw e.getException();
    }
    return is;
}

From source file:org.apache.axis2.jaxws.description.builder.converter.JavaClassToDBCConverter.java

/**
 * The only method we will expose to users of this class. It will trigger the creation of the
 * <code>DescriptionBuilderComposite</code> based on our service class. It will also handle the
 * case of an impl class that references an SEI.
 *
 * @return - <code>DescriptionBuilderComposite</code>
 *///from   ww w. ja  v a 2s  .c om
public HashMap<String, DescriptionBuilderComposite> produceDBC() {
    if (log.isDebugEnabled()) {
        log.debug("Creating DescriptionBuilderComposite map from Java Class.");
    }

    HashMap<String, DescriptionBuilderComposite> dbcMap = new HashMap<String, DescriptionBuilderComposite>();
    for (int i = 0; i < classes.size(); i++) {
        buildDBC(dbcMap, classes.get(i));
        if (seiClassName != null && !seiClassName.equals("")) {
            try {
                final ClassLoader contextClassLoader = (ClassLoader) AccessController
                        .doPrivileged(new PrivilegedAction() {
                            public Object run() {
                                return Thread.currentThread().getContextClassLoader();
                            }
                        });
                Class seiClass = null;
                try {
                    seiClass = (Class) AccessController.doPrivileged(new PrivilegedExceptionAction() {
                        public Object run() throws ClassNotFoundException {
                            return contextClassLoader.loadClass(seiClassName);
                        }
                    });
                } catch (PrivilegedActionException e) {
                    throw (ClassNotFoundException) e.getException();
                }
                buildDBC(dbcMap, seiClass);

                // Also try to see if the SEI has any super interfaces  
                Class[] interfaces = seiClass.getInterfaces();
                for (int j = 0; j < interfaces.length; j++) {
                    buildDBC(dbcMap, interfaces[j]);
                }
            } catch (ClassNotFoundException e) {
                if (log.isDebugEnabled()) {
                    log.debug("Class not found exception caught for class: " + seiClassName, e);
                }
            }
        }
    }
    return dbcMap;
}

From source file:org.apache.axis2.jaxws.marshaller.impl.alt.MethodMarshallerUtils.java

/**
 * Return the class for this name//w w  w.  j  a va  2s. 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:com.liferay.portal.template.soy.internal.SoyTemplate.java

@Override
protected void processTemplates(List<TemplateResource> templateResources, Writer writer) throws Exception {

    try {//  w w w.  ja  v  a 2s.co m
        String namespace = GetterUtil.getString(get(TemplateConstants.NAMESPACE));

        if (Validator.isNull(namespace)) {
            throw new TemplateException("Namespace is not specified");
        }

        SoyTofuCacheBag soyTofuCacheBag = getSoyTofuCacheBag(templateResources);

        SoyTofu soyTofu = soyTofuCacheBag.getSoyTofu();

        Renderer renderer = soyTofu.newRenderer(namespace);

        renderer.setData(getSoyMapData());
        renderer.setIjData(getSoyMapInjectedData());

        SoyFileSet soyFileSet = soyTofuCacheBag.getSoyFileSet();

        Optional<SoyMsgBundle> soyMsgBundle = getSoyMsgBundle(soyFileSet, soyTofuCacheBag);

        if (soyMsgBundle.isPresent()) {
            renderer.setMsgBundle(soyMsgBundle.get());
        }

        boolean renderStrict = GetterUtil.getBoolean(get(TemplateConstants.RENDER_STRICT), true);

        if (renderStrict) {
            SanitizedContent sanitizedContent = renderer.renderStrict();

            writer.write(sanitizedContent.stringValue());
        } else {
            writer.write(renderer.render());
        }
    } catch (PrivilegedActionException pae) {
        throw pae.getException();
    }
}

From source file:org.apache.axis2.jaxws.marshaller.impl.alt.MethodMarshallerUtils.java

/** @return ClassLoader */
private static ClassLoader getContextClassLoader() {
    // NOTE: This method must remain private because it uses AccessController
    ClassLoader cl = null;//from w w w . ja 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 ExceptionFactory.makeWebServiceException(e.getException());
    }

    return cl;
}

From source file:org.apache.jk.server.JkCoyoteHandler.java

private void appendHead(org.apache.coyote.Response res) throws IOException {
    if (log.isDebugEnabled())
        log.debug("COMMIT sending headers " + res + " " + res.getMimeHeaders());

    C2BConverter c2b = (C2BConverter) res.getNote(utfC2bNote);
    if (c2b == null) {
        if (System.getSecurityManager() != null) {
            try {
                c2b = (C2BConverter) AccessController.doPrivileged(new PrivilegedExceptionAction() {
                    public Object run() throws IOException {
                        return new C2BConverter("UTF8");
                    }// w ww. j a  v a  2s.  c om
                });
            } catch (PrivilegedActionException pae) {
                Exception ex = pae.getException();
                if (ex instanceof IOException)
                    throw (IOException) ex;
            }
        } else {
            c2b = new C2BConverter("UTF8");
        }
        res.setNote(utfC2bNote, c2b);
    }

    MsgContext ep = (MsgContext) res.getNote(epNote);
    MsgAjp msg = (MsgAjp) ep.getNote(headersMsgNote);
    msg.reset();
    msg.appendByte(HandlerRequest.JK_AJP13_SEND_HEADERS);
    msg.appendInt(res.getStatus());

    MessageBytes mb = (MessageBytes) ep.getNote(tmpMessageBytesNote);
    if (mb == null) {
        mb = new MessageBytes();
        ep.setNote(tmpMessageBytesNote, mb);
    }
    String message = res.getMessage();
    if (message == null) {
        if (System.getSecurityManager() != null) {
            message = (String) AccessController.doPrivileged(new StatusLinePrivilegedAction(res.getStatus()));
        } else {
            message = HttpMessages.getMessage(res.getStatus());
        }
    } else {
        message = message.replace('\n', ' ').replace('\r', ' ');
    }
    mb.setString(message);
    c2b.convert(mb);
    msg.appendBytes(mb);

    // XXX add headers

    MimeHeaders headers = res.getMimeHeaders();
    String contentType = res.getContentType();
    if (contentType != null) {
        headers.setValue("Content-Type").setString(contentType);
    }
    String contentLanguage = res.getContentLanguage();
    if (contentLanguage != null) {
        headers.setValue("Content-Language").setString(contentLanguage);
    }
    int contentLength = res.getContentLength();
    if (contentLength >= 0) {
        headers.setValue("Content-Length").setInt(contentLength);
    }
    int numHeaders = headers.size();
    msg.appendInt(numHeaders);
    for (int i = 0; i < numHeaders; i++) {
        MessageBytes hN = headers.getName(i);
        // no header to sc conversion - there's little benefit
        // on this direction
        c2b.convert(hN);
        msg.appendBytes(hN);

        MessageBytes hV = headers.getValue(i);
        c2b.convert(hV);
        msg.appendBytes(hV);
    }
    ep.setType(JkHandler.HANDLE_SEND_PACKET);
    ep.getSource().invoke(msg, ep);
}

From source file:org.apache.openjpa.lib.meta.ClassArgParser.java

/**
 * Returns the class named in the given .class file.
 */// www. ja va  2  s  .  c o m
private String getFromClassFile(File file) throws IOException {
    FileInputStream fin = null;
    try {
        fin = AccessController.doPrivileged(J2DoPrivHelper.newFileInputStreamAction(file));
        return getFromClass(fin);
    } catch (PrivilegedActionException pae) {
        throw (FileNotFoundException) pae.getException();
    } finally {
        if (fin != null)
            try {
                fin.close();
            } catch (IOException ioe) {
            }
    }
}

From source file:org.echocat.nodoodle.classloading.FileClassLoader.java

@Override
protected synchronized Class<?> findClass(final String name) throws ClassNotFoundException {
    ensureNotClosed();/* ww  w .  j a v  a 2s .  co m*/
    try {
        return doPrivileged(new PrivilegedExceptionAction<Class<?>>() {
            @Override
            public Class<?> run() throws Exception {
                Class<?> result;
                result = null;
                final String path = name.replace('.', '/').concat(".class");
                final Iterator<File> i = _directories.iterator();
                while (result == null && i.hasNext()) {
                    final File directory = i.next();
                    final File file = new File(directory, path);
                    if (file.isFile()) {
                        result = defineClass(name, new DirectoryResource(directory, file));
                    }
                }
                if (result == null) {
                    final Iterator<JarFile> j = _jarFiles.iterator();
                    while (result == null && j.hasNext()) {
                        final JarFile jarFile = j.next();
                        final JarEntry jarEntry = jarFile.getJarEntry(path);
                        if (jarEntry != null) {
                            result = defineClass(name, new JarResource(jarFile, jarEntry));
                        }
                    }
                }
                if (result == null) {
                    throw new ClassNotFoundException(name);
                }
                return result;
            }
        }, _acc);
    } catch (PrivilegedActionException e) {
        final Exception exception = e.getException();
        if (exception instanceof ClassNotFoundException) {
            throw (ClassNotFoundException) exception;
        } else {
            throw new RuntimeException(e);
        }
    }
}