// Path: pax-shiro-cdi/src/main/java/org/ops4j/pax/shiro/cdi/impl/NamedBeanMap.java
// public class NamedBeanMap implements Map<String, Object> {
// 
//     private static Logger log = LoggerFactory.getLogger(NamedBeanMap.class);
// 
//     private Map<String, Object> beans = new HashMap<String, Object>();
// 
//     /**
//      * 
//      */
//     public NamedBeanMap(BeanManager beanManager) {
//         for (Bean<?> bean : beanManager.getBeans(Object.class, ShiroIniLiteral.INSTANCE)) {
//             String beanName = getShiroBeanName(bean);
//             if (beanName == null) {
//                 log.warn("Shiro cannot derive a default name for [{}], "
//                     + "so this bean cannot be referenced in shiro.ini. "
//                     + "Consider adding a @Named qualifier.", bean);
//             }
//             else {
//                 log.debug("Found @ShiroIni bean with name [{}]", beanName);
//                 CreationalContext<Object> cc = beanManager.createCreationalContext(null);
//                 Object object = beanManager.getReference(bean, Object.class, cc);
//                 beans.put(beanName, object);
//             }
//         }
//     }
// 
//     /**
//      * @param bean
//      * @return
//      */
//     private String getShiroBeanName(Bean<?> bean) {
//         String beanName = bean.getName();
//         if (beanName == null) {
//             if (bean.getTypes().contains(bean.getBeanClass())) {
//                 String className = bean.getBeanClass().getSimpleName();
//                 char first = Character.toLowerCase(className.charAt(0));
//                 beanName = first + className.substring(1);
//             }
//         }
//         return beanName;
//     }
// 
//     public int size() {
//         return beans.size();
//     }
// 
//     public boolean isEmpty() {
//         return beans.isEmpty();
//     }
// 
//     public boolean containsKey(Object key) {
//         return beans.containsKey(key);
//     }
// 
//     public boolean containsValue(Object value) {
//         throw new UnsupportedOperationException();
//     }
// 
//     public Object get(Object key) {
//         return beans.get(key);
//     }
// 
//     public Object put(String key, Object value) {
//         throw new UnsupportedOperationException();
//     }
// 
//     public Object remove(Object key) {
//         throw new UnsupportedOperationException();
//     }
// 
//     public void putAll(Map<? extends String, ? extends Object> m) {
//         throw new UnsupportedOperationException();
//     }
// 
//     public void clear() {
//         throw new UnsupportedOperationException();
//     }
// 
//     public Set<String> keySet() {
//         return beans.keySet();
//     }
// 
//     public Collection<Object> values() {
//         return beans.values();
//     }
// 
//     public Set<java.util.Map.Entry<String, Object>> entrySet() {
//         return beans.entrySet();
//     }
// }


import java.util.Map;
import javax.enterprise.inject.spi.BeanManager;
import org.apache.shiro.config.Ini;
import org.apache.shiro.config.Ini.Section;
import org.apache.shiro.web.config.WebIniSecurityManagerFactory;
import org.ops4j.pax.shiro.cdi.impl.NamedBeanMap;
/*
 * Copyright 2013 Harald Wellmann
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.
 *
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.ops4j.pax.shiro.cdi.web;





/**
 * A CDI-aware extension of {@link WebIniSecurityManagerFactory}. Constructs a named bean
 * map from the CDI BeanManager and uses these beans as additional default for Shiro
 * bean lookup.
 * 
 * @author Harald Wellmann
 *
 */
public class CdiWebIniSecurityManagerFactory extends WebIniSecurityManagerFactory {
    
    
    private Map<String, ?> namedBeanMap;

    public CdiWebIniSecurityManagerFactory(BeanManager beanManager) {
// Path: pax-shiro-cdi/src/main/java/org/ops4j/pax/shiro/cdi/impl/NamedBeanMap.java
// public class NamedBeanMap implements Map<String, Object> {
// 
//     private static Logger log = LoggerFactory.getLogger(NamedBeanMap.class);
// 
//     private Map<String, Object> beans = new HashMap<String, Object>();
// 
//     /**
//      * 
//      */
//     public NamedBeanMap(BeanManager beanManager) {
//         for (Bean<?> bean : beanManager.getBeans(Object.class, ShiroIniLiteral.INSTANCE)) {
//             String beanName = getShiroBeanName(bean);
//             if (beanName == null) {
//                 log.warn("Shiro cannot derive a default name for [{}], "
//                     + "so this bean cannot be referenced in shiro.ini. "
//                     + "Consider adding a @Named qualifier.", bean);
//             }
//             else {
//                 log.debug("Found @ShiroIni bean with name [{}]", beanName);
//                 CreationalContext<Object> cc = beanManager.createCreationalContext(null);
//                 Object object = beanManager.getReference(bean, Object.class, cc);
//                 beans.put(beanName, object);
//             }
//         }
//     }
// 
//     /**
//      * @param bean
//      * @return
//      */
//     private String getShiroBeanName(Bean<?> bean) {
//         String beanName = bean.getName();
//         if (beanName == null) {
//             if (bean.getTypes().contains(bean.getBeanClass())) {
//                 String className = bean.getBeanClass().getSimpleName();
//                 char first = Character.toLowerCase(className.charAt(0));
//                 beanName = first + className.substring(1);
//             }
//         }
//         return beanName;
//     }
// 
//     public int size() {
//         return beans.size();
//     }
// 
//     public boolean isEmpty() {
//         return beans.isEmpty();
//     }
// 
//     public boolean containsKey(Object key) {
//         return beans.containsKey(key);
//     }
// 
//     public boolean containsValue(Object value) {
//         throw new UnsupportedOperationException();
//     }
// 
//     public Object get(Object key) {
//         return beans.get(key);
//     }
// 
//     public Object put(String key, Object value) {
//         throw new UnsupportedOperationException();
//     }
// 
//     public Object remove(Object key) {
//         throw new UnsupportedOperationException();
//     }
// 
//     public void putAll(Map<? extends String, ? extends Object> m) {
//         throw new UnsupportedOperationException();
//     }
// 
//     public void clear() {
//         throw new UnsupportedOperationException();
//     }
// 
//     public Set<String> keySet() {
//         return beans.keySet();
//     }
// 
//     public Collection<Object> values() {
//         return beans.values();
//     }
// 
//     public Set<java.util.Map.Entry<String, Object>> entrySet() {
//         return beans.entrySet();
//     }
// }


// Path: pax-shiro-cdi-web/src/main/java/org/ops4j/pax/shiro/cdi/web/CdiWebIniSecurityManagerFactory.java
import java.util.Map;
import javax.enterprise.inject.spi.BeanManager;
import org.apache.shiro.config.Ini;
import org.apache.shiro.config.Ini.Section;
import org.apache.shiro.web.config.WebIniSecurityManagerFactory;
import org.ops4j.pax.shiro.cdi.impl.NamedBeanMap;

/*
 * Copyright 2013 Harald Wellmann
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.
 *
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.ops4j.pax.shiro.cdi.web;





/**
 * A CDI-aware extension of {@link WebIniSecurityManagerFactory}. Constructs a named bean
 * map from the CDI BeanManager and uses these beans as additional default for Shiro
 * bean lookup.
 * 
 * @author Harald Wellmann
 *
 */
public class CdiWebIniSecurityManagerFactory extends WebIniSecurityManagerFactory {
    
    
    private Map<String, ?> namedBeanMap;

    public CdiWebIniSecurityManagerFactory(BeanManager beanManager) {
        this.namedBeanMap = new NamedBeanMap(beanManager);