public static void init(Object o) throws ShiroException { if (o instanceof Initializable) { init((Initializable) o); } }
public void destroy() throws Exception { LifecycleUtils.destroy(this.objects.values()); } }
/** * Calls {@link #init(Object) init} for each object in the collection. If the collection is {@code null} or empty, * this method returns quietly. * * @param c the collection containing objects to {@link #init init}. * @throws ShiroException if unable to initialize one or more instances. * @since 0.9 */ public static void init(Collection c) throws ShiroException { if (c == null || c.isEmpty()) { return; } for (Object o : c) { init(o); } }
/** * Calls {@link #destroy(Object) destroy} for each object in the collection. * If the collection is {@code null} or empty, this method returns quietly. * * @param c the collection of objects to destroy. * @since 0.9 */ public static void destroy(Collection c) { if (c == null || c.isEmpty()) { return; } for (Object o : c) { destroy(o); } } }
private void addToRealms(Collection<Realm> realms, RealmFactory factory) { LifecycleUtils.init(factory); Collection<Realm> factoryRealms = factory.getRealms(); //SHIRO-238: check factoryRealms (was 'realms'): if (!CollectionUtils.isEmpty(factoryRealms)) { realms.addAll(factoryRealms); } }
/** * Cleanup method that first {@link LifecycleUtils#destroy destroys} all of it's managed caches and then * {@link java.util.Map#clear clears} out the internally referenced cache map. * * @throws Exception if any of the managed caches can't destroy properly. */ public void destroy() throws Exception { while (!caches.isEmpty()) { for (Cache cache : caches.values()) { LifecycleUtils.destroy(cache); } caches.clear(); } }
LifecycleUtils.init(environment);
protected void destroy(SecurityManager sm) { LifecycleUtils.destroy(sm); }
@SuppressWarnings({"unchecked"}) public Map<String, ?> buildObjects(Map<String, String> kvPairs) { if (kvPairs != null && !kvPairs.isEmpty()) { BeanConfigurationProcessor processor = new BeanConfigurationProcessor(); for (Map.Entry<String, String> entry : kvPairs.entrySet()) { String lhs = entry.getKey(); String rhs = interpolator.interpolate(entry.getValue()); String beanId = parseBeanId(lhs); if (beanId != null) { //a beanId could be parsed, so the line is a bean instance definition processor.add(new InstantiationStatement(beanId, rhs)); } else { //the line must be a property configuration processor.add(new AssignmentStatement(lhs, rhs)); } } processor.execute(); } //SHIRO-413: init method must be called for constructed objects that are Initializable LifecycleUtils.init(objects.values()); return objects; }
/** * Destroys the {@link WebEnvironment} for the given servlet context. * * @param servletContext the ServletContext attributed to the WebSecurityManager */ public void destroyEnvironment(ServletContext servletContext) { servletContext.log("Cleaning up Shiro Environment"); try { Object environment = servletContext.getAttribute(ENVIRONMENT_ATTRIBUTE_KEY); if (environment instanceof WebEnvironment) { finalizeEnvironment((WebEnvironment) environment); } LifecycleUtils.destroy(environment); } finally { servletContext.removeAttribute(ENVIRONMENT_ATTRIBUTE_KEY); } }
public void execute() { for( Statement statement : statements) { statement.execute(); BeanConfiguration bd = statement.getBeanConfiguration(); if (bd.isExecuted()) { //bean is fully configured, no more statements to execute for it: //bean configured overrides the 'eventBus' bean - replace the existing eventBus with the one configured: if (bd.getBeanName().equals(EVENT_BUS_NAME)) { EventBus eventBus = (EventBus)bd.getBean(); enableEvents(eventBus); } //ignore global 'shiro.' shortcut mechanism: if (!bd.isGlobalConfig()) { BeanEvent event = new ConfiguredBeanEvent(bd.getBeanName(), bd.getBean(), Collections.unmodifiableMap(objects)); eventBus.publish(event); } //initialize the bean if necessary: LifecycleUtils.init(bd.getBean()); //ignore global 'shiro.' shortcut mechanism: if (!bd.isGlobalConfig()) { BeanEvent event = new InitializedBeanEvent(bd.getBeanName(), bd.getBean(), Collections.unmodifiableMap(objects)); eventBus.publish(event); } } } } }
private void addToRealms(Collection<Realm> realms, RealmFactory factory) { LifecycleUtils.init(factory); Collection<Realm> factoryRealms = factory.getRealms(); //SHIRO-238: check factoryRealms (was 'realms'): if (!CollectionUtils.isEmpty(factoryRealms)) { realms.addAll(factoryRealms); } }
public void destroy() { final Map<String, Object> immutableObjects = Collections.unmodifiableMap(objects); //destroy objects in the opposite order they were initialized: List<Map.Entry<String,?>> entries = new ArrayList<Map.Entry<String,?>>(objects.entrySet()); Collections.reverse(entries); for(Map.Entry<String, ?> entry: entries) { String id = entry.getKey(); Object bean = entry.getValue(); //don't destroy the eventbus until the end - we need it to still be 'alive' while publishing destroy events: if (bean != this.eventBus) { //memory equality check (not .equals) on purpose LifecycleUtils.destroy(bean); BeanEvent event = new DestroyedBeanEvent(id, bean, immutableObjects); eventBus.publish(event); this.eventBus.unregister(bean); //bean is now destroyed - it should not receive any other events } } //only now destroy the event bus: LifecycleUtils.destroy(this.eventBus); }
public static void init(Object o) throws ShiroException { if (o instanceof Initializable) { init((Initializable) o); } }
public void destroy() { LifecycleUtils.destroy(getAuthorizer()); this.authorizer = null; super.destroy(); }
public static void init(Object o) throws ShiroException { if (o instanceof Initializable) { init((Initializable) o); } }
public void destroy() { LifecycleUtils.destroy(getRealms()); this.realms = null; super.destroy(); }
/** * Calls {@link #init(Object) init} for each object in the collection. If the collection is {@code null} or empty, * this method returns quietly. * * @param c the collection containing objects to {@link #init init}. * @throws ShiroException if unable to initialize one or more instances. * @since 0.9 */ public static void init(Collection c) throws ShiroException { if (c == null || c.isEmpty()) { return; } for (Object o : c) { init(o); } }