Example usage for java.security PrivilegedActionException getCause

List of usage examples for java.security PrivilegedActionException getCause

Introduction

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

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.apache.hadoop.gateway.provider.federation.jwt.filter.JWTFederationFilter.java

private void continueWithEstablishedSecurityContext(Subject subject, final HttpServletRequest request,
        final HttpServletResponse response, final FilterChain chain) throws IOException, ServletException {
    try {/*from   ww w .ja va2  s . c om*/
        Subject.doAs(subject, new PrivilegedExceptionAction<Object>() {
            @Override
            public Object run() throws Exception {
                chain.doFilter(request, response);
                return null;
            }
        });
    } catch (PrivilegedActionException e) {
        Throwable t = e.getCause();
        if (t instanceof IOException) {
            throw (IOException) t;
        } else if (t instanceof ServletException) {
            throw (ServletException) t;
        } else {
            throw new ServletException(t);
        }
    }
}

From source file:org.exoplatform.services.command.impl.CommandService.java

/**
 * puts catalog (add or update) using XML input stream
 * //from www.j ava 2  s.  c  o m
 * @param xml
 * @throws IOException
 * @throws SAXException
 */
public void putCatalog(final InputStream xml) throws IOException, SAXException {
    // ConfigParser parser = new ConfigParser();
    // Prepare our Digester instance
    // Digester digester = parser.getDigester();
    digester.clear();

    try {
        SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Void>() {
            public Void run() throws Exception {
                digester.parse(xml);
                return null;
            }
        });
    } catch (PrivilegedActionException pae) {
        Throwable cause = pae.getCause();
        if (cause instanceof IOException) {
            throw (IOException) cause;
        } else if (cause instanceof SAXException) {
            throw (SAXException) cause;
        } else if (cause instanceof RuntimeException) {
            throw (RuntimeException) cause;
        } else {
            throw new RuntimeException(cause);
        }
    }

    // parser.getDigester().parse(xml);
}

From source file:org.exoplatform.services.rest.impl.provider.MultipartFormDataEntityProvider.java

/**
 * {@inheritDoc}//from w  w  w  .  j  a va  2  s.com
 */
@SuppressWarnings("unchecked")
public Iterator<FileItem> readFrom(Class<Iterator<FileItem>> type, Type genericType, Annotation[] annotations,
        MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
        throws IOException {
    try {
        ApplicationContext context = ApplicationContextImpl.getCurrent();
        int bufferSize = context.getProperties().get(RequestHandler.WS_RS_BUFFER_SIZE) == null
                ? RequestHandler.WS_RS_BUFFER_SIZE_VALUE
                : Integer.parseInt(context.getProperties().get(RequestHandler.WS_RS_BUFFER_SIZE));
        File repo = new File(context.getProperties().get(RequestHandler.WS_RS_TMP_DIR));

        DefaultFileItemFactory factory = new DefaultFileItemFactory(bufferSize, repo);
        final FileUpload upload = new FileUpload(factory);

        return SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Iterator<FileItem>>() {
            public Iterator<FileItem> run() throws Exception {
                return upload.parseRequest(httpRequest).iterator();
            }
        });
    } catch (PrivilegedActionException pae) {
        Throwable cause = pae.getCause();
        if (cause instanceof FileUploadException) {
            throw new IOException("Can't process multipart data item " + cause, cause);
        } else if (cause instanceof RuntimeException) {
            throw (RuntimeException) cause;
        } else {
            throw new RuntimeException(cause);
        }
    }
}

From source file:org.apache.lens.client.SpnegoClientFilter.java

private byte[] getToken(String spn, Oid oid) throws GSSException, LoginException {
    LoginContext lc = buildLoginContext();
    lc.login();/*from   w  w  w  .  j av a  2s  .  c om*/
    Subject subject = lc.getSubject();

    GSSManager manager = GSSManager.getInstance();
    GSSName serverName = manager.createName(spn, null); // 2nd oid

    GSSContext context = manager.createContext(serverName.canonicalize(oid), oid, null,
            GSSContext.DEFAULT_LIFETIME);

    final byte[] token = new byte[0];

    try {
        return Subject.doAs(subject, new CreateServiceTicketAction(context, token));
    } catch (PrivilegedActionException e) {
        if (e.getCause() instanceof GSSException) {
            throw (GSSException) e.getCause();
        }
        log.error("initSecContext", e);
        return null;
    }
}

From source file:org.jolokia.jvmagent.JolokiaHttpHandler.java

/**
 * Handle a request. If the handler is not yet started, an exception is thrown. If running with JAAS
 * security enabled it will run as the given subject.
 *
 * @param pHttpExchange the request/response object
 * @throws IOException if something fails during handling
 * @throws IllegalStateException if the handler has not yet been started
 *///  ww w  . j a v a 2  s. c  o  m
public void handle(final HttpExchange pHttpExchange) throws IOException {
    Subject subject = (Subject) pHttpExchange.getAttribute(ConfigKey.JAAS_SUBJECT_REQUEST_ATTRIBUTE);
    if (subject != null) {
        try {
            Subject.doAs(subject, new PrivilegedExceptionAction<Void>() {
                public Void run() throws IOException {
                    doHandle(pHttpExchange);
                    return null;
                }
            });
        } catch (PrivilegedActionException e) {
            throw new SecurityException("Security exception: " + e.getCause(), e.getCause());
        }
    } else {
        doHandle(pHttpExchange);
    }
}

From source file:com.zimbra.cs.security.sasl.GssAuthenticator.java

@Override
public boolean initialize() throws IOException {
    Krb5Keytab keytab = getKeytab(LC.krb5_keytab.value());
    if (keytab == null) {
        sendFailed("mechanism not supported");
        return false;
    }/*from w  ww. j a  v a 2 s  .c o  m*/
    debug("keytab file = %s", keytab.getFile());

    final String host;
    if (LC.krb5_service_principal_from_interface_address.booleanValue()) {
        String localSocketHostname = localAddress.getCanonicalHostName().toLowerCase();
        if (localSocketHostname.length() == 0 || Character.isDigit(localSocketHostname.charAt(0)))
            localSocketHostname = LC.zimbra_server_hostname.value();
        host = localSocketHostname;
    } else {
        host = LC.zimbra_server_hostname.value();
    }

    KerberosPrincipal kp = new KerberosPrincipal(getProtocol() + '/' + host);
    debug("kerberos principal = %s", kp);
    Subject subject = getSubject(keytab, kp);
    if (subject == null) {
        sendFailed();
        return false;
    }
    debug("subject = %s", subject);

    final Map<String, String> props = getSaslProperties();
    if (DEBUG && props != null) {
        String qop = props.get(Sasl.QOP);
        debug("Sent QOP = " + (qop != null ? qop : "auth"));
    }

    try {
        mSaslServer = (SaslServer) Subject.doAs(subject, new PrivilegedExceptionAction<Object>() {
            @Override
            public Object run() throws SaslException {
                return Sasl.createSaslServer(getMechanism(), getProtocol(), host, props,
                        new GssCallbackHandler());
            }
        });
    } catch (PrivilegedActionException e) {
        sendFailed();
        getLog().warn("Could not create SaslServer", e.getCause());
        return false;
    }
    return true;
}

From source file:org.jolokia.jvmagent.handler.JolokiaHttpHandler.java

private void doHandleAs(Subject subject, final HttpExchange pHttpExchange) {
    try {/*from  w  w w . j  a v  a 2s.c  o m*/
        Subject.doAs(subject, new PrivilegedExceptionAction<Void>() {
            public Void run() throws IOException {
                doHandle(pHttpExchange);
                return null;
            }
        });
    } catch (PrivilegedActionException e) {
        throw new SecurityException("Security exception: " + e.getCause(), e.getCause());
    }
}

From source file:org.codice.ddf.security.crl.generator.CrlGenerator.java

/**
 * Writes out the CRL to the given file and adds its path to the property files.
 *
 * @param byteSource - CRL byte source/*from   w  w w .j  a  va  2  s.  c o m*/
 * @param crlFile - the file to write the CRL to
 */
private void writeCrlToFile(ByteSource byteSource, File crlFile) {
    try {
        AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
            // Write out to file
            try (OutputStream outStream = new FileOutputStream(crlFile);
                    InputStream inputStream = byteSource.openStream()) {
                IOUtils.copy(inputStream, outStream);
                SecurityLogger.audit("Copied the content of the CRl at {} to the local CRL at {}.",
                        crlLocationUrl, crlFile.getPath());
                setCrlFileLocationInPropertiesFile(crlFile.getPath());
            }
            return null;
        });
    } catch (PrivilegedActionException e) {
        LOGGER.warn("Unable to save the CRL.");
        LOGGER.debug("Unable to save the CRL. {}", e.getCause());
        postErrorEvent("Unable to save the CRL.");
    }
}

From source file:LinkedTransferQueue.java

/**
 * Returns a sun.misc.Unsafe.  Suitable for use in a 3rd party package.
 * Replace with a simple call to Unsafe.getUnsafe when integrating
 * into a jdk./* www.ja  v  a2  s .c  o  m*/
 *
 * @return a sun.misc.Unsafe
 */
static sun.misc.Unsafe getUnsafe() {
    try {
        return sun.misc.Unsafe.getUnsafe();
    } catch (SecurityException se) {
        try {
            return java.security.AccessController
                    .doPrivileged(new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
                        public sun.misc.Unsafe run() throws Exception {
                            java.lang.reflect.Field f = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
                            f.setAccessible(true);
                            return (sun.misc.Unsafe) f.get(null);
                        }
                    });
        } catch (java.security.PrivilegedActionException e) {
            throw new RuntimeException("Could not initialize intrinsics", e.getCause());
        }
    }
}

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

private static Boolean testJAXBProperty(String propName) {
    final Map<String, String> props = new HashMap<String, String>();
    props.put(propName, "http://test");
    try {//from ww w.  j  ava 2  s  .  c  om
        AccessController.doPrivileged(new PrivilegedExceptionAction() {
            public Object run() throws JAXBException {
                return JAXBContext.newInstance(new Class[] { Integer.class }, props);
            }
        });
        return Boolean.TRUE;
    } catch (PrivilegedActionException e) {
        if (e.getCause() instanceof JAXBException) {
            return Boolean.FALSE;
        }
        return null;
    }
}