Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/security/sasl/Sasl/DisabledMechanisms.java
38853 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* @library /lib/testlibrary27* @run main/othervm DisabledMechanisms28* DIGEST-MD5 DIGEST-MD529* @run main/othervm -DdisabledMechanisms= DisabledMechanisms30* DIGEST-MD5 DIGEST-MD531* @run main/othervm -DdisabledMechanisms=DIGEST-MD5,NTLM DisabledMechanisms32* null null33* @run main/othervm -DdisabledMechanisms=DIGEST-MD5 DisabledMechanisms34* NTLM null35* @run main/othervm -DdisabledMechanisms=NTLM DisabledMechanisms36* DIGEST-MD5 DIGEST-MD537*/3839import java.security.Security;40import java.util.Collections;41import java.util.Map;42import javax.security.auth.callback.PasswordCallback;43import javax.security.sasl.Sasl;44import javax.security.sasl.SaslClient;45import javax.security.sasl.SaslServer;46import javax.security.auth.callback.Callback;47import javax.security.auth.callback.CallbackHandler;4849import jdk.testlibrary.Asserts;5051public class DisabledMechanisms {5253public static void main(String[] args) throws Exception {5455String authorizationId = "username";56String protocol = "ldap";57String serverName = "server1";58Map props = Collections.emptyMap();5960String disabled = System.getProperty("disabledMechanisms");61if (disabled != null) {62Security.setProperty("jdk.sasl.disabledMechanisms", disabled);63}6465CallbackHandler callbackHandler = callbacks -> {66for (Callback cb : callbacks) {67if (cb instanceof PasswordCallback) {68((PasswordCallback) cb).setPassword("password".toCharArray());69}70}71};7273SaslClient client = Sasl.createSaslClient(74new String[]{"DIGEST-MD5", "NTLM"}, authorizationId,75protocol, serverName, props, callbackHandler);76Asserts.assertEQ(client == null ? null : client.getMechanismName(),77args[0].equals("null") ? null : args[0]);7879SaslServer server = Sasl.createSaslServer(80"DIGEST-MD5", protocol, serverName, props, callbackHandler);81Asserts.assertEQ(server == null ? null : server.getMechanismName(),82args[1].equals("null") ? null : args[1]);83}84}858687