001package org.apache.maven.wagon.providers.ssh.jsch.interactive;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import com.jcraft.jsch.UIKeyboardInteractive;
023import com.jcraft.jsch.UserInfo;
024
025/**
026 * A proxy that let you merge a <code>UserInfo</code> and a
027 * <code>UIKeyboardInteractive</code>
028 *
029 * @author Juan F. Codagnone
030 * @since Sep 22, 2005
031 */
032public class UserInfoUIKeyboardInteractiveProxy
033    implements UserInfo, UIKeyboardInteractive
034{
035    private final UIKeyboardInteractive interactive;
036
037    private final UserInfo userInfo;
038
039    public UserInfoUIKeyboardInteractiveProxy( UserInfo userInfo, UIKeyboardInteractive interactive )
040    {
041        this.userInfo = userInfo;
042        this.interactive = interactive;
043    }
044
045    /**
046     * @see com.jcraft.jsch.UIKeyboardInteractive#promptKeyboardInteractive(String,String,String,String[],boolean[])
047     */
048    public String[] promptKeyboardInteractive( String destination, String name, String instruction, String[] prompt,
049                                               boolean[] echo )
050    {
051        if ( userInfo.getPassword() != null )
052        {
053            prompt[0] = "Keyboard interactive required, supplied password is ignored\n" + prompt[0];
054        }
055        return interactive.promptKeyboardInteractive( destination, name, instruction, prompt, echo );
056    }
057
058    /**
059     * @see com.jcraft.jsch.UserInfo#getPassphrase()
060     */
061    public String getPassphrase()
062    {
063        return userInfo.getPassphrase();
064    }
065
066    /**
067     * @see com.jcraft.jsch.UserInfo#getPassword()
068     */
069    public String getPassword()
070    {
071        return userInfo.getPassword();
072    }
073
074    /**
075     * @see com.jcraft.jsch.UserInfo#promptPassword(String)
076     */
077    public boolean promptPassword( String arg0 )
078    {
079        return userInfo.promptPassword( arg0 );
080    }
081
082    /**
083     * @see com.jcraft.jsch.UserInfo#promptPassphrase(String)
084     */
085    public boolean promptPassphrase( String arg0 )
086    {
087        return userInfo.promptPassphrase( arg0 );
088    }
089
090    /**
091     * @see com.jcraft.jsch.UserInfo#promptYesNo(String)
092     */
093    public boolean promptYesNo( String arg0 )
094    {
095        return userInfo.promptYesNo( arg0 );
096    }
097
098    /**
099     * @see com.jcraft.jsch.UserInfo#showMessage(String)
100     */
101    public void showMessage( String arg0 )
102    {
103        userInfo.showMessage( arg0 );
104    }
105
106}