Path: blob/master/src/java.base/share/classes/javax/security/auth/callback/NameCallback.java
41161 views
/*1* Copyright (c) 1999, 2019, 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.callback;2627/**28* <p> Underlying security services instantiate and pass a29* {@code NameCallback} to the {@code handle}30* method of a {@code CallbackHandler} to retrieve name information.31*32* @since 1.433* @see javax.security.auth.callback.CallbackHandler34*/35public class NameCallback implements Callback, java.io.Serializable {3637@java.io.Serial38private static final long serialVersionUID = 3770938795909392253L;3940/**41* @serial42* @since 1.443*/44private String prompt;45/**46* @serial47* @since 1.448*/49private String defaultName;50/**51* @serial52* @since 1.453*/54private String inputName;5556/**57* Construct a {@code NameCallback} with a prompt.58*59* @param prompt the prompt used to request the name.60*61* @exception IllegalArgumentException if {@code prompt} is null62* or if {@code prompt} has a length of 0.63*/64public NameCallback(String prompt) {65if (prompt == null || prompt.isEmpty())66throw new IllegalArgumentException();67this.prompt = prompt;68}6970/**71* Construct a {@code NameCallback} with a prompt72* and default name.73*74* @param prompt the prompt used to request the information.75*76* @param defaultName the name to be used as the default name displayed77* with the prompt.78*79* @exception IllegalArgumentException if {@code prompt} is null,80* if {@code prompt} has a length of 0,81* if {@code defaultName} is null,82* or if {@code defaultName} has a length of 0.83*/84public NameCallback(String prompt, String defaultName) {85if (prompt == null || prompt.isEmpty() ||86defaultName == null || defaultName.isEmpty())87throw new IllegalArgumentException();8889this.prompt = prompt;90this.defaultName = defaultName;91}9293/**94* Get the prompt.95*96* @return the prompt.97*/98public String getPrompt() {99return prompt;100}101102/**103* Get the default name.104*105* @return the default name, or null if this {@code NameCallback}106* was not instantiated with a {@code defaultName}.107*/108public String getDefaultName() {109return defaultName;110}111112/**113* Set the retrieved name.114*115* @param name the retrieved name (which may be null).116*117* @see #getName118*/119public void setName(String name) {120this.inputName = name;121}122123/**124* Get the retrieved name.125*126* @return the retrieved name (which may be null)127*128* @see #setName129*/130public String getName() {131return inputName;132}133}134135136