1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.geronimo.gshell.remote.server.handler;
21
22 import org.apache.geronimo.gshell.remote.crypto.CryptoContext;
23 import org.apache.geronimo.gshell.remote.message.ConnectMessage;
24 import org.apache.geronimo.gshell.remote.server.RshServer;
25 import org.apache.geronimo.gshell.remote.server.timeout.TimeoutManager;
26 import org.apache.mina.common.IoSession;
27 import org.codehaus.plexus.component.annotations.Component;
28 import org.codehaus.plexus.component.annotations.Requirement;
29
30 /**
31 * ???
32 *
33 * @version $Rev: 580731 $ $Date: 2007-09-30 07:52:42 -0700 (Sun, 30 Sep 2007) $
34 */
35 @Component(role=ServerMessageHandler.class, hint="connect")
36 public class ConnectHandler
37 extends ServerMessageHandlerSupport<ConnectMessage>
38 {
39 @Requirement
40 private CryptoContext crypto;
41
42 @Requirement
43 private TimeoutManager timeoutManager;
44
45 public ConnectHandler() {
46 super(ConnectMessage.class);
47 }
48
49 public void handle(final IoSession session, final ServerSessionContext context, final ConnectMessage message) throws Exception {
50
51 if (!timeoutManager.cancelTimeout(session)) {
52 log.warn("Aborting handshake processing; timeout has triggered");
53 }
54 else {
55
56 context.pk = message.getPublicKey();
57
58
59 ConnectMessage.Result reply = new ConnectMessage.Result(crypto.getPublicKey());
60 reply.setCorrelationId(message.getId());
61 session.write(reply);
62
63
64 timeoutManager.scheduleTimeout(session, RshServer.AUTH_TIMEOUT, new Runnable() {
65 public void run() {
66 log.error("Timeout waiting for login from: {}", session.getRemoteAddress());
67 session.close();
68 }
69 });
70 }
71 }
72 }