jdk/test/sun/security/krb5/auto/KDC.java
changeset 36967 d041d2e80712
parent 34438 9ecd0f296185
child 39049 1108f7f41940
equal deleted inserted replaced
36966:4209c9e19c45 36967:d041d2e80712
     1 /*
     1 /*
     2  * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    33 import java.time.temporal.TemporalAmount;
    33 import java.time.temporal.TemporalAmount;
    34 import java.time.temporal.TemporalUnit;
    34 import java.time.temporal.TemporalUnit;
    35 import java.util.*;
    35 import java.util.*;
    36 import java.util.concurrent.*;
    36 import java.util.concurrent.*;
    37 
    37 
    38 import sun.net.spi.nameservice.NameService;
       
    39 import sun.net.spi.nameservice.NameServiceDescriptor;
       
    40 import sun.security.krb5.*;
    38 import sun.security.krb5.*;
    41 import sun.security.krb5.internal.*;
    39 import sun.security.krb5.internal.*;
    42 import sun.security.krb5.internal.ccache.CredentialsCache;
    40 import sun.security.krb5.internal.ccache.CredentialsCache;
    43 import sun.security.krb5.internal.crypto.EType;
    41 import sun.security.krb5.internal.crypto.EType;
    44 import sun.security.krb5.internal.crypto.KeyUsage;
    42 import sun.security.krb5.internal.crypto.KeyUsage;
   127 public class KDC {
   125 public class KDC {
   128 
   126 
   129     public static final int DEFAULT_LIFETIME = 39600;
   127     public static final int DEFAULT_LIFETIME = 39600;
   130     public static final int DEFAULT_RENEWTIME = 86400;
   128     public static final int DEFAULT_RENEWTIME = 86400;
   131 
   129 
       
   130     public static String NOT_EXISTING_HOST = "not.existing.host";
       
   131 
   132     // Under the hood.
   132     // Under the hood.
   133 
   133 
   134     // The random generator to generate random keys (including session keys)
   134     // The random generator to generate random keys (including session keys)
   135     private static SecureRandom secureRandom = new SecureRandom();
   135     private static SecureRandom secureRandom = new SecureRandom();
   136 
   136 
   217          */
   217          */
   218         CHECK_ADDRESSES,
   218         CHECK_ADDRESSES,
   219     };
   219     };
   220 
   220 
   221     static {
   221     static {
   222         System.setProperty("sun.net.spi.nameservice.provider.1", "ns,mock");
   222         String hostsFileName = System.getProperty("test.src", ".") + "/TestHosts";
       
   223         System.setProperty("jdk.net.hosts.file", hostsFileName);
   223     }
   224     }
   224 
   225 
   225     /**
   226     /**
   226      * A standalone KDC server.
   227      * A standalone KDC server.
   227      */
   228      */
  1446                 e.printStackTrace();
  1447                 e.printStackTrace();
  1447             }
  1448             }
  1448         }
  1449         }
  1449     }
  1450     }
  1450 
  1451 
  1451     public static class KDCNameService implements NameServiceDescriptor {
       
  1452 
       
  1453         public static String NOT_EXISTING_HOST = "not.existing.host";
       
  1454 
       
  1455         @Override
       
  1456         public NameService createNameService() throws Exception {
       
  1457             NameService ns = new NameService() {
       
  1458                 @Override
       
  1459                 public InetAddress[] lookupAllHostAddr(String host)
       
  1460                         throws UnknownHostException {
       
  1461                     // Everything is localhost except NOT_EXISTING_HOST
       
  1462                     if (NOT_EXISTING_HOST.equals(host)) {
       
  1463                         throw new UnknownHostException("Unknown host name: "
       
  1464                                 + NOT_EXISTING_HOST);
       
  1465                     }
       
  1466                     return new InetAddress[]{
       
  1467                         InetAddress.getByAddress(host, new byte[]{127,0,0,1})
       
  1468                     };
       
  1469                 }
       
  1470                 @Override
       
  1471                 public String getHostByAddr(byte[] addr)
       
  1472                         throws UnknownHostException {
       
  1473                     // No reverse lookup, PrincipalName use original string
       
  1474                     throw new UnknownHostException();
       
  1475                 }
       
  1476             };
       
  1477             return ns;
       
  1478         }
       
  1479 
       
  1480         @Override
       
  1481         public String getProviderName() {
       
  1482             return "mock";
       
  1483         }
       
  1484 
       
  1485         @Override
       
  1486         public String getType() {
       
  1487             return "ns";
       
  1488         }
       
  1489     }
       
  1490 
  1452 
  1491     // Calling private methods thru reflections
  1453     // Calling private methods thru reflections
  1492     private static final Field getPADataField;
  1454     private static final Field getPADataField;
  1493     private static final Field getEType;
  1455     private static final Field getEType;
  1494     private static final Constructor<EncryptedData> ctorEncryptedData;
  1456     private static final Constructor<EncryptedData> ctorEncryptedData;