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);
}
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);
}
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();
}
}
}
}
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());
}
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);
}
Aggregations