Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/security/sasl/Sasl/PassSysProps.java
38853 views
/*1* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @author Vincent Ryan26* @bug 622841227* @summary Check that a Properties object can be passed to the Sasl create28* client and create server methods.29*/3031import java.util.Hashtable;32import java.util.Map;33import java.util.Properties;34import javax.security.sasl.*;35import javax.security.auth.callback.*;36import org.ietf.jgss.GSSException;3738public class PassSysProps {3940private static final String PLAIN = "PLAIN";41private static final String DIGEST = "DIGEST-MD5";42private static final String CRAM = "CRAM-MD5";43private static final String EXTERNAL = "EXTERNAL";44private static final String GSSAPI = "GSSAPI";4546public static void main(String[] args) throws Exception {4748String authorizationId = null;49String protocol = "ldap";50String serverName = "server1";5152CallbackHandler callbackHandler = new CallbackHandler(){53public void handle(Callback[] callbacks) {54}55};5657// pass in system properties5859Properties sysprops = System.getProperties();6061SaslClient client1 =62Sasl.createSaslClient(new String[]{DIGEST, PLAIN}, authorizationId,63protocol, serverName, (Map) sysprops, callbackHandler);64System.out.println(client1);6566SaslServer server1 =67Sasl.createSaslServer(DIGEST, protocol, serverName, (Map) sysprops,68callbackHandler);69System.out.println(server1);7071// pass in string-valued props7273Map<String, String> stringProps = new Hashtable<String, String>();74stringProps.put(Sasl.POLICY_NOPLAINTEXT, "true");7576try {7778SaslClient client2 =79Sasl.createSaslClient(new String[]{GSSAPI, PLAIN},80authorizationId, protocol, serverName, stringProps,81callbackHandler);82System.out.println(client2);8384SaslServer server2 =85Sasl.createSaslServer(GSSAPI, protocol, serverName,86stringProps, callbackHandler);87System.out.println(server2);8889} catch (SaslException se) {90Throwable t = se.getCause();91if (t instanceof GSSException) {92// allow GSSException because kerberos has not been initialized9394} else {95throw se;96}97}9899// pass in object-valued props100101Map<String, Object> objProps = new Hashtable<String, Object>();102objProps.put("some.object.valued.property", System.err);103104SaslClient client3 =105Sasl.createSaslClient(new String[]{EXTERNAL, CRAM}, authorizationId,106protocol, serverName, objProps, callbackHandler);107System.out.println(client3);108109SaslServer server3 =110Sasl.createSaslServer(CRAM, protocol, serverName, objProps,111callbackHandler);112System.out.println(server3);113114// pass in raw-type props115116Map rawProps = new Hashtable();117rawProps.put(Sasl.POLICY_NOPLAINTEXT, "true");118rawProps.put("some.object.valued.property", System.err);119120SaslClient client4 =121Sasl.createSaslClient(new String[]{EXTERNAL, CRAM}, authorizationId,122protocol, serverName, rawProps, callbackHandler);123System.out.println(client4);124125SaslServer server4 =126Sasl.createSaslServer(CRAM, protocol, serverName, rawProps,127callbackHandler);128System.out.println(server4);129130}131}132133134