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.Map;
024
025 import javax.security.auth.spi.LoginModule;
026 import javax.security.auth.Subject;
027 import javax.security.auth.login.LoginException;
028 import javax.security.auth.callback.CallbackHandler;
029
030 import org.apache.geronimo.security.ContextManager;
031 import org.apache.geronimo.security.SubjectId;
032 import org.apache.geronimo.security.IdentificationPrincipal;
033
034 /**
035 <<<<<<< .working
036 * @version $Rev: 565936 $ $Date: 2007-08-14 17:54:50 -0400 (Tue, 14 Aug 2007) $
037 =======
038 * SubjectRegistrationLoginModule registers the Subject with geronimo and adds an identification principal.
039 *
040 * This login module does not check credentials so it should never be able to cause a login to succeed.
041 * Therefore the lifecycle methods must return false to indicate success or throw a LoginException to indicate failure.
042 *
043 * @version $Rev: 565936 $ $Date: 2007-08-14 17:54:50 -0400 (Tue, 14 Aug 2007) $
044 >>>>>>> .merge-right.r565912
045 */
046 public class SubjectRegistrationLoginModule implements LoginModule {
047
048 private Subject subject;
049
050 public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) {
051 this.subject = subject;
052 }
053
054 public boolean login() throws LoginException {
055 return false;
056 }
057
058 public boolean commit() throws LoginException {
059 SubjectId id = ContextManager.registerSubject(subject);
060 IdentificationPrincipal principal = new IdentificationPrincipal(id);
061 subject.getPrincipals().add(principal);
062 return false;
063 }
064
065 public boolean abort() throws LoginException {
066 return false;
067 }
068
069 public boolean logout() throws LoginException {
070 ContextManager.unregisterSubject(subject);
071 return false;
072 }
073 }