jdk/test/sun/security/krb5/auto/DynamicKeytab.java
changeset 9542 6f715a596a2e
parent 9499 f3115698a012
child 14895 5ad2d7032375
equal deleted inserted replaced
9541:7ce475045bf0 9542:6f715a596a2e
    28  * @summary always refresh keytab
    28  * @summary always refresh keytab
    29  */
    29  */
    30 
    30 
    31 import java.io.File;
    31 import java.io.File;
    32 import java.io.FileOutputStream;
    32 import java.io.FileOutputStream;
       
    33 import java.nio.file.Files;
       
    34 import java.nio.file.Paths;
    33 import org.ietf.jgss.GSSException;
    35 import org.ietf.jgss.GSSException;
    34 import sun.security.jgss.GSSUtil;
    36 import sun.security.jgss.GSSUtil;
    35 import sun.security.krb5.KrbException;
    37 import sun.security.krb5.KrbException;
    36 import sun.security.krb5.internal.Krb5;
    38 import sun.security.krb5.internal.Krb5;
    37 
    39 
    45 
    47 
    46     void go() throws Exception {
    48     void go() throws Exception {
    47         OneKDC k = new OneKDC(null);
    49         OneKDC k = new OneKDC(null);
    48         k.writeJAASConf();
    50         k.writeJAASConf();
    49 
    51 
    50         new File(OneKDC.KTAB).delete();
    52         Files.delete(Paths.get(OneKDC.KTAB));
    51 
       
    52 
    53 
    53         // Starts with no keytab
    54         // Starts with no keytab
    54         c = Context.fromJAAS("client");
    55         c = Context.fromJAAS("client");
    55         s = Context.fromJAAS("com.sun.security.jgss.krb5.accept");
    56         s = Context.fromJAAS("com.sun.security.jgss.krb5.accept");
    56 
    57 
    77         k.appendKtab(OneKDC.KTAB);
    78         k.appendKtab(OneKDC.KTAB);
    78         k.addPrincipal(OneKDC.SERVER, "pass3".toCharArray());
    79         k.addPrincipal(OneKDC.SERVER, "pass3".toCharArray());
    79         connect();
    80         connect();
    80 
    81 
    81         // Test 5: invalid keytab file, should ignore
    82         // Test 5: invalid keytab file, should ignore
    82         new FileOutputStream(OneKDC.KTAB).write("BADBADBAD".getBytes());
    83         try (FileOutputStream fos = new FileOutputStream(OneKDC.KTAB)) {
       
    84             fos.write("BADBADBAD".getBytes());
       
    85         }
    83         connect();
    86         connect();
    84 
    87 
    85         // Test 6: delete keytab file, identical to revoke all
    88         // Test 6: delete keytab file, identical to revoke all
    86         new File(OneKDC.KTAB).delete();
    89         Files.delete(Paths.get(OneKDC.KTAB));
    87         try {
    90         try {
    88             connect();
    91             connect();
    89             throw new Exception("Should not success");
    92             throw new Exception("Should not success");
    90         } catch (GSSException gsse) {
    93         } catch (GSSException gsse) {
    91             System.out.println(gsse);
    94             System.out.println(gsse);