Search in sources :

Example 31 with PrivilegedExceptionAction

use of java.security.PrivilegedExceptionAction 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 32 with PrivilegedExceptionAction

use of java.security.PrivilegedExceptionAction in project intellij-community by JetBrains.

the class SystemClassLoaderAction method initSystemClassLoader.

private static synchronized void initSystemClassLoader() {
    if (!sclSet) {
        if (scl != null)
            throw new IllegalStateException("recursive call");
        sun.misc.Launcher l = sun.misc.Launcher.getLauncher();
        if (l != null) {
            Throwable oops = null;
            scl = l.getClassLoader();
            try {
                PrivilegedExceptionAction a;
                a = new SystemClassLoaderAction(scl);
                scl = (ClassLoader) AccessController.doPrivileged(a);
            } catch (PrivilegedActionException pae) {
                oops = pae.getCause();
                if (oops instanceof InvocationTargetException) {
                    oops = oops.getCause();
                }
            }
            if (oops != null) {
                if (oops instanceof Error) {
                    throw (Error) oops;
                } else {
                    // wrap the exception
                    throw new Error(oops);
                }
            }
        }
        sclSet = true;
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 33 with PrivilegedExceptionAction

use of java.security.PrivilegedExceptionAction in project phoenix by apache.

the class SecureUserConnectionsTest method testMultipleInvocationsBySameUserAreEquivalent.

@Test
public void testMultipleInvocationsBySameUserAreEquivalent() throws Exception {
    final HashSet<ConnectionInfo> connections = new HashSet<>();
    final String princ1 = getUserPrincipal(1);
    final File keytab1 = getUserKeytabFile(1);
    UserGroupInformation ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(princ1, keytab1.getPath());
    PrivilegedExceptionAction<Void> callable = new PrivilegedExceptionAction<Void>() {

        public Void run() throws Exception {
            String url = joinUserAuthentication(BASE_URL, princ1, keytab1);
            connections.add(ConnectionInfo.create(url).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES));
            return null;
        }
    };
    // Using the same UGI should result in two equivalent ConnectionInfo objects
    ugi.doAs(callable);
    assertEquals(1, connections.size());
    verifyAllConnectionsAreKerberosBased(connections);
    ugi.doAs(callable);
    assertEquals(1, connections.size());
    verifyAllConnectionsAreKerberosBased(connections);
}
Also used : ConnectionInfo(org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.ConnectionInfo) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) File(java.io.File) HashSet(java.util.HashSet) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test)

Example 34 with PrivilegedExceptionAction

use of java.security.PrivilegedExceptionAction in project sling by apache.

the class ProtectedFunctionMapper method getMapForFunction.

/**
     * Creates an instance for this class, and stores the Method for the given
     * EL function prefix and name. This method is used for the case when there
     * is only one function in the EL expression.
     * 
     * @param fnQName
     *            The EL function qualified name (including prefix)
     * @param c
     *            The class containing the Java method
     * @param methodName
     *            The name of the Java method
     * @param args
     *            The arguments of the Java method
     * @throws RuntimeException
     *             if no method with the given signature could be found.
     */
public static ProtectedFunctionMapper getMapForFunction(String fnQName, final Class c, final String methodName, final Class[] args) {
    java.lang.reflect.Method method;
    ProtectedFunctionMapper funcMapper;
    if (SecurityUtil.isPackageProtectionEnabled()) {
        funcMapper = (ProtectedFunctionMapper) AccessController.doPrivileged(new PrivilegedAction() {

            public Object run() {
                return new ProtectedFunctionMapper();
            }
        });
        try {
            method = (java.lang.reflect.Method) AccessController.doPrivileged(new PrivilegedExceptionAction() {

                public Object run() throws Exception {
                    return c.getDeclaredMethod(methodName, args);
                }
            });
        } catch (PrivilegedActionException ex) {
            throw new RuntimeException("Invalid function mapping - no such method: " + ex.getException().getMessage());
        }
    } else {
        funcMapper = new ProtectedFunctionMapper();
        try {
            method = c.getDeclaredMethod(methodName, args);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException("Invalid function mapping - no such method: " + e.getMessage());
        }
    }
    funcMapper.theMethod = method;
    return funcMapper;
}
Also used : PrivilegedAction(java.security.PrivilegedAction) PrivilegedActionException(java.security.PrivilegedActionException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) Method(java.lang.reflect.Method) PrivilegedActionException(java.security.PrivilegedActionException)

Example 35 with PrivilegedExceptionAction

use of java.security.PrivilegedExceptionAction in project sling by apache.

the class PageContextImpl method proprietaryEvaluate.

/**
	 * 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
	 * @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;
    final ExpressionFactory exprFactory = JspFactory.getDefaultFactory().getJspApplicationContext(pageContext.getServletContext()).getExpressionFactory();
    if (SecurityUtil.isPackageProtectionEnabled()) {
        try {
            retValue = AccessController.doPrivileged(new PrivilegedExceptionAction() {

                public Object run() throws Exception {
                    ELContextImpl ctx = (ELContextImpl) pageContext.getELContext();
                    ctx.setFunctionMapper(new FunctionMapperImpl(functionMap));
                    ValueExpression ve = exprFactory.createValueExpression(ctx, expression, expectedType);
                    return ve.getValue(ctx);
                }
            });
        } catch (PrivilegedActionException ex) {
            Exception realEx = ex.getException();
            if (realEx instanceof ELException) {
                throw (ELException) realEx;
            } else {
                throw new ELException(realEx);
            }
        }
    } else {
        ELContextImpl ctx = (ELContextImpl) pageContext.getELContext();
        ctx.setFunctionMapper(new FunctionMapperImpl(functionMap));
        ValueExpression ve = exprFactory.createValueExpression(ctx, expression, expectedType);
        retValue = ve.getValue(ctx);
    }
    if (escape && retValue != null) {
        retValue = XmlEscape(retValue.toString());
    }
    return retValue;
}
Also used : FunctionMapperImpl(org.apache.sling.scripting.jsp.jasper.el.FunctionMapperImpl) ExpressionFactory(javax.el.ExpressionFactory) PrivilegedActionException(java.security.PrivilegedActionException) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.sling.scripting.jsp.jasper.el.ELContextImpl) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) ELException(javax.servlet.jsp.el.ELException) ServletException(javax.servlet.ServletException) JspException(javax.servlet.jsp.JspException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) ELException(javax.servlet.jsp.el.ELException) SlingPageException(org.apache.sling.scripting.jsp.SlingPageException)

Aggregations

PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)390 IOException (java.io.IOException)200 PrivilegedActionException (java.security.PrivilegedActionException)138 Test (org.junit.Test)104 Connection (org.apache.hadoop.hbase.client.Connection)81 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)76 Table (org.apache.hadoop.hbase.client.Table)62 TableName (org.apache.hadoop.hbase.TableName)57 Result (org.apache.hadoop.hbase.client.Result)56 Scan (org.apache.hadoop.hbase.client.Scan)55 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)53 Delete (org.apache.hadoop.hbase.client.Delete)48 InterruptedIOException (java.io.InterruptedIOException)47 Cell (org.apache.hadoop.hbase.Cell)38 CellScanner (org.apache.hadoop.hbase.CellScanner)38 Configuration (org.apache.hadoop.conf.Configuration)36 File (java.io.File)34 AuthorizationException (org.apache.hadoop.security.authorize.AuthorizationException)33 Path (org.apache.hadoop.fs.Path)23 ArrayList (java.util.ArrayList)22