mulecallbackhandler.java

来自「提供ESB 应用mule源代码 提供ESB 应用mule源代码」· Java 代码 · 共 69 行

JAVA
69
字号
/* * $Id: MuleCallbackHandler.java 10662 2008-02-01 13:10:14Z romikk $ * -------------------------------------------------------------------------------------- * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com * * The software in this package is published under the terms of the CPAL v1.0 * license, a copy of which has been included with this distribution in the * LICENSE.txt file. */package org.mule.module.jaas;import org.mule.api.security.Authentication;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;public class MuleCallbackHandler implements CallbackHandler{    private Authentication authentication;    private String username;    private String password;    /**     * @param authentication     */    public MuleCallbackHandler(Authentication authentication)    {        this.authentication = authentication;        this.username = (String) this.authentication.getPrincipal();        this.password = (String) this.authentication.getCredentials();    }    /**     * The handle() method handles the callbacks to be passed to the Jaas security.     * It makes use of two types of callbacks: the NameCallback and the     * PasswordCallback.     *      * @param callbacks     * @throws IOException     * @throws UnsupportedCallbackException     */    public final void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException    {        for (int i = 0; i < callbacks.length; i++)        {            if (callbacks[i] instanceof NameCallback)            {                NameCallback nameCb = (NameCallback) callbacks[i];                nameCb.setName(username);            }            else if (callbacks[i] instanceof PasswordCallback)            {                PasswordCallback passCb = (PasswordCallback) callbacks[i];                passCb.setPassword(password.toCharArray());            }            else            {                throw (new UnsupportedCallbackException(callbacks[i], "Callback class not supported"));            }        }    }}

⌨️ 快捷键说明

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