Path: blob/master/test/jdk/javax/security/sasl/Sasl/PassSysProps.java
41152 views
/*1* Copyright (c) 2005, 2017, 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* @modules java.security.sasl28* @summary Check that a Properties object can be passed to the Sasl create29* client and create server methods.30*/3132import java.util.Hashtable;33import java.util.Map;34import java.util.Properties;35import javax.security.sasl.Sasl;36import javax.security.sasl.SaslClient;37import javax.security.sasl.SaslException;38import javax.security.sasl.SaslServer;39import javax.security.auth.callback.Callback;40import javax.security.auth.callback.CallbackHandler;41import org.ietf.jgss.GSSException;4243public class PassSysProps {4445private static final String PLAIN = "PLAIN";46private static final String DIGEST = "DIGEST-MD5";47private static final String CRAM = "CRAM-MD5";48private static final String EXTERNAL = "EXTERNAL";49private static final String GSSAPI = "GSSAPI";5051public static void main(String[] args) throws Exception {5253String authorizationId = null;54String protocol = "ldap";55String serverName = "server1";5657CallbackHandler callbackHandler = new CallbackHandler(){58public void handle(Callback[] callbacks) {59}60};6162// pass in system properties6364Properties sysprops = System.getProperties();6566SaslClient client1 =67Sasl.createSaslClient(new String[]{DIGEST, PLAIN}, authorizationId,68protocol, serverName, (Map) sysprops, callbackHandler);69System.out.println(client1);7071SaslServer server1 =72Sasl.createSaslServer(DIGEST, protocol, serverName, (Map) sysprops,73callbackHandler);74System.out.println(server1);7576// pass in string-valued props7778Map<String, String> stringProps = new Hashtable<String, String>();79stringProps.put(Sasl.POLICY_NOPLAINTEXT, "true");8081try {8283SaslClient client2 =84Sasl.createSaslClient(new String[]{GSSAPI, PLAIN},85authorizationId, protocol, serverName, stringProps,86callbackHandler);87System.out.println(client2);8889SaslServer server2 =90Sasl.createSaslServer(GSSAPI, protocol, serverName,91stringProps, callbackHandler);92System.out.println(server2);9394} catch (SaslException se) {95Throwable t = se.getCause();96if (t instanceof GSSException) {97// allow GSSException because kerberos has not been initialized9899} else {100throw se;101}102}103104// pass in object-valued props105106Map<String, Object> objProps = new Hashtable<String, Object>();107objProps.put("some.object.valued.property", System.err);108109SaslClient client3 =110Sasl.createSaslClient(new String[]{EXTERNAL, CRAM}, authorizationId,111protocol, serverName, objProps, callbackHandler);112System.out.println(client3);113114SaslServer server3 =115Sasl.createSaslServer(CRAM, protocol, serverName, objProps,116callbackHandler);117System.out.println(server3);118119// pass in raw-type props120121Map rawProps = new Hashtable();122rawProps.put(Sasl.POLICY_NOPLAINTEXT, "true");123rawProps.put("some.object.valued.property", System.err);124125SaslClient client4 =126Sasl.createSaslClient(new String[]{EXTERNAL, CRAM}, authorizationId,127protocol, serverName, rawProps, callbackHandler);128System.out.println(client4);129130SaslServer server4 =131Sasl.createSaslServer(CRAM, protocol, serverName, rawProps,132callbackHandler);133System.out.println(server4);134135}136}137138139