001 /** 002 * 003 * Copyright 2004 The Apache Software Foundation 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * 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 018 package org.apache.geronimo.security.jaas; 019 020 import java.io.ObjectStreamException; 021 import java.io.Serializable; 022 import javax.security.auth.login.AppConfigurationEntry; 023 024 025 /** 026 * A wrapper for the JAAS login module control flag that is Serializable. 027 * 028 * @version $Rev: 355877 $ $Date: 2005-12-10 18:48:27 -0800 (Sat, 10 Dec 2005) $ 029 */ 030 public class LoginModuleControlFlag implements Serializable { 031 032 private static final LoginModuleControlFlag[] values = new LoginModuleControlFlag[4]; 033 034 public static final LoginModuleControlFlag REQUIRED = new LoginModuleControlFlag(0, AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, "REQUIRED"); 035 public static final LoginModuleControlFlag REQUISITE = new LoginModuleControlFlag(1, AppConfigurationEntry.LoginModuleControlFlag.REQUISITE, "REQUISITE"); 036 public static final LoginModuleControlFlag SUFFICIENT = new LoginModuleControlFlag(2, AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT, "SUFFICIENT"); 037 public static final LoginModuleControlFlag OPTIONAL = new LoginModuleControlFlag(3, AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL, "OPTIONAL"); 038 039 private final int ordinal; 040 private final String toString; 041 private final transient AppConfigurationEntry.LoginModuleControlFlag flag; 042 043 private LoginModuleControlFlag(int ordinal, AppConfigurationEntry.LoginModuleControlFlag flag, String toString) { 044 this.ordinal = ordinal; 045 this.flag = flag; 046 this.toString = toString; 047 values[ordinal] = this; 048 } 049 050 public AppConfigurationEntry.LoginModuleControlFlag getFlag() { 051 return flag; 052 } 053 054 public String toString() { 055 return toString; 056 } 057 058 Object readResolve() throws ObjectStreamException { 059 return values[ordinal]; 060 } 061 062 public static LoginModuleControlFlag getInstance(AppConfigurationEntry.LoginModuleControlFlag flag) { 063 for(int i = 0; i < values.length; i++) { 064 if(values[i].flag == flag) { 065 return values[i]; 066 } 067 } 068 return null; 069 } 070 }