View Javadoc

1   /**
2    *  Licensed to the Apache Software Foundation (ASF) under one or more
3    *  contributor license agreements.  See the NOTICE file distributed with
4    *  this work for additional information regarding copyright ownership.
5    *  The ASF licenses this file to You under the Apache License, Version 2.0
6    *  (the "License"); you may not use this file except in compliance with
7    *  the License.  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 javax.security.auth.message.config;
18  
19  import java.security.PrivilegedActionException;
20  import java.util.Map;
21  
22  import javax.security.auth.AuthPermission;
23  import javax.security.auth.message.AuthException;
24  
25  /**
26   * @version $Rev: 780105 $ $Date: 2009-05-29 13:42:00 -0700 (Fri, 29 May 2009) $
27   */
28  public abstract class AuthConfigFactory {
29  
30      public static final String DEFAULT_FACTORY_SECURITY_PROPERTY = "authconfigprovider.factory";
31      private static final String DEFAULT_JASPI_AUTHCONFIGFACTORYIMPL = "org.apache.geronimo.components.jaspi.AuthConfigFactoryImpl";
32  
33      private static AuthConfigFactory factory;
34      private static ClassLoader contextClassLoader;
35  
36      static {
37          contextClassLoader = (ClassLoader) java.security.AccessController
38                  .doPrivileged(new java.security.PrivilegedAction() {
39                      public Object run() {
40                          return Thread.currentThread().getContextClassLoader();
41                      }
42                  });
43      }
44  
45      public static AuthConfigFactory getFactory() {
46          SecurityManager sm = System.getSecurityManager();
47          if (sm != null) {
48              sm.checkPermission(new AuthPermission("getAuthConfigFactory"));
49          }
50          if (factory == null) {
51              String className = (String) java.security.AccessController
52                      .doPrivileged(new java.security.PrivilegedAction() {
53                          public Object run() {
54                              return java.security.Security.getProperty(DEFAULT_FACTORY_SECURITY_PROPERTY);
55                          }
56                      });
57              if (className == null) {
58                  className = DEFAULT_JASPI_AUTHCONFIGFACTORYIMPL;
59              }
60              try {
61                  final String finalClassName = className;
62                  factory = (AuthConfigFactory) java.security.AccessController
63                          .doPrivileged(new java.security.PrivilegedExceptionAction() {
64                              public Object run() throws ClassNotFoundException, InstantiationException,
65                                      IllegalAccessException {
66                                  return Class.forName(finalClassName, true, contextClassLoader).newInstance();
67                              }
68                          });
69              } catch (PrivilegedActionException e) {
70                  Exception inner = e.getException();
71                  if (inner instanceof InstantiationException) {
72                      throw (SecurityException) new SecurityException("AuthConfigFactory error:"
73                              + inner.getCause().getMessage()).initCause(inner.getCause());
74                  } else {
75                      throw (SecurityException) new SecurityException("AuthConfigFactory error: " + inner).initCause(inner);
76                  }
77              }
78          }
79          return factory;
80      }
81  
82      public static void setFactory(AuthConfigFactory factory) {
83          SecurityManager sm = System.getSecurityManager();
84          if (sm != null) {
85              sm.checkPermission(new AuthPermission("setAuthConfigFactory"));
86          }
87          AuthConfigFactory.factory = factory;
88      }
89  
90  
91      public AuthConfigFactory() {
92      }
93  
94      public abstract String[] detachListener(RegistrationListener listener, String layer, String appContext);
95  
96      public abstract AuthConfigProvider getConfigProvider(String layer, String appContext, RegistrationListener listener);
97  
98      public abstract RegistrationContext getRegistrationContext(String registrationID);
99  
100     public abstract String[] getRegistrationIDs(AuthConfigProvider provider);
101 
102     public abstract void refresh();
103 
104     public abstract String registerConfigProvider(AuthConfigProvider provider, String layer, String appContext, String description);
105 
106     public abstract String registerConfigProvider(String className, Map properties, String layer, String appContext, String description);
107 
108     public abstract boolean removeRegistration(String registrationID);
109 
110     public static interface RegistrationContext {
111 
112         String getAppContext();
113 
114         String getDescription();
115 
116         String getMessageLayer();
117 
118         boolean isPersistent();
119 
120     }
121 
122 }