Home » geronimo-2.2-source-release » org.apache.geronimo.security.jaspi » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one
    3    * or more contributor license agreements.  See the NOTICE file
    4    * distributed with this work for additional information
    5    * regarding copyright ownership.  The ASF licenses this file
    6    * to you under the Apache License, Version 2.0 (the
    7    * "License"); you may not use this file except in compliance
    8    * with the License.  You may obtain a copy of the License at
    9    *
   10    *  http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    * Unless required by applicable law or agreed to in writing,
   13    * software distributed under the License is distributed on an
   14    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15    * KIND, either express or implied.  See the License for the
   16    * specific language governing permissions and limitations
   17    * under the License.
   18    */
   19   
   20   
   21   package org.apache.geronimo.security.jaspi;
   22   
   23   import java.io.StringReader;
   24   import java.io.IOException;
   25   
   26   import javax.security.auth.message.config.AuthConfigFactory;
   27   import javax.security.auth.message.config.AuthConfigProvider;
   28   import javax.security.auth.message.config.AuthConfig;
   29   import javax.security.auth.message.AuthException;
   30   import javax.security.auth.callback.CallbackHandler;
   31   import javax.xml.bind.JAXBException;
   32   import javax.xml.parsers.ParserConfigurationException;
   33   import javax.xml.stream.XMLStreamException;
   34   
   35   import org.apache.geronimo.gbean.annotation.GBean;
   36   import org.apache.geronimo.gbean.annotation.ParamAttribute;
   37   import org.apache.geronimo.gbean.annotation.ParamSpecial;
   38   import org.apache.geronimo.gbean.annotation.SpecialAttributeType;
   39   import org.apache.geronimo.gbean.GBeanLifecycle;
   40   import org.apache.geronimo.components.jaspi.model.ConfigProviderType;
   41   import org.apache.geronimo.components.jaspi.model.JaspiUtil;
   42   import org.apache.geronimo.components.jaspi.model.JaspiXmlUtil;
   43   import org.apache.geronimo.components.jaspi.model.ClientAuthConfigType;
   44   import org.apache.geronimo.components.jaspi.model.ClientAuthContextType;
   45   import org.apache.geronimo.components.jaspi.model.AuthModuleType;
   46   import org.apache.geronimo.components.jaspi.model.ServerAuthConfigType;
   47   import org.apache.geronimo.components.jaspi.model.ServerAuthContextType;
   48   import org.apache.geronimo.components.jaspi.ClassLoaderLookup;
   49   import org.apache.geronimo.components.jaspi.ConstantClassLoaderLookup;
   50   import org.xml.sax.SAXException;
   51   
   52   /**
   53    * Holds a bit of xml configuring an AuthConfigProvider, [Client|Server][AuthConfig|AuthContext|AuthModule]
   54    * and registers/unregisters it when start/stopped.
   55    *
   56    * @version $Rev: 720842 $ $Date: 2008-11-26 05:18:49 -0800 (Wed, 26 Nov 2008) $
   57    */
   58   
   59   @GBean
   60   public class AuthConfigProviderGBean implements GBeanLifecycle {
   61   
   62       private final String registrationID;
   63   
   64       public AuthConfigProviderGBean(
   65               @ParamAttribute(name = "config") String config,
   66               @ParamSpecial(type = SpecialAttributeType.classLoader) ClassLoader classLoader) throws AuthException, JAXBException, IOException, ParserConfigurationException, SAXException, XMLStreamException {
   67           ClassLoaderLookup classLoaderLookup = new ConstantClassLoaderLookup(classLoader);
   68   
   69           String messageLayer = null;
   70           String appContext = null;
   71   
   72           AuthConfigFactory authConfigFactory = AuthConfigFactory.getFactory();
   73           ConfigProviderType configProviderType = JaspiXmlUtil.loadConfigProvider(new StringReader(config));
   74           AuthConfigProvider authConfigProvider = JaspiUtil.wraptAuthConfigProvider(configProviderType, classLoaderLookup);
   75           registrationID = authConfigFactory.registerConfigProvider(authConfigProvider, messageLayer, appContext, null);
   76       }
   77   
   78   
   79       /**
   80        * Starts the GBean.  This informs the GBean that it is about to transition to the running state.
   81        *
   82        * @throws Exception if the target failed to start; this will cause a transition to the failed state
   83        */
   84       public void doStart() throws Exception {
   85       }
   86   
   87       /**
   88        * Stops the target.  This informs the GBean that it is about to transition to the stopped state.
   89        *
   90        * @throws Exception if the target failed to stop; this will cause a transition to the failed state
   91        */
   92       public void doStop() throws Exception {
   93           AuthConfigFactory authConfigFactory = AuthConfigFactory.getFactory();
   94           authConfigFactory.removeRegistration(registrationID);
   95       }
   96   
   97       /**
   98        * Fails the GBean.  This informs the GBean that it is about to transition to the failed state.
   99        */
  100       public void doFail() {
  101       }
  102   }

Home » geronimo-2.2-source-release » org.apache.geronimo.security.jaspi » [javadoc | source]