001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)UsrPwdCallbackHandler.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: /**
030: * UsrPwdCallbackHandler.java
031: *
032: * SUN PROPRIETARY/CONFIDENTIAL.
033: * This software is the proprietary information of Sun Microsystems, Inc.
034: * Use is subject to license terms.
035: *
036: * Created on January 25, 2005, 10:37 PM
037: */package com.sun.jbi.internal.security.callback;
038:
039: import javax.security.auth.callback.Callback;
040: import javax.security.auth.callback.CallbackHandler;
041: import javax.security.auth.callback.NameCallback;
042: import javax.security.auth.callback.PasswordCallback;
043:
044: /**
045: * This CallbackHandler handles only NameCallback and
046: * PasswordCallbacks, this handler is primarily used to provide
047: * username and password information which is known apriori to
048: * a LoginModule.
049: *
050: * @author Sun Microsystems, Inc.
051: */
052: public class UsrPwdCallbackHandler implements CallbackHandler {
053: /** The Username to provide to a NameCallback. */
054: private String mUsername = null;
055:
056: /** The Password to provide to a PasswordCallback. */
057: private char[] mPassword = null;
058:
059: /**
060: * @param username - user name
061: * @param password - password
062: */
063: public UsrPwdCallbackHandler(String username, String password) {
064: mUsername = username;
065: mPassword = password.toCharArray();
066: }
067:
068: /**
069: * @param username - user name
070: * @param password - password char array
071: */
072: public UsrPwdCallbackHandler(String username, char[] password) {
073: mUsername = username;
074: mPassword = password;
075: }
076:
077: /**
078: * Handle an array of Callbacks.
079: *
080: * @param callbacks an array of Callback objects which contain
081: * the information requested by an underlying security
082: * service to be retrieved or displayed.
083: * @exception java.io.IOException if an input or output error occurs.
084: * @exception javax.security.auth.callback.UnsupportedCallbackException
085: * if the implementation of this method does not support one or more of the Callbacks
086: * specified in the callbacks parameter.
087: */
088: public void handle(Callback[] callbacks)
089: throws java.io.IOException,
090: javax.security.auth.callback.UnsupportedCallbackException {
091: for (int i = 0; i < callbacks.length; i++) {
092: if (callbacks[i] instanceof PasswordCallback) {
093: ((PasswordCallback) callbacks[i])
094: .setPassword(mPassword);
095: } else if (callbacks[i] instanceof NameCallback) {
096: ((NameCallback) callbacks[i]).setName(mUsername);
097: } else {
098: throw new javax.security.auth.callback.UnsupportedCallbackException(
099: callbacks[i]);
100: }
101: }
102: }
103: }
|