001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. 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: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 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 }