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