01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package javax.security.auth.callback;
19:
20: import java.io.Serializable;
21: import java.util.Arrays;
22:
23: import org.apache.harmony.auth.internal.nls.Messages;
24:
25: public class PasswordCallback implements Callback, Serializable {
26:
27: private static final long serialVersionUID = 2267422647454909926L;
28:
29: private String prompt;
30:
31: boolean echoOn;
32:
33: private char[] inputPassword;
34:
35: private void setPrompt(String prompt)
36: throws IllegalArgumentException {
37: if (prompt == null || prompt.length() == 0) {
38: throw new IllegalArgumentException(Messages
39: .getString("auth.14")); //$NON-NLS-1$
40: }
41: this .prompt = prompt;
42: }
43:
44: public PasswordCallback(String prompt, boolean echoOn) {
45: super ();
46: setPrompt(prompt);
47: this .echoOn = echoOn;
48: }
49:
50: public String getPrompt() {
51: return prompt;
52: }
53:
54: public boolean isEchoOn() {
55: return echoOn;
56: }
57:
58: public void setPassword(char[] password) {
59: if (password == null) {
60: this .inputPassword = password;
61: } else {
62: inputPassword = new char[password.length];
63: System.arraycopy(password, 0, inputPassword, 0,
64: inputPassword.length);
65: }
66: }
67:
68: public char[] getPassword() {
69: if (inputPassword != null) {
70: char[] tmp = new char[inputPassword.length];
71: System.arraycopy(inputPassword, 0, tmp, 0, tmp.length);
72: return tmp;
73: }
74: return null;
75: }
76:
77: public void clearPassword() {
78: if (inputPassword != null) {
79: Arrays.fill(inputPassword, '\u0000');
80: }
81: }
82: }
|