From ae21671f1f262c7db4e8d614feaae90ec4af34e5 Mon Sep 17 00:00:00 2001 From: Alex Mukha Date: Fri, 22 Jan 2016 10:07:52 +0000 Subject: [PATCH] Merged 5.1.N (5.1.1) to HEAD (5.1) 121275 amukha: Merged 5.0.N (5.0.4) to 5.1.N (5.1.1) 121273 amukha: Merged V4.2-BUG-FIX (4.2.6) to 5.0.N (5.0.4) (PARTIAL MERGE) 121272 amukha: Merged V4.1-BUG-FIX (4.1.11) to V4.2-BUG-FIX (4.2.6) 121271 amukha: MNT-15543: CLONE - Remote access via JMX should be disabled by default - Added additional bean configuration to fully disable RMI by default. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@121291 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/repository.properties | 2 +- .../AlfrescoRmiRegistryFactoryBean.java | 103 ++++++++++++++++++ 2 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 source/java/org/alfresco/util/remote/server/AlfrescoRmiRegistryFactoryBean.java diff --git a/config/alfresco/repository.properties b/config/alfresco/repository.properties index 6d84641e57..b20c893f9c 100644 --- a/config/alfresco/repository.properties +++ b/config/alfresco/repository.properties @@ -592,7 +592,7 @@ monitor.rmi.service.port=50508 # # enable or disable individual RMI services # -monitor.rmi.service.enabled=true +monitor.rmi.service.enabled=false # Should the Mbean server bind to an existing server. Set to true for most application servers. diff --git a/source/java/org/alfresco/util/remote/server/AlfrescoRmiRegistryFactoryBean.java b/source/java/org/alfresco/util/remote/server/AlfrescoRmiRegistryFactoryBean.java new file mode 100644 index 0000000000..a05e401983 --- /dev/null +++ b/source/java/org/alfresco/util/remote/server/AlfrescoRmiRegistryFactoryBean.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2005-2016 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.util.remote.server; + +import org.springframework.remoting.rmi.RmiRegistryFactoryBean; + +import java.rmi.RemoteException; +import java.rmi.registry.Registry; +import java.rmi.server.RMIClientSocketFactory; +import java.rmi.server.RMIServerSocketFactory; + +/** + * This class controls the RMI connectivity via alfresco.jmx.connector.enabled property + * + * @author alex.mukha + */ +public class AlfrescoRmiRegistryFactoryBean extends RmiRegistryFactoryBean +{ + private static final String ERR_MSG_NOT_ENABLED = "The RMI registry factory is disabled."; + + private boolean enabled = true; + + public void setEnabled(boolean enabled) + { + this.enabled = enabled; + } + + public boolean isEnabled() + { + return enabled; + } + + @Override + public void afterPropertiesSet() throws Exception + { + if (enabled) + { + super.afterPropertiesSet(); + } + } + + @Override + protected Registry getRegistry( + String registryHost, + int registryPort, + RMIClientSocketFactory clientSocketFactory, + RMIServerSocketFactory serverSocketFactory) throws RemoteException + { + if(enabled) + { + return super.getRegistry(registryHost, registryPort, clientSocketFactory, serverSocketFactory); + } + else + { + throw new RemoteException(ERR_MSG_NOT_ENABLED); + } + } + + @Override + protected Registry getRegistry( + int registryPort, + RMIClientSocketFactory clientSocketFactory, + RMIServerSocketFactory serverSocketFactory) throws RemoteException + { + if(enabled) + { + return super.getRegistry(registryPort, clientSocketFactory, serverSocketFactory); + } + else + { + throw new RemoteException(ERR_MSG_NOT_ENABLED); + } + } + + @Override + protected Registry getRegistry(int registryPort) throws RemoteException + { + if(enabled) + { + return super.getRegistry(registryPort); + } + else + { + throw new RemoteException(ERR_MSG_NOT_ENABLED); + } + } +}