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 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: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $ 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 }