@Before public void setUp() throws Exception { final ProtectionDomain empty = new ProtectionDomain(null, new Permissions()); provider = new SecurityContextProvider() { private final AccessControlContext acc = new AccessControlContext( new ProtectionDomain[] { empty }); @Override public AccessControlContext getAccessControlContext() { return acc; } }; DefaultResourceLoader drl = new DefaultResourceLoader(); Resource config = drl .getResource("/org/springframework/beans/factory/support/security/callbacks.xml"); beanFactory = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(config); beanFactory.setSecurityContextProvider(provider); }
protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { super.postProcessBeanFactory(beanFactory); beanFactory.addBeanPostProcessor(new BundleContextAwareProcessor(this.bundleContext)); beanFactory.ignoreDependencyInterface(BundleContextAware.class); if (beanFactory instanceof AbstractBeanFactory) { AbstractBeanFactory bf = (AbstractBeanFactory) beanFactory; bf.setSecurityContextProvider(new SecurityContextProvider() { public AccessControlContext getAccessControlContext() { return acc; } }); } enforceExporterImporterDependency(beanFactory); // add predefined beans // bundleContext addPredefinedBean(beanFactory, BUNDLE_CONTEXT_BEAN_NAME, this.bundleContext); addPredefinedBean(beanFactory, BUNDLE_BEAN_NAME, this.bundle); // register property editors registerPropertyEditors(beanFactory); // register a 'bundle' scope beanFactory.registerScope(OsgiBundleScope.SCOPE_NAME, new OsgiBundleScope()); }
/** * Set the security context provider for this bean factory. If a security manager * is set, interaction with the user code will be executed using the privileged * of the provided security context. */ public void setSecurityContextProvider(SecurityContextProvider securityProvider) { this.securityContextProvider = securityProvider; }