1 |
/* |
/* |
2 |
* $Id$ |
* SaslCallbackHandler.java |
3 |
* Copyright (C) 2002 The Free Software Foundation |
* Copyright (C) 2002 The Free Software Foundation |
4 |
* |
* |
5 |
* This file is part of GNU inetlib, a library. |
* This file is part of GNU inetlib, a library. |
50 |
* A callback handler that can manage username and password callbacks. |
* A callback handler that can manage username and password callbacks. |
51 |
* |
* |
52 |
* @author <a href="mailto:dog@gnu.org">Chris Burdess</a> |
* @author <a href="mailto:dog@gnu.org">Chris Burdess</a> |
|
* @version $Revision$ $Date$ |
|
53 |
*/ |
*/ |
54 |
public final class SaslCallbackHandler implements CallbackHandler |
public final class SaslCallbackHandler |
55 |
|
implements CallbackHandler |
56 |
{ |
{ |
57 |
|
|
58 |
/* |
/* |
70 |
* @param username the value to respond to Name callbacks with |
* @param username the value to respond to Name callbacks with |
71 |
* @param password the value to respond to Password callbacks with |
* @param password the value to respond to Password callbacks with |
72 |
*/ |
*/ |
73 |
public SaslCallbackHandler (String username, String password) |
public SaslCallbackHandler(String username, String password) |
74 |
{ |
{ |
75 |
this.username = username; |
this.username = username; |
76 |
this.password = password; |
this.password = password; |
77 |
} |
} |
78 |
|
|
79 |
/** |
/** |
80 |
* Handle callbacks. |
* Handle callbacks. |
81 |
*/ |
*/ |
82 |
public void handle (Callback[] callbacks) |
public void handle(Callback[] callbacks) |
83 |
throws IOException, UnsupportedCallbackException |
throws IOException, UnsupportedCallbackException |
84 |
{ |
{ |
85 |
for (int i = 0; i < callbacks.length; i++) |
for (int i = 0; i < callbacks.length; i++) |
86 |
{ |
{ |
87 |
if (callbacks[i] instanceof NameCallback) |
if (callbacks[i] instanceof NameCallback) |
88 |
{ |
{ |
89 |
NameCallback nc = (NameCallback) callbacks[i]; |
NameCallback nc = (NameCallback) callbacks[i]; |
90 |
nc.setName (username); |
nc.setName(username); |
91 |
} |
} |
92 |
else if (callbacks[i] instanceof PasswordCallback) |
else if (callbacks[i] instanceof PasswordCallback) |
93 |
{ |
{ |
94 |
PasswordCallback pc = (PasswordCallback) callbacks[i]; |
PasswordCallback pc = (PasswordCallback) callbacks[i]; |
95 |
pc.setPassword (password.toCharArray ()); |
pc.setPassword(password.toCharArray ()); |
96 |
} |
} |
97 |
else |
else |
98 |
throw new UnsupportedCallbackException (callbacks[i]); |
{ |
99 |
} |
throw new UnsupportedCallbackException(callbacks[i]); |
100 |
} |
} |
101 |
|
} |
102 |
|
} |
103 |
|
|
104 |
} |
} |
105 |
|
|