Path: blob/master/test/jdk/com/sun/security/sasl/digest/AuthRealmChoices.java
41154 views
/*1* Copyright (c) 2013, 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 801385526* @run main AuthRealmChoices 127* @run main AuthRealmChoices 228* @summary DigestMD5Client has not checked RealmChoiceCallback value29*/3031import java.io.IOException;32import java.util.HashMap;33import java.util.Map;34import javax.security.auth.callback.Callback;35import javax.security.auth.callback.CallbackHandler;36import javax.security.auth.callback.UnsupportedCallbackException;37import javax.security.sasl.*;3839public class AuthRealmChoices {40private static final String MECH = "DIGEST-MD5";41private static final String SERVER_FQDN = "machineX.imc.org";42private static final String PROTOCOL = "jmx";4344private static final byte[] EMPTY = new byte[0];4546public static void main(String[] args) throws Exception {4748Map props = new HashMap();49props.put("com.sun.security.sasl.digest.realm",50"IMC.ORG foo.bar machineX");5152SaslClient clnt = Sasl.createSaslClient(53new String[]{MECH}, null, PROTOCOL, SERVER_FQDN, null,54new CallbackHandler() {55@Override56public void handle(Callback[] callbacks)57throws IOException, UnsupportedCallbackException {58for (Callback cb: callbacks) {59if (cb instanceof RealmChoiceCallback) {60// Two tests:61// 1. Set an index out of bound62// 2. No index set at all63if (args[0].equals("1")) {64((RealmChoiceCallback)cb).setSelectedIndex(10);65}66}67}68}69});7071SaslServer srv = Sasl.createSaslServer(MECH, PROTOCOL, SERVER_FQDN, props,72new CallbackHandler() {73@Override74public void handle(Callback[] callbacks)75throws IOException, UnsupportedCallbackException {76for (Callback cb: callbacks) {77System.out.println(cb);78}79}80});8182byte[] challenge = srv.evaluateResponse(EMPTY);8384try {85clnt.evaluateChallenge(challenge);86throw new Exception();87} catch (SaslException se) {88System.out.println(se);89}90}91}929394