View Javadoc

1   /**
2    *
3    * Copyright 2003-2004 The Apache Software Foundation
4    *
5    *  Licensed under the Apache License, Version 2.0 (the "License");
6    *  you may not use this file except in compliance with the License.
7    *  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17  package org.apache.geronimo.security.jacc;
18  
19  import java.security.Permission;
20  import java.security.PermissionCollection;
21  import java.security.Policy;
22  import java.util.Enumeration;
23  import java.util.HashMap;
24  import java.util.Iterator;
25  import java.util.Map;
26  import java.util.Set;
27  import javax.security.auth.Subject;
28  import javax.security.jacc.PolicyConfiguration;
29  import javax.security.jacc.PolicyConfigurationFactory;
30  import javax.security.jacc.PolicyContextException;
31  
32  import org.apache.geronimo.gbean.GBeanInfo;
33  import org.apache.geronimo.gbean.GBeanInfoBuilder;
34  import org.apache.geronimo.gbean.GBeanLifecycle;
35  import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
36  import org.apache.geronimo.security.ContextManager;
37  import org.apache.geronimo.security.IdentificationPrincipal;
38  import org.apache.geronimo.security.SubjectId;
39  
40  /**
41   * @version $Rev: 410741 $ $Date: 2006-05-31 21:35:48 -0700 (Wed, 31 May 2006) $
42   */
43  public class ApplicationPrincipalRoleConfigurationManager implements PrincipalRoleMapper {
44  
45      private final Map principalRoleMap;
46  
47      public ApplicationPrincipalRoleConfigurationManager(Map principalRoleMap) throws PolicyContextException, ClassNotFoundException {
48          this.principalRoleMap = principalRoleMap;
49      }
50  
51  
52      public void install(Set contextIds) throws PolicyContextException {
53          GeronimoPolicyConfigurationFactory roleMapperFactory = GeronimoPolicyConfigurationFactory.getSingleton();
54          if (roleMapperFactory == null) {
55              throw new IllegalStateException("Inconsistent security setup.  GeronimoPolicyConfigurationFactory is not being used");
56          }
57  
58          for (Iterator iterator = contextIds.iterator(); iterator.hasNext();) {
59              String contextID = (String) iterator.next();
60  
61              GeronimoPolicyConfiguration geronimoPolicyConfiguration = roleMapperFactory.getGeronimoPolicyConfiguration(contextID);
62              geronimoPolicyConfiguration.setPrincipalRoleMapping(principalRoleMap);
63          }
64  
65      }
66  
67  
68      public void uninstall() throws PolicyContextException {
69      }
70  
71  
72      public static final GBeanInfo GBEAN_INFO;
73  
74      static {
75          GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(ApplicationPrincipalRoleConfigurationManager.class, NameFactory.JACC_MANAGER);
76          infoBuilder.addAttribute("principalRoleMap", Map.class, true);
77          infoBuilder.addInterface(PrincipalRoleMapper.class);
78          infoBuilder.setConstructor(new String[] {"principalRoleMap"});
79          GBEAN_INFO = infoBuilder.getBeanInfo();
80      }
81  
82      public GBeanInfo getGBeanInfo() {
83          return GBEAN_INFO;
84      }
85  }