jdk/test/javax/management/security/SecurityTest.java
author olagneau
Fri, 18 Dec 2015 17:42:06 +0100
changeset 34827 de746e7eb1e3
child 43503 bc7f8619ab70
permissions -rw-r--r--
8058865: JMX Test Refactoring Reviewed-by: jbachorik
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34827
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
     1
/*
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
     2
 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
     4
 *
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
     7
 * published by the Free Software Foundation.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
     8
 *
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    13
 * accompanied this code).
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    14
 *
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    18
 *
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    21
 * questions.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    22
 */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    23
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    24
/*
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    25
 * @test
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    26
 * @bug 8058865
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    27
 * @summary Checks various secure ways of connecting from remote jmx client
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    28
 * @author Olivier Lagneau
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    29
 * @modules java.management
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    30
 * @library /lib/testlibrary
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    31
 * @compile MBS_Light.java ServerDelegate.java TestSampleLoginModule.java
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    32
 * @run main/othervm/timeout=300 -DDEBUG_STANDARD -Dusername=SQE_username -Dpassword=SQE_password SecurityTest -server -mapType x.password.file -client -mapType credentials
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    33
 * @run main/othervm/timeout=300 -DDEBUG_STANDARD -Dusername=UNKNOWN_username -Dpassword=SQE_password SecurityTest -server -mapType x.password.file -client -mapType credentials -expectedThrowable java.lang.SecurityException
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    34
 * @run main/othervm/timeout=300 -DDEBUG_STANDARD -Dusername=SQE_username -Dpassword=WRONG_password SecurityTest -server -mapType x.password.file -client -mapType credentials -expectedThrowable java.lang.SecurityException
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    35
 * @run main/othervm/timeout=300 -DDEBUG_STANDARD -Dsusername=TestJMXAuthenticatorUsername -Dspassword=TestJMXAuthenticatorPassword -Dusername=TestJMXAuthenticatorUsername -Dpassword=TestJMXAuthenticatorPassword SecurityTest -server -mapType x.authenticator -client -mapType credentials
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    36
 * @run main/othervm/timeout=300 -DDEBUG_STANDARD -Dsusername=TestJMXAuthenticatorUsername -Dspassword=TestJMXAuthenticatorPassword -Dusername=AnotherTestJMXAuthenticatorUsername -Dpassword=TestJMXAuthenticatorPassword SecurityTest -server -mapType x.authenticator -client -mapType credentials -expectedThrowable java.lang.SecurityException
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    37
 * @run main/othervm/timeout=300 -DDEBUG_STANDARD -Dlogin.config.file=${test.src}/login.config -Dpassword.file=password.properties -Dusername=usernameFileLoginModule -Dpassword=passwordFileLoginModule SecurityTest -server -mapType x.login.config.PasswordFileAuthentication -client -mapType credentials
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    38
 * @run main/othervm/timeout=300 -DDEBUG_STANDARD -Dlogin.config.file=${test.src}/login.config.UNKNOWN -Dpassword.file=password.properties -Dusername=usernameFileLoginModule -Dpassword=passwordFileLoginModule SecurityTest -server -mapType x.login.config.PasswordFileAuthentication -client -mapType credentialss -expectedThrowable java.lang.SecurityException
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    39
 * @run main/othervm/timeout=300 -DDEBUG_STANDARD -Dlogin.config.file=${test.src}/login.config -Dpassword.file=password.properties -Dusername=usernameFileLoginModule -Dpassword=passwordFileLoginModule SecurityTest -server -mapType x.login.config.UnknownAuthentication -client -mapType credentials -expectedThrowable java.lang.SecurityException
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    40
 * @run main/othervm/timeout=300 -DDEBUG_STANDARD -Dlogin.config.file=${test.src}/login.config -Dsusername=usernameSampleLoginModule -Dspassword=passwordSampleLoginModule -Dpassword.file=password.properties -Dusername=usernameSampleLoginModule -Dpassword=passwordSampleLoginModule SecurityTest -server -mapType x.login.config.SampleLoginModule -client -mapType credentials
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    41
 * @run main/othervm/timeout=300 -DDEBUG_STANDARD -Dlogin.config.file=${test.src}/login.config -Dsusername=usernameSampleLoginModule -Dspassword=passwordSampleLoginModule -Dpassword.file=password.properties -Dusername=AnotherUsernameSampleLoginModule -Dpassword=passwordSampleLoginModule SecurityTest -server -mapType x.login.config.SampleLoginModule -client -mapType credentials -expectedThrowable java.lang.SecurityException
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    42
 * @run main/othervm/timeout=300 -DDEBUG_STANDARD SecurityTest -server -mapType rmi.client.socket.factory.ssl;rmi.server.socket.factory.ssl -keystore keystoreAgent -keystorepassword glopglop -client -truststore truststoreClient -truststorepassword glopglop
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    43
 * @run main/othervm/timeout=300 -DDEBUG_STANDARD SecurityTest -server -mapType rmi.client.socket.factory.ssl;rmi.server.socket.factory.ssl -keystore keystoreAgent -keystorepassword glopglop -client -truststore truststoreClient -truststorepassword WRONG_password -expectedThrowable java.io.IOException
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    44
 * @run main/othervm/timeout=300 -DDEBUG_STANDARD SecurityTest -server -mapType rmi.server.socket.factory.ssl -keystore keystoreAgent -keystorepassword glopglop -client -truststore truststoreClient -truststorepassword glopglop -expectedThrowable java.io.IOException
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    45
 * @run main/othervm/timeout=300 -DDEBUG_STANDARD SecurityTest -server -mapType rmi.client.socket.factory.ssl -keystore keystoreAgent -keystorepassword glopglop -client -truststore truststoreClient -truststorepassword glopglop -expectedThrowable java.io.IOException
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    46
 * @run main/othervm/timeout=300 -DDEBUG_STANDARD SecurityTest -server -mapType rmi.client.socket.factory.ssl;rmi.server.socket.factory.ssl -keystore keystoreAgent -keystorepassword glopglop -client -expectedThrowable java.io.IOException
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    47
 * @run main/othervm/timeout=300 -DDEBUG_STANDARD SecurityTest -server -mapType rmi.client.socket.factory.ssl;rmi.server.socket.factory.ssl.need.client.authentication -keystore keystoreAgent -keystorepassword glopglop -truststore truststoreAgent -truststorepassword glopglop -client  -keystore keystoreClient -keystorepassword glopglop -truststore truststoreClient -truststorepassword glopglop
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    48
 * @run main/othervm/timeout=300 -DDEBUG_STANDARD SecurityTest -server -mapType rmi.client.socket.factory.ssl;rmi.server.socket.factory.ssl.need.client.authentication -keystore keystoreAgent -keystorepassword glopglop -truststore truststoreAgent -truststorepassword glopglop -client -keystore keystoreClient -keystorepassword WRONG_password -truststore truststoreClient -truststorepassword glopglop -expectedThrowable java.io.IOException
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    49
 * @run main/othervm/timeout=300 -DDEBUG_STANDARD SecurityTest -server -mapType rmi.client.socket.factory.ssl;rmi.server.socket.factory.ssl.need.client.authentication -keystore keystoreAgent -keystorepassword glopglop -truststore truststoreAgent -truststorepassword glopglop -client -truststore truststoreClient -truststorepassword glopglop -expectedThrowable java.io.IOException
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    50
 * @run main/othervm/timeout=300 -DDEBUG_STANDARD SecurityTest -server -mapType rmi.client.socket.factory.ssl;rmi.server.socket.factory.ssl.need.client.authentication -keystore keystoreAgent -keystorepassword glopglop -client -keystore keystoreClient -keystorepassword glopglop -truststore truststoreClient -truststorepassword glopglop -expectedThrowable java.io.IOException
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    51
 * @run main/othervm/timeout=300 -DDEBUG_STANDARD -Djavax.rmi.ssl.client.enabledCipherSuites=SSL_RSA_WITH_RC4_128_MD5 SecurityTest -server -mapType rmi.client.socket.factory.ssl;rmi.server.socket.factory.ssl.enabled.cipher.suites.md5 -keystore keystoreAgent -keystorepassword glopglop -client -truststore truststoreClient -truststorepassword glopglop
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    52
 * @run main/othervm/timeout=300 -DDEBUG_STANDARD -Djavax.rmi.ssl.client.enabledCipherSuites=SSL_RSA_WITH_RC4_128_SHA SecurityTest -server -mapType rmi.client.socket.factory.ssl;rmi.server.socket.factory.ssl.enabled.cipher.suites.md5 -keystore keystoreAgent -keystorepassword glopglop -client -truststore truststoreClient -truststorepassword glopglop -expectedThrowable java.io.IOException
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    53
 * @run main/othervm/timeout=300 -DDEBUG_STANDARD -Djavax.rmi.ssl.client.enabledCipherSuites=SSL_RSA_WITH_RC4_128_MD5 SecurityTest -server -mapType rmi.client.socket.factory.ssl;rmi.server.socket.factory.ssl.enabled.cipher.suites.sha -keystore keystoreAgent -keystorepassword glopglop -client -truststore truststoreClient -truststorepassword glopglop -expectedThrowable java.io.IOException
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    54
 * @run main/othervm/timeout=300 -DDEBUG_STANDARD -Djavax.rmi.ssl.client.enabledProtocols=SSLv3 SecurityTest -server -mapType rmi.client.socket.factory.ssl;rmi.server.socket.factory.ssl.enabled.protocols.sslv3 -keystore keystoreAgent -keystorepassword glopglop -client -truststore truststoreClient -truststorepassword glopglop
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    55
 * @run main/othervm/timeout=300 -DDEBUG_STANDARD -Djavax.rmi.ssl.client.enabledProtocols=TLSv1 SecurityTest -server -mapType rmi.client.socket.factory.ssl;rmi.server.socket.factory.ssl.enabled.protocols.sslv3 -keystore keystoreAgent -keystorepassword glopglop -client -truststore truststoreClient -truststorepassword glopglop -expectedThrowable java.io.IOException
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    56
 * @run main/othervm/timeout=300 -DDEBUG_STANDARD -Djavax.rmi.ssl.client.enabledProtocols=SSLv3 SecurityTest -server -mapType rmi.client.socket.factory.ssl;rmi.server.socket.factory.ssl.enabled.protocols.tlsv1 -keystore keystoreAgent -keystorepassword glopglop -client -truststore truststoreClient -truststorepassword glopglop -expectedThrowable java.io.IOException
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    57
 */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    58
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    59
import java.io.File;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    60
import java.util.Map ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    61
import java.util.HashMap ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    62
import java.util.List;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    63
import java.util.ArrayList;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    64
import java.util.Arrays;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    65
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    66
import javax.management.MBeanServer;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    67
import javax.management.MBeanServerFactory ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    68
import javax.management.MBeanServerConnection;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    69
import javax.management.remote.JMXConnector;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    70
import javax.management.remote.JMXConnectorFactory;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    71
import javax.management.remote.JMXConnectorServer;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    72
import javax.management.remote.JMXConnectorServerFactory;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    73
import javax.management.remote.JMXServiceURL;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    74
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    75
import javax.management.Attribute ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    76
import javax.management.ObjectName ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    77
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    78
import javax.rmi.ssl.SslRMIClientSocketFactory;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    79
import javax.rmi.ssl.SslRMIServerSocketFactory;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    80
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    81
import java.security.Security;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    82
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    83
import jdk.testlibrary.ProcessTools;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    84
import jdk.testlibrary.JDKToolFinder;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    85
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    86
public class SecurityTest {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    87
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    88
    static final String SERVER_CLASS_NAME = "SecurityTest";
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    89
    static final String CLIENT_CLASS_NAME = "SecurityTest$ClientSide";
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    90
    static final String CLIENT_CLASS_MAIN = CLIENT_CLASS_NAME;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    91
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    92
    static final String USERNAME_PROPERTY = "username";
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    93
    static final String PASSWORD_PROPERTY = "password";
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    94
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    95
    static final String SERVER_DELEGATE_MBEAN_NAME =
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    96
        "defaultDomain:class=ServerDelegate";
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    97
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    98
    static final String RMI_SERVER_SOCKET_FACTORY_SSL = "rmi.server.socket.factory.ssl";
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    99
    static final String RMI_CLIENT_SOCKET_FACTORY_SSL = "rmi.client.socket.factory.ssl";
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   100
    static final String KEYSTORE_PROPNAME = "javax.net.ssl.keyStore";
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   101
    static final String KEYSTORE_PWD_PROPNAME = "javax.net.ssl.keyStorePassword";
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   102
    static final String TRUSTSTORE_PROPNAME = "javax.net.ssl.trustStore";
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   103
    static final String TRUSTSTORE_PWD_PROPNAME = "javax.net.ssl.trustStorePassword";
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   104
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   105
    static final String RMI_SSL_CLIENT_ENABLEDCIPHERSUITES =
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   106
        "javax.rmi.ssl.client.enabledCipherSuites";
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   107
    static final String RMI_SSL_CLIENT_ENABLEDPROTOCOLS =
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   108
        "javax.rmi.ssl.client.enabledProtocols";
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   109
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   110
    private JMXConnectorServer cs;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   111
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   112
    // Construct and set keyStore properties from given map
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   113
    static void setKeyStoreProperties(Map<String, Object> map) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   114
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   115
        String keyStore = (String) map.get("-keystore");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   116
        keyStore = buildSourcePath(keyStore);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   117
        System.setProperty(KEYSTORE_PROPNAME, keyStore);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   118
        System.out.println("keyStore location = \"" + keyStore + "\"");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   119
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   120
        String password = (String) map.get("-keystorepassword");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   121
        System.setProperty(KEYSTORE_PWD_PROPNAME, password);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   122
        System.out.println("keyStore password = " + password);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   123
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   124
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   125
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   126
    // Construct and set trustStore properties from given map
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   127
    static void setTrustStoreProperties(Map<String, Object> map) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   128
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   129
        String trustStore = (String) map.get("-truststore");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   130
        trustStore = buildSourcePath(trustStore);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   131
        System.setProperty(TRUSTSTORE_PROPNAME, trustStore);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   132
        System.out.println("trustStore location = \"" + trustStore + "\"");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   133
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   134
        String password = (String) map.get("-truststorepassword");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   135
        System.setProperty(TRUSTSTORE_PWD_PROPNAME, password);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   136
        System.out.println("trustStore password = " + password);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   137
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   138
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   139
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   140
    /*
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   141
     * First Debug properties and arguments are collect in expected
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   142
     * map  (argName, value) format, then calls original test's run method.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   143
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   144
    public static void main(String args[]) throws Exception {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   145
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   146
        System.out.println("=================================================");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   147
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   148
        // Parses parameters
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   149
        Utils.parseDebugProperties();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   150
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   151
        // Supported parameters list format is :
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   152
        // "MainClass [-server <param-spec> ...] [-client <param-spec> ...]
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   153
        // with <param-spec> either "-parami valuei" or "-parami"
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   154
        HashMap<String, Object> serverMap = new HashMap<>() ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   155
        int clientArgsIndex =
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   156
            Utils.parseServerParameters(args, SERVER_CLASS_NAME, serverMap);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   157
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   158
        // Extract and records client params
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   159
        String[] clientParams = null;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   160
        if (clientArgsIndex < args.length) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   161
            int clientParamsSize = args.length - clientArgsIndex;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   162
            clientParams = new String[clientParamsSize];
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   163
            System.arraycopy(args, clientArgsIndex, clientParams, 0, clientParamsSize);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   164
        } else {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   165
            clientParams = new String[0];
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   166
        }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   167
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   168
        // Run test
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   169
        SecurityTest test = new SecurityTest();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   170
        test.run(serverMap, clientParams);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   171
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   172
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   173
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   174
    // Return full path of filename in the test sopurce directory
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   175
    private static String buildSourcePath(String filename) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   176
        return System.getProperty("test.src") + File.separator + filename;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   177
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   178
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   179
    /*
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   180
     * Collects security run params for server side.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   181
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   182
    private HashMap<String, Object> setServerSecurityEnv(Map<String, Object> map)
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   183
    throws Exception {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   184
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   185
        // Creates Authentication environment from server side params
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   186
        HashMap<String, Object> env = new HashMap<>();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   187
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   188
        // Retrieve and set keystore and truststore config if any
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   189
        if (map.containsKey("-keystore") &&
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   190
            map.get("-keystore") != null) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   191
            setKeyStoreProperties(map);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   192
        }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   193
        System.out.println("Done keystore properties");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   194
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   195
        if (map.containsKey("-truststore") &&
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   196
            map.get("-truststore") != null) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   197
            setTrustStoreProperties(map);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   198
        }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   199
        System.out.println("Done truststore properties");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   200
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   201
        String value = null;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   202
        if ((value = (String)map.get("-mapType")) != null) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   203
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   204
            // Case of remote password file with all authorized credentials
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   205
            if (value.contains("x.password.file")) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   206
                String passwordFileStr = buildSourcePath("password.properties");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   207
                env.put("jmx.remote.x.password.file", passwordFileStr);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   208
                System.out.println("Added " + passwordFileStr +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   209
                    " file as jmx.remote.x.password.file");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   210
            }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   211
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   212
            // Case of dedicated authenticator class : TestJMXAuthenticator
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   213
            if (value.contains("x.authenticator")) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   214
                env.put("jmx.remote.authenticator", new TestJMXAuthenticator()) ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   215
                System.out.println(
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   216
                    "Added \"jmx.remote.authenticator\" = TestJMXAuthenticator");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   217
            }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   218
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   219
            // Case of security config file with standard Authentication
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   220
            if (value.contains("x.login.config.PasswordFileAuthentication")) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   221
                String loginConfig = System.getProperty("login.config.file");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   222
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   223
                // Override the default JAAS configuration
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   224
                System.setProperty("java.security.auth.login.config",
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   225
                    "file:" + loginConfig);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   226
                System.out.println("Overrided default JAAS configuration with " +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   227
                    "\"java.security.auth.login.config\" = \"" + loginConfig + "\"") ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   228
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   229
                env.put("jmx.remote.x.login.config", "PasswordFileAuthentication") ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   230
                System.out.println(
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   231
                    "Added \"jmx.remote.x.login.config\" = " +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   232
                    "\"PasswordFileAuthentication\"") ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   233
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   234
                // redirects "password.file" property to file in ${test.src}
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   235
                String passwordFileStr =
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   236
                    buildSourcePath(System.getProperty("password.file"));
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   237
                System.setProperty("password.file", passwordFileStr);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   238
                System.out.println(
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   239
                    "Redirected \"password.file\" property value to = " +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   240
                    passwordFileStr) ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   241
            }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   242
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   243
            // Case of security config file with unexisting athentication config
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   244
            if (value.contains("x.login.config.UnknownAuthentication")) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   245
                String loginConfig = System.getProperty("login.config.file");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   246
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   247
                // Override the default JAAS configuration
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   248
                System.setProperty("java.security.auth.login.config",
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   249
                        "file:" + loginConfig);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   250
                System.out.println("Overrided default JAAS configuration with " +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   251
                    "\"java.security.auth.login.config\" = \"" + loginConfig + "\"") ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   252
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   253
                env.put("jmx.remote.x.login.config", "UnknownAuthentication") ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   254
                System.out.println(
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   255
                    "Added \"jmx.remote.x.login.config\" = " +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   256
                    "\"UnknownAuthentication\"") ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   257
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   258
                // redirects "password.file" property to file in ${test.src}
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   259
                 String passwordFileStr =
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   260
                   buildSourcePath(System.getProperty("password.file"));
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   261
                System.setProperty("password.file", passwordFileStr);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   262
                System.out.println(
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   263
                    "Redirected \"password.file\" property value to = " +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   264
                    passwordFileStr) ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   265
            }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   266
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   267
            // Case of security config file with dedicated login module
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   268
            if (value.contains("x.login.config.SampleLoginModule")) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   269
                String loginConfig = System.getProperty("login.config.file");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   270
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   271
                // Override the default JAAS configuration
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   272
                System.setProperty("java.security.auth.login.config",
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   273
                        "file:" + loginConfig);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   274
                System.out.println("Overrided default JAAS configuration with " +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   275
                    "\"java.security.auth.login.config\" = \"" + loginConfig + "\"") ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   276
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   277
                env.put("jmx.remote.x.login.config", "SampleLoginModule") ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   278
                System.out.println(
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   279
                    "Added \"jmx.remote.x.login.config\" = " +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   280
                    "\"SampleLoginModule\"") ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   281
            }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   282
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   283
            // Simple rmi ssl authentication
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   284
            if (value.contains(RMI_CLIENT_SOCKET_FACTORY_SSL)) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   285
                env.put("jmx.remote.rmi.client.socket.factory",
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   286
                    new SslRMIClientSocketFactory()) ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   287
                System.out.println(
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   288
                     "Added \"jmx.remote.rmi.client.socket.factory\"" +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   289
                     " = SslRMIClientSocketFactory") ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   290
            }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   291
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   292
            if (value.contains(RMI_SERVER_SOCKET_FACTORY_SSL)) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   293
                if (value.contains(
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   294
                        "rmi.server.socket.factory.ssl.need.client.authentication")) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   295
                   // rmi ssl authentication with client authentication
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   296
                   env.put("jmx.remote.rmi.server.socket.factory",
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   297
                       new SslRMIServerSocketFactory(null, null, true)) ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   298
                   System.out.println(
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   299
                       "Added \"jmx.remote.rmi.server.socket.factory\"" +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   300
                       " = SslRMIServerSocketFactory with client authentication") ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   301
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   302
                } else if (value.contains("rmi.server.socket.factory.ssl.enabled.cipher.suites.md5")) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   303
                    // Allows all ciphering and protocols for testing purpose
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   304
                    Security.setProperty("jdk.tls.disabledAlgorithms", "");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   305
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   306
                    env.put("jmx.remote.rmi.server.socket.factory",
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   307
                        new SslRMIServerSocketFactory(
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   308
                            new String[] {"SSL_RSA_WITH_RC4_128_MD5"}, null, false));
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   309
                    System.out.println(
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   310
                        "Added \"jmx.remote.rmi.server.socket.factory\"" +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   311
                        " = SslRMIServerSocketFactory with SSL_RSA_WITH_RC4_128_MD5 cipher suite");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   312
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   313
                } else if (value.contains("rmi.server.socket.factory.ssl.enabled.cipher.suites.sha")) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   314
                    // Allows all ciphering and protocols for testing purpose
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   315
                    Security.setProperty("jdk.tls.disabledAlgorithms", "");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   316
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   317
                    env.put("jmx.remote.rmi.server.socket.factory",
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   318
                        new SslRMIServerSocketFactory(
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   319
                            new String[] { "SSL_RSA_WITH_RC4_128_SHA" }, null, false)) ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   320
                    System.out.println(
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   321
                        "Added \"jmx.remote.rmi.server.socket.factory\"" +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   322
                        " = SslRMIServerSocketFactory with SSL_RSA_WITH_RC4_128_SHA cipher suite") ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   323
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   324
                } else if (value.contains("rmi.server.socket.factory.ssl.enabled.protocols.sslv3")) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   325
                    // Allows all ciphering and protocols for testing purpose
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   326
                    Security.setProperty("jdk.tls.disabledAlgorithms", "");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   327
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   328
                    env.put("jmx.remote.rmi.server.socket.factory",
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   329
                        new SslRMIServerSocketFactory(null, new String[] {"SSLv3"}, false)) ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   330
                    System.out.println(
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   331
                        "Added \"jmx.remote.rmi.server.socket.factory\"" +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   332
                        " = SslRMIServerSocketFactory with SSLv3 protocol") ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   333
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   334
                } else if (value.contains("rmi.server.socket.factory.ssl.enabled.protocols.tlsv1")) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   335
                    // Allows all ciphering and protocols for testing purpose
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   336
                    Security.setProperty("jdk.tls.disabledAlgorithms", "");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   337
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   338
                    env.put("jmx.remote.rmi.server.socket.factory",
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   339
                        new SslRMIServerSocketFactory(null, new String[] {"TLSv1"}, false)) ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   340
                    System.out.println(
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   341
                        "Added \"jmx.remote.rmi.server.socket.factory\"" +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   342
                        " = SslRMIServerSocketFactory with TLSv1 protocol") ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   343
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   344
                } else {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   345
                    env.put("jmx.remote.rmi.server.socket.factory",
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   346
                        new SslRMIServerSocketFactory());
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   347
                    System.out.println(
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   348
                        "Added \"jmx.remote.rmi.server.socket.factory\"" +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   349
                        " = SslRMIServerSocketFactory");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   350
                }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   351
            }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   352
        }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   353
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   354
        return env;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   355
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   356
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   357
    /*
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   358
     * Create the MBeansServer side of the test and returns its address
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   359
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   360
    private JMXServiceURL createServerSide(Map<String, Object> serverMap)
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   361
    throws Exception {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   362
        final int NINETY_SECONDS = 90;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   363
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   364
        System.out.println("SecurityTest::createServerSide: Start") ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   365
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   366
        // Prepare server side security env
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   367
        HashMap<String, Object> env = setServerSecurityEnv(serverMap);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   368
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   369
        // Create and start mbean server and connector server
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   370
        MBeanServer mbs = MBeanServerFactory.newMBeanServer();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   371
        JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   372
        cs = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   373
        cs.start();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   374
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   375
        // Waits availibility of connector server
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   376
        Utils.waitReady(cs, NINETY_SECONDS);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   377
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   378
        JMXServiceURL addr = cs.getAddress();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   379
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   380
        System.out.println("SecurityTest::createServerSide: Done.") ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   381
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   382
        return addr;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   383
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   384
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   385
    /*
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   386
     * Creating command-line for running subprocess JVM:
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   387
     *
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   388
     * JVM command line is like:
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   389
     * {test_jdk}/bin/java {defaultopts} -cp {test.class.path} {testopts} main
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   390
     *
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   391
     * {defaultopts} are the default java options set by the framework.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   392
     *
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   393
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   394
    private List<String> buildCommandLine(String args[]) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   395
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   396
        System.out.println("SecurityTest::buildCommandLine: Start") ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   397
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   398
        List<String> opts = new ArrayList<>();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   399
        opts.add(JDKToolFinder.getJDKTool("java"));
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   400
        opts.addAll(Arrays.asList(jdk.testlibrary.Utils.getTestJavaOpts()));
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   401
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   402
        // We need to forward some properties to the client side
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   403
        opts.add("-Dtest.src=" + System.getProperty("test.src"));
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   404
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   405
        String usernameValue = System.getProperty(USERNAME_PROPERTY);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   406
        if (usernameValue != null) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   407
            System.out.println("SecurityTest::buildCommandLine: "+
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   408
                " forward username property to client side");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   409
            opts.add("-D" + USERNAME_PROPERTY + "=" + usernameValue);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   410
        }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   411
        String passwordValue = System.getProperty(PASSWORD_PROPERTY);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   412
        if (passwordValue != null) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   413
            System.out.println("SecurityTest::buildCommandLine: "+
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   414
                " forward password property to client side");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   415
            opts.add("-D" + PASSWORD_PROPERTY + "=" + passwordValue);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   416
        }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   417
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   418
        String enabledCipherSuites =
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   419
            System.getProperty(RMI_SSL_CLIENT_ENABLEDCIPHERSUITES);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   420
        if (enabledCipherSuites != null) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   421
            System.out.println("SecurityTest::buildCommandLine: "+
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   422
                " forward enabledCipherSuites property to client side");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   423
            opts.add("-D" + RMI_SSL_CLIENT_ENABLEDCIPHERSUITES +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   424
                "=" + enabledCipherSuites);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   425
        }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   426
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   427
        String enabledProtocols =
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   428
            System.getProperty(RMI_SSL_CLIENT_ENABLEDPROTOCOLS);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   429
        if (enabledProtocols != null) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   430
            System.out.println("SecurityTest::buildCommandLine: "+
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   431
                " forward enabledProtocols property to client side");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   432
            opts.add("-D" + RMI_SSL_CLIENT_ENABLEDPROTOCOLS +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   433
                "=" + enabledProtocols);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   434
        }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   435
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   436
        opts.add("-cp");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   437
        opts.add(System.getProperty("test.class.path", "test.class.path"));
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   438
        opts.add(CLIENT_CLASS_MAIN);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   439
        opts.addAll(Arrays.asList(args));
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   440
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   441
        System.out.println("SecurityTest::buildCommandLine: Done.") ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   442
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   443
        return opts;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   444
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   445
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   446
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   447
     * Runs SecurityTest$ClientSide with the passed options and redirects
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   448
     * subprocess standard I/O to the current (parent) process. This provides a
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   449
     * trace of what happens in the subprocess while it is runnning (and before
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   450
     * it terminates).
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   451
     *
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   452
     * @param serviceUrlStr string representing the JMX service Url to connect to.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   453
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   454
    private int runClientSide(String args[], String serviceUrlStr) throws Exception {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   455
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   456
        System.out.println("SecurityTest::runClientSide: Start") ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   457
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   458
        // Building command-line
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   459
        List<String> opts = buildCommandLine(args);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   460
        opts.add("-serviceUrl");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   461
        opts.add(serviceUrlStr);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   462
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   463
        // Launch separate JVM subprocess
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   464
        int exitCode = 0;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   465
        String[] optsArray = opts.toArray(new String[0]);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   466
        ProcessBuilder pb = new ProcessBuilder(optsArray);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   467
        Process p = ProcessTools.startProcess("SecurityTest$ClientSide", pb);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   468
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   469
        // Handling end of subprocess
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   470
        try {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   471
            exitCode = p.waitFor();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   472
            if (exitCode != 0) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   473
                System.out.println(
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   474
                    "Subprocess unexpected exit value of [" + exitCode +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   475
                    "]. Expected 0.\n");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   476
            }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   477
        } catch (InterruptedException e) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   478
            System.out.println("Parent process interrupted with exception : \n " + e + " :" );
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   479
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   480
            // Parent thread unknown state, killing subprocess.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   481
            p.destroyForcibly();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   482
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   483
            throw new RuntimeException(
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   484
                "Parent process interrupted with exception : \n " + e + " :" );
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   485
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   486
        } finally {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   487
            if (p.isAlive()) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   488
                p.destroyForcibly();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   489
            }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   490
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   491
            System.out.println("SecurityTest::runClientSide: Done") ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   492
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   493
            return exitCode;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   494
        }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   495
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   496
     }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   497
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   498
    public void run(Map<String, Object> serverArgs, String clientArgs[]) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   499
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   500
        System.out.println("SecurityTest::run: Start") ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   501
        int errorCount = 0;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   502
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   503
        try {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   504
            // Initialise the server side
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   505
            JMXServiceURL urlToUse = createServerSide(serverArgs);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   506
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   507
            // Run client side
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   508
            errorCount = runClientSide(clientArgs, urlToUse.toString());
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   509
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   510
            if ( errorCount == 0 ) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   511
                System.out.println("SecurityTest::run: Done without any error") ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   512
            } else {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   513
                System.out.println(
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   514
                    "SecurityTest::run: Done with " + errorCount + " error(s)");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   515
                throw new RuntimeException("errorCount = " + errorCount);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   516
            }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   517
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   518
            cs.stop();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   519
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   520
        } catch(Exception e) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   521
            throw new RuntimeException(e);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   522
        }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   523
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   524
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   525
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   526
    private static class ClientSide {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   527
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   528
        private JMXConnector cc = null;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   529
        private MBeanServerConnection mbsc = null;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   530
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   531
        public static void main(String args[]) throws Exception {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   532
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   533
            // Parses parameters
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   534
            Utils.parseDebugProperties();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   535
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   536
            // Supported parameters list format is : "MainClass [-client <param-spec> ...]
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   537
            // with <param-spec> either "-parami valuei" or "-parami"
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   538
            HashMap<String, Object> clientMap = new HashMap<>() ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   539
            Utils.parseClientParameters(args, CLIENT_CLASS_NAME, clientMap);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   540
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   541
            // Run test
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   542
            ClientSide test = new ClientSide();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   543
            test.run(clientMap);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   544
        }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   545
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   546
        public void run(Map<String, Object> args) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   547
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   548
            System.out.println("ClientSide::run: Start");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   549
            int errorCount = 0;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   550
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   551
            try {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   552
                // Setup client side parameters
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   553
                HashMap<String, Object> env = new HashMap<>();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   554
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   555
                // If needed allows all ciphering and protocols for testing purpose
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   556
                if (System.getProperty(RMI_SSL_CLIENT_ENABLEDCIPHERSUITES) != null) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   557
                    Security.setProperty("jdk.tls.disabledAlgorithms", "");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   558
                }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   559
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   560
                // If needed allows all ciphering and protocols for testing purpose
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   561
                if (System.getProperty(RMI_SSL_CLIENT_ENABLEDPROTOCOLS) != null) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   562
                    Security.setProperty("jdk.tls.disabledAlgorithms", "");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   563
                }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   564
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   565
                // Retrieve and set keystore and truststore config if any
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   566
                if (args.containsKey("-keystore") &&
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   567
                    args.get("-keystore") != null) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   568
                    SecurityTest.setKeyStoreProperties(args);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   569
                }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   570
                if (args.containsKey("-truststore") &&
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   571
                    args.get("-truststore") != null) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   572
                    SecurityTest.setTrustStoreProperties(args);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   573
                }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   574
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   575
                Object value = args.get("-mapType");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   576
                if ((value != null) &&
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   577
                    value.equals("credentials")) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   578
                    String username = System.getProperty("username");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   579
                    String password = System.getProperty("password");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   580
                    Utils.debug(Utils.DEBUG_STANDARD,
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   581
                        "add \"jmx.remote.credentials\" = \"" +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   582
                        username + "\", \"" + password + "\"");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   583
                    env.put("jmx.remote.credentials",
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   584
                        new String[] { username , password });
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   585
                }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   586
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   587
                String expectedThrowable = (String) args.get("-expectedThrowable");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   588
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   589
                String authCallCountName = "-expectedAuthenticatorCallCount";
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   590
                int authCallCountValue = 0;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   591
                if (args.containsKey(authCallCountName)) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   592
                    authCallCountValue =
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   593
                        (new Integer((String) args.get(authCallCountName))).intValue();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   594
                }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   595
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   596
                try {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   597
                    // Get a connection to remote mbean server
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   598
                    JMXServiceURL addr = new JMXServiceURL((String)args.get("-serviceUrl"));
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   599
                    cc = JMXConnectorFactory.connect(addr,env);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   600
                    mbsc = cc.getMBeanServerConnection();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   601
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   602
                    // In case we should have got an exception
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   603
                    if (expectedThrowable != null) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   604
                        System.out.println("ClientSide::run: (ERROR) " +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   605
                            " Connect did not fail with expected " + expectedThrowable);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   606
                        errorCount++;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   607
                    } else {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   608
                        System.out.println("ClientSide::run: (OK) Connect succeed");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   609
                    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   610
                } catch (Throwable e) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   611
                    Utils.printThrowable(e, true);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   612
                    if (expectedThrowable != null) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   613
                        if (Utils.compareThrowable(e, expectedThrowable)) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   614
                            System.out.println("ClientSide::run: (OK) " +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   615
                                "Connect failed with expected " + expectedThrowable);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   616
                        } else {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   617
                            System.out.println("ClientSide::run: (ERROR) Connect failed with " +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   618
                                e.getClass() + " instead of expected " +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   619
                                expectedThrowable);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   620
                            errorCount++;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   621
                        }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   622
                    } else {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   623
                        System.out.println("ClientSide::run: (ERROR) " +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   624
                            "Connect failed with exception");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   625
                        errorCount++;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   626
                    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   627
                }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   628
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   629
                // Depending on the client state,
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   630
                // perform some requests
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   631
                if (mbsc != null && errorCount == 0) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   632
                    // Perform some little JMX requests
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   633
                    System.out.println("ClientSide::run: Start sending requests");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   634
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   635
                    doRequests();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   636
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   637
                    // In case authentication has been used we check how it did.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   638
                    if (authCallCountValue != 0) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   639
                        errorCount += checkAuthenticator(mbsc, authCallCountValue);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   640
                    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   641
                }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   642
            } catch (Exception e) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   643
                Utils.printThrowable(e, true);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   644
                errorCount++;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   645
            } finally {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   646
                // Terminate the JMX Client if any
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   647
                if (cc != null) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   648
                    try {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   649
                        cc.close();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   650
                    } catch (Exception e) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   651
                        Utils.printThrowable(e, true) ;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   652
                        errorCount++;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   653
                    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   654
                }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   655
            }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   656
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   657
            System.out.println("ClientSide::run: Done");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   658
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   659
            // Handle result
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   660
            if (errorCount != 0) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   661
                throw new RuntimeException();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   662
            }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   663
        }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   664
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   665
        private void doRequests() throws Exception {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   666
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   667
            // Send  some requests to the remote JMX server
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   668
            ObjectName objName1 =
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   669
                new ObjectName("TestDomain:class=MBS_Light,rank=1");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   670
            String mbeanClass = "MBS_Light";
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   671
            Exception exception = new Exception("MY TEST EXCEPTION");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   672
            Attribute attException = new Attribute("AnException", exception);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   673
            Error error = new Error("MY TEST ERROR");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   674
            Attribute attError = new Attribute("AnError", error);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   675
            String opParamString = "TOTORO";
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   676
            RjmxMBeanParameter opParam = new RjmxMBeanParameter(opParamString);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   677
            Object[] params1 = {opParamString};
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   678
            String[] sig1 = {"java.lang.String"};
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   679
            Object[] params2 = {opParam};
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   680
            String[] sig2 = {"RjmxMBeanParameter"};
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   681
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   682
            // Create and register the MBean
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   683
            Utils.debug(Utils.DEBUG_STANDARD,
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   684
                "ClientSide::doRequests: Create and register the MBean");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   685
            mbsc.createMBean(mbeanClass, objName1);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   686
            if (!mbsc.isRegistered(objName1)) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   687
                throw new Exception("Unable to register an MBean");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   688
            }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   689
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   690
            // Set attributes of the MBean
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   691
            Utils.debug(Utils.DEBUG_STANDARD,
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   692
                "ClientSide::doRequests: Set attributes of the MBean");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   693
            mbsc.setAttribute(objName1, attException);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   694
            mbsc.setAttribute(objName1, attError);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   695
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   696
            // Get attributes of the MBean
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   697
            Utils.debug(Utils.DEBUG_STANDARD,
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   698
                "ClientSide::doRequests: Get attributes of the MBean");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   699
            Exception retException =
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   700
                (Exception) mbsc.getAttribute(objName1,"AnException");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   701
            if (!retException.getMessage().equals(exception.getMessage())) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   702
                System.out.println("Expected = " + exception);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   703
                System.out.println("Got = " + retException);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   704
                throw new Exception("Attribute AnException not as expected");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   705
            }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   706
            Error retError = (Error) mbsc.getAttribute(objName1, "AnError");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   707
            if (!retError.getMessage().equals(error.getMessage())) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   708
                System.out.println("Expected = " + error);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   709
                System.out.println("Got = " + retError);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   710
                throw new Exception("Attribute AnError not as expected");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   711
            }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   712
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   713
            // Invoke operations on the MBean
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   714
            Utils.debug(Utils.DEBUG_STANDARD,
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   715
                "ClientSide::doRequests: Invoke operations on the MBean");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   716
            RjmxMBeanParameter res1 =
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   717
                (RjmxMBeanParameter) mbsc.invoke(objName1, "operate1", params1, sig1);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   718
            if (!res1.equals(opParam)) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   719
                System.out.println("Expected = " + opParam);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   720
                System.out.println("Got = " + res1);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   721
                throw new Exception("Operation operate1 behaved badly");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   722
            }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   723
            String res2 =
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   724
                (String) mbsc.invoke(objName1, "operate2", params2, sig2);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   725
            if (!res2.equals(opParamString)) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   726
                System.out.println("Expected = " + opParamString);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   727
                System.out.println("Got = " + res2);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   728
                throw new Exception("Operation operate2 behaved badly");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   729
            }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   730
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   731
            // Unregister the MBean
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   732
            Utils.debug(Utils.DEBUG_STANDARD,
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   733
                "ClientSide::doRequests: Unregister the MBean");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   734
            mbsc.unregisterMBean(objName1);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   735
            if (mbsc.isRegistered(objName1)) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   736
                throw new Exception("Unable to unregister an MBean");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   737
            }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   738
        }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   739
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   740
        /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   741
         * Make some check about the instance of TestJMXAuthenticator.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   742
         * The authenticator is supposed to have set some properties on
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   743
         * a ServerDelegate MBean.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   744
         * We compare the number of times it has been called with the expected value.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   745
         * We also check the Principal that has been given to the authenticator
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   746
         * was not null.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   747
         * That method is of use to authentication with the JSR 262.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   748
         * @param mbs
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   749
         * @param expectedAuthenticatorCallCount
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   750
         * @return The number of errors encountered.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   751
         * @throws java.lang.Exception
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   752
         */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   753
        protected int checkAuthenticator(MBeanServerConnection mbs,
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   754
                int expectedAuthenticatorCallCount) throws Exception {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   755
            int errorCount = 0;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   756
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   757
            // Ensure the authenticator has been called the right number
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   758
            // of times.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   759
            int callCount =
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   760
                    ((Integer) mbs.getAttribute(
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   761
                    new ObjectName(SERVER_DELEGATE_MBEAN_NAME),
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   762
                    "TestJMXAuthenticatorCallCount")).intValue();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   763
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   764
            if (callCount == expectedAuthenticatorCallCount) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   765
                System.out.println("---- OK Authenticator has been called "
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   766
                        + expectedAuthenticatorCallCount + " time");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   767
            } else {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   768
                errorCount++;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   769
                System.out.println("---- ERROR Authenticator has been called " + callCount
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   770
                        + " times in place of " + expectedAuthenticatorCallCount);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   771
            }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   772
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   773
            // Ensure the provider has been called with
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   774
            // a non null Principal.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   775
            String principalString =
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   776
                (String) mbs.getAttribute(
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   777
                new ObjectName(SERVER_DELEGATE_MBEAN_NAME),
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   778
                "TestJMXAuthenticatorPrincipalString");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   779
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   780
            if (principalString == null) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   781
                errorCount++;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   782
                System.out.println("---- ERROR Authenticator has been called"
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   783
                        + " with a null Principal");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   784
            } else {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   785
                if (principalString.length() > 0) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   786
                    System.out.println("---- OK Authenticator has been called"
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   787
                            + " with the Principal " + principalString);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   788
                } else {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   789
                    errorCount++;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   790
                    System.out.println("---- ERROR Authenticator has been called"
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   791
                            + " with an empty Principal");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   792
                }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   793
            }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   794
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   795
            return errorCount;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   796
        }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   797
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   798
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   799
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   800
}