feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,52 @@
/*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.security.auth.callback;
/**
* <p> Implementations of this interface are passed to a
* {@code CallbackHandler}, allowing underlying security services
* the ability to interact with a calling application to retrieve specific
* authentication data such as usernames and passwords, or to display
* certain information, such as error and warning messages.
*
* <p> {@code Callback} implementations do not retrieve or
* display the information requested by underlying security services.
* {@code Callback} implementations simply provide the means
* to pass such requests to applications, and for applications,
* if appropriate, to return requested information back to the
* underlying security services.
*
* @see javax.security.auth.callback.CallbackHandler
* @see javax.security.auth.callback.ChoiceCallback
* @see javax.security.auth.callback.ConfirmationCallback
* @see javax.security.auth.callback.LanguageCallback
* @see javax.security.auth.callback.NameCallback
* @see javax.security.auth.callback.PasswordCallback
* @see javax.security.auth.callback.TextInputCallback
* @see javax.security.auth.callback.TextOutputCallback
*/
public interface Callback { }

View File

@@ -0,0 +1,150 @@
/*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.security.auth.callback;
/**
* <p> An application implements a {@code CallbackHandler} and passes
* it to underlying security services so that they may interact with
* the application to retrieve specific authentication data,
* such as usernames and passwords, or to display certain information,
* such as error and warning messages.
*
* <p> CallbackHandlers are implemented in an application-dependent fashion.
* For example, implementations for an application with a graphical user
* interface (GUI) may pop up windows to prompt for requested information
* or to display error messages. An implementation may also choose to obtain
* requested information from an alternate source without asking the end user.
*
* <p> Underlying security services make requests for different types
* of information by passing individual Callbacks to the
* {@code CallbackHandler}. The {@code CallbackHandler}
* implementation decides how to retrieve and display information
* depending on the Callbacks passed to it. For example,
* if the underlying service needs a username and password to
* authenticate a user, it uses a {@code NameCallback} and
* {@code PasswordCallback}. The {@code CallbackHandler}
* can then choose to prompt for a username and password serially,
* or to prompt for both in a single window.
*
* <p> A default {@code CallbackHandler} class implementation
* may be specified by setting the value of the
* {@code auth.login.defaultCallbackHandler} security property.
*
* <p> If the security property is set to the fully qualified name of a
* {@code CallbackHandler} implementation class,
* then a {@code LoginContext} will load the specified
* {@code CallbackHandler} and pass it to the underlying LoginModules.
* The {@code LoginContext} only loads the default handler
* if it was not provided one.
*
* <p> All default handler implementations must provide a public
* zero-argument constructor.
*
* @see java.security.Security security properties
*/
public interface CallbackHandler {
/**
* <p> Retrieve or display the information requested in the
* provided Callbacks.
*
* <p> The {@code handle} method implementation checks the
* instance(s) of the {@code Callback} object(s) passed in
* to retrieve or display the requested information.
* The following example is provided to help demonstrate what an
* {@code handle} method implementation might look like.
* This example code is for guidance only. Many details,
* including proper error handling, are left out for simplicity.
*
* <pre>{@code
* public void handle(Callback[] callbacks)
* throws IOException, UnsupportedCallbackException {
*
* for (int i = 0; i < callbacks.length; i++) {
* if (callbacks[i] instanceof TextOutputCallback) {
*
* // display the message according to the specified type
* TextOutputCallback toc = (TextOutputCallback)callbacks[i];
* switch (toc.getMessageType()) {
* case TextOutputCallback.INFORMATION:
* System.out.println(toc.getMessage());
* break;
* case TextOutputCallback.ERROR:
* System.out.println("ERROR: " + toc.getMessage());
* break;
* case TextOutputCallback.WARNING:
* System.out.println("WARNING: " + toc.getMessage());
* break;
* default:
* throw new IOException("Unsupported message type: " +
* toc.getMessageType());
* }
*
* } else if (callbacks[i] instanceof NameCallback) {
*
* // prompt the user for a username
* NameCallback nc = (NameCallback)callbacks[i];
*
* // ignore the provided defaultName
* System.err.print(nc.getPrompt());
* System.err.flush();
* nc.setName((new BufferedReader
* (new InputStreamReader(System.in))).readLine());
*
* } else if (callbacks[i] instanceof PasswordCallback) {
*
* // prompt the user for sensitive information
* PasswordCallback pc = (PasswordCallback)callbacks[i];
* System.err.print(pc.getPrompt());
* System.err.flush();
* pc.setPassword(readPassword(System.in));
*
* } else {
* throw new UnsupportedCallbackException
* (callbacks[i], "Unrecognized Callback");
* }
* }
* }
*
* // Reads user password from given input stream.
* private char[] readPassword(InputStream in) throws IOException {
* // insert code to read a user password from the input stream
* }
* }</pre>
*
* @param callbacks an array of {@code Callback} objects provided
* by an underlying security service which contains
* the information requested to be retrieved or displayed.
*
* @exception java.io.IOException if an input or output error occurs. <p>
*
* @exception UnsupportedCallbackException if the implementation of this
* method does not support one or more of the Callbacks
* specified in the {@code callbacks} parameter.
*/
void handle(Callback[] callbacks)
throws java.io.IOException, UnsupportedCallbackException;
}

View File

@@ -0,0 +1,248 @@
/*
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.security.auth.callback;
import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
/**
* <p> Underlying security services instantiate and pass a
* {@code ChoiceCallback} to the {@code handle}
* method of a {@code CallbackHandler} to display a list of choices
* and to retrieve the selected choice(s).
*
* @see javax.security.auth.callback.CallbackHandler
*/
public class ChoiceCallback implements Callback, java.io.Serializable {
private static final long serialVersionUID = -3975664071579892167L;
/**
* @serial
* @since 1.4
*/
private final String prompt;
/**
* @serial the list of choices
* @since 1.4
*/
private String[] choices;
/**
* @serial the choice to be used as the default choice
* @since 1.4
*/
private final int defaultChoice;
/**
* @serial whether multiple selections are allowed from the list of
* choices
* @since 1.4
*/
private final boolean multipleSelectionsAllowed;
/**
* @serial the selected choices, represented as indexes into the
* {@code choices} list.
* @since 1.4
*/
private int[] selections;
/**
* Construct a {@code ChoiceCallback} with a prompt,
* a list of choices, a default choice, and a boolean specifying
* whether or not multiple selections from the list of choices are allowed.
*
* <p>
*
* @param prompt the prompt used to describe the list of choices. <p>
*
* @param choices the list of choices. <p>
*
* @param defaultChoice the choice to be used as the default choice
* when the list of choices are displayed. This value
* is represented as an index into the
* {@code choices} array. <p>
*
* @param multipleSelectionsAllowed boolean specifying whether or
* not multiple selections can be made from the
* list of choices.
*
* @exception IllegalArgumentException if {@code prompt} is null,
* if {@code prompt} has a length of 0,
* if {@code choices} is null,
* if {@code choices} has a length of 0,
* if any element from {@code choices} is null,
* if any element from {@code choices}
* has a length of 0 or if {@code defaultChoice}
* does not fall within the array boundaries of
* {@code choices}.
*/
public ChoiceCallback(String prompt, String[] choices,
int defaultChoice, boolean multipleSelectionsAllowed) {
if (prompt == null || prompt.length() == 0 ||
choices == null || choices.length == 0 ||
defaultChoice < 0 || defaultChoice >= choices.length)
throw new IllegalArgumentException();
this.prompt = prompt;
this.defaultChoice = defaultChoice;
this.multipleSelectionsAllowed = multipleSelectionsAllowed;
this.choices = choices.clone();
for (int i = 0; i < choices.length; i++) {
if (choices[i] == null || choices[i].length() == 0)
throw new IllegalArgumentException();
}
}
/**
* Get the prompt.
*
* <p>
*
* @return the prompt.
*/
public String getPrompt() {
return prompt;
}
/**
* Get the list of choices.
*
* <p>
*
* @return the list of choices.
*/
public String[] getChoices() {
return choices.clone();
}
/**
* Get the defaultChoice.
*
* <p>
*
* @return the defaultChoice, represented as an index into
* the {@code choices} list.
*/
public int getDefaultChoice() {
return defaultChoice;
}
/**
* Get the boolean determining whether multiple selections from
* the {@code choices} list are allowed.
*
* <p>
*
* @return whether multiple selections are allowed.
*/
public boolean allowMultipleSelections() {
return multipleSelectionsAllowed;
}
/**
* Set the selected choice.
*
* <p>
*
* @param selection the selection represented as an index into the
* {@code choices} list.
*
* @see #getSelectedIndexes
*/
public void setSelectedIndex(int selection) {
this.selections = new int[1];
this.selections[0] = selection;
}
/**
* Set the selected choices.
*
* <p>
*
* @param selections the selections represented as indexes into the
* {@code choices} list.
*
* @exception UnsupportedOperationException if multiple selections are
* not allowed, as determined by
* {@code allowMultipleSelections}.
*
* @see #getSelectedIndexes
*/
public void setSelectedIndexes(int[] selections) {
if (!multipleSelectionsAllowed)
throw new UnsupportedOperationException();
this.selections = selections == null ? null : selections.clone();
}
/**
* Get the selected choices.
*
* <p>
*
* @return the selected choices, represented as indexes into the
* {@code choices} list.
*
* @see #setSelectedIndexes
*/
public int[] getSelectedIndexes() {
return selections == null ? null : selections.clone();
}
/**
* Restores the state of this object from the stream.
*
* @param stream the {@code ObjectInputStream} from which data is read
* @throws IOException if an I/O error occurs
* @throws ClassNotFoundException if a serialized class cannot be loaded
*/
private void readObject(ObjectInputStream stream)
throws IOException, ClassNotFoundException {
stream.defaultReadObject();
if ((prompt == null) || prompt.isEmpty() ||
(choices == null) || (choices.length == 0) ||
(defaultChoice < 0) || (defaultChoice >= choices.length)) {
throw new InvalidObjectException(
"Missing/invalid prompt/choices");
}
choices = choices.clone();
for (int i = 0; i < choices.length; i++) {
if ((choices[i] == null) || choices[i].isEmpty())
throw new InvalidObjectException("Null/empty choices");
}
if (selections != null) {
selections = selections.clone();
if (!multipleSelectionsAllowed && (selections.length != 1)) {
throw new InvalidObjectException(
"Multiple selections not allowed");
}
}
}
}

View File

@@ -0,0 +1,526 @@
/*
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.security.auth.callback;
import java.io.IOException;
import java.io.ObjectInputStream;
/**
* <p> Underlying security services instantiate and pass a
* {@code ConfirmationCallback} to the {@code handle}
* method of a {@code CallbackHandler} to ask for YES/NO,
* OK/CANCEL, YES/NO/CANCEL or other similar confirmations.
*
* @see javax.security.auth.callback.CallbackHandler
*/
public class ConfirmationCallback implements Callback, java.io.Serializable {
private static final long serialVersionUID = -9095656433782481624L;
/**
* Unspecified option type.
*
* <p> The {@code getOptionType} method returns this
* value if this {@code ConfirmationCallback} was instantiated
* with {@code options} instead of an {@code optionType}.
*/
public static final int UNSPECIFIED_OPTION = -1;
/**
* YES/NO confirmation option.
*
* <p> An underlying security service specifies this as the
* {@code optionType} to a {@code ConfirmationCallback}
* constructor if it requires a confirmation which can be answered
* with either {@code YES} or {@code NO}.
*/
public static final int YES_NO_OPTION = 0;
/**
* YES/NO/CANCEL confirmation confirmation option.
*
* <p> An underlying security service specifies this as the
* {@code optionType} to a {@code ConfirmationCallback}
* constructor if it requires a confirmation which can be answered
* with either {@code YES}, {@code NO} or {@code CANCEL}.
*/
public static final int YES_NO_CANCEL_OPTION = 1;
/**
* OK/CANCEL confirmation confirmation option.
*
* <p> An underlying security service specifies this as the
* {@code optionType} to a {@code ConfirmationCallback}
* constructor if it requires a confirmation which can be answered
* with either {@code OK} or {@code CANCEL}.
*/
public static final int OK_CANCEL_OPTION = 2;
/**
* YES option.
*
* <p> If an {@code optionType} was specified to this
* {@code ConfirmationCallback}, this option may be specified as a
* {@code defaultOption} or returned as the selected index.
*/
public static final int YES = 0;
/**
* NO option.
*
* <p> If an {@code optionType} was specified to this
* {@code ConfirmationCallback}, this option may be specified as a
* {@code defaultOption} or returned as the selected index.
*/
public static final int NO = 1;
/**
* CANCEL option.
*
* <p> If an {@code optionType} was specified to this
* {@code ConfirmationCallback}, this option may be specified as a
* {@code defaultOption} or returned as the selected index.
*/
public static final int CANCEL = 2;
/**
* OK option.
*
* <p> If an {@code optionType} was specified to this
* {@code ConfirmationCallback}, this option may be specified as a
* {@code defaultOption} or returned as the selected index.
*/
public static final int OK = 3;
/** INFORMATION message type. */
public static final int INFORMATION = 0;
/** WARNING message type. */
public static final int WARNING = 1;
/** ERROR message type. */
public static final int ERROR = 2;
/**
* @serial
* @since 1.4
*/
private final String prompt;
/**
* @serial
* @since 1.4
*/
private final int messageType;
/**
* @serial
* @since 1.4
*/
private final int optionType;
/**
* @serial
* @since 1.4
*/
private final int defaultOption;
/**
* @serial
* @since 1.4
*/
private String[] options;
/**
* @serial
* @since 1.4
*/
private int selection;
/**
* Construct a {@code ConfirmationCallback} with a
* message type, an option type and a default option.
*
* <p> Underlying security services use this constructor if
* they require either a YES/NO, YES/NO/CANCEL or OK/CANCEL
* confirmation.
*
* <p>
*
* @param messageType the message type ({@code INFORMATION},
* {@code WARNING} or {@code ERROR}). <p>
*
* @param optionType the option type ({@code YES_NO_OPTION},
* {@code YES_NO_CANCEL_OPTION} or
* {@code OK_CANCEL_OPTION}). <p>
*
* @param defaultOption the default option
* from the provided optionType ({@code YES},
* {@code NO}, {@code CANCEL} or
* {@code OK}).
*
* @exception IllegalArgumentException if messageType is not either
* {@code INFORMATION}, {@code WARNING},
* or {@code ERROR}, if optionType is not either
* {@code YES_NO_OPTION},
* {@code YES_NO_CANCEL_OPTION}, or
* {@code OK_CANCEL_OPTION},
* or if {@code defaultOption}
* does not correspond to one of the options in
* {@code optionType}.
*/
public ConfirmationCallback(int messageType,
int optionType, int defaultOption) {
if (messageType < INFORMATION || messageType > ERROR ||
optionType < YES_NO_OPTION || optionType > OK_CANCEL_OPTION)
throw new IllegalArgumentException();
switch (optionType) {
case YES_NO_OPTION:
if (defaultOption != YES && defaultOption != NO)
throw new IllegalArgumentException();
break;
case YES_NO_CANCEL_OPTION:
if (defaultOption != YES && defaultOption != NO &&
defaultOption != CANCEL)
throw new IllegalArgumentException();
break;
case OK_CANCEL_OPTION:
if (defaultOption != OK && defaultOption != CANCEL)
throw new IllegalArgumentException();
break;
}
this.prompt = null;
this.messageType = messageType;
this.optionType = optionType;
this.options = null;
this.defaultOption = defaultOption;
}
/**
* Construct a {@code ConfirmationCallback} with a
* message type, a list of options and a default option.
*
* <p> Underlying security services use this constructor if
* they require a confirmation different from the available preset
* confirmations provided (for example, CONTINUE/ABORT or STOP/GO).
* The confirmation options are listed in the {@code options} array,
* and are displayed by the {@code CallbackHandler} implementation
* in a manner consistent with the way preset options are displayed.
*
* <p>
*
* @param messageType the message type ({@code INFORMATION},
* {@code WARNING} or {@code ERROR}). <p>
*
* @param options the list of confirmation options. <p>
*
* @param defaultOption the default option, represented as an index
* into the {@code options} array.
*
* @exception IllegalArgumentException if messageType is not either
* {@code INFORMATION}, {@code WARNING},
* or {@code ERROR}, if {@code options} is null,
* if {@code options} has a length of 0,
* if any element from {@code options} is null,
* if any element from {@code options}
* has a length of 0, or if {@code defaultOption}
* does not lie within the array boundaries of
* {@code options}.
*/
public ConfirmationCallback(int messageType,
String[] options, int defaultOption) {
if (messageType < INFORMATION || messageType > ERROR ||
options == null || options.length == 0 ||
defaultOption < 0 || defaultOption >= options.length)
throw new IllegalArgumentException();
this.prompt = null;
this.messageType = messageType;
this.optionType = UNSPECIFIED_OPTION;
this.defaultOption = defaultOption;
this.options = options.clone();
for (int i = 0; i < options.length; i++) {
if (options[i] == null || options[i].length() == 0)
throw new IllegalArgumentException();
}
}
/**
* Construct a {@code ConfirmationCallback} with a prompt,
* message type, an option type and a default option.
*
* <p> Underlying security services use this constructor if
* they require either a YES/NO, YES/NO/CANCEL or OK/CANCEL
* confirmation.
*
* <p>
*
* @param prompt the prompt used to describe the list of options. <p>
*
* @param messageType the message type ({@code INFORMATION},
* {@code WARNING} or {@code ERROR}). <p>
*
* @param optionType the option type ({@code YES_NO_OPTION},
* {@code YES_NO_CANCEL_OPTION} or
* {@code OK_CANCEL_OPTION}). <p>
*
* @param defaultOption the default option
* from the provided optionType ({@code YES},
* {@code NO}, {@code CANCEL} or
* {@code OK}).
*
* @exception IllegalArgumentException if {@code prompt} is null,
* if {@code prompt} has a length of 0,
* if messageType is not either
* {@code INFORMATION}, {@code WARNING},
* or {@code ERROR}, if optionType is not either
* {@code YES_NO_OPTION},
* {@code YES_NO_CANCEL_OPTION}, or
* {@code OK_CANCEL_OPTION},
* or if {@code defaultOption}
* does not correspond to one of the options in
* {@code optionType}.
*/
public ConfirmationCallback(String prompt, int messageType,
int optionType, int defaultOption) {
if (prompt == null || prompt.length() == 0 ||
messageType < INFORMATION || messageType > ERROR ||
optionType < YES_NO_OPTION || optionType > OK_CANCEL_OPTION)
throw new IllegalArgumentException();
switch (optionType) {
case YES_NO_OPTION:
if (defaultOption != YES && defaultOption != NO)
throw new IllegalArgumentException();
break;
case YES_NO_CANCEL_OPTION:
if (defaultOption != YES && defaultOption != NO &&
defaultOption != CANCEL)
throw new IllegalArgumentException();
break;
case OK_CANCEL_OPTION:
if (defaultOption != OK && defaultOption != CANCEL)
throw new IllegalArgumentException();
break;
}
this.prompt = prompt;
this.messageType = messageType;
this.optionType = optionType;
this.options = null;
this.defaultOption = defaultOption;
}
/**
* Construct a {@code ConfirmationCallback} with a prompt,
* message type, a list of options and a default option.
*
* <p> Underlying security services use this constructor if
* they require a confirmation different from the available preset
* confirmations provided (for example, CONTINUE/ABORT or STOP/GO).
* The confirmation options are listed in the {@code options} array,
* and are displayed by the {@code CallbackHandler} implementation
* in a manner consistent with the way preset options are displayed.
*
* <p>
*
* @param prompt the prompt used to describe the list of options. <p>
*
* @param messageType the message type ({@code INFORMATION},
* {@code WARNING} or {@code ERROR}). <p>
*
* @param options the list of confirmation options. <p>
*
* @param defaultOption the default option, represented as an index
* into the {@code options} array.
*
* @exception IllegalArgumentException if {@code prompt} is null,
* if {@code prompt} has a length of 0,
* if messageType is not either
* {@code INFORMATION}, {@code WARNING},
* or {@code ERROR}, if {@code options} is null,
* if {@code options} has a length of 0,
* if any element from {@code options} is null,
* if any element from {@code options}
* has a length of 0, or if {@code defaultOption}
* does not lie within the array boundaries of
* {@code options}.
*/
public ConfirmationCallback(String prompt, int messageType,
String[] options, int defaultOption) {
if (prompt == null || prompt.length() == 0 ||
messageType < INFORMATION || messageType > ERROR ||
options == null || options.length == 0 ||
defaultOption < 0 || defaultOption >= options.length)
throw new IllegalArgumentException();
this.prompt = prompt;
this.messageType = messageType;
this.optionType = UNSPECIFIED_OPTION;
this.defaultOption = defaultOption;
this.options = options.clone();
for (int i = 0; i < options.length; i++) {
if (options[i] == null || options[i].length() == 0)
throw new IllegalArgumentException();
}
}
/**
* Get the prompt.
*
* <p>
*
* @return the prompt, or null if this {@code ConfirmationCallback}
* was instantiated without a {@code prompt}.
*/
public String getPrompt() {
return prompt;
}
/**
* Get the message type.
*
* <p>
*
* @return the message type ({@code INFORMATION},
* {@code WARNING} or {@code ERROR}).
*/
public int getMessageType() {
return messageType;
}
/**
* Get the option type.
*
* <p> If this method returns {@code UNSPECIFIED_OPTION}, then this
* {@code ConfirmationCallback} was instantiated with
* {@code options} instead of an {@code optionType}.
* In this case, invoke the {@code getOptions} method
* to determine which confirmation options to display.
*
* <p>
*
* @return the option type ({@code YES_NO_OPTION},
* {@code YES_NO_CANCEL_OPTION} or
* {@code OK_CANCEL_OPTION}), or
* {@code UNSPECIFIED_OPTION} if this
* {@code ConfirmationCallback} was instantiated with
* {@code options} instead of an {@code optionType}.
*/
public int getOptionType() {
return optionType;
}
/**
* Get the confirmation options.
*
* <p>
*
* @return the list of confirmation options, or null if this
* {@code ConfirmationCallback} was instantiated with
* an {@code optionType} instead of {@code options}.
*/
public String[] getOptions() {
return options == null ? null : options.clone();
}
/**
* Get the default option.
*
* <p>
*
* @return the default option, represented as
* {@code YES}, {@code NO}, {@code OK} or
* {@code CANCEL} if an {@code optionType}
* was specified to the constructor of this
* {@code ConfirmationCallback}.
* Otherwise, this method returns the default option as
* an index into the
* {@code options} array specified to the constructor
* of this {@code ConfirmationCallback}.
*/
public int getDefaultOption() {
return defaultOption;
}
/**
* Set the selected confirmation option.
*
* <p>
*
* @param selection the selection represented as {@code YES},
* {@code NO}, {@code OK} or {@code CANCEL}
* if an {@code optionType} was specified to the constructor
* of this {@code ConfirmationCallback}.
* Otherwise, the selection represents the index into the
* {@code options} array specified to the constructor
* of this {@code ConfirmationCallback}.
*
* @see #getSelectedIndex
*/
public void setSelectedIndex(int selection) {
this.selection = selection;
}
/**
* Get the selected confirmation option.
*
* <p>
*
* @return the selected confirmation option represented as
* {@code YES}, {@code NO}, {@code OK} or
* {@code CANCEL} if an {@code optionType}
* was specified to the constructor of this
* {@code ConfirmationCallback}.
* Otherwise, this method returns the selected confirmation
* option as an index into the
* {@code options} array specified to the constructor
* of this {@code ConfirmationCallback}.
*
* @see #setSelectedIndex
*/
public int getSelectedIndex() {
return selection;
}
/**
* Restores the state of this object from the stream.
*
* @param stream the {@code ObjectInputStream} from which data is read
* @throws IOException if an I/O error occurs
* @throws ClassNotFoundException if a serialized class cannot be loaded
*/
private void readObject(ObjectInputStream stream)
throws IOException, ClassNotFoundException {
stream.defaultReadObject();
if (options != null) {
options = options.clone();
}
}
}

View File

@@ -0,0 +1,79 @@
/*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.security.auth.callback;
import java.util.Locale;
/**
* <p> Underlying security services instantiate and pass a
* {@code LanguageCallback} to the {@code handle}
* method of a {@code CallbackHandler} to retrieve the {@code Locale}
* used for localizing text.
*
* @see javax.security.auth.callback.CallbackHandler
*/
public class LanguageCallback implements Callback, java.io.Serializable {
private static final long serialVersionUID = 2019050433478903213L;
/**
* @serial
* @since 1.4
*/
private Locale locale;
/**
* Construct a {@code LanguageCallback}.
*/
public LanguageCallback() { }
/**
* Set the retrieved {@code Locale}.
*
* <p>
*
* @param locale the retrieved {@code Locale}.
*
* @see #getLocale
*/
public void setLocale(Locale locale) {
this.locale = locale;
}
/**
* Get the retrieved {@code Locale}.
*
* <p>
*
* @return the retrieved {@code Locale}, or null
* if no {@code Locale} could be retrieved.
*
* @see #setLocale
*/
public Locale getLocale() {
return locale;
}
}

View File

@@ -0,0 +1,144 @@
/*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.security.auth.callback;
/**
* <p> Underlying security services instantiate and pass a
* {@code NameCallback} to the {@code handle}
* method of a {@code CallbackHandler} to retrieve name information.
*
* @see javax.security.auth.callback.CallbackHandler
*/
public class NameCallback implements Callback, java.io.Serializable {
private static final long serialVersionUID = 3770938795909392253L;
/**
* @serial
* @since 1.4
*/
private String prompt;
/**
* @serial
* @since 1.4
*/
private String defaultName;
/**
* @serial
* @since 1.4
*/
private String inputName;
/**
* Construct a {@code NameCallback} with a prompt.
*
* <p>
*
* @param prompt the prompt used to request the name.
*
* @exception IllegalArgumentException if {@code prompt} is null
* or if {@code prompt} has a length of 0.
*/
public NameCallback(String prompt) {
if (prompt == null || prompt.length() == 0)
throw new IllegalArgumentException();
this.prompt = prompt;
}
/**
* Construct a {@code NameCallback} with a prompt
* and default name.
*
* <p>
*
* @param prompt the prompt used to request the information. <p>
*
* @param defaultName the name to be used as the default name displayed
* with the prompt.
*
* @exception IllegalArgumentException if {@code prompt} is null,
* if {@code prompt} has a length of 0,
* if {@code defaultName} is null,
* or if {@code defaultName} has a length of 0.
*/
public NameCallback(String prompt, String defaultName) {
if (prompt == null || prompt.length() == 0 ||
defaultName == null || defaultName.length() == 0)
throw new IllegalArgumentException();
this.prompt = prompt;
this.defaultName = defaultName;
}
/**
* Get the prompt.
*
* <p>
*
* @return the prompt.
*/
public String getPrompt() {
return prompt;
}
/**
* Get the default name.
*
* <p>
*
* @return the default name, or null if this {@code NameCallback}
* was not instantiated with a {@code defaultName}.
*/
public String getDefaultName() {
return defaultName;
}
/**
* Set the retrieved name.
*
* <p>
*
* @param name the retrieved name (which may be null).
*
* @see #getName
*/
public void setName(String name) {
this.inputName = name;
}
/**
* Get the retrieved name.
*
* <p>
*
* @return the retrieved name (which may be null)
*
* @see #setName
*/
public String getName() {
return inputName;
}
}

View File

@@ -0,0 +1,192 @@
/*
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.security.auth.callback;
import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
import java.util.Arrays;
import sun.misc.Cleaner;
/**
* <p> Underlying security services instantiate and pass a
* {@code PasswordCallback} to the {@code handle}
* method of a {@code CallbackHandler} to retrieve password information.
*
* @see javax.security.auth.callback.CallbackHandler
*/
public class PasswordCallback implements Callback, java.io.Serializable {
private static final long serialVersionUID = 2267422647454909926L;
/**
* @serial
* @since 1.4
*/
private final String prompt;
/**
* @serial
* @since 1.4
*/
private final boolean echoOn;
/**
* @serial
* @since 1.4
*/
private char[] inputPassword;
private transient Cleaner cleaner;
/**
* Construct a {@code PasswordCallback} with a prompt
* and a boolean specifying whether the password should be displayed
* as it is being typed.
*
* <p>
*
* @param prompt the prompt used to request the password. <p>
*
* @param echoOn true if the password should be displayed
* as it is being typed.
*
* @exception IllegalArgumentException if {@code prompt} is null or
* if {@code prompt} has a length of 0.
*/
public PasswordCallback(String prompt, boolean echoOn) {
if (prompt == null || prompt.length() == 0)
throw new IllegalArgumentException();
this.prompt = prompt;
this.echoOn = echoOn;
}
/**
* Get the prompt.
*
* <p>
*
* @return the prompt.
*/
public String getPrompt() {
return prompt;
}
/**
* Return whether the password
* should be displayed as it is being typed.
*
* <p>
*
* @return the whether the password
* should be displayed as it is being typed.
*/
public boolean isEchoOn() {
return echoOn;
}
/**
* Set the retrieved password.
*
* <p> This method makes a copy of the input <i>password</i>
* before storing it.
*
* <p>
*
* @param password the retrieved password, which may be null.
*
* @see #getPassword
*/
public void setPassword(char[] password) {
// Cleanup the last buffered password copy.
if (cleaner != null) {
cleaner.clean();
cleaner = null;
}
// Set the retrieved password.
this.inputPassword = (password == null ? null : password.clone());
if (this.inputPassword != null) {
cleaner = Cleaner.create(this, cleanerFor(inputPassword));
}
}
/**
* Get the retrieved password.
*
* <p> This method returns a copy of the retrieved password.
*
* <p>
*
* @return the retrieved password, which may be null.
*
* @see #setPassword
*/
public char[] getPassword() {
return (inputPassword == null ? null : inputPassword.clone());
}
/**
* Clear the retrieved password.
*/
public void clearPassword() {
// Cleanup the last retrieved password copy.
if (cleaner != null) {
cleaner.clean();
cleaner = null;
}
}
private static Runnable cleanerFor(char[] password) {
return () -> {
Arrays.fill(password, ' ');
};
}
/**
* Restores the state of this object from the stream.
*
* @param stream the {@code ObjectInputStream} from which data is read
* @throws IOException if an I/O error occurs
* @throws ClassNotFoundException if a serialized class cannot be loaded
*/
private void readObject(ObjectInputStream stream)
throws IOException, ClassNotFoundException {
stream.defaultReadObject();
if (prompt == null || prompt.isEmpty()) {
throw new InvalidObjectException("Missing prompt");
}
if (inputPassword != null) {
inputPassword = inputPassword.clone();
cleaner = Cleaner.create(this, cleanerFor(inputPassword));
}
}
}

View File

@@ -0,0 +1,145 @@
/*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.security.auth.callback;
/**
* <p> Underlying security services instantiate and pass a
* {@code TextInputCallback} to the {@code handle}
* method of a {@code CallbackHandler} to retrieve generic text
* information.
*
* @see javax.security.auth.callback.CallbackHandler
*/
public class TextInputCallback implements Callback, java.io.Serializable {
private static final long serialVersionUID = -8064222478852811804L;
/**
* @serial
* @since 1.4
*/
private String prompt;
/**
* @serial
* @since 1.4
*/
private String defaultText;
/**
* @serial
* @since 1.4
*/
private String inputText;
/**
* Construct a {@code TextInputCallback} with a prompt.
*
* <p>
*
* @param prompt the prompt used to request the information.
*
* @exception IllegalArgumentException if {@code prompt} is null
* or if {@code prompt} has a length of 0.
*/
public TextInputCallback(String prompt) {
if (prompt == null || prompt.length() == 0)
throw new IllegalArgumentException();
this.prompt = prompt;
}
/**
* Construct a {@code TextInputCallback} with a prompt
* and default input value.
*
* <p>
*
* @param prompt the prompt used to request the information. <p>
*
* @param defaultText the text to be used as the default text displayed
* with the prompt.
*
* @exception IllegalArgumentException if {@code prompt} is null,
* if {@code prompt} has a length of 0,
* if {@code defaultText} is null
* or if {@code defaultText} has a length of 0.
*/
public TextInputCallback(String prompt, String defaultText) {
if (prompt == null || prompt.length() == 0 ||
defaultText == null || defaultText.length() == 0)
throw new IllegalArgumentException();
this.prompt = prompt;
this.defaultText = defaultText;
}
/**
* Get the prompt.
*
* <p>
*
* @return the prompt.
*/
public String getPrompt() {
return prompt;
}
/**
* Get the default text.
*
* <p>
*
* @return the default text, or null if this {@code TextInputCallback}
* was not instantiated with {@code defaultText}.
*/
public String getDefaultText() {
return defaultText;
}
/**
* Set the retrieved text.
*
* <p>
*
* @param text the retrieved text, which may be null.
*
* @see #getText
*/
public void setText(String text) {
this.inputText = text;
}
/**
* Get the retrieved text.
*
* <p>
*
* @return the retrieved text, which may be null.
*
* @see #setText
*/
public String getText() {
return inputText;
}
}

View File

@@ -0,0 +1,107 @@
/*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.security.auth.callback;
/**
* <p> Underlying security services instantiate and pass a
* {@code TextOutputCallback} to the {@code handle}
* method of a {@code CallbackHandler} to display information messages,
* warning messages and error messages.
*
* @see javax.security.auth.callback.CallbackHandler
*/
public class TextOutputCallback implements Callback, java.io.Serializable {
private static final long serialVersionUID = 1689502495511663102L;
/** Information message. */
public static final int INFORMATION = 0;
/** Warning message. */
public static final int WARNING = 1;
/** Error message. */
public static final int ERROR = 2;
/**
* @serial
* @since 1.4
*/
private int messageType;
/**
* @serial
* @since 1.4
*/
private String message;
/**
* Construct a TextOutputCallback with a message type and message
* to be displayed.
*
* <p>
*
* @param messageType the message type ({@code INFORMATION},
* {@code WARNING} or {@code ERROR}). <p>
*
* @param message the message to be displayed. <p>
*
* @exception IllegalArgumentException if {@code messageType}
* is not either {@code INFORMATION},
* {@code WARNING} or {@code ERROR},
* if {@code message} is null,
* or if {@code message} has a length of 0.
*/
public TextOutputCallback(int messageType, String message) {
if ((messageType != INFORMATION &&
messageType != WARNING && messageType != ERROR) ||
message == null || message.length() == 0)
throw new IllegalArgumentException();
this.messageType = messageType;
this.message = message;
}
/**
* Get the message type.
*
* <p>
*
* @return the message type ({@code INFORMATION},
* {@code WARNING} or {@code ERROR}).
*/
public int getMessageType() {
return messageType;
}
/**
* Get the message to be displayed.
*
* <p>
*
* @return the message to be displayed.
*/
public String getMessage() {
return message;
}
}

View File

@@ -0,0 +1,81 @@
/*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.security.auth.callback;
/**
* Signals that a {@code CallbackHandler} does not
* recognize a particular {@code Callback}.
*
*/
public class UnsupportedCallbackException extends Exception {
private static final long serialVersionUID = -6873556327655666839L;
/**
* @serial
*/
private Callback callback;
/**
* Constructs a {@code UnsupportedCallbackException}
* with no detail message.
*
* <p>
*
* @param callback the unrecognized {@code Callback}.
*/
public UnsupportedCallbackException(Callback callback) {
super();
this.callback = callback;
}
/**
* Constructs a UnsupportedCallbackException with the specified detail
* message. A detail message is a String that describes this particular
* exception.
*
* <p>
*
* @param callback the unrecognized {@code Callback}. <p>
*
* @param msg the detail message.
*/
public UnsupportedCallbackException(Callback callback, String msg) {
super(msg);
this.callback = callback;
}
/**
* Get the unrecognized {@code Callback}.
*
* <p>
*
* @return the unrecognized {@code Callback}.
*/
public Callback getCallback() {
return callback;
}
}

View File

@@ -0,0 +1,35 @@
/*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* This package provides the classes necessary for services
* to interact with applications in order to retrieve
* information (authentication data including usernames
* or passwords, for example) or to display information
* (error and warning messages, for example).
*
* @since JDK1.4
*/
package javax.security.auth.callback;