1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.waarp.commandexec.ssl.server;
21
22 import io.netty.channel.ChannelPipeline;
23 import io.netty.channel.socket.SocketChannel;
24 import io.netty.handler.codec.DelimiterBasedFrameDecoder;
25 import io.netty.handler.codec.Delimiters;
26 import io.netty.handler.codec.string.StringDecoder;
27 import io.netty.handler.codec.string.StringEncoder;
28 import io.netty.handler.ssl.SslHandler;
29 import io.netty.util.concurrent.EventExecutorGroup;
30 import org.waarp.commandexec.server.LocalExecServerInitializer;
31 import org.waarp.commandexec.utils.LocalExecDefaultResult;
32 import org.waarp.common.crypto.ssl.WaarpSslContextFactory;
33
34
35
36
37 public class LocalExecSslServerInitializer extends LocalExecServerInitializer {
38
39 private final WaarpSslContextFactory waarpSslContextFactory;
40
41 private long delay = LocalExecDefaultResult.MAXWAITPROCESS;
42
43
44
45
46
47
48
49 public LocalExecSslServerInitializer(
50 final WaarpSslContextFactory waarpSslContextFactory,
51 final EventExecutorGroup eventExecutorGroup) {
52
53 super(eventExecutorGroup);
54 this.waarpSslContextFactory = waarpSslContextFactory;
55 }
56
57
58
59
60
61
62
63 public LocalExecSslServerInitializer(
64 final WaarpSslContextFactory waarpSslContextFactory, final long newdelay,
65 final EventExecutorGroup eventExecutorGroup) {
66 super(eventExecutorGroup);
67 delay = newdelay;
68 this.waarpSslContextFactory = waarpSslContextFactory;
69 }
70
71 @Override
72 public void initChannel(final SocketChannel ch) {
73
74 final ChannelPipeline pipeline = ch.pipeline();
75
76
77 final SslHandler sslhandler = waarpSslContextFactory.createHandlerServer(
78 waarpSslContextFactory.needClientAuthentication(), ch);
79 pipeline.addLast("ssl", sslhandler);
80
81 pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192,
82 Delimiters.lineDelimiter()));
83 pipeline.addLast(eventExecutorGroup, "decoder", new StringDecoder());
84 pipeline.addLast(eventExecutorGroup, "encoder", new StringEncoder());
85
86
87
88 pipeline.addLast(eventExecutorGroup, "handler",
89 new LocalExecSslServerHandler(this, delay));
90 }
91
92 }