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.mappingprovider; 018 019 import java.util.Map; 020 import java.util.Set; 021 022 import javax.security.jacc.PolicyContextException; 023 024 import org.apache.geronimo.gbean.GBeanInfo; 025 import org.apache.geronimo.gbean.GBeanInfoBuilder; 026 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 027 import org.apache.geronimo.security.jacc.PrincipalRoleMapper; 028 029 /** 030 * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $ 031 */ 032 public class ApplicationPrincipalRoleConfigurationManager implements PrincipalRoleMapper { 033 034 private static PrincipalRoleConfigurationFactory principalRoleConfigurationFactory; 035 private final Map principalRoleMap; 036 037 public ApplicationPrincipalRoleConfigurationManager(Map principalRoleMap) throws PolicyContextException, ClassNotFoundException { 038 this.principalRoleMap = principalRoleMap; 039 } 040 041 public static void setPrincipalRoleConfigurationFactory(PrincipalRoleConfigurationFactory principalRoleConfigurationFactory) { 042 if (ApplicationPrincipalRoleConfigurationManager.principalRoleConfigurationFactory != null) { 043 throw new IllegalStateException("ApplicationPrincipalRoleConfigurationManager.principalRoleConfigurationFactory already set"); 044 } 045 ApplicationPrincipalRoleConfigurationManager.principalRoleConfigurationFactory = principalRoleConfigurationFactory; 046 } 047 048 public void install(Set<String> contextIds) throws PolicyContextException { 049 if (principalRoleConfigurationFactory == null) { 050 throw new IllegalStateException("Inconsistent security setup. PrincipalRoleConfigurationFactory is not set"); 051 } 052 053 for (String contextID : contextIds) { 054 PrincipalRoleConfiguration principalRoleConfiguration = principalRoleConfigurationFactory.getPrincipalRoleConfiguration(contextID); 055 principalRoleConfiguration.setPrincipalRoleMapping(principalRoleMap); 056 } 057 058 } 059 060 061 public void uninstall(Set<String> contextIds) throws PolicyContextException { 062 } 063 064 065 public static final GBeanInfo GBEAN_INFO; 066 067 static { 068 GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(ApplicationPrincipalRoleConfigurationManager.class, NameFactory.JACC_MANAGER); 069 infoBuilder.addAttribute("principalRoleMap", Map.class, true); 070 infoBuilder.addInterface(PrincipalRoleMapper.class); 071 infoBuilder.setConstructor(new String[] {"principalRoleMap"}); 072 GBEAN_INFO = infoBuilder.getBeanInfo(); 073 } 074 075 public GBeanInfo getGBeanInfo() { 076 return GBEAN_INFO; 077 } 078 }