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.jaas;
018    
019    import java.util.Collections;
020    import java.util.Map;
021    
022    import org.apache.geronimo.gbean.GBeanInfo;
023    import org.apache.geronimo.gbean.GBeanInfoBuilder;
024    import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
025    
026    
027    /**
028     * A GBean that wraps a LoginModule, plus options to configure the LoginModule.
029     * If you want to deploy the same LoginModule with different options, you need
030     * more than one of these GBeans.  But if you want two security realms to refer
031     * to exactly the same login module configuration, you can have both realms
032     * refer to a single login module GBean.
033     *
034     * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
035     */
036    public class LoginModuleGBean implements LoginModuleSettings {
037        private String loginDomainName;
038        private String loginModuleClass;
039        private Map<String, Object> options;
040        private final String objectName;
041        private boolean wrapPrincipals;
042        private final ClassLoader classLoader;
043    
044        public LoginModuleGBean(String loginModuleClass, String objectName, boolean wrapPrincipals, Map<String, Object> options, String loginDomainName, ClassLoader classLoader) {
045            this.loginModuleClass = loginModuleClass;
046            this.objectName = objectName;
047            this.wrapPrincipals = wrapPrincipals;
048            this.options = options == null? Collections.<String, Object>emptyMap(): options;
049            this.loginDomainName = loginDomainName;
050            this.classLoader = classLoader;
051        }
052    
053        public String getLoginDomainName() {
054            return loginDomainName;
055        }
056    
057        public void setLoginDomainName(String loginDomainName) {
058            this.loginDomainName = loginDomainName;
059        }
060    
061        public Map<String, Object> getOptions() {
062            return options;
063        }
064    
065        public void setOptions(Map<String, Object> options) {
066            this.options = options;
067        }
068    
069        public String getLoginModuleClass() {
070            return loginModuleClass;
071        }
072    
073        public void setLoginModuleClass(String loginModuleClass) {
074            this.loginModuleClass = loginModuleClass;
075        }
076    
077        public String getObjectName() {
078            return objectName;
079        }
080    
081        public boolean isWrapPrincipals() {
082            return wrapPrincipals;
083        }
084    
085        public void setWrapPrincipals(boolean wrapPrincipals) {
086            this.wrapPrincipals = wrapPrincipals;
087        }
088    
089        public ClassLoader getClassLoader() {
090            return classLoader;
091        }
092    
093        public static final GBeanInfo GBEAN_INFO;
094    
095        static {
096            GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(LoginModuleGBean.class, NameFactory.LOGIN_MODULE);
097            infoFactory.addAttribute("classLoader", ClassLoader.class, false);
098            infoFactory.addInterface(LoginModuleSettings.class, new String[] {"options", "loginModuleClass", "loginDomainName", "wrapPrincipals"},
099                                             new String[] {"options", "loginModuleClass", "wrapPrincipals"} );
100            infoFactory.setConstructor(new String[]{"loginModuleClass", "objectName", "wrapPrincipals", "options", "loginDomainName", "classLoader"});
101    
102            GBEAN_INFO = infoFactory.getBeanInfo();
103        }
104    
105        public static GBeanInfo getGBeanInfo() {
106            return GBEAN_INFO;
107        }
108    }