Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/krb5/auto/OkAsDelegate.java
38854 views
/*1* Copyright (c) 2009, 2012, 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 717270126* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock OkAsDelegate false true true false false false27* FORWARDABLE ticket not allowed, always fail28* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock OkAsDelegate true false false false false false29* Service ticket no OK-AS-DELEGATE. Request nothing, gain nothing30* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock OkAsDelegate true false true false false false31* Service ticket no OK-AS-DELEGATE. Request deleg policy, gain nothing32* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock OkAsDelegate true true false true false true33* Service ticket no OK-AS-DELEGATE. Request deleg, granted34* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock OkAsDelegate true true true true false true35* Service ticket no OK-AS-DELEGATE. Request deleg and deleg policy, granted, with info not by policy36* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock -Dtest.kdc.policy.ok-as-delegate OkAsDelegate true false true true true true37* Service ticket has OK-AS-DELEGATE. Request deleg policy, granted38* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock -Dtest.kdc.policy.ok-as-delegate OkAsDelegate true true true true true true39* Service ticket has OK-AS-DELEGATE. granted, with info by policy40* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock -Dtest.spnego OkAsDelegate false true true false false false41* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock -Dtest.spnego OkAsDelegate true false false false false false42* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock -Dtest.spnego OkAsDelegate true false true false false false43* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock -Dtest.spnego OkAsDelegate true true false true false true44* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock -Dtest.spnego OkAsDelegate true true true true false true45* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock -Dtest.spnego -Dtest.kdc.policy.ok-as-delegate OkAsDelegate true false true true true true46* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock -Dtest.spnego -Dtest.kdc.policy.ok-as-delegate OkAsDelegate true true true true true true47* @summary Support OK-AS-DELEGATE flag48*/49import com.sun.security.jgss.ExtendedGSSContext;50import org.ietf.jgss.GSSCredential;51import org.ietf.jgss.GSSException;52import org.ietf.jgss.Oid;53import sun.security.jgss.GSSUtil;54import sun.security.krb5.Config;5556public class OkAsDelegate {5758public static void main(String[] args)59throws Exception {60OkAsDelegate ok = new OkAsDelegate();61ok.go(62Boolean.valueOf(args[0]), // FORWARDABLE in krb5.conf on?63Boolean.valueOf(args[1]), // requestDelegState64Boolean.valueOf(args[2]), // requestDelegPolicyState65Boolean.valueOf(args[3]), // DelegState in response66Boolean.valueOf(args[4]), // DelegPolicyState in response67Boolean.valueOf(args[5]) // getDelegCred OK?68);69}7071void go(72boolean forwardable,73boolean requestDelegState,74boolean requestDelegPolicyState,75boolean delegState,76boolean delegPolicyState,77boolean delegated78) throws Exception {79OneKDC kdc = new OneKDC(null);80kdc.setOption(KDC.Option.OK_AS_DELEGATE,81System.getProperty("test.kdc.policy.ok-as-delegate"));82kdc.writeJAASConf();83if (!forwardable) {84// The default OneKDC always includes "forwardable = true"85// in krb5.conf, override it.86KDC.saveConfig(OneKDC.KRB5_CONF, kdc,87"default_keytab_name = " + OneKDC.KTAB);88Config.refresh();89}9091Context c, s;92c = Context.fromJAAS("client");93s = Context.fromJAAS("com.sun.security.jgss.krb5.accept");9495Oid mech = GSSUtil.GSS_KRB5_MECH_OID;96if (System.getProperty("test.spnego") != null) {97mech = GSSUtil.GSS_SPNEGO_MECH_OID;98}99c.startAsClient(OneKDC.SERVER, mech);100ExtendedGSSContext cx = (ExtendedGSSContext)c.x();101cx.requestCredDeleg(requestDelegState);102cx.requestDelegPolicy(requestDelegPolicyState);103s.startAsServer(mech);104ExtendedGSSContext sx = (ExtendedGSSContext)s.x();105106Context.handshake(c, s);107108if (cx.getCredDelegState() != delegState) {109throw new Exception("Initiator cred state error");110}111if (sx.getCredDelegState() != delegState) {112throw new Exception("Acceptor cred state error");113}114if (cx.getDelegPolicyState() != delegPolicyState) {115throw new Exception("Initiator cred policy state error");116}117118GSSCredential cred = null;119try {120cred = s.x().getDelegCred();121} catch (GSSException e) {122// leave cred as null123}124125if (delegated != (cred != null)) {126throw new Exception("get cred error");127}128}129}130131132