Search in sources :

Example 6 with PrivilegedActionException

use of java.security.PrivilegedActionException in project jersey by jersey.

the class EjbComponentProvider method registerEjbInterceptor.

private void registerEjbInterceptor() {
    try {
        final Object interceptor = new EjbComponentInterceptor(injectionManager);
        initialContext = getInitialContext();
        final EjbContainerUtil ejbUtil = EjbContainerUtilImpl.getInstance();
        final ApplicationInfo appInfo = getApplicationInfo(ejbUtil);
        final List<String> tempLibNames = new LinkedList<>();
        for (ModuleInfo moduleInfo : appInfo.getModuleInfos()) {
            final String jarName = moduleInfo.getName();
            if (jarName.endsWith(".jar") || jarName.endsWith(".war")) {
                final String moduleName = jarName.substring(0, jarName.length() - 4);
                tempLibNames.add(moduleName);
                final Object bundleDescriptor = moduleInfo.getMetaData(EjbBundleDescriptorImpl.class.getName());
                if (bundleDescriptor instanceof EjbBundleDescriptorImpl) {
                    final Collection<EjbDescriptor> ejbs = ((EjbBundleDescriptorImpl) bundleDescriptor).getEjbs();
                    for (final EjbDescriptor ejb : ejbs) {
                        final BaseContainer ejbContainer = EjbContainerUtilImpl.getInstance().getContainer(ejb.getUniqueId());
                        try {
                            AccessController.doPrivileged(new PrivilegedExceptionAction() {

                                @Override
                                public Object run() throws Exception {
                                    final Method registerInterceptorMethod = BaseContainer.class.getDeclaredMethod("registerSystemInterceptor", java.lang.Object.class);
                                    registerInterceptorMethod.setAccessible(true);
                                    registerInterceptorMethod.invoke(ejbContainer, interceptor);
                                    return null;
                                }
                            });
                        } catch (PrivilegedActionException pae) {
                            final Throwable cause = pae.getCause();
                            LOGGER.log(Level.WARNING, LocalizationMessages.EJB_INTERCEPTOR_BINDING_WARNING(ejb.getEjbClassName()), cause);
                        }
                    }
                }
            }
        }
        libNames.addAll(tempLibNames);
        final Object interceptorBinder = initialContext.lookup("java:org.glassfish.ejb.container.interceptor_binding_spi");
        // the name
        if (interceptorBinder == null) {
            throw new IllegalStateException(LocalizationMessages.EJB_INTERCEPTOR_BIND_API_NOT_AVAILABLE());
        }
        try {
            AccessController.doPrivileged(new PrivilegedExceptionAction() {

                @Override
                public Object run() throws Exception {
                    Method interceptorBinderMethod = interceptorBinder.getClass().getMethod("registerInterceptor", java.lang.Object.class);
                    interceptorBinderMethod.invoke(interceptorBinder, interceptor);
                    EjbComponentProvider.this.ejbInterceptorRegistered = true;
                    LOGGER.log(Level.CONFIG, LocalizationMessages.EJB_INTERCEPTOR_BOUND());
                    return null;
                }
            });
        } catch (PrivilegedActionException pae) {
            throw new IllegalStateException(LocalizationMessages.EJB_INTERCEPTOR_CONFIG_ERROR(), pae.getCause());
        }
    } catch (NamingException ex) {
        throw new IllegalStateException(LocalizationMessages.EJB_INTERCEPTOR_BIND_API_NOT_AVAILABLE(), ex);
    } catch (LinkageError ex) {
        throw new IllegalStateException(LocalizationMessages.EJB_INTERCEPTOR_CONFIG_LINKAGE_ERROR(), ex);
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) EjbContainerUtil(com.sun.ejb.containers.EjbContainerUtil) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) Method(java.lang.reflect.Method) LinkedList(java.util.LinkedList) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) NamingException(javax.naming.NamingException) PrivilegedActionException(java.security.PrivilegedActionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) BaseContainer(com.sun.ejb.containers.BaseContainer) ModuleInfo(org.glassfish.internal.data.ModuleInfo) NamingException(javax.naming.NamingException) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Example 7 with PrivilegedActionException

use of java.security.PrivilegedActionException in project jersey by jersey.

the class WebComponent method createResourceConfig.

/**
     * Create a {@link ResourceConfig} instance from given {@link WebConfig}.
     *
     * @param config web config to create resource config from.
     * @return resource config instance.
     * @throws ServletException if an error has occurred.
     */
private static ResourceConfig createResourceConfig(final WebConfig config) throws ServletException {
    final ServletContext servletContext = config.getServletContext();
    // check if ResourceConfig has already been created, if so use it
    ResourceConfig resourceConfig = Utils.retrieve(config.getServletContext(), config.getName());
    if (resourceConfig != null) {
        return resourceConfig;
    }
    final Map<String, Object> initParams = getInitParams(config);
    final Map<String, Object> contextParams = Utils.getContextParams(servletContext);
    // check if the JAX-RS application config class property is present
    final String jaxrsApplicationClassName = config.getInitParameter(ServletProperties.JAXRS_APPLICATION_CLASS);
    if (jaxrsApplicationClassName == null) {
        // If no resource config class property is present, create default config
        resourceConfig = new ResourceConfig().addProperties(initParams).addProperties(contextParams);
        final String webApp = config.getInitParameter(ServletProperties.PROVIDER_WEB_APP);
        if (webApp != null && !"false".equals(webApp)) {
            resourceConfig.registerFinder(new WebAppResourcesScanner(servletContext));
        }
        return resourceConfig;
    }
    try {
        final Class<? extends javax.ws.rs.core.Application> jaxrsApplicationClass = AccessController.doPrivileged(ReflectionHelper.<javax.ws.rs.core.Application>classForNameWithExceptionPEA(jaxrsApplicationClassName));
        if (javax.ws.rs.core.Application.class.isAssignableFrom(jaxrsApplicationClass)) {
            return ResourceConfig.forApplicationClass(jaxrsApplicationClass).addProperties(initParams).addProperties(contextParams);
        } else {
            throw new ServletException(LocalizationMessages.RESOURCE_CONFIG_PARENT_CLASS_INVALID(jaxrsApplicationClassName, javax.ws.rs.core.Application.class));
        }
    } catch (final PrivilegedActionException e) {
        throw new ServletException(LocalizationMessages.RESOURCE_CONFIG_UNABLE_TO_LOAD(jaxrsApplicationClassName), e.getCause());
    } catch (final ClassNotFoundException e) {
        throw new ServletException(LocalizationMessages.RESOURCE_CONFIG_UNABLE_TO_LOAD(jaxrsApplicationClassName), e);
    }
}
Also used : Providers(org.glassfish.jersey.internal.inject.Providers) Collectors(java.util.stream.Collectors) PrivilegedActionException(java.security.PrivilegedActionException) ServletException(javax.servlet.ServletException) ServletContext(javax.servlet.ServletContext) ResourceConfig(org.glassfish.jersey.server.ResourceConfig)

Example 8 with PrivilegedActionException

use of java.security.PrivilegedActionException in project netty by netty.

the class PrivilegedSocketOperationsBenchmark method testWithSM.

@Benchmark
public ServerSocketChannel testWithSM(final SecurityManagerInstalled sm) throws IOException {
    try {
        final ServerSocketChannel ssc = AccessController.doPrivileged(new PrivilegedExceptionAction<ServerSocketChannel>() {

            @Override
            public ServerSocketChannel run() throws Exception {
                final ServerSocketChannel ssc = ServerSocketChannel.open();
                ssc.socket().bind(null);
                ssc.configureBlocking(false);
                ssc.accept();
                return ssc;
            }
        });
        ssc.close();
        return ssc;
    } catch (final PrivilegedActionException e) {
        throw (IOException) e.getCause();
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) ServerSocketChannel(java.nio.channels.ServerSocketChannel) PrivilegedActionException(java.security.PrivilegedActionException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 9 with PrivilegedActionException

use of java.security.PrivilegedActionException in project netty by netty.

the class PrivilegedSocketOperationsBenchmark method testWithoutSM.

@Benchmark
public ServerSocketChannel testWithoutSM(final SecurityManagerEmpty sm) throws IOException {
    try {
        final ServerSocketChannel ssc = AccessController.doPrivileged(new PrivilegedExceptionAction<ServerSocketChannel>() {

            @Override
            public ServerSocketChannel run() throws Exception {
                final ServerSocketChannel ssc = ServerSocketChannel.open();
                ssc.socket().bind(null);
                ssc.configureBlocking(false);
                ssc.accept();
                return ssc;
            }
        });
        ssc.close();
        return ssc;
    } catch (final PrivilegedActionException e) {
        throw (IOException) e.getCause();
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) ServerSocketChannel(java.nio.channels.ServerSocketChannel) PrivilegedActionException(java.security.PrivilegedActionException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 10 with PrivilegedActionException

use of java.security.PrivilegedActionException in project robovm by robovm.

the class myPrivilegedExceptionAction method test_doAs_02.

/**
     * javax.security.auth.Subject#doAs(Subject subject, PrivilegedExceptionAction action)
     */
public void test_doAs_02() {
    Subject subj = new Subject();
    PrivilegedExceptionAction<Object> pea = new myPrivilegedExceptionAction();
    PrivilegedExceptionAction<Object> peaNull = null;
    try {
        Object obj = Subject.doAs(null, pea);
    } catch (Exception e) {
        fail("Unexpected exception: " + e);
    }
    try {
        Object obj = Subject.doAs(subj, pea);
    } catch (Exception e) {
        fail("Unexpected exception: " + e);
    }
    try {
        Object obj = Subject.doAs(subj, peaNull);
        fail("NullPointerException wasn't thrown");
    } catch (NullPointerException npe) {
    } catch (Exception e) {
        fail(e + " was thrown instead of NullPointerException");
    }
    try {
        Subject.doAs(subj, new PrivilegedExceptionAction<Object>() {

            public Object run() throws PrivilegedActionException {
                throw new PrivilegedActionException(null);
            }
        });
        fail("PrivilegedActionException wasn't thrown");
    } catch (PrivilegedActionException e) {
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) Subject(javax.security.auth.Subject) PrivilegedActionException(java.security.PrivilegedActionException)

Aggregations

PrivilegedActionException (java.security.PrivilegedActionException)135 IOException (java.io.IOException)58 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)56 Subject (javax.security.auth.Subject)23 LoginContext (javax.security.auth.login.LoginContext)14 LoginException (javax.security.auth.login.LoginException)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)11 Method (java.lang.reflect.Method)11 URISyntaxException (java.net.URISyntaxException)11 HashSet (java.util.HashSet)11 ServletException (javax.servlet.ServletException)11 AccessControlContext (java.security.AccessControlContext)10 Principal (java.security.Principal)9 GSSException (org.ietf.jgss.GSSException)9 Field (java.lang.reflect.Field)8 SolrServerException (org.apache.solr.client.solrj.SolrServerException)7 GSSManager (org.ietf.jgss.GSSManager)7 MalformedURLException (java.net.MalformedURLException)6 ArrayList (java.util.ArrayList)6 YardException (org.apache.stanbol.entityhub.servicesapi.yard.YardException)6