KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > security > domain > DomainServerSocketFactoryService


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.remoting.security.domain;
8
9 import java.io.IOException JavaDoc;
10 import java.net.InetAddress JavaDoc;
11 import java.net.ServerSocket JavaDoc;
12 import javax.naming.InitialContext JavaDoc;
13 import org.jboss.security.SecurityDomain;
14 import org.jboss.security.ssl.DomainServerSocketFactory;
15
16 /**
17  * @author <a HREF="mailto:tom.elrod@jboss.com">Tom Elrod</a>
18  */

19 public class DomainServerSocketFactoryService implements DomainServerSocketFactoryServiceMBean
20 {
21    private String JavaDoc securityDomain = null;
22    private DomainServerSocketFactory serverSocketFactory = null;
23
24    /**
25     * Returns an unbound server socket. The socket is configured with the socket
26     * options (such as accept timeout) given to this factory.
27     *
28     * @return
29     * @throws java.io.IOException
30     */

31    public ServerSocket JavaDoc createServerSocket() throws IOException JavaDoc
32    {
33       return serverSocketFactory.createServerSocket();
34    }
35
36    /**
37     * Returns a server socket bound to the specified port. The socket is configured
38     * with the socket options (such as accept timeout) given to this factory.
39     *
40     * @param i
41     * @return
42     * @throws java.io.IOException
43     */

44    public ServerSocket JavaDoc createServerSocket(int i) throws IOException JavaDoc
45    {
46       return serverSocketFactory.createServerSocket(i);
47    }
48
49    /**
50     * Returns a server socket bound to the specified port,
51     * and uses the specified connection backlog. The socket is configured
52     * with the socket options (such as accept timeout) given to this factory.
53     *
54     * @param i
55     * @param i1
56     * @return
57     * @throws java.io.IOException
58     */

59    public ServerSocket JavaDoc createServerSocket(int i, int i1) throws IOException JavaDoc
60    {
61       return serverSocketFactory.createServerSocket(i, i1);
62    }
63
64    /**
65     * Returns a server socket bound to the specified port, with a specified
66     * listen backlog and local IP. The bindAddr argument can be used on a multi-homed
67     * host for a ServerSocket that will only accept connect requests to one of its addresses.
68     * The socket is configured with the socket options (such as accept timeout) given to this factory.
69     *
70     * @param i
71     * @param i1
72     * @param inetAddress
73     * @return
74     * @throws java.io.IOException
75     */

76    public ServerSocket JavaDoc createServerSocket(int i, int i1, InetAddress JavaDoc inetAddress) throws IOException JavaDoc
77    {
78       return serverSocketFactory.createServerSocket(i, i1, inetAddress);
79    }
80
81    public void setSecurityDomain(String JavaDoc securityDomain)
82    {
83       this.securityDomain = securityDomain;
84    }
85
86    public String JavaDoc getSecurityDomain()
87    {
88       return securityDomain;
89    }
90
91    /**
92     * start the service, create is already called
93     */

94    public void start() throws Exception JavaDoc
95    {
96       if(securityDomain != null)
97       {
98          InitialContext JavaDoc ctx = new InitialContext JavaDoc();
99          SecurityDomain domain = (SecurityDomain) ctx.lookup(securityDomain);
100          serverSocketFactory = new DomainServerSocketFactory();
101          serverSocketFactory.setSecurityDomain(domain);
102       }
103       else
104       {
105          throw new Exception JavaDoc("Can not create server socket factory due to the SecurityDomain not being set.");
106       }
107    }
108
109    /**
110     * create the service, do expensive operations etc
111     */

112    public void create() throws Exception JavaDoc
113    {
114       //NOOP
115
}
116
117    /**
118     * stop the service
119     */

120    public void stop()
121    {
122       //NOOP
123
}
124
125    /**
126     * destroy the service, tear down
127     */

128    public void destroy()
129    {
130       //NOOP
131
}
132
133 }
Popular Tags