Path: blob/master/test/jdk/javax/management/security/ServerDelegate.java
41149 views
/*1* Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.security.Principal;24import java.util.ArrayList;25import java.util.List;2627import javax.management.remote.JMXServiceURL ;28import javax.management.MBeanRegistration;29import javax.management.MBeanServer;30import javax.management.ObjectName;31import javax.management.StandardMBean;3233/**34* This class defines an MBean that can be registered and used on client side35* to handle informations or properties of the remote server.36*37* For example, this MBean can store IOR addresses38* of RMI/IIOP connector(s) used in a test.39*40* That MBean might not be used for testing purpose itself.41*/42public class ServerDelegate implements ServerDelegateMBean, MBeanRegistration {4344private MBeanServer mbeanServer = null;45private List<JMXServiceURL> addresses = null;46private String port;47private static String javaVersion = System.getProperty("java.version");48private int sqeJmxwsCredentialsProviderCallCount = 0;49private String jmxwsCredentialsProviderUrl = null;50private int testJMXAuthenticatorCallCount = 0;51private Principal testJMXAuthenticatorPrincipal = null;5253@SqeDescriptorKey("NO PARAMETER CONSTRUCTOR ServerDelegate")54public ServerDelegate() {55addresses = new ArrayList<JMXServiceURL>();56}5758public ObjectName preRegister(MBeanServer server, ObjectName name)59throws Exception {60// Initialize MBeanServer attribute61mbeanServer = server;62return name;63}64public void postRegister(Boolean registrationDone) {65}66public void preDeregister() throws Exception {67}68public void postDeregister() {69}7071public void addAddress(JMXServiceURL url) {72addresses.add(url) ;73}7475public List<JMXServiceURL> getAddresses() {76return addresses ;77}7879public void setPort(String p) {80port = p ;81}8283public String getPort() {84return port ;85}8687public String getJavaVersion() {88return javaVersion;89}9091public void sqeJmxwsCredentialsProviderCalled() {92sqeJmxwsCredentialsProviderCallCount++;93}9495public int getSqeJmxwsCredentialsProviderCallCount() {96return sqeJmxwsCredentialsProviderCallCount;97}9899public void setJmxwsCredentialsProviderUrl(String url) {100jmxwsCredentialsProviderUrl = url;101}102103public String getJmxwsCredentialsProviderUrl() {104return jmxwsCredentialsProviderUrl;105}106107public void testJMXAuthenticatorCalled() {108testJMXAuthenticatorCallCount++;109}110111public int getTestJMXAuthenticatorCallCount() {112return testJMXAuthenticatorCallCount;113}114115public void setTestJMXAuthenticatorPrincipal(Principal principal) {116testJMXAuthenticatorPrincipal = principal;117}118119public String getTestJMXAuthenticatorPrincipalString() {120if ( testJMXAuthenticatorPrincipal != null ) {121return testJMXAuthenticatorPrincipal.toString();122}123124return null;125}126127/**128* Instantiates and registers a StandardMBean in the MBean server.129*130* @param implementationClassName131* The implementation class name of the MBean.132* @param interfaceClassName133* The management interface class name of the MBean.134* @param isMXBean135* If true, the resultant MBean is an MXBean.136* @param name137* The object name of the StandardMBean.138*/139@SuppressWarnings("unchecked")140public void createStandardMBean(141String implementationClassName,142String interfaceClassName,143boolean isMXBean,144ObjectName name)145throws Exception {146147Object implementation =148Class.forName(implementationClassName).newInstance();149Class<Object> interfaceClass = interfaceClassName == null ? null :150(Class<Object>)Class.forName(interfaceClassName);151152// Create the StandardMBean153StandardMBean standardMBean = new StandardMBean(154implementation,155interfaceClass,156isMXBean);157158// Register the StandardMBean159mbeanServer.registerMBean(standardMBean, name);160}161162/**163* Instantiates and registers a StandardMBean in the MBean server.164* The object will use standard JMX design pattern to determine165* the management interface associated with the given implementation.166*/167@SuppressWarnings("unchecked")168public void createStandardMBean(169String implementationClassName,170boolean isMXBean,171ObjectName name)172throws Exception {173174createStandardMBean(implementationClassName, null, isMXBean, name);175}176}177178179