simplecallbackhandler.java
来自「Chinaxp 论坛源代码」· Java 代码 · 共 56 行
JAVA
56 行
package org.redsoft.forum.security;import java.io.IOException;import javax.security.auth.callback.Callback;import javax.security.auth.callback.CallbackHandler;import javax.security.auth.callback.NameCallback;import javax.security.auth.callback.PasswordCallback;import javax.security.auth.callback.UnsupportedCallbackException;/* * A simple CallbackHandler that handles name and password * * * @author Charles Huang * @since JDK1.4 * @version $Id: SimpleCallbackHandler.java,v 1.2 2004/04/10 19:57:00 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 + =
减小字号Ctrl + -
显示快捷键?