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 * SubjectRegistrationLoginModule registers the Subject with geronimo and adds an identification principal. 036 * 037 * This login module does not check credentials so it should never be able to cause a login to succeed. 038 * Therefore the lifecycle methods must return false to indicate success or throw a LoginException to indicate failure. 039 * 040 * @version $Rev: 565912 $ $Date: 2007-08-14 17:03:11 -0400 (Tue, 14 Aug 2007) $ 041 */ 042 public class SubjectRegistrationLoginModule implements LoginModule { 043 044 private Subject subject; 045 046 public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) { 047 this.subject = subject; 048 } 049 050 public boolean login() throws LoginException { 051 return false; 052 } 053 054 public boolean commit() throws LoginException { 055 SubjectId id = ContextManager.registerSubject(subject); 056 IdentificationPrincipal principal = new IdentificationPrincipal(id); 057 subject.getPrincipals().add(principal); 058 return false; 059 } 060 061 public boolean abort() throws LoginException { 062 return false; 063 } 064 065 public boolean logout() throws LoginException { 066 ContextManager.unregisterSubject(subject); 067 return false; 068 } 069 }