⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simplecallbackhandler.java

📁 如题ServletJSP.rar 为网络收集的JSP网站源文件
💻 JAVA
字号:
package org.redsoft.forum.security;

import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.UnsupportedCallbackException;
import java.io.IOException;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.PasswordCallback;

/*
 * A simple CallbackHandler that handles name and password
 *
 *
 * @author Charles Huang
 * @since JDK1.4
 * @version $Id: SimpleCallbackHandler.java,v 1.1.1.1 2003/07/08 08:25:17 cinc Exp $
 */
public class SimpleCallbackHandler implements CallbackHandler{
    private String username;
    private String password;

    public SimpleCallbackHandler( final String username, final String password) {
        this.username = username;
        this.password = password;
    }

    /**
     * This handler only hanldes name and password
     *
     * @param callbacks an array of <code>Callback</code> objects provided
     *		by an underlying security service which contains
     *		the information requested to be retrieved or displayed.
     *
     * @exception java.io.IOException if an input or output error occurs. <p>
     *
     * @exception UnsupportedCallbackException if the implementation of this
     *		method does not support one or more of the Callbacks
     *		specified in the <code>callbacks</code> parameter.
     */
    public void handle(Callback[] callbacks)
            throws IOException, UnsupportedCallbackException {
        for( int index = 0; index < callbacks.length; index++ ){
            if(callbacks[ index ] instanceof NameCallback){
                NameCallback ncb = (NameCallback)callbacks[ index ];
                ncb.setName(username);
            }
            if(callbacks[ index ] instanceof PasswordCallback){
                PasswordCallback pcb = (PasswordCallback)callbacks[ index ];
                pcb.setPassword(password.toCharArray());
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -