001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019
020
021 package org.apache.geronimo.security.jaas;
022
023 import java.util.Arrays;
024 import java.util.Collections;
025 import java.util.List;
026 import java.util.Map;
027
028 import javax.security.auth.Subject;
029 import javax.security.auth.callback.CallbackHandler;
030 import javax.security.auth.login.LoginException;
031 import javax.security.auth.spi.LoginModule;
032
033 /**
034 * This provides a workaround to the problem of the LoginContext not knowing what classloader to use for creating LoginModules.
035 *
036 * @version $Revision: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
037 */
038 public class ClassOptionLoginModule implements LoginModule {
039 public static final String CLASS_OPTION = WrappingLoginModule.class.getName() + ".LoginModuleClass";
040 public static final List<String> supportedOptions = Collections.unmodifiableList(Arrays.asList(CLASS_OPTION));
041 private Subject subject;
042 private LoginModule delegate;
043
044
045 public ClassOptionLoginModule() {
046 }
047
048 public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) {
049 this.subject = subject;
050 Class lmClass = (Class) options.get(CLASS_OPTION);
051 try {
052 delegate = (LoginModule) lmClass.newInstance();
053 } catch (Exception e) {
054 throw new RuntimeException("Could not create login module instance", e);
055 }
056 delegate.initialize(subject, callbackHandler, sharedState, options);
057 }
058
059 public boolean login() throws LoginException {
060 return delegate.login();
061 }
062
063 public boolean abort() throws LoginException {
064 return delegate.abort();
065 }
066
067 public boolean commit() throws LoginException {
068 return delegate.commit();
069 }
070
071 public boolean logout() throws LoginException {
072 return delegate.logout();
073 }
074 }