KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > transport > tcp > SslTransportServer


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * 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, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 package org.apache.activemq.transport.tcp;
20
21 import org.apache.activemq.wireformat.WireFormat;
22 import org.apache.activemq.transport.Transport;
23
24 import java.io.IOException JavaDoc;
25 import java.net.Socket JavaDoc;
26 import java.net.URI JavaDoc;
27 import java.net.URISyntaxException JavaDoc;
28
29 import javax.net.ssl.SSLServerSocket;
30 import javax.net.ssl.SSLServerSocketFactory;
31 import javax.net.ssl.SSLSocket;
32
33 /**
34  * An SSL TransportServer.
35  *
36  * Allows for client certificate authentication (refer to setNeedClientAuth for
37  * details).
38  * NOTE: Client certificate authentication is disabled by default.
39  *
40  */

41 public class SslTransportServer extends TcpTransportServer {
42     
43     // Specifies if sockets created from this server should needClientAuth.
44
private boolean needClientAuth = false;
45     
46     // Specifies if sockets created from this server should wantClientAuth.
47
private boolean wantClientAuth = false;
48     
49     
50     /**
51      * Creates a ssl transport server for the specified url using the provided
52      * serverSocketFactory
53      *
54      * @param transportFactory The factory used to create transports when connections arrive.
55      * @param location The location of the broker to bind to.
56      * @param serverSocketFactory The factory used to create this server.
57      * @throws IOException passed up from TcpTransportFactory.
58      * @throws URISyntaxException passed up from TcpTransportFactory.
59      */

60     public SslTransportServer(
61             SslTransportFactory transportFactory,
62             URI JavaDoc location,
63             SSLServerSocketFactory serverSocketFactory) throws IOException JavaDoc, URISyntaxException JavaDoc {
64         super(transportFactory, location, serverSocketFactory);
65     }
66     
67     /**
68      * Sets whether client authentication should be required
69      * Must be called before {@link #bind()}
70      * Note: Calling this method clears the wantClientAuth flag
71      * in the underlying implementation.
72      */

73     public void setNeedClientAuth(boolean needAuth) {
74         this.needClientAuth = needAuth;
75     }
76     
77     /**
78      * Returns whether client authentication should be required.
79      */

80     public boolean getNeedClientAuth() {
81         return this.needClientAuth;
82     }
83     
84     /**
85      * Returns whether client authentication should be requested.
86      */

87     public boolean getWantClientAuth() {
88         return this.wantClientAuth;
89     }
90     
91     /**
92      * Sets whether client authentication should be requested.
93      * Must be called before {@link #bind()}
94      * Note: Calling this method clears the needClientAuth flag
95      * in the underlying implementation.
96      */

97     public void setWantClientAuth(boolean wantAuth) {
98         this.wantClientAuth = wantAuth;
99     }
100     
101     /**
102      * Binds this socket to the previously specified URI.
103      *
104      * Overridden to allow for proper handling of needClientAuth.
105      *
106      * @throws IOException passed up from TcpTransportServer.
107      */

108     public void bind() throws IOException JavaDoc {
109         super.bind();
110         ((SSLServerSocket)this.serverSocket).setWantClientAuth(wantClientAuth);
111         ((SSLServerSocket)this.serverSocket).setNeedClientAuth(needClientAuth);
112     }
113     
114     /**
115      * Used to create Transports for this server.
116      *
117      * Overridden to allow the use of SslTransports (instead of TcpTransports).
118      *
119      * @param socket The incoming socket that will be wrapped into the new Transport.
120      * @param format The WireFormat being used.
121      * @return The newly return (SSL) Transport.
122      * @throws IOException
123      */

124     protected Transport createTransport(Socket JavaDoc socket, WireFormat format) throws IOException JavaDoc {
125         return new SslTransport(format, (SSLSocket)socket);
126     }
127 }
128
Popular Tags