jdk/test/javax/security/sasl/Sasl/PassSysProps.java
author never
Mon, 12 Jul 2010 22:27:18 -0700
changeset 5926 a36f90d986b6
parent 5506 202f599c92aa
child 44357 e0fbf5f9da3c
permissions -rw-r--r--
6968385: malformed xml in sweeper logging Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2005, 2006, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/**
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @summary Check that a Properties object can be passed to the Sasl create
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *          client and create server methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.security.sasl.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.security.auth.callback.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import org.ietf.jgss.GSSException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class PassSysProps {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private static final String PLAIN = "PLAIN";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private static final String DIGEST = "DIGEST-MD5";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private static final String CRAM = "CRAM-MD5";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private static final String EXTERNAL = "EXTERNAL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private static final String GSSAPI = "GSSAPI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        String authorizationId = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        String protocol = "ldap";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        String serverName = "server1";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        CallbackHandler callbackHandler = new CallbackHandler(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            public void handle(Callback[] callbacks) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        // pass in system properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        Properties sysprops = System.getProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        SaslClient client1 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            Sasl.createSaslClient(new String[]{DIGEST, PLAIN}, authorizationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                protocol, serverName, (Map) sysprops, callbackHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        System.out.println(client1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        SaslServer server1 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            Sasl.createSaslServer(DIGEST, protocol, serverName, (Map) sysprops,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                callbackHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        System.out.println(server1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        // pass in string-valued props
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        Map<String, String> stringProps = new Hashtable<String, String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        stringProps.put(Sasl.POLICY_NOPLAINTEXT, "true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            SaslClient client2 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                Sasl.createSaslClient(new String[]{GSSAPI, PLAIN},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                    authorizationId, protocol, serverName, stringProps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                    callbackHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            System.out.println(client2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            SaslServer server2 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                Sasl.createSaslServer(GSSAPI, protocol, serverName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                    stringProps, callbackHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            System.out.println(server2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        } catch (SaslException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            Throwable t = se.getCause();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            if (t instanceof GSSException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                // allow GSSException because kerberos has not been initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                throw se;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        // pass in object-valued props
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        Map<String, Object> objProps = new Hashtable<String, Object>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        objProps.put("some.object.valued.property", System.err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        SaslClient client3 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            Sasl.createSaslClient(new String[]{EXTERNAL, CRAM}, authorizationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                protocol, serverName, objProps, callbackHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        System.out.println(client3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        SaslServer server3 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            Sasl.createSaslServer(CRAM, protocol, serverName, objProps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                callbackHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        System.out.println(server3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        // pass in raw-type props
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        Map rawProps = new Hashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        rawProps.put(Sasl.POLICY_NOPLAINTEXT, "true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        rawProps.put("some.object.valued.property", System.err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        SaslClient client4 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            Sasl.createSaslClient(new String[]{EXTERNAL, CRAM}, authorizationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                protocol, serverName, rawProps, callbackHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        System.out.println(client4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        SaslServer server4 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            Sasl.createSaslServer(CRAM, protocol, serverName, rawProps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                callbackHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        System.out.println(server4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
}