Search in sources :

Example 16 with PrivilegedAction

use of java.security.PrivilegedAction in project geode by apache.

the class DeltaSession8 method getSession.

/**
   * Return the <code>HttpSession</code> for which this object is the facade.
   */
@SuppressWarnings("unchecked")
public HttpSession getSession() {
    if (facade == null) {
        if (SecurityUtil.isPackageProtectionEnabled()) {
            final DeltaSession8 fsession = this;
            facade = (DeltaSessionFacade) AccessController.doPrivileged(new PrivilegedAction() {

                public Object run() {
                    return new DeltaSessionFacade(fsession);
                }
            });
        } else {
            facade = new DeltaSessionFacade(this);
        }
    }
    return (facade);
}
Also used : PrivilegedAction(java.security.PrivilegedAction)

Example 17 with PrivilegedAction

use of java.security.PrivilegedAction in project geode by apache.

the class DeltaSession7 method getSession.

/**
   * Return the <code>HttpSession</code> for which this object is the facade.
   */
@SuppressWarnings("unchecked")
public HttpSession getSession() {
    if (facade == null) {
        if (SecurityUtil.isPackageProtectionEnabled()) {
            final DeltaSession7 fsession = this;
            facade = (DeltaSessionFacade) AccessController.doPrivileged(new PrivilegedAction() {

                public Object run() {
                    return new DeltaSessionFacade(fsession);
                }
            });
        } else {
            facade = new DeltaSessionFacade(this);
        }
    }
    return (facade);
}
Also used : PrivilegedAction(java.security.PrivilegedAction)

Example 18 with PrivilegedAction

use of java.security.PrivilegedAction in project spring-framework by spring-projects.

the class DefaultListableBeanFactory method preInstantiateSingletons.

@Override
public void preInstantiateSingletons() throws BeansException {
    if (this.logger.isDebugEnabled()) {
        this.logger.debug("Pre-instantiating singletons in " + this);
    }
    // Iterate over a copy to allow for init methods which in turn register new bean definitions.
    // While this may not be part of the regular factory bootstrap, it does otherwise work fine.
    List<String> beanNames = new ArrayList<>(this.beanDefinitionNames);
    // Trigger initialization of all non-lazy singleton beans...
    for (String beanName : beanNames) {
        RootBeanDefinition bd = getMergedLocalBeanDefinition(beanName);
        if (!bd.isAbstract() && bd.isSingleton() && !bd.isLazyInit()) {
            if (isFactoryBean(beanName)) {
                final FactoryBean<?> factory = (FactoryBean<?>) getBean(FACTORY_BEAN_PREFIX + beanName);
                boolean isEagerInit;
                if (System.getSecurityManager() != null && factory instanceof SmartFactoryBean) {
                    isEagerInit = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {

                        @Override
                        public Boolean run() {
                            return ((SmartFactoryBean<?>) factory).isEagerInit();
                        }
                    }, getAccessControlContext());
                } else {
                    isEagerInit = (factory instanceof SmartFactoryBean && ((SmartFactoryBean<?>) factory).isEagerInit());
                }
                if (isEagerInit) {
                    getBean(beanName);
                }
            } else {
                getBean(beanName);
            }
        }
    }
    // Trigger post-initialization callback for all applicable beans...
    for (String beanName : beanNames) {
        Object singletonInstance = getSingleton(beanName);
        if (singletonInstance instanceof SmartInitializingSingleton) {
            final SmartInitializingSingleton smartSingleton = (SmartInitializingSingleton) singletonInstance;
            if (System.getSecurityManager() != null) {
                AccessController.doPrivileged(new PrivilegedAction<Object>() {

                    @Override
                    public Object run() {
                        smartSingleton.afterSingletonsInstantiated();
                        return null;
                    }
                }, getAccessControlContext());
            } else {
                smartSingleton.afterSingletonsInstantiated();
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SmartFactoryBean(org.springframework.beans.factory.SmartFactoryBean) SmartInitializingSingleton(org.springframework.beans.factory.SmartInitializingSingleton) PrivilegedAction(java.security.PrivilegedAction) FactoryBean(org.springframework.beans.factory.FactoryBean) SmartFactoryBean(org.springframework.beans.factory.SmartFactoryBean)

Example 19 with PrivilegedAction

use of java.security.PrivilegedAction in project spring-framework by spring-projects.

the class DefaultListableBeanFactoryTests method testInitSecurityAwarePrototypeBean.

@SuppressWarnings("unchecked")
@Test
public void testInitSecurityAwarePrototypeBean() {
    final DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition bd = new RootBeanDefinition(TestSecuredBean.class);
    bd.setScope(ConfigurableBeanFactory.SCOPE_PROTOTYPE);
    bd.setInitMethodName("init");
    lbf.registerBeanDefinition("test", bd);
    final Subject subject = new Subject();
    subject.getPrincipals().add(new TestPrincipal("user1"));
    TestSecuredBean bean = (TestSecuredBean) Subject.doAsPrivileged(subject, new PrivilegedAction() {

        @Override
        public Object run() {
            return lbf.getBean("test");
        }
    }, null);
    assertNotNull(bean);
    assertEquals("user1", bean.getUserName());
}
Also used : PrivilegedAction(java.security.PrivilegedAction) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Example 20 with PrivilegedAction

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

the class Subject method doAs_PrivilegedAction.

// instantiates a new context and passes it to AccessController
@SuppressWarnings("unchecked")
private static <T> T doAs_PrivilegedAction(Subject subject, PrivilegedAction<T> action, final AccessControlContext context) {
    AccessControlContext newContext;
    final SubjectDomainCombiner combiner;
    if (subject == null) {
        // performance optimization
        // if subject is null there is nothing to combine
        combiner = null;
    } else {
        combiner = new SubjectDomainCombiner(subject);
    }
    PrivilegedAction dccAction = new PrivilegedAction() {

        public Object run() {
            return new AccessControlContext(context, combiner);
        }
    };
    newContext = (AccessControlContext) AccessController.doPrivileged(dccAction);
    return AccessController.doPrivileged(action, newContext);
}
Also used : AccessControlContext(java.security.AccessControlContext) PrivilegedAction(java.security.PrivilegedAction)

Aggregations

PrivilegedAction (java.security.PrivilegedAction)359 IOException (java.io.IOException)85 Subject (javax.security.auth.Subject)61 AccessControlContext (java.security.AccessControlContext)31 File (java.io.File)29 HashMap (java.util.HashMap)29 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)29 Method (java.lang.reflect.Method)24 ArrayList (java.util.ArrayList)23 ClientResponse (com.sun.jersey.api.client.ClientResponse)21 InputStream (java.io.InputStream)21 URL (java.net.URL)21 FileNotFoundException (java.io.FileNotFoundException)18 UnsupportedEncodingException (java.io.UnsupportedEncodingException)18 Iterator (java.util.Iterator)18 MalformedURLException (java.net.MalformedURLException)17 List (java.util.List)17 UnknownHostException (java.net.UnknownHostException)16 Principal (java.security.Principal)15 PrivilegedActionException (java.security.PrivilegedActionException)15