001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2006-2008 Sun Microsystems, Inc. 015 * Portions Copyright 2014-2015 ForgeRock AS. 016 */ 017package org.opends.server.protocols.jmx; 018 019import java.io.IOException; 020import java.net.InetAddress; 021import java.net.ServerSocket; 022import java.rmi.server.RMIServerSocketFactory; 023 024/** 025 * An implementation of the socketServer. 026 * <p> 027 * The RMI connector class starts and stops the JMX RMI connector server. 028 * There are 2 different connector servers 029 * <ul> 030 * <li>the RMI Client connector server, supporting TLS-encrypted communication, 031 * server authentication by certificate and client 032 * authentication by providing appropriate LDAP credentials through 033 * SASL/PLAIN.</li> 034 * <li>the RMI client connector server, supporting TLS-encrypted communication, 035 * server authentication by certificate, client 036 * authentication by certificate and identity assertion through SASL/PLAIN.</li> 037 * </ul> 038 * <p> 039 * Each connector is registered into the JMX MBean server. 040 */ 041public class OpendsRmiServerSocketFactory implements RMIServerSocketFactory 042{ 043 /** The address to listen on, which could be INADDR_ANY. */ 044 private final InetAddress listenAddress; 045 046 /** The created ServerSocket. */ 047 private ServerSocket serverSocket; 048 049 /** 050 * Create a new socket factory which will listen on the specified address. 051 * 052 * @param listenAddress The address to listen on. 053 */ 054 public OpendsRmiServerSocketFactory(InetAddress listenAddress) 055 { 056 this.listenAddress = listenAddress; 057 } 058 059 /** {@inheritDoc} */ 060 @Override 061 public ServerSocket createServerSocket(int port) throws IOException 062 { 063 serverSocket = new ServerSocket(port, 50, listenAddress); 064 return serverSocket; 065 } 066 067 /** 068 * Close the underlying socket. 069 * 070 * @throws IOException If an I/O error occurs when closing the socket. 071 */ 072 void close() throws IOException 073 { 074 if (serverSocket != null) 075 { 076 serverSocket.close(); 077 serverSocket = null; 078 } 079 } 080}