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.message.module.ServerAuthModule; 31 import javax.security.auth.callback.CallbackHandler; 32 import javax.xml.bind.JAXBException; 33 import javax.xml.parsers.ParserConfigurationException; 34 import javax.xml.stream.XMLStreamException; 35 36 import org.apache.geronimo.gbean.annotation.GBean; 37 import org.apache.geronimo.gbean.annotation.ParamAttribute; 38 import org.apache.geronimo.gbean.annotation.ParamSpecial; 39 import org.apache.geronimo.gbean.annotation.SpecialAttributeType; 40 import org.apache.geronimo.gbean.GBeanLifecycle; 41 import org.apache.geronimo.components.jaspi.model.ConfigProviderType; 42 import org.apache.geronimo.components.jaspi.model.JaspiUtil; 43 import org.apache.geronimo.components.jaspi.model.JaspiXmlUtil; 44 import org.apache.geronimo.components.jaspi.model.ClientAuthConfigType; 45 import org.apache.geronimo.components.jaspi.model.ClientAuthContextType; 46 import org.apache.geronimo.components.jaspi.model.AuthModuleType; 47 import org.apache.geronimo.components.jaspi.model.ServerAuthConfigType; 48 import org.apache.geronimo.components.jaspi.model.ServerAuthContextType; 49 import org.apache.geronimo.components.jaspi.ClassLoaderLookup; 50 import org.apache.geronimo.components.jaspi.ConstantClassLoaderLookup; 51 import org.xml.sax.SAXException; 52 53 /** 54 * Holds a bit of xml configuring an AuthConfigProvider, [Client|Server][AuthConfig|AuthContext|AuthModule] 55 * and registers/unregisters it when start/stopped. 56 * 57 * @version $Rev: 720842 $ $Date: 2008-11-26 05:18:49 -0800 (Wed, 26 Nov 2008) $ 58 */ 59 60 @GBean 61 public class ClientAuthConfigGBean implements GBeanLifecycle { 62 63 private final String registrationID; 64 65 public ClientAuthConfigGBean( 66 @ParamAttribute(name = "config") String config, 67 @ParamSpecial(type = SpecialAttributeType.classLoader) ClassLoader classLoader) throws AuthException, JAXBException, IOException, ParserConfigurationException, SAXException, XMLStreamException { 68 ClassLoaderLookup classLoaderLookup = new ConstantClassLoaderLookup(classLoader); 69 70 AuthConfigFactory authConfigFactory = AuthConfigFactory.getFactory(); 71 ClientAuthContextType clientAuthContextType = JaspiXmlUtil.loadClientAuthContext(new StringReader(config)); 72 AuthConfigProvider authConfigProvider = JaspiUtil.wrapClientAuthContext(clientAuthContextType, true, classLoaderLookup); 73 registrationID = authConfigFactory.registerConfigProvider(authConfigProvider, clientAuthContextType.getMessageLayer(), clientAuthContextType.getAppContext(), null); 74 } 75 76 77 /** 78 * Starts the GBean. This informs the GBean that it is about to transition to the running state. 79 * 80 * @throws Exception if the target failed to start; this will cause a transition to the failed state 81 */ 82 public void doStart() throws Exception { 83 } 84 85 /** 86 * Stops the target. This informs the GBean that it is about to transition to the stopped state. 87 * 88 * @throws Exception if the target failed to stop; this will cause a transition to the failed state 89 */ 90 public void doStop() throws Exception { 91 AuthConfigFactory authConfigFactory = AuthConfigFactory.getFactory(); 92 authConfigFactory.removeRegistration(registrationID); 93 } 94 95 /** 96 * Fails the GBean. This informs the GBean that it is about to transition to the failed state. 97 */ 98 public void doFail() { 99 } 100 }