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.server;
018
019 import java.io.Serializable;
020 import java.util.Map;
021 import javax.security.auth.spi.LoginModule;
022
023 import org.apache.geronimo.common.GeronimoSecurityException;
024 import org.apache.geronimo.security.jaas.LoginModuleControlFlag;
025
026
027 /**
028 * Describes the configuration of a LoginModule -- its name, class, control
029 * flag, options, and the Geronimo extension for whether it should run on
030 * the client side or server side.
031 *
032 * @version $Rev: 487175 $ $Date: 2006-12-14 03:10:31 -0800 (Thu, 14 Dec 2006) $
033 */
034 public class JaasLoginModuleConfiguration implements Serializable {
035 private final boolean serverSide;
036 private final String loginDomainName;
037 private final LoginModuleControlFlag flag;
038 private final String loginModuleName;
039 private final Map options;
040 private final boolean wrapPrincipals;
041 private final transient ClassLoader classLoader;
042
043 public JaasLoginModuleConfiguration(String loginModuleName, LoginModuleControlFlag flag, Map options,
044 boolean serverSide, String loginDomainName, boolean wrapPrincipals, ClassLoader classLoader)
045 {
046 this.serverSide = serverSide;
047 this.flag = flag;
048 this.loginModuleName = loginModuleName;
049 this.options = options;
050 this.loginDomainName = loginDomainName;
051 this.wrapPrincipals = wrapPrincipals;
052 this.classLoader = classLoader;
053 }
054
055 public JaasLoginModuleConfiguration(String loginModuleName, LoginModuleControlFlag flag, Map options, boolean serverSide, ClassLoader classLoader) {
056 this(loginModuleName, flag, options, serverSide, null, false, classLoader);
057 }
058
059 public String getLoginModuleClassName() {
060 return loginModuleName;
061 }
062
063 public LoginModule getLoginModule(ClassLoader loader) throws GeronimoSecurityException {
064 //TODO determine if this is ever called after serialization: if not the classloader passed in is unnecessary.
065 if (classLoader != null) {
066 loader = classLoader;
067 }
068 try {
069 return (LoginModule) loader.loadClass(loginModuleName).newInstance();
070 } catch (Exception e) {
071 throw new GeronimoSecurityException("Unable to instantiate login module", e);
072 }
073 }
074
075 public boolean isServerSide() {
076 return serverSide;
077 }
078
079 public LoginModuleControlFlag getFlag() {
080 return flag;
081 }
082
083 public Map getOptions() {
084 return options;
085 }
086
087 public String getLoginDomainName() {
088 return loginDomainName;
089 }
090
091 public boolean isWrapPrincipals() {
092 return wrapPrincipals;
093 }
094 }