Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/krb5/auto/LongLife.java
38854 views
/*1* Copyright (c) 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 8131051 818721826* @summary KDC might issue a renewable ticket even if not requested27* @compile -XDignore.symbol.file LongLife.java28* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock LongLife29*/3031import org.ietf.jgss.GSSCredential;32import org.ietf.jgss.GSSManager;33import sun.security.krb5.Config;34import javax.security.auth.Subject;35import javax.security.auth.kerberos.KerberosTicket;36import java.security.PrivilegedExceptionAction;3738public class LongLife {3940public static void main(String[] args) throws Exception {4142OneKDC kdc = new OneKDC(null).writeJAASConf();4344test(kdc, "10h", false, 36000, false);45test(kdc, "2d", false, KDC.DEFAULT_LIFETIME, true);46test(kdc, "2d", true, 2 * 24 * 3600, false);4748// 8187218: getRemainingLifetime() is negative if lifetime49// is longer than 30 days.50test(kdc, "30d", true, 30 * 24 * 3600, false);51}5253static void test(54KDC kdc,55String ticketLifetime,56boolean forceTill, // if true, KDC will not try RENEWABLE57int expectedLifeTime,58boolean expectedRenewable) throws Exception {5960KDC.saveConfig(OneKDC.KRB5_CONF, kdc);61Config.refresh();6263System.setProperty("test.kdc.ttl.value", ticketLifetime);6465if (forceTill) {66System.setProperty("test.kdc.force.till", "");67} else {68System.clearProperty("test.kdc.force.till");69}7071Context c = Context.fromJAAS("client");7273GSSCredential cred = Subject.doAs(c.s(),74(PrivilegedExceptionAction<GSSCredential>)75()-> {76GSSManager m = GSSManager.getInstance();77return m.createCredential(GSSCredential.INITIATE_ONLY);78});7980KerberosTicket tgt = c.s().getPrivateCredentials(KerberosTicket.class)81.iterator().next();82System.out.println(tgt);8384int actualLifeTime = cred.getRemainingLifetime();85if (actualLifeTime < (expectedLifeTime - 60 )86|| actualLifeTime > (expectedLifeTime + 60)) {87throw new Exception("actualLifeTime is " + actualLifeTime +88" ExpectedLifeTime is " + expectedLifeTime);89}9091if (tgt.isRenewable() != expectedRenewable) {92throw new Exception("TGT's RENEWABLE flag is " + tgt.isRenewable());93}94}95}969798