Path: blob/master/test/jdk/sun/security/krb5/auto/LongLife.java
41152 views
/*1* Copyright (c) 2015, 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 8194486 818721826* @summary KDC might issue a renewable ticket even if not requested27* @library /test/lib28* @compile -XDignore.symbol.file LongLife.java29* @run main jdk.test.lib.FileInstaller TestHosts TestHosts30* @run main/othervm -Djdk.net.hosts.file=TestHosts LongLife31*/3233import org.ietf.jgss.GSSCredential;34import org.ietf.jgss.GSSManager;35import sun.security.krb5.Config;36import javax.security.auth.Subject;37import javax.security.auth.kerberos.KerberosTicket;38import java.security.PrivilegedExceptionAction;3940public class LongLife {4142public static void main(String[] args) throws Exception {4344OneKDC kdc = new OneKDC(null).writeJAASConf();4546test(kdc, "10h", false, 36000, false);47test(kdc, "2d", false, KDC.DEFAULT_LIFETIME, true);48test(kdc, "2d", true, 2 * 24 * 3600, false);4950// 8187218: getRemainingLifetime() is negative if lifetime51// is longer than 30 days.52test(kdc, "30d", true, 30 * 24 * 3600, false);53}5455static void test(56KDC kdc,57String ticketLifetime,58boolean forceTill, // if true, KDC will not try RENEWABLE59int expectedLifeTime,60boolean expectedRenewable) throws Exception {6162KDC.saveConfig(OneKDC.KRB5_CONF, kdc,63"ticket_lifetime = " + ticketLifetime);64Config.refresh();6566if (forceTill) {67System.setProperty("test.kdc.force.till", "");68} else {69System.clearProperty("test.kdc.force.till");70}7172Context c = Context.fromJAAS("client");7374GSSCredential cred = Subject.doAs(c.s(),75(PrivilegedExceptionAction<GSSCredential>)76()-> {77GSSManager m = GSSManager.getInstance();78return m.createCredential(GSSCredential.INITIATE_ONLY);79});8081KerberosTicket tgt = c.s().getPrivateCredentials(KerberosTicket.class)82.iterator().next();83System.out.println(tgt);8485int actualLifeTime = cred.getRemainingLifetime();86if (actualLifeTime < expectedLifeTime - 6087|| actualLifeTime > expectedLifeTime + 60) {88throw new Exception("actualLifeTime is " + actualLifeTime);89}9091if (tgt.isRenewable() != expectedRenewable) {92throw new Exception("TGT's RENEWABLE flag is " + tgt.isRenewable());93}94}95}969798