01: /*
02: * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05: package com.sun.portal.monitoring.security.sasl;
06:
07: import com.sun.portal.monitoring.security.User;
08: import com.sun.portal.monitoring.security.UserManager;
09:
10: import javax.security.auth.callback.*;
11: import javax.security.sasl.SaslException;
12: import java.io.File;
13: import java.io.IOException;
14:
15: public class SaslCallbackHandler implements CallbackHandler {
16: public SaslCallbackHandler(SaslContext saslContext) {
17: this .saslContext = saslContext;
18: }
19:
20: public void handle(Callback[] callbacks) throws IOException,
21: UnsupportedCallbackException {
22: String userId;
23: char[] password;
24:
25: try {
26: UserManager userManager = new UserManager(saslContext
27: .getPropertyHelper());
28: User user = userManager.read(saslContext
29: .getUserPasswordDirectory()
30: + File.separator
31: + saslContext.getUserPasswordFileName());
32: userId = user.getName();
33: password = user.getPassword();
34: } catch (com.sun.portal.monitoring.security.SecurityException se) {
35: throw new SaslException(se.toString());
36: }
37:
38: NameCallback cbName = null;
39: PasswordCallback cbPassword = null;
40:
41: for (int i = 0; i < callbacks.length; i++) {
42: if (callbacks[i] instanceof NameCallback) {
43: cbName = (NameCallback) callbacks[i];
44: } else if (callbacks[i] instanceof PasswordCallback) {
45: cbPassword = (PasswordCallback) callbacks[i];
46: }
47: }
48:
49: if ((cbName != null) && (cbPassword != null)) {
50: cbName.setName(userId);
51: cbPassword.setPassword(password);
52: }
53: }
54:
55: private SaslContext saslContext;
56: }
|