KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > security > jauth > callback > PasswordValidationCallback


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.security.jauth.callback;
25
26 import javax.security.auth.callback.Callback JavaDoc;
27 import java.util.Arrays JavaDoc;
28
29 /**
30  * Callback for PasswordValidation.
31  *
32  * @version %I%, %G%
33  */

34 public class PasswordValidationCallback implements Callback JavaDoc {
35
36     private String JavaDoc username;
37     private char[] password;
38     private boolean result = false;
39
40     /**
41      * Create a PasswordValidationCallback.
42      *
43      * @param username the username to authenticate
44      *
45      * @param password the user's password, which may be null.
46      */

47     public PasswordValidationCallback(String JavaDoc username, char[] password) {
48     this.username = username;
49     if (password != null) {
50         this.password = (char[])password.clone();
51     }
52     }
53
54     /**
55      * Get the username.
56      *
57      * @return the username.
58      */

59     public String JavaDoc getUsername() {
60     return username;
61     }
62
63     /**
64      * Get the password.
65      *
66      * <p> Note that this method returns a reference to the password.
67      * If a clone of the array is created it is the caller's
68      * responsibility to zero out the password information after
69      * it is no longer needed.
70      *
71      * @return the password, which may be null.
72      */

73     public char[] getPassword() {
74     return password;
75     }
76
77     /**
78      * Clear the password.
79      */

80     public void clearPassword() {
81     if (password != null) {
82         Arrays.fill(password, ' ');
83     }
84     }
85
86     /**
87      * Set the authentication result.
88      *
89      * @param result true if authentication succeeded, false otherwise
90      */

91     public void setResult(boolean result) {
92     this.result = result;
93     }
94
95     /**
96      * Get the authentication result.
97      *
98      * @return true if authentication succeeded, false otherwise
99      */

100     public boolean getResult() {
101     return result;
102     }
103 }
104
Popular Tags