Path: blob/master/src/java.base/share/classes/javax/security/auth/login/AppConfigurationEntry.java
67848 views
/*1* Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.security.auth.login;2627import java.util.Map;28import java.util.Collections;2930/**31* This class represents a single {@code LoginModule} entry32* configured for the application specified in the33* {@code getAppConfigurationEntry(String appName)}34* method in the {@code Configuration} class. Each respective35* {@code AppConfigurationEntry} contains a {@code LoginModule} name,36* a control flag (specifying whether this {@code LoginModule} is37* REQUIRED, REQUISITE, SUFFICIENT, or OPTIONAL), and LoginModule-specific38* options. Please refer to the {@code Configuration} class for39* more information on the different control flags and their semantics.40*41* @since 1.442* @see javax.security.auth.login.Configuration43*/44public class AppConfigurationEntry {4546private String loginModuleName;47private LoginModuleControlFlag controlFlag;48private Map<String,?> options;4950/**51* Default constructor for this class.52*53* <p> This entry represents a single {@code LoginModule}54* entry configured for the application specified in the55* {@code getAppConfigurationEntry(String appName)}56* method from the {@code Configuration} class.57*58* @param loginModuleName String representing the class name of the59* {@code LoginModule} configured for the60* specified application.61*62* @param controlFlag either REQUIRED, REQUISITE, SUFFICIENT,63* or OPTIONAL.64*65* @param options the options configured for this {@code LoginModule}.66*67* @exception IllegalArgumentException if {@code loginModuleName}68* is null, if {@code LoginModuleName}69* has a length of 0, if {@code controlFlag}70* is not either REQUIRED, REQUISITE, SUFFICIENT71* or OPTIONAL, or if {@code options} is null.72*/73public AppConfigurationEntry(String loginModuleName,74LoginModuleControlFlag controlFlag,75Map<String,?> options)76{77if (loginModuleName == null || loginModuleName.isEmpty() ||78(controlFlag != LoginModuleControlFlag.REQUIRED &&79controlFlag != LoginModuleControlFlag.REQUISITE &&80controlFlag != LoginModuleControlFlag.SUFFICIENT &&81controlFlag != LoginModuleControlFlag.OPTIONAL) ||82options == null)83throw new IllegalArgumentException();8485this.loginModuleName = loginModuleName;86this.controlFlag = controlFlag;87this.options = Collections.unmodifiableMap(options);88}8990/**91* Get the class name of the configured {@code LoginModule}.92*93* @return the class name of the configured {@code LoginModule} as94* a String.95*/96public String getLoginModuleName() {97return loginModuleName;98}99100/**101* Return the controlFlag102* (either REQUIRED, REQUISITE, SUFFICIENT, or OPTIONAL)103* for this {@code LoginModule}.104*105* @return the controlFlag106* (either REQUIRED, REQUISITE, SUFFICIENT, or OPTIONAL)107* for this {@code LoginModule}.108*/109public LoginModuleControlFlag getControlFlag() {110return controlFlag;111}112113/**114* Get the options configured for this {@code LoginModule}.115*116* @return the options configured for this {@code LoginModule}117* as an unmodifiable {@code Map}.118*/119public Map<String,?> getOptions() {120return options;121}122123/**124* This class represents whether or not a {@code LoginModule}125* is REQUIRED, REQUISITE, SUFFICIENT or OPTIONAL.126*/127public static class LoginModuleControlFlag {128129private String controlFlag;130131/**132* Required {@code LoginModule}.133*/134public static final LoginModuleControlFlag REQUIRED =135new LoginModuleControlFlag("required");136137/**138* Requisite {@code LoginModule}.139*/140public static final LoginModuleControlFlag REQUISITE =141new LoginModuleControlFlag("requisite");142143/**144* Sufficient {@code LoginModule}.145*/146public static final LoginModuleControlFlag SUFFICIENT =147new LoginModuleControlFlag("sufficient");148149/**150* Optional {@code LoginModule}.151*/152public static final LoginModuleControlFlag OPTIONAL =153new LoginModuleControlFlag("optional");154155private LoginModuleControlFlag(String controlFlag) {156this.controlFlag = controlFlag;157}158159/**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*/168public String toString() {169return (sun.security.util.ResourcesMgr.getString170("LoginModuleControlFlag.") + controlFlag);171}172}173}174175176