Path: blob/master/test/jdk/javax/security/sasl/Sasl/DisabledMechanisms.java
41152 views
/*1* Copyright (c) 2019, 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* @bug 820040026* @modules java.security.sasl27* @library /test/lib28* @run main/othervm DisabledMechanisms29* DIGEST-MD5 DIGEST-MD530* @run main/othervm -DdisabledMechanisms= DisabledMechanisms31* DIGEST-MD5 DIGEST-MD532* @run main/othervm -DdisabledMechanisms=DIGEST-MD5,NTLM DisabledMechanisms33* null null34* @run main/othervm -DdisabledMechanisms=DIGEST-MD5 DisabledMechanisms35* NTLM null36* @run main/othervm -DdisabledMechanisms=NTLM DisabledMechanisms37* DIGEST-MD5 DIGEST-MD538*/3940import java.security.Security;41import java.util.Collections;42import java.util.Map;43import javax.security.auth.callback.PasswordCallback;44import javax.security.sasl.Sasl;45import javax.security.sasl.SaslClient;46import javax.security.sasl.SaslServer;47import javax.security.auth.callback.Callback;48import javax.security.auth.callback.CallbackHandler;4950import jdk.test.lib.Asserts;5152public class DisabledMechanisms {5354public static void main(String[] args) throws Exception {5556String authorizationId = "username";57String protocol = "ldap";58String serverName = "server1";59Map props = Collections.emptyMap();6061String disabled = System.getProperty("disabledMechanisms");62if (disabled != null) {63Security.setProperty("jdk.sasl.disabledMechanisms", disabled);64}6566CallbackHandler callbackHandler = callbacks -> {67for (Callback cb : callbacks) {68if (cb instanceof PasswordCallback) {69((PasswordCallback) cb).setPassword("password".toCharArray());70}71}72};7374SaslClient client = Sasl.createSaslClient(75new String[]{"DIGEST-MD5", "NTLM"}, authorizationId,76protocol, serverName, props, callbackHandler);77Asserts.assertEQ(client == null ? null : client.getMechanismName(),78args[0].equals("null") ? null : args[0]);7980SaslServer server = Sasl.createSaslServer(81"DIGEST-MD5", protocol, serverName, props, callbackHandler);82Asserts.assertEQ(server == null ? null : server.getMechanismName(),83args[1].equals("null") ? null : args[1]);84}85}868788