001    /**
002     *
003     * Copyright 2003-2004 The Apache Software Foundation
004     *
005     *  Licensed under the Apache License, Version 2.0 (the "License");
006     *  you may not use this file except in compliance with the License.
007     *  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    package org.apache.geronimo.security.jacc;
018    
019    import java.security.Permission;
020    import java.security.PermissionCollection;
021    import java.security.Policy;
022    import java.util.Enumeration;
023    import java.util.HashMap;
024    import java.util.Iterator;
025    import java.util.Map;
026    import java.util.Set;
027    import javax.security.auth.Subject;
028    import javax.security.jacc.PolicyConfiguration;
029    import javax.security.jacc.PolicyConfigurationFactory;
030    import javax.security.jacc.PolicyContextException;
031    
032    import org.apache.geronimo.gbean.GBeanInfo;
033    import org.apache.geronimo.gbean.GBeanInfoBuilder;
034    import org.apache.geronimo.gbean.GBeanLifecycle;
035    import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
036    import org.apache.geronimo.security.ContextManager;
037    import org.apache.geronimo.security.IdentificationPrincipal;
038    import org.apache.geronimo.security.SubjectId;
039    
040    /**
041     * @version $Rev: 410741 $ $Date: 2006-05-31 21:35:48 -0700 (Wed, 31 May 2006) $
042     */
043    public class ApplicationPrincipalRoleConfigurationManager implements PrincipalRoleMapper {
044    
045        private final Map principalRoleMap;
046    
047        public ApplicationPrincipalRoleConfigurationManager(Map principalRoleMap) throws PolicyContextException, ClassNotFoundException {
048            this.principalRoleMap = principalRoleMap;
049        }
050    
051    
052        public void install(Set contextIds) throws PolicyContextException {
053            GeronimoPolicyConfigurationFactory roleMapperFactory = GeronimoPolicyConfigurationFactory.getSingleton();
054            if (roleMapperFactory == null) {
055                throw new IllegalStateException("Inconsistent security setup.  GeronimoPolicyConfigurationFactory is not being used");
056            }
057    
058            for (Iterator iterator = contextIds.iterator(); iterator.hasNext();) {
059                String contextID = (String) iterator.next();
060    
061                GeronimoPolicyConfiguration geronimoPolicyConfiguration = roleMapperFactory.getGeronimoPolicyConfiguration(contextID);
062                geronimoPolicyConfiguration.setPrincipalRoleMapping(principalRoleMap);
063            }
064    
065        }
066    
067    
068        public void uninstall() throws PolicyContextException {
069        }
070    
071    
072        public static final GBeanInfo GBEAN_INFO;
073    
074        static {
075            GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(ApplicationPrincipalRoleConfigurationManager.class, NameFactory.JACC_MANAGER);
076            infoBuilder.addAttribute("principalRoleMap", Map.class, true);
077            infoBuilder.addInterface(PrincipalRoleMapper.class);
078            infoBuilder.setConstructor(new String[] {"principalRoleMap"});
079            GBEAN_INFO = infoBuilder.getBeanInfo();
080        }
081    
082        public GBeanInfo getGBeanInfo() {
083            return GBEAN_INFO;
084        }
085    }