1 /* 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 8044500 27 * @summary Add kinit options and krb5.conf flags that allow users to 28 * obtain renewable tickets and specify ticket lifetimes 29 * @modules java.security.jgss/sun.security.krb5 30 * @compile -XDignore.symbol.file Duration.java 31 * @run main Duration 32 */ 33 import sun.security.krb5.Config; 34 import sun.security.krb5.KrbException; 35 36 public class Duration { 37 public static void main(String[] args) throws Exception { 38 check("123", 123); 39 check("1:1", 3660); 40 check("1:1:1", 3661); 41 check("1d", 86400); 42 check("1h", 3600); 43 check("1h1m", 3660); 44 check("1h 1m", 3660); 45 check("1d 1h 1m 1s", 90061); 46 check("1d1h1m1s", 90061); 47 48 check("", -1); 49 check("abc", -1); 50 check("1ms", -1); 51 check("1d1d", -1); 52 check("1h1d", -1); 53 check("x1h", -1); 54 check("1h x 1m", -1); 55 check(":", -1); 56 check("1:60", -1); 57 check("1:1:1:1", -1); 58 check("1:1:1:", -1); 59 } 60 61 static void check(String s, int ex) throws Exception { 62 System.out.print("\u001b[1;37;41m" +s + " " + ex); 63 System.out.print("\u001b[m\n"); 64 try { 65 int result = Config.duration(s); 66 if (result != ex) throw new Exception("for " + s + " is " + result); 67 } catch (KrbException ke) { 68 ke.printStackTrace(); 69 if (ex != -1) throw new Exception(); 70 } 71 } 72 }