01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software
10: * distributed under the License is distributed on an "AS IS" BASIS,
11: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: * See the License for the specific language governing permissions and
13: * limitations under the License.
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: * The most basic Callbacks to be handled when using a LoginContext from JAAS, are the NameCallback and
28: * PasswordCallback. The acegi security framework provides the JaasPasswordCallbackHandler specifically tailored to
29: * handling the PasswordCallback. <br>
30: *
31: * @author Ray Krueger
32: * @version $Id: JaasPasswordCallbackHandler.java 1784 2007-02-24 21:00:24Z luke_t $
33: *
34: * @see <a href="http://java.sun.com/j2se/1.4.2/docs/api/javax/security/auth/callback/Callback.html">Callback</a>
35: * @see <a href="http://java.sun.com/j2se/1.4.2/docs/api/javax/security/auth/callback/PasswordCallback.html">
36: * PasswordCallback</a>
37: */
38: public class JaasPasswordCallbackHandler implements
39: JaasAuthenticationCallbackHandler {
40: //~ Methods ========================================================================================================
41:
42: /**
43: * If the callback passed to the 'handle' method is an instance of PasswordCallback, the
44: * JaasPasswordCallbackHandler will call, callback.setPassword(authentication.getCredentials().toString()).
45: *
46: * @param callback
47: * @param auth
48: *
49: * @throws IOException
50: * @throws UnsupportedCallbackException
51: */
52: public void handle(Callback callback, Authentication auth)
53: throws IOException, UnsupportedCallbackException {
54: if (callback instanceof PasswordCallback) {
55: PasswordCallback pc = (PasswordCallback) callback;
56: pc.setPassword(auth.getCredentials().toString()
57: .toCharArray());
58: }
59: }
60: }
|