Path: blob/master/test/jdk/sun/security/krb5/auto/OkAsDelegate.java
41152 views
/*1* Copyright (c) 2009, 2018, 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 6853328 7172701 819448626* @summary Support OK-AS-DELEGATE flag27* @library /test/lib28* @run main jdk.test.lib.FileInstaller TestHosts TestHosts29* @run main/othervm -Djdk.net.hosts.file=TestHosts OkAsDelegate30* false true true false false false31* FORWARDABLE ticket not allowed, always fail32* @run main/othervm -Djdk.net.hosts.file=TestHosts OkAsDelegate33* true false false false false false34* Service ticket no OK-AS-DELEGATE. Request nothing, gain nothing35* @run main/othervm -Djdk.net.hosts.file=TestHosts OkAsDelegate36* true false true false false false37* Service ticket no OK-AS-DELEGATE. Request deleg policy, gain nothing38* @run main/othervm -Djdk.net.hosts.file=TestHosts OkAsDelegate39* true true false true false true40* Service ticket no OK-AS-DELEGATE. Request deleg, granted41* @run main/othervm -Djdk.net.hosts.file=TestHosts42* OkAsDelegate true true true true false true43* Service ticket no OK-AS-DELEGATE. Request deleg and deleg policy, granted, with info not by policy44* @run main/othervm -Djdk.net.hosts.file=TestHosts45* -Dtest.kdc.policy.ok-as-delegate OkAsDelegate46* true false true true true true47* Service ticket has OK-AS-DELEGATE. Request deleg policy, granted48* @run main/othervm -Djdk.net.hosts.file=TestHosts49* -Dtest.kdc.policy.ok-as-delegate OkAsDelegate50* true true true true true true51* Service ticket has OK-AS-DELEGATE. granted, with info by policy52* @run main/othervm -Djdk.net.hosts.file=TestHosts -Dtest.spnego53* OkAsDelegate false true true false false false54* @run main/othervm -Djdk.net.hosts.file=TestHosts -Dtest.spnego55* OkAsDelegate true false false false false false56* @run main/othervm -Djdk.net.hosts.file=TestHosts -Dtest.spnego57* OkAsDelegate true false true false false false58* @run main/othervm -Djdk.net.hosts.file=TestHosts -Dtest.spnego59* OkAsDelegate true true false true false true60* @run main/othervm -Djdk.net.hosts.file=TestHosts -Dtest.spnego61* OkAsDelegate true true true true false true62* @run main/othervm -Djdk.net.hosts.file=TestHosts -Dtest.spnego63* -Dtest.kdc.policy.ok-as-delegate OkAsDelegate64* true false true true true true65* @run main/othervm -Djdk.net.hosts.file=TestHosts -Dtest.spnego66* -Dtest.kdc.policy.ok-as-delegate OkAsDelegate67* true true true true true true68*/69import com.sun.security.jgss.ExtendedGSSContext;70import org.ietf.jgss.GSSContext;71import org.ietf.jgss.GSSCredential;72import org.ietf.jgss.GSSException;73import org.ietf.jgss.Oid;74import sun.security.jgss.GSSUtil;75import sun.security.krb5.Config;7677public class OkAsDelegate {7879public static void main(String[] args)80throws Exception {81OkAsDelegate ok = new OkAsDelegate();82ok.go(83Boolean.valueOf(args[0]), // FORWARDABLE in krb5.conf on?84Boolean.valueOf(args[1]), // requestDelegState85Boolean.valueOf(args[2]), // requestDelegPolicyState86Boolean.valueOf(args[3]), // DelegState in response87Boolean.valueOf(args[4]), // DelegPolicyState in response88Boolean.valueOf(args[5]) // getDelegCred OK?89);90}9192void go(93boolean forwardable,94boolean requestDelegState,95boolean requestDelegPolicyState,96boolean delegState,97boolean delegPolicyState,98boolean delegated99) throws Exception {100OneKDC kdc = new OneKDC(null);101kdc.setOption(KDC.Option.OK_AS_DELEGATE,102System.getProperty("test.kdc.policy.ok-as-delegate"));103kdc.writeJAASConf();104if (!forwardable) {105// The default OneKDC always includes "forwardable = true"106// in krb5.conf, override it.107KDC.saveConfig(OneKDC.KRB5_CONF, kdc,108"default_keytab_name = " + OneKDC.KTAB);109Config.refresh();110}111112Context c, s;113c = Context.fromJAAS("client");114s = Context.fromJAAS("com.sun.security.jgss.krb5.accept");115116Oid mech = GSSUtil.GSS_KRB5_MECH_OID;117if (System.getProperty("test.spnego") != null) {118mech = GSSUtil.GSS_SPNEGO_MECH_OID;119}120c.startAsClient(OneKDC.SERVER, mech);121ExtendedGSSContext cx = (ExtendedGSSContext)c.x();122cx.requestCredDeleg(requestDelegState);123cx.requestDelegPolicy(requestDelegPolicyState);124s.startAsServer(mech);125GSSContext sx = s.x();126127Context.handshake(c, s);128129if (cx.getCredDelegState() != delegState) {130throw new Exception("Initiator cred state error");131}132if (sx.getCredDelegState() != delegState) {133throw new Exception("Acceptor cred state error");134}135if (cx.getDelegPolicyState() != delegPolicyState) {136throw new Exception("Initiator cred policy state error");137}138139GSSCredential cred = null;140try {141cred = s.x().getDelegCred();142} catch (GSSException e) {143// leave cred as null144}145146if (delegated != (cred != null)) {147throw new Exception("get cred error");148}149}150}151152153