J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 1998-2006 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | package javax.security.auth.login; |
| 27 | |
| 28 | import java.util.Map; |
| 29 | import java.util.Collections; |
| 30 | |
| 31 | /** |
| 32 | * This class represents a single <code>LoginModule</code> entry |
| 33 | * configured for the application specified in the |
| 34 | * <code>getAppConfigurationEntry(String appName)</code> |
| 35 | * method in the <code>Configuration</code> class. Each respective |
| 36 | * <code>AppConfigurationEntry</code> contains a <code>LoginModule</code> name, |
| 37 | * a control flag (specifying whether this <code>LoginModule</code> is |
| 38 | * REQUIRED, REQUISITE, SUFFICIENT, or OPTIONAL), and LoginModule-specific |
| 39 | * options. Please refer to the <code>Configuration</code> class for |
| 40 | * more information on the different control flags and their semantics. |
| 41 | * |
| 42 | * @see javax.security.auth.login.Configuration |
| 43 | */ |
| 44 | public class AppConfigurationEntry { |
| 45 | |
| 46 | private String loginModuleName; |
| 47 | private LoginModuleControlFlag controlFlag; |
| 48 | private Map<String,?> options; |
| 49 | |
| 50 | /** |
| 51 | * Default constructor for this class. |
| 52 | * |
| 53 | * <p> This entry represents a single <code>LoginModule</code> |
| 54 | * entry configured for the application specified in the |
| 55 | * <code>getAppConfigurationEntry(String appName)</code> |
| 56 | * method from the <code>Configuration</code> class. |
| 57 | * |
| 58 | * @param loginModuleName String representing the class name of the |
| 59 | * <code>LoginModule</code> configured for the |
| 60 | * specified application. <p> |
| 61 | * |
| 62 | * @param controlFlag either REQUIRED, REQUISITE, SUFFICIENT, |
| 63 | * or OPTIONAL. <p> |
| 64 | * |
| 65 | * @param options the options configured for this <code>LoginModule</code>. |
| 66 | * |
| 67 | * @exception IllegalArgumentException if <code>loginModuleName</code> |
| 68 | * is null, if <code>LoginModuleName</code> |
| 69 | * has a length of 0, if <code>controlFlag</code> |
| 70 | * is not either REQUIRED, REQUISITE, SUFFICIENT |
| 71 | * or OPTIONAL, or if <code>options</code> is null. |
| 72 | */ |
| 73 | public AppConfigurationEntry(String loginModuleName, |
| 74 | LoginModuleControlFlag controlFlag, |
| 75 | Map<String,?> options) |
| 76 | { |
| 77 | if (loginModuleName == null || loginModuleName.length() == 0 || |
| 78 | (controlFlag != LoginModuleControlFlag.REQUIRED && |
| 79 | controlFlag != LoginModuleControlFlag.REQUISITE && |
| 80 | controlFlag != LoginModuleControlFlag.SUFFICIENT && |
| 81 | controlFlag != LoginModuleControlFlag.OPTIONAL) || |
| 82 | options == null) |
| 83 | throw new IllegalArgumentException(); |
| 84 | |
| 85 | this.loginModuleName = loginModuleName; |
| 86 | this.controlFlag = controlFlag; |
| 87 | this.options = Collections.unmodifiableMap(options); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Get the class name of the configured <code>LoginModule</code>. |
| 92 | * |
| 93 | * @return the class name of the configured <code>LoginModule</code> as |
| 94 | * a String. |
| 95 | */ |
| 96 | public String getLoginModuleName() { |
| 97 | return loginModuleName; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Return the controlFlag |
| 102 | * (either REQUIRED, REQUISITE, SUFFICIENT, or OPTIONAL) |
| 103 | * for this <code>LoginModule</code>. |
| 104 | * |
| 105 | * @return the controlFlag |
| 106 | * (either REQUIRED, REQUISITE, SUFFICIENT, or OPTIONAL) |
| 107 | * for this <code>LoginModule</code>. |
| 108 | */ |
| 109 | public LoginModuleControlFlag getControlFlag() { |
| 110 | return controlFlag; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Get the options configured for this <code>LoginModule</code>. |
| 115 | * |
| 116 | * @return the options configured for this <code>LoginModule</code> |
| 117 | * as an unmodifiable <code>Map</code>. |
| 118 | */ |
| 119 | public Map<String,?> getOptions() { |
| 120 | return options; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * This class represents whether or not a <code>LoginModule</code> |
| 125 | * is REQUIRED, REQUISITE, SUFFICIENT or OPTIONAL. |
| 126 | */ |
| 127 | public static class LoginModuleControlFlag { |
| 128 | |
| 129 | private String controlFlag; |
| 130 | |
| 131 | /** |
| 132 | * Required <code>LoginModule</code>. |
| 133 | */ |
| 134 | public static final LoginModuleControlFlag REQUIRED = |
| 135 | new LoginModuleControlFlag("required"); |
| 136 | |
| 137 | /** |
| 138 | * Requisite <code>LoginModule</code>. |
| 139 | */ |
| 140 | public static final LoginModuleControlFlag REQUISITE = |
| 141 | new LoginModuleControlFlag("requisite"); |
| 142 | |
| 143 | /** |
| 144 | * Sufficient <code>LoginModule</code>. |
| 145 | */ |
| 146 | public static final LoginModuleControlFlag SUFFICIENT = |
| 147 | new LoginModuleControlFlag("sufficient"); |
| 148 | |
| 149 | /** |
| 150 | * Optional <code>LoginModule</code>. |
| 151 | */ |
| 152 | public static final LoginModuleControlFlag OPTIONAL = |
| 153 | new LoginModuleControlFlag("optional"); |
| 154 | |
| 155 | private LoginModuleControlFlag(String controlFlag) { |
| 156 | this.controlFlag = controlFlag; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Return a String representation of this controlFlag. |
| 161 | * |
| 162 | * <p> The String has the format, "LoginModuleControlFlag: <i>flag</i>", |
| 163 | * where <i>flag</i> is either <i>required</i>, <i>requisite</i>, |
| 164 | * <i>sufficient</i>, or <i>optional</i>. |
| 165 | * |
| 166 | * @return a String representation of this controlFlag. |
| 167 | */ |
| 168 | public String toString() { |
| 169 | return (sun.security.util.ResourcesMgr.getString |
| 170 | ("LoginModuleControlFlag: ") + controlFlag); |
| 171 | } |
| 172 | } |
| 173 | } |