From d7955ce24d294fb2014c59d11fca184471056f44 Mon Sep 17 00:00:00 2001 From: Shuyi Chen Date: Wed, 22 May 2013 14:51:55 -0700 Subject: Add android smack source. Change-Id: I49ce97136c17173c4ae3965c694af6e7bc49897d --- .../javax/security/auth/callback/Callback.java | 25 +++ .../security/auth/callback/CallbackHandler.java | 54 +++++ .../security/auth/callback/ChoiceCallback.java | 109 ++++++++++ .../auth/callback/ConfirmationCallback.java | 234 +++++++++++++++++++++ .../security/auth/callback/LanguageCallback.java | 41 ++++ .../javax/security/auth/callback/NameCallback.java | 74 +++++++ .../security/auth/callback/PasswordCallback.java | 124 +++++++++++ .../security/auth/callback/TextInputCallback.java | 74 +++++++ .../security/auth/callback/TextOutputCallback.java | 56 +++++ .../callback/UnsupportedCallbackException.java | 64 ++++++ 10 files changed, 855 insertions(+) create mode 100644 src/org/apache/harmony/javax/security/auth/callback/Callback.java create mode 100644 src/org/apache/harmony/javax/security/auth/callback/CallbackHandler.java create mode 100644 src/org/apache/harmony/javax/security/auth/callback/ChoiceCallback.java create mode 100644 src/org/apache/harmony/javax/security/auth/callback/ConfirmationCallback.java create mode 100644 src/org/apache/harmony/javax/security/auth/callback/LanguageCallback.java create mode 100644 src/org/apache/harmony/javax/security/auth/callback/NameCallback.java create mode 100644 src/org/apache/harmony/javax/security/auth/callback/PasswordCallback.java create mode 100644 src/org/apache/harmony/javax/security/auth/callback/TextInputCallback.java create mode 100644 src/org/apache/harmony/javax/security/auth/callback/TextOutputCallback.java create mode 100644 src/org/apache/harmony/javax/security/auth/callback/UnsupportedCallbackException.java (limited to 'src/org/apache/harmony/javax/security/auth/callback') diff --git a/src/org/apache/harmony/javax/security/auth/callback/Callback.java b/src/org/apache/harmony/javax/security/auth/callback/Callback.java new file mode 100644 index 0000000..8fd745c --- /dev/null +++ b/src/org/apache/harmony/javax/security/auth/callback/Callback.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.javax.security.auth.callback; + +/** + * Defines an empty base interface for all {@code Callback}s used during + * authentication. + */ +public interface Callback { +} \ No newline at end of file diff --git a/src/org/apache/harmony/javax/security/auth/callback/CallbackHandler.java b/src/org/apache/harmony/javax/security/auth/callback/CallbackHandler.java new file mode 100644 index 0000000..d09fafa --- /dev/null +++ b/src/org/apache/harmony/javax/security/auth/callback/CallbackHandler.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.javax.security.auth.callback; + +import java.io.IOException; + +/** + * Needs to be implemented by classes that want to handle authentication + * {@link Callback}s. A single method {@link #handle(Callback[])} must be + * provided that checks the type of the incoming {@code Callback}s and reacts + * accordingly. {@code CallbackHandler}s can be installed per application. It is + * also possible to configure a system-default {@code CallbackHandler} by + * setting the {@code auth.login.defaultCallbackHandler} property in the + * standard {@code security.properties} file. + */ +public interface CallbackHandler { + + /** + * Handles the actual {@link Callback}. A {@code CallbackHandler} needs to + * implement this method. In the method, it is free to select which {@code + * Callback}s it actually wants to handle and in which way. For example, a + * console-based {@code CallbackHandler} might choose to sequentially ask + * the user for login and password, if it implements these {@code Callback} + * s, whereas a GUI-based one might open a single dialog window for both + * values. If a {@code CallbackHandler} is not able to handle a specific + * {@code Callback}, it needs to throw an + * {@link UnsupportedCallbackException}. + * + * @param callbacks + * the array of {@code Callback}s that need handling + * @throws IOException + * if an I/O related error occurs + * @throws UnsupportedCallbackException + * if the {@code CallbackHandler} is not able to handle a + * specific {@code Callback} + */ + void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException; + +} diff --git a/src/org/apache/harmony/javax/security/auth/callback/ChoiceCallback.java b/src/org/apache/harmony/javax/security/auth/callback/ChoiceCallback.java new file mode 100644 index 0000000..1e53fb6 --- /dev/null +++ b/src/org/apache/harmony/javax/security/auth/callback/ChoiceCallback.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.javax.security.auth.callback; + +import java.io.Serializable; + + + +public class ChoiceCallback implements Callback, Serializable { + + private static final long serialVersionUID = -3975664071579892167L; + + private int defaultChoice; + + private String prompt; + + private boolean multipleSelectionsAllowed; + + private String[] choices; + + private int[] selections; + + private void setChoices(String[] choices) { + if (choices == null || choices.length == 0) { + throw new IllegalArgumentException("auth.1C"); //$NON-NLS-1$ + } + for (int i = 0; i < choices.length; i++) { + if (choices[i] == null || choices[i].length() == 0) { + throw new IllegalArgumentException("auth.1C"); //$NON-NLS-1$ + } + } + //FIXME: System.arraycopy(choices, 0 , new String[choices.length], 0, choices.length); + this.choices = choices; + + } + + private void setPrompt(String prompt) { + if (prompt == null || prompt.length() == 0) { + throw new IllegalArgumentException("auth.14"); //$NON-NLS-1$ + } + this.prompt = prompt; + } + + private void setDefaultChoice(int defaultChoice) { + if (0 > defaultChoice || defaultChoice >= choices.length) { + throw new IllegalArgumentException("auth.1D"); //$NON-NLS-1$ + } + this.defaultChoice = defaultChoice; + } + + public ChoiceCallback(String prompt, String[] choices, int defaultChoice, + boolean multipleSelectionsAllowed) { + super(); + setPrompt(prompt); + setChoices(choices); + setDefaultChoice(defaultChoice); + this.multipleSelectionsAllowed = multipleSelectionsAllowed; + } + + public boolean allowMultipleSelections() { + return multipleSelectionsAllowed; + } + + public String[] getChoices() { + return choices; + } + + public int getDefaultChoice() { + return defaultChoice; + } + + public String getPrompt() { + return prompt; + } + + public int[] getSelectedIndexes() { + return selections; + } + + public void setSelectedIndex(int selection) { + this.selections = new int[1]; + this.selections[0] = selection; + } + + public void setSelectedIndexes(int[] selections) { + if (!multipleSelectionsAllowed) { + throw new UnsupportedOperationException(); + } + this.selections = selections; + //FIXME: + // this.selections = new int[selections.length] + //System.arraycopy(selections, 0, this.selections, 0, this.selections.length); + } +} diff --git a/src/org/apache/harmony/javax/security/auth/callback/ConfirmationCallback.java b/src/org/apache/harmony/javax/security/auth/callback/ConfirmationCallback.java new file mode 100644 index 0000000..a1893f3 --- /dev/null +++ b/src/org/apache/harmony/javax/security/auth/callback/ConfirmationCallback.java @@ -0,0 +1,234 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.javax.security.auth.callback; + +import java.io.Serializable; + + + +public class ConfirmationCallback implements Callback, Serializable { + + private static final long serialVersionUID = -9095656433782481624L; + + public static final int YES = 0; // default options + + public static final int NO = 1; + + public static final int CANCEL = 2; + + public static final int OK = 3; + + public static final int YES_NO_OPTION = 0; // options type + + public static final int YES_NO_CANCEL_OPTION = 1; + + public static final int OK_CANCEL_OPTION = 2; + + public static final int UNSPECIFIED_OPTION = -1; + + public static final int INFORMATION = 0; // messages type + + public static final int WARNING = 1; + + public static final int ERROR = 2; + + private String prompt; + + private int messageType; + + private int optionType = UNSPECIFIED_OPTION; + + private int defaultOption; + + private String[] options; + + private int selection; + + public ConfirmationCallback(int messageType, int optionType, int defaultOption) { + super(); + if (messageType > ERROR || messageType < INFORMATION) { + throw new IllegalArgumentException("auth.16"); //$NON-NLS-1$ + } + + switch (optionType) { + case YES_NO_OPTION: + if (defaultOption != YES && defaultOption != NO) { + throw new IllegalArgumentException("auth.17"); //$NON-NLS-1$ + } + break; + case YES_NO_CANCEL_OPTION: + if (defaultOption != YES && defaultOption != NO && defaultOption != CANCEL) { + throw new IllegalArgumentException("auth.17"); //$NON-NLS-1$ + } + break; + case OK_CANCEL_OPTION: + if (defaultOption != OK && defaultOption != CANCEL) { + throw new IllegalArgumentException("auth.17"); //$NON-NLS-1$ + } + break; + default: + throw new IllegalArgumentException("auth.18"); //$NON-NLS-1$ + } + this.messageType = messageType; + this.optionType = optionType; + this.defaultOption = defaultOption; + } + + public ConfirmationCallback(int messageType, String[] options, int defaultOption) { + super(); + if (messageType > ERROR || messageType < INFORMATION) { + throw new IllegalArgumentException("auth.16"); //$NON-NLS-1$ + } + + if (options == null || options.length == 0) { + throw new IllegalArgumentException("auth.1A"); //$NON-NLS-1$ + } + for (int i = 0; i < options.length; i++) { + if (options[i] == null || options[i].length() == 0) { + throw new IllegalArgumentException("auth.1A"); //$NON-NLS-1$ + } + } + if (0 > defaultOption || defaultOption >= options.length) { + throw new IllegalArgumentException("auth.17"); //$NON-NLS-1$ + } + // FIXME:System.arraycopy(options, 0 , new String[this.options.length], + // 0, this.options.length); + this.options = options; + this.defaultOption = defaultOption; + this.messageType = messageType; + } + + public ConfirmationCallback(String prompt, int messageType, int optionType, + int defaultOption) { + super(); + if (prompt == null || prompt.length() == 0) { + throw new IllegalArgumentException("auth.14"); //$NON-NLS-1$ + } + + if (messageType > ERROR || messageType < INFORMATION) { + throw new IllegalArgumentException("auth.16"); //$NON-NLS-1$ + } + + switch (optionType) { + case YES_NO_OPTION: + if (defaultOption != YES && defaultOption != NO) { + throw new IllegalArgumentException("auth.17"); //$NON-NLS-1$ + } + break; + case YES_NO_CANCEL_OPTION: + if (defaultOption != YES && defaultOption != NO && defaultOption != CANCEL) { + throw new IllegalArgumentException("auth.17"); //$NON-NLS-1$ + } + break; + case OK_CANCEL_OPTION: + if (defaultOption != OK && defaultOption != CANCEL) { + throw new IllegalArgumentException("auth.17"); //$NON-NLS-1$ + } + break; + default: + throw new IllegalArgumentException("auth.18"); //$NON-NLS-1$ + } + this.prompt = prompt; + this.messageType = messageType; + this.optionType = optionType; + this.defaultOption = defaultOption; + } + + public ConfirmationCallback(String prompt, int messageType, String[] options, + int defaultOption) { + super(); + if (prompt == null || prompt.length() == 0) { + throw new IllegalArgumentException("auth.14"); //$NON-NLS-1$ + } + + if (messageType > ERROR || messageType < INFORMATION) { + throw new IllegalArgumentException("auth.16"); //$NON-NLS-1$ + } + + if (options == null || options.length == 0) { + throw new IllegalArgumentException("auth.1A"); //$NON-NLS-1$ + } + for (int i = 0; i < options.length; i++) { + if (options[i] == null || options[i].length() == 0) { + throw new IllegalArgumentException("auth.1A"); //$NON-NLS-1$ + } + } + if (0 > defaultOption || defaultOption >= options.length) { + throw new IllegalArgumentException("auth.17"); //$NON-NLS-1$ + } + // FIXME:System.arraycopy(options, 0 , new String[this.options.length], + // 0, this.options.length); + this.options = options; + this.defaultOption = defaultOption; + this.messageType = messageType; + this.prompt = prompt; + } + + public String getPrompt() { + return prompt; + } + + public int getMessageType() { + return messageType; + } + + public int getDefaultOption() { + return defaultOption; + } + + public String[] getOptions() { + return options; + } + + public int getOptionType() { + return optionType; + } + + public int getSelectedIndex() { + return selection; + } + + public void setSelectedIndex(int selection) { + if (options != null) { + if (0 <= selection && selection <= options.length) { + this.selection = selection; + } else { + throw new ArrayIndexOutOfBoundsException("auth.1B"); //$NON-NLS-1$ + } + } else { + switch (optionType) { + case YES_NO_OPTION: + if (selection != YES && selection != NO) { + throw new IllegalArgumentException("auth.19"); //$NON-NLS-1$ + } + break; + case YES_NO_CANCEL_OPTION: + if (selection != YES && selection != NO && selection != CANCEL) { + throw new IllegalArgumentException("auth.19"); //$NON-NLS-1$ + } + break; + case OK_CANCEL_OPTION: + if (selection != OK && selection != CANCEL) { + throw new IllegalArgumentException("auth.19"); //$NON-NLS-1$ + } + break; + } + this.selection = selection; + } + } +} diff --git a/src/org/apache/harmony/javax/security/auth/callback/LanguageCallback.java b/src/org/apache/harmony/javax/security/auth/callback/LanguageCallback.java new file mode 100644 index 0000000..729bb49 --- /dev/null +++ b/src/org/apache/harmony/javax/security/auth/callback/LanguageCallback.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.javax.security.auth.callback; + +import java.io.Serializable; +import java.util.Locale; + +public class LanguageCallback implements Callback, Serializable { + + private static final long serialVersionUID = 2019050433478903213L; + + private Locale locale; + + public LanguageCallback() { + super(); + } + + public Locale getLocale() { + return locale; + } + + public void setLocale(Locale locale) { + this.locale = locale; + } + +} diff --git a/src/org/apache/harmony/javax/security/auth/callback/NameCallback.java b/src/org/apache/harmony/javax/security/auth/callback/NameCallback.java new file mode 100644 index 0000000..97264ef --- /dev/null +++ b/src/org/apache/harmony/javax/security/auth/callback/NameCallback.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.javax.security.auth.callback; + +import java.io.Serializable; + + + +public class NameCallback implements Callback, Serializable { + + private static final long serialVersionUID = 3770938795909392253L; + + private String prompt; + + private String defaultName; + + private String inputName; + + private void setPrompt(String prompt) { + if (prompt == null || prompt.length() == 0) { + throw new IllegalArgumentException("auth.14"); //$NON-NLS-1$ + } + this.prompt = prompt; + } + + private void setDefaultName(String defaultName) { + if (defaultName == null || defaultName.length() == 0) { + throw new IllegalArgumentException("auth.1E"); //$NON-NLS-1$ + } + this.defaultName = defaultName; + } + + public NameCallback(String prompt) { + super(); + setPrompt(prompt); + } + + public NameCallback(String prompt, String defaultName) { + super(); + setPrompt(prompt); + setDefaultName(defaultName); + } + + public String getPrompt() { + return prompt; + } + + public String getDefaultName() { + return defaultName; + } + + public void setName(String name) { + this.inputName = name; + } + + public String getName() { + return inputName; + } +} diff --git a/src/org/apache/harmony/javax/security/auth/callback/PasswordCallback.java b/src/org/apache/harmony/javax/security/auth/callback/PasswordCallback.java new file mode 100644 index 0000000..bd142fc --- /dev/null +++ b/src/org/apache/harmony/javax/security/auth/callback/PasswordCallback.java @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.javax.security.auth.callback; + +import java.io.Serializable; +import java.util.Arrays; + + + +/** + * Is used in conjunction with a {@link CallbackHandler} to retrieve a password + * when needed. + */ +public class PasswordCallback implements Callback, Serializable { + + private static final long serialVersionUID = 2267422647454909926L; + + private String prompt; + + boolean echoOn; + + private char[] inputPassword; + + private void setPrompt(String prompt) throws IllegalArgumentException { + if (prompt == null || prompt.length() == 0) { + throw new IllegalArgumentException("auth.14"); //$NON-NLS-1$ + } + this.prompt = prompt; + } + + /** + * Creates a new {@code PasswordCallback} instance. + * + * @param prompt + * the message that should be displayed to the user + * @param echoOn + * determines whether the user input should be echoed + */ + public PasswordCallback(String prompt, boolean echoOn) { + super(); + setPrompt(prompt); + this.echoOn = echoOn; + } + + /** + * Returns the prompt that was specified when creating this {@code + * PasswordCallback} + * + * @return the prompt + */ + public String getPrompt() { + return prompt; + } + + /** + * Queries whether this {@code PasswordCallback} expects user input to be + * echoed, which is specified during the creation of the object. + * + * @return {@code true} if (and only if) user input should be echoed + */ + public boolean isEchoOn() { + return echoOn; + } + + /** + * Sets the password. The {@link CallbackHandler} that performs the actual + * provisioning or input of the password needs to call this method to hand + * back the password to the security service that requested it. + * + * @param password + * the password. A copy of this is stored, so subsequent changes + * to the input array do not affect the {@code PasswordCallback}. + */ + public void setPassword(char[] password) { + if (password == null) { + this.inputPassword = password; + } else { + inputPassword = new char[password.length]; + System.arraycopy(password, 0, inputPassword, 0, inputPassword.length); + } + } + + /** + * Returns the password. The security service that needs the password + * usually calls this method once the {@link CallbackHandler} has finished + * its work. + * + * @return the password. A copy of the internal password is created and + * returned, so subsequent changes to the internal password do not + * affect the result. + */ + public char[] getPassword() { + if (inputPassword != null) { + char[] tmp = new char[inputPassword.length]; + System.arraycopy(inputPassword, 0, tmp, 0, tmp.length); + return tmp; + } + return null; + } + + /** + * Clears the password stored in this {@code PasswordCallback}. + */ + public void clearPassword() { + if (inputPassword != null) { + Arrays.fill(inputPassword, '\u0000'); + } + } +} diff --git a/src/org/apache/harmony/javax/security/auth/callback/TextInputCallback.java b/src/org/apache/harmony/javax/security/auth/callback/TextInputCallback.java new file mode 100644 index 0000000..c7de222 --- /dev/null +++ b/src/org/apache/harmony/javax/security/auth/callback/TextInputCallback.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.javax.security.auth.callback; + +import java.io.Serializable; + + + +public class TextInputCallback implements Callback, Serializable { + + private static final long serialVersionUID = -8064222478852811804L; + + private String defaultText; + + private String prompt; + + private String inputText; + + private void setPrompt(String prompt) { + if (prompt == null || prompt.length() == 0) { + throw new IllegalArgumentException("auth.14"); //$NON-NLS-1$ + } + this.prompt = prompt; + } + + private void setDefaultText(String defaultText) { + if (defaultText == null || defaultText.length() == 0) { + throw new IllegalArgumentException("auth.15"); //$NON-NLS-1$ + } + this.defaultText = defaultText; + } + + public TextInputCallback(String prompt) { + super(); + setPrompt(prompt); + } + + public TextInputCallback(String prompt, String defaultText) { + super(); + setPrompt(prompt); + setDefaultText(defaultText); + } + + public String getDefaultText() { + return defaultText; + } + + public String getPrompt() { + return prompt; + } + + public String getText() { + return inputText; + } + + public void setText(String text) { + this.inputText = text; + } +} diff --git a/src/org/apache/harmony/javax/security/auth/callback/TextOutputCallback.java b/src/org/apache/harmony/javax/security/auth/callback/TextOutputCallback.java new file mode 100644 index 0000000..23a72fa --- /dev/null +++ b/src/org/apache/harmony/javax/security/auth/callback/TextOutputCallback.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.javax.security.auth.callback; + +import java.io.Serializable; + + + +public class TextOutputCallback implements Callback, Serializable { + + private static final long serialVersionUID = 1689502495511663102L; + + public static final int INFORMATION = 0; + + public static final int WARNING = 1; + + public static final int ERROR = 2; + + private String message; + + private int messageType; + + public TextOutputCallback(int messageType, String message) { + if (messageType > ERROR || messageType < INFORMATION) { + throw new IllegalArgumentException("auth.16"); //$NON-NLS-1$ + } + if (message == null || message.length() == 0) { + throw new IllegalArgumentException("auth.1F"); //$NON-NLS-1$ + } + this.messageType = messageType; + this.message = message; + } + + public String getMessage() { + return message; + } + + public int getMessageType() { + return messageType; + } +} diff --git a/src/org/apache/harmony/javax/security/auth/callback/UnsupportedCallbackException.java b/src/org/apache/harmony/javax/security/auth/callback/UnsupportedCallbackException.java new file mode 100644 index 0000000..19f6e40 --- /dev/null +++ b/src/org/apache/harmony/javax/security/auth/callback/UnsupportedCallbackException.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.javax.security.auth.callback; + +/** + * Thrown when a {@link CallbackHandler} does not support a particular {@link + * Callback}. + */ +public class UnsupportedCallbackException extends Exception { + + private static final long serialVersionUID = -6873556327655666839L; + + private Callback callback; + + /** + * Creates a new exception instance and initializes it with just the + * unsupported {@code Callback}, but no error message. + * + * @param callback + * the {@code Callback} + */ + public UnsupportedCallbackException(Callback callback) { + super(); + this.callback = callback; + } + + /** + * Creates a new exception instance and initializes it with both the + * unsupported {@code Callback} and an error message. + * + * @param callback + * the {@code Callback} + * @param message + * the error message + */ + public UnsupportedCallbackException(Callback callback, String message) { + super(message); + this.callback = callback; + } + + /** + * Returns the unsupported {@code Callback} that triggered this exception. + * + * @return the {@code Callback} + */ + public Callback getCallback() { + return callback; + } +} -- cgit v1.2.3