Example usage for java.security PrivilegedAction PrivilegedAction

List of usage examples for java.security PrivilegedAction PrivilegedAction

Introduction

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

Prototype

PrivilegedAction

Source Link

Usage

From source file:com.triage.bytecodemaster.CachingGroovyClassLoader.java

@Override
protected ClassCollector createCollector(CompilationUnit unit, SourceUnit su) {
    // These six lines copied from Groovy itself, with the intention to
    // return a subclass
    InnerLoader loader = AccessController.doPrivileged(new PrivilegedAction<InnerLoader>() {
        public InnerLoader run() {
            return new InnerLoader(CachingGroovyClassLoader.this);
        }/*w w  w.j a  va 2 s  . c o m*/
    });
    return new BytecodeClassCollector(classBytes, loader, unit, su);
}

From source file:org.vaadin.spring.events.support.VaadinEventBusAwareProcessor.java

@Override
public Object postProcessBeforeInitialization(final Object bean, String beanName) throws BeansException {
    AccessControlContext acc = null;

    if (System.getSecurityManager() != null && (bean instanceof EventBusAware)) {
        acc = this.applicationContext.getBeanFactory().getAccessControlContext();
    }/*from   w w w.j  av a2  s  . c om*/

    if (acc != null) {
        AccessController.doPrivileged(new PrivilegedAction<Object>() {

            @Override
            public Object run() {
                invokeAwareInterfaces(bean);
                return null;
            }

        }, acc);
    } else {
        invokeAwareInterfaces(bean);
    }

    return bean;
}

From source file:org.java.plugin.drftpd.SynchronizedPluginLifecycleHandler.java

/**
 * Creates synchronized implementation of plug-in class loader.
 * @see org.java.plugin.standard.StandardPluginLifecycleHandler#createPluginClassLoader(
 *      org.java.plugin.registry.PluginDescriptor)
 *//* w  w w.j a  va2  s.  c  o m*/
@Override
protected org.java.plugin.PluginClassLoader createPluginClassLoader(final PluginDescriptor descr) {
    SynchronizedPluginClassLoader result;
    if (System.getSecurityManager() != null) {
        result = AccessController.doPrivileged(new PrivilegedAction<SynchronizedPluginClassLoader>() {
            public SynchronizedPluginClassLoader run() {
                return new SynchronizedPluginClassLoader(getPluginManager(), descr,
                        SynchronizedPluginLifecycleHandler.this.getClass().getClassLoader());
            }
        });
    } else {
        result = new SynchronizedPluginClassLoader(getPluginManager(), descr,
                SynchronizedPluginLifecycleHandler.this.getClass().getClassLoader());
    }
    result.setProbeParentLoaderLast(probeParentLoaderLast);
    result.setStickySynchronizing(stickySynchronizing);
    result.setLocalClassLoadingOptimization(localClassLoadingOptimization);
    result.setForeignClassLoadingOptimization(foreignClassLoadingOptimization);

    return result;
}

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

public CommonsXMLConfigurationPlugin(InitParams params, ConfigurationManager configurationManager)
        throws Exception {
    ValueParam confFile = params.getValueParam("config-file");
    if (confFile != null) {
        final String path = confFile.getValue();
        final ConfigParser parser = new ConfigParser();
        // may work for StandaloneContainer

        URL res = SecurityHelper.doPrivilegedAction(new PrivilegedAction<URL>() {
            public URL run() {
                return Thread.currentThread().getContextClassLoader().getResource(path);
            }//from w  w  w  .j a v  a 2  s.  com
        });

        // for PortalContainer
        if (res == null)
            res = configurationManager.getResource(path);
        if (res == null)
            throw new Exception("Resource not found " + path);
        LOG.info("Catalog configuration found at " + res);

        final URL fRes = res;
        SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Void>() {
            public Void run() throws Exception {
                parser.parse(fRes);
                return null;
            }
        });
    }

}

From source file:SecuritySupport.java

static InputStream getResourceAsStream(final ClassLoader cl, final String name) {
    return (InputStream) AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            InputStream ris;/* w w w  .  ja  v a2 s .  co m*/
            if (cl == null) {
                ris = ClassLoader.getSystemResourceAsStream(name);
            } else {
                ris = cl.getResourceAsStream(name);
            }
            return ris;
        }
    });
}

From source file:org.javascool.polyfilewriter.Gateway.java

/**
 * Read a file on a location./*w w  w.  j  a  v a  2s.  com*/
 * Replace the FileReader API for text files (code e.g.)
 *
 * @param location Where have I got to read your file ?
 * @return The file content
 * @see FileManager#load(String)
 */
public String load(final String location) throws Exception {
    assertSafeUsage();
    try {
        return AccessController.doPrivileged(new PrivilegedAction<String>() {
            public String run() {
                return FileManager.load(location);
            }
        });
    } catch (Exception e) {
        popException(e);
        throw e;
    }
}

From source file:org.vaadin.spring.security.support.VaadinSecurityAwareProcessor.java

@Override
public Object postProcessBeforeInitialization(final Object bean, String beanName) throws BeansException {

    AccessControlContext acc = null;

    if (System.getSecurityManager() != null && (bean instanceof VaadinSecurityAware)) {
        acc = this.applicationContext.getBeanFactory().getAccessControlContext();
    }/*from  w ww  .j a v a2s  .  c  o  m*/

    if (acc != null) {
        AccessController.doPrivileged(new PrivilegedAction<Object>() {

            @Override
            public Object run() {
                invokeAwareInterfaces(bean);
                return null;
            }

        }, acc);
    } else {
        invokeAwareInterfaces(bean);
    }

    return bean;

}

From source file:org.beangle.model.persist.hibernate.internal.ChainedClassLoader.java

public URL getResource(final String name) {
    if (System.getSecurityManager() != null) {
        return AccessController.doPrivileged(new PrivilegedAction<URL>() {

            public URL run() {
                return doGetResource(name);
            }/*  www .  j ava  2 s.  co  m*/
        });
    } else {
        return doGetResource(name);
    }
}

From source file:org.apache.ranger.hive.client.HiveClient.java

public void initHive() {
    isKerberosAuth = getConfigHolder().isKerberosAuthentication();
    if (isKerberosAuth) {
        LOG.info("Secured Mode: JDBC Connection done with preAuthenticated Subject");
        Subject.doAs(getLoginSubject(), new PrivilegedAction<Object>() {
            public Object run() {
                initConnection();//  ww  w. j a  v a  2s .  c  o  m
                return null;
            }
        });
    } else {
        LOG.info("Since Password is NOT provided, Trying to use UnSecure client with username and password");
        final String userName = getConfigHolder().getUserName();
        final String password = getConfigHolder().getPassword();
        Subject.doAs(getLoginSubject(), new PrivilegedAction<Object>() {
            public Object run() {
                initConnection(userName, password);
                return null;
            }
        });
    }
}

From source file:org.apache.clerezza.platform.dashboard.UserLoginNode.java

@Override
public GraphNode addUserContext(GraphNode node) {

    final AccessControlContext context = AccessController.getContext();
    GraphNode agent = AccessController.doPrivileged(new PrivilegedAction<GraphNode>() {
        @Override/*w w w .  ja v a2  s  .  co m*/
        public GraphNode run() {
            final String userName = UserUtil.getUserName(context);
            if (userName == null) {
                return null;
            }
            return userManager.getUserGraphNode(userName);
        }
    });
    if (agent != null) {
        if (agent.getNode() instanceof UriRef) {
            WebIdInfo webIdInfo = webIdGraphsService.getWebIdInfo((UriRef) agent.getNode());
            MGraph userGraph = webIdInfo.localPublicUserData();
            agent = new GraphNode(agent.getNode(), new UnionMGraph(agent.getGraph(), userGraph));
        }
        node.addProperty(PLATFORM.user, agent.getNode());
        MGraph userContext = new SimpleMGraph(agent.getNodeContext());
        removeTripleWithProperty(userContext, PERMISSION.password);
        removeTripleWithProperty(userContext, PERMISSION.passwordSha1);
        node.getGraph().addAll(userContext);
    }
    return node;
}