0N/A/*
0N/A * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
0N/A * questions.
0N/A */
0N/A
0N/A/**
0N/A * @test
0N/A * @author Vincent Ryan
0N/A * @bug 6228412
0N/A * @summary Check that a Properties object can be passed to the Sasl create
0N/A * client and create server methods.
0N/A */
0N/A
0N/Aimport java.util.Hashtable;
0N/Aimport java.util.Map;
0N/Aimport java.util.Properties;
0N/Aimport javax.security.sasl.*;
0N/Aimport javax.security.auth.callback.*;
0N/Aimport org.ietf.jgss.GSSException;
0N/A
0N/Apublic class PassSysProps {
0N/A
0N/A private static final String PLAIN = "PLAIN";
0N/A private static final String DIGEST = "DIGEST-MD5";
0N/A private static final String CRAM = "CRAM-MD5";
0N/A private static final String EXTERNAL = "EXTERNAL";
0N/A private static final String GSSAPI = "GSSAPI";
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A
0N/A String authorizationId = null;
0N/A String protocol = "ldap";
0N/A String serverName = "server1";
0N/A
0N/A CallbackHandler callbackHandler = new CallbackHandler(){
0N/A public void handle(Callback[] callbacks) {
0N/A }
0N/A };
0N/A
0N/A // pass in system properties
0N/A
0N/A Properties sysprops = System.getProperties();
0N/A
0N/A SaslClient client1 =
0N/A Sasl.createSaslClient(new String[]{DIGEST, PLAIN}, authorizationId,
0N/A protocol, serverName, (Map) sysprops, callbackHandler);
0N/A System.out.println(client1);
0N/A
0N/A SaslServer server1 =
0N/A Sasl.createSaslServer(DIGEST, protocol, serverName, (Map) sysprops,
0N/A callbackHandler);
0N/A System.out.println(server1);
0N/A
0N/A // pass in string-valued props
0N/A
0N/A Map<String, String> stringProps = new Hashtable<String, String>();
0N/A stringProps.put(Sasl.POLICY_NOPLAINTEXT, "true");
0N/A
0N/A try {
0N/A
0N/A SaslClient client2 =
0N/A Sasl.createSaslClient(new String[]{GSSAPI, PLAIN},
0N/A authorizationId, protocol, serverName, stringProps,
0N/A callbackHandler);
0N/A System.out.println(client2);
0N/A
0N/A SaslServer server2 =
0N/A Sasl.createSaslServer(GSSAPI, protocol, serverName,
0N/A stringProps, callbackHandler);
0N/A System.out.println(server2);
0N/A
0N/A } catch (SaslException se) {
0N/A Throwable t = se.getCause();
0N/A if (t instanceof GSSException) {
0N/A // allow GSSException because kerberos has not been initialized
0N/A
0N/A } else {
0N/A throw se;
0N/A }
0N/A }
0N/A
0N/A // pass in object-valued props
0N/A
0N/A Map<String, Object> objProps = new Hashtable<String, Object>();
0N/A objProps.put("some.object.valued.property", System.err);
0N/A
0N/A SaslClient client3 =
0N/A Sasl.createSaslClient(new String[]{EXTERNAL, CRAM}, authorizationId,
0N/A protocol, serverName, objProps, callbackHandler);
0N/A System.out.println(client3);
0N/A
0N/A SaslServer server3 =
0N/A Sasl.createSaslServer(CRAM, protocol, serverName, objProps,
0N/A callbackHandler);
0N/A System.out.println(server3);
0N/A
0N/A // pass in raw-type props
0N/A
0N/A Map rawProps = new Hashtable();
0N/A rawProps.put(Sasl.POLICY_NOPLAINTEXT, "true");
0N/A rawProps.put("some.object.valued.property", System.err);
0N/A
0N/A SaslClient client4 =
0N/A Sasl.createSaslClient(new String[]{EXTERNAL, CRAM}, authorizationId,
0N/A protocol, serverName, rawProps, callbackHandler);
0N/A System.out.println(client4);
0N/A
0N/A SaslServer server4 =
0N/A Sasl.createSaslServer(CRAM, protocol, serverName, rawProps,
0N/A callbackHandler);
0N/A System.out.println(server4);
0N/A
0N/A }
0N/A}
0N/A