test/jdk/javax/security/sasl/Sasl/PassSysProps.java
author dfuchs
Thu, 07 Nov 2019 16:18:02 +0000
changeset 58968 7f1daafda27b
parent 47216 71c04702a3d5
permissions -rw-r--r--
8233403: Improve verbosity of some httpclient tests Summary: improve the verbosity of some httpclient tests to help diagnosis of intermittent failures. Also fixes ShortRequestBody test. Reviewed-by: chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
44357
e0fbf5f9da3c 8177324: Some javax/security/ tests don't have correct module dependencies
skovalev
parents: 5506
diff changeset
     2
 * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
44357
e0fbf5f9da3c 8177324: Some javax/security/ tests don't have correct module dependencies
skovalev
parents: 5506
diff changeset
    24
/*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @author Vincent Ryan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @bug 6228412
44357
e0fbf5f9da3c 8177324: Some javax/security/ tests don't have correct module dependencies
skovalev
parents: 5506
diff changeset
    28
 * @modules java.security.sasl
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @summary Check that a Properties object can be passed to the Sasl create
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *          client and create server methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Properties;
44357
e0fbf5f9da3c 8177324: Some javax/security/ tests don't have correct module dependencies
skovalev
parents: 5506
diff changeset
    36
import javax.security.sasl.Sasl;
e0fbf5f9da3c 8177324: Some javax/security/ tests don't have correct module dependencies
skovalev
parents: 5506
diff changeset
    37
import javax.security.sasl.SaslClient;
e0fbf5f9da3c 8177324: Some javax/security/ tests don't have correct module dependencies
skovalev
parents: 5506
diff changeset
    38
import javax.security.sasl.SaslException;
e0fbf5f9da3c 8177324: Some javax/security/ tests don't have correct module dependencies
skovalev
parents: 5506
diff changeset
    39
import javax.security.sasl.SaslServer;
e0fbf5f9da3c 8177324: Some javax/security/ tests don't have correct module dependencies
skovalev
parents: 5506
diff changeset
    40
import javax.security.auth.callback.Callback;
e0fbf5f9da3c 8177324: Some javax/security/ tests don't have correct module dependencies
skovalev
parents: 5506
diff changeset
    41
import javax.security.auth.callback.CallbackHandler;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import org.ietf.jgss.GSSException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
public class PassSysProps {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private static final String PLAIN = "PLAIN";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private static final String DIGEST = "DIGEST-MD5";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static final String CRAM = "CRAM-MD5";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private static final String EXTERNAL = "EXTERNAL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private static final String GSSAPI = "GSSAPI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        String authorizationId = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        String protocol = "ldap";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        String serverName = "server1";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        CallbackHandler callbackHandler = new CallbackHandler(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            public void handle(Callback[] callbacks) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        // pass in system properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        Properties sysprops = System.getProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        SaslClient client1 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            Sasl.createSaslClient(new String[]{DIGEST, PLAIN}, authorizationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                protocol, serverName, (Map) sysprops, callbackHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        System.out.println(client1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        SaslServer server1 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            Sasl.createSaslServer(DIGEST, protocol, serverName, (Map) sysprops,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                callbackHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        System.out.println(server1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        // pass in string-valued props
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        Map<String, String> stringProps = new Hashtable<String, String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        stringProps.put(Sasl.POLICY_NOPLAINTEXT, "true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            SaslClient client2 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                Sasl.createSaslClient(new String[]{GSSAPI, PLAIN},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                    authorizationId, protocol, serverName, stringProps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                    callbackHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            System.out.println(client2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            SaslServer server2 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                Sasl.createSaslServer(GSSAPI, protocol, serverName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                    stringProps, callbackHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            System.out.println(server2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        } catch (SaslException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            Throwable t = se.getCause();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            if (t instanceof GSSException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                // allow GSSException because kerberos has not been initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                throw se;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        // pass in object-valued props
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        Map<String, Object> objProps = new Hashtable<String, Object>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        objProps.put("some.object.valued.property", System.err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        SaslClient client3 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            Sasl.createSaslClient(new String[]{EXTERNAL, CRAM}, authorizationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                protocol, serverName, objProps, callbackHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        System.out.println(client3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        SaslServer server3 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            Sasl.createSaslServer(CRAM, protocol, serverName, objProps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                callbackHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        System.out.println(server3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        // pass in raw-type props
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        Map rawProps = new Hashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        rawProps.put(Sasl.POLICY_NOPLAINTEXT, "true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        rawProps.put("some.object.valued.property", System.err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        SaslClient client4 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            Sasl.createSaslClient(new String[]{EXTERNAL, CRAM}, authorizationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                protocol, serverName, rawProps, callbackHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        System.out.println(client4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        SaslServer server4 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            Sasl.createSaslServer(CRAM, protocol, serverName, rawProps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                callbackHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        System.out.println(server4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
}