1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity.providers.jaas;
17
18 import org.acegisecurity.Authentication;
19
20 import java.io.IOException;
21
22 import javax.security.auth.callback.Callback;
23 import javax.security.auth.callback.PasswordCallback;
24 import javax.security.auth.callback.UnsupportedCallbackException;
25
26
27 /***
28 * The most basic Callbacks to be handled when using a LoginContext from JAAS,
29 * are the NameCallback and PasswordCallback. The acegi security framework
30 * provides the JaasPasswordCallbackHandler specifically tailored to handling
31 * the PasswordCallback. <br>
32 *
33 * @author Ray Krueger
34 * @version $Id: JaasPasswordCallbackHandler.java,v 1.4 2005/11/17 00:55:52 benalex Exp $
35 *
36 * @see <a
37 * href="http://java.sun.com/j2se/1.4.2/docs/api/javax/security/auth/callback/Callback.html">Callback</a>
38 * @see <a
39 * href="http://java.sun.com/j2se/1.4.2/docs/api/javax/security/auth/callback/PasswordCallback.html">PasswordCallback</a>
40 */
41 public class JaasPasswordCallbackHandler
42 implements JaasAuthenticationCallbackHandler {
43
44
45 /***
46 * If the callback passed to the 'handle' method is an instance of
47 * PasswordCallback, the JaasPasswordCallbackHandler will call,
48 * callback.setPassword(authentication.getCredentials().toString()).
49 *
50 * @param callback
51 * @param auth
52 *
53 * @throws IOException
54 * @throws UnsupportedCallbackException
55 */
56 public void handle(Callback callback, Authentication auth)
57 throws IOException, UnsupportedCallbackException {
58 if (callback instanceof PasswordCallback) {
59 PasswordCallback pc = (PasswordCallback) callback;
60 pc.setPassword(auth.getCredentials().toString().toCharArray());
61 }
62 }
63 }