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 2015 ForgeRock AS.
016 */
017package org.opends.server.protocols.jmx;
018
019import java.io.IOException;
020import java.rmi.server.RMIClientSocketFactory;
021import java.rmi.server.RMIServerSocketFactory;
022import java.util.Map;
023import java.util.Set;
024
025import javax.management.remote.rmi.RMIJRMPServerImpl;
026import javax.management.remote.rmi.RMIConnection;
027import javax.security.auth.Subject;
028
029/**
030 * An <code>OpendsRMIJRMPServerImpl</code> object that is exported
031 * through JRMP and that creates client connections as RMI objects exported
032 * through JRMP.
033 */
034public class OpendsRMIJRMPServerImpl
035    extends RMIJRMPServerImpl
036{
037  /**
038   * Creates a new RMIServer object that will be exported on the given port
039   * using the given socket factories.
040   *
041   * @param port
042   *        the port on which this object and the RMIConnectionImpl objects
043   *        it creates will be exported. Can be zero, to indicate any
044   *        available port
045   * @param csf
046   *        the client socket factory for the created RMI objects. Can be
047   *        null.
048   * @param ssf
049   *        the server socket factory for the created RMI objects. Can be
050   *        null.
051   * @param env
052   *        the environment map. Can be null.
053   * @throws IOException
054   *         if the RMIServer object cannot be created.
055   */
056  public OpendsRMIJRMPServerImpl(int port, RMIClientSocketFactory csf,
057      RMIServerSocketFactory ssf, Map<String, ?> env) throws IOException
058  {
059    super(port, csf, ssf, env);
060  }
061
062  /** {@inheritDoc} */
063  @Override
064  protected RMIConnection makeClient(String connectionId, Subject subject)
065      throws IOException
066  {
067    if (subject != null)
068    {
069      Set<Credential> privateCreds = subject
070          .getPrivateCredentials(Credential.class);
071      JmxClientConnection jmxClientConnection =
072       (JmxClientConnection)
073       privateCreds.iterator().next().getClientConnection();
074      jmxClientConnection.jmxConnectionID = connectionId;
075    }
076
077    return super.makeClient(connectionId, subject);
078  }
079
080}