Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
86 | rm5248 | 1 | /* |
2 | * Licensed to the Apache Software Foundation (ASF) under one |
||
3 | * or more contributor license agreements. See the NOTICE file |
||
4 | * distributed with this work for additional information |
||
5 | * regarding copyright ownership. The ASF licenses this file |
||
6 | * to you under the Apache License, Version 2.0 (the |
||
7 | * "License"); you may not use this file except in compliance |
||
8 | * with the License. You may obtain a copy of the License at |
||
9 | * |
||
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
11 | * |
||
12 | * Unless required by applicable law or agreed to in writing, |
||
13 | * software distributed under the License is distributed on an |
||
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||
15 | * KIND, either express or implied. See the License for the |
||
16 | * specific language governing permissions and limitations |
||
17 | * under the License. |
||
18 | */ |
||
19 | package org.apache.sshd.agent.local; |
||
20 | |||
21 | import java.io.IOException; |
||
22 | import java.util.UUID; |
||
23 | |||
24 | import org.apache.sshd.agent.SshAgent; |
||
25 | import org.apache.sshd.agent.SshAgentServer; |
||
26 | import org.apache.sshd.client.future.OpenFuture; |
||
27 | import org.apache.sshd.common.session.ConnectionService; |
||
28 | import org.apache.sshd.server.session.ServerSession; |
||
29 | import org.slf4j.Logger; |
||
30 | import org.slf4j.LoggerFactory; |
||
31 | |||
32 | /** |
||
33 | * The server side fake agent, acting as an agent, but actually forwarding the requests to the auth channel on the client side. |
||
34 | */ |
||
35 | public class AgentServerProxy implements SshAgentServer { |
||
36 | |||
37 | private static final Logger LOG = LoggerFactory.getLogger(AgentServerProxy.class); |
||
38 | |||
39 | private final ConnectionService service; |
||
40 | private String id; |
||
41 | |||
42 | public AgentServerProxy(ConnectionService service) throws IOException { |
||
43 | this.service = service; |
||
44 | this.id = UUID.randomUUID().toString(); |
||
45 | } |
||
46 | |||
47 | public SshAgent createClient() throws IOException { |
||
48 | try { |
||
49 | AgentForwardedChannel channel = new AgentForwardedChannel(); |
||
50 | this.service.registerChannel(channel); |
||
51 | OpenFuture future = channel.open().await(); |
||
52 | Throwable t = future.getException(); |
||
53 | if (t instanceof Exception) { |
||
54 | throw (Exception) t; |
||
55 | } else if (t != null) { |
||
56 | throw new Exception(t); |
||
57 | } |
||
58 | return channel.getAgent(); |
||
59 | } catch (IOException e) { |
||
60 | throw e; |
||
61 | } catch (Exception e) { |
||
62 | throw (IOException) new IOException().initCause(e); |
||
63 | } |
||
64 | } |
||
65 | |||
66 | public String getId() { |
||
67 | return id; |
||
68 | } |
||
69 | |||
70 | public void close() { |
||
71 | } |
||
72 | |||
73 | } |