001 /*
002 * Copyright 1998-2006 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.security.auth.login;
027
028 import java.util.Map;
029 import java.util.Collections;
030
031 /**
032 * This class represents a single <code>LoginModule</code> entry
033 * configured for the application specified in the
034 * <code>getAppConfigurationEntry(String appName)</code>
035 * method in the <code>Configuration</code> class. Each respective
036 * <code>AppConfigurationEntry</code> contains a <code>LoginModule</code> name,
037 * a control flag (specifying whether this <code>LoginModule</code> is
038 * REQUIRED, REQUISITE, SUFFICIENT, or OPTIONAL), and LoginModule-specific
039 * options. Please refer to the <code>Configuration</code> class for
040 * more information on the different control flags and their semantics.
041 *
042 * @version 1.43, 05/05/07
043 * @see javax.security.auth.login.Configuration
044 */
045 public class AppConfigurationEntry {
046
047 private String loginModuleName;
048 private LoginModuleControlFlag controlFlag;
049 private Map<String, ?> options;
050
051 /**
052 * Default constructor for this class.
053 *
054 * <p> This entry represents a single <code>LoginModule</code>
055 * entry configured for the application specified in the
056 * <code>getAppConfigurationEntry(String appName)</code>
057 * method from the <code>Configuration</code> class.
058 *
059 * @param loginModuleName String representing the class name of the
060 * <code>LoginModule</code> configured for the
061 * specified application. <p>
062 *
063 * @param controlFlag either REQUIRED, REQUISITE, SUFFICIENT,
064 * or OPTIONAL. <p>
065 *
066 * @param options the options configured for this <code>LoginModule</code>.
067 *
068 * @exception IllegalArgumentException if <code>loginModuleName</code>
069 * is null, if <code>LoginModuleName</code>
070 * has a length of 0, if <code>controlFlag</code>
071 * is not either REQUIRED, REQUISITE, SUFFICIENT
072 * or OPTIONAL, or if <code>options</code> is null.
073 */
074 public AppConfigurationEntry(String loginModuleName,
075 LoginModuleControlFlag controlFlag, Map<String, ?> options) {
076 if (loginModuleName == null
077 || loginModuleName.length() == 0
078 || (controlFlag != LoginModuleControlFlag.REQUIRED
079 && controlFlag != LoginModuleControlFlag.REQUISITE
080 && controlFlag != LoginModuleControlFlag.SUFFICIENT && controlFlag != LoginModuleControlFlag.OPTIONAL)
081 || options == null)
082 throw new IllegalArgumentException();
083
084 this .loginModuleName = loginModuleName;
085 this .controlFlag = controlFlag;
086 this .options = Collections.unmodifiableMap(options);
087 }
088
089 /**
090 * Get the class name of the configured <code>LoginModule</code>.
091 *
092 * @return the class name of the configured <code>LoginModule</code> as
093 * a String.
094 */
095 public String getLoginModuleName() {
096 return loginModuleName;
097 }
098
099 /**
100 * Return the controlFlag
101 * (either REQUIRED, REQUISITE, SUFFICIENT, or OPTIONAL)
102 * for this <code>LoginModule</code>.
103 *
104 * @return the controlFlag
105 * (either REQUIRED, REQUISITE, SUFFICIENT, or OPTIONAL)
106 * for this <code>LoginModule</code>.
107 */
108 public LoginModuleControlFlag getControlFlag() {
109 return controlFlag;
110 }
111
112 /**
113 * Get the options configured for this <code>LoginModule</code>.
114 *
115 * @return the options configured for this <code>LoginModule</code>
116 * as an unmodifiable <code>Map</code>.
117 */
118 public Map<String, ?> getOptions() {
119 return options;
120 }
121
122 /**
123 * This class represents whether or not a <code>LoginModule</code>
124 * is REQUIRED, REQUISITE, SUFFICIENT or OPTIONAL.
125 */
126 public static class LoginModuleControlFlag {
127
128 private String controlFlag;
129
130 /**
131 * Required <code>LoginModule</code>.
132 */
133 public static final LoginModuleControlFlag REQUIRED = new LoginModuleControlFlag(
134 "required");
135
136 /**
137 * Requisite <code>LoginModule</code>.
138 */
139 public static final LoginModuleControlFlag REQUISITE = new LoginModuleControlFlag(
140 "requisite");
141
142 /**
143 * Sufficient <code>LoginModule</code>.
144 */
145 public static final LoginModuleControlFlag SUFFICIENT = new LoginModuleControlFlag(
146 "sufficient");
147
148 /**
149 * Optional <code>LoginModule</code>.
150 */
151 public static final LoginModuleControlFlag OPTIONAL = new LoginModuleControlFlag(
152 "optional");
153
154 private LoginModuleControlFlag(String controlFlag) {
155 this .controlFlag = controlFlag;
156 }
157
158 /**
159 * Return a String representation of this controlFlag.
160 *
161 * <p> The String has the format, "LoginModuleControlFlag: <i>flag</i>",
162 * where <i>flag</i> is either <i>required</i>, <i>requisite</i>,
163 * <i>sufficient</i>, or <i>optional</i>.
164 *
165 * @return a String representation of this controlFlag.
166 */
167 public String toString() {
168 return (sun.security.util.ResourcesMgr
169 .getString("LoginModuleControlFlag: ") + controlFlag);
170 }
171 }
172 }
|