jdk/src/share/classes/sun/security/krb5/internal/CredentialsUtil.java
changeset 13247 74902cfeb9c6
parent 5506 202f599c92aa
child 14342 8435a30053c1
equal deleted inserted replaced
13246:a54c4f70775c 13247:74902cfeb9c6
    70     * @return a <code>Credentials</code> object.
    70     * @return a <code>Credentials</code> object.
    71     */
    71     */
    72     public static Credentials acquireServiceCreds(
    72     public static Credentials acquireServiceCreds(
    73                 String service, Credentials ccreds)
    73                 String service, Credentials ccreds)
    74     throws KrbException, IOException {
    74     throws KrbException, IOException {
    75         ServiceName sname = new ServiceName(service);
    75         PrincipalName sname = new PrincipalName(service);
    76         String serviceRealm = sname.getRealmString();
    76         String serviceRealm = sname.getRealmString();
    77         String localRealm = ccreds.getClient().getRealmString();
    77         String localRealm = ccreds.getClient().getRealmString();
    78         String defaultRealm = Config.getInstance().getDefaultRealm();
       
    79 
       
    80         if (localRealm == null) {
       
    81             PrincipalName temp = null;
       
    82             if ((temp = ccreds.getServer()) != null)
       
    83                 localRealm = temp.getRealmString();
       
    84         }
       
    85         if (localRealm == null) {
       
    86             localRealm = defaultRealm;
       
    87         }
       
    88         if (serviceRealm == null) {
       
    89             serviceRealm = localRealm;
       
    90             sname.setRealm(serviceRealm);
       
    91         }
       
    92 
    78 
    93         /*
    79         /*
    94           if (!localRealm.equalsIgnoreCase(serviceRealm)) { //do cross-realm auth entication
    80           if (!localRealm.equalsIgnoreCase(serviceRealm)) { //do cross-realm auth entication
    95           if (DEBUG) {
    81           if (DEBUG) {
    96           System.out.println(">>>DEBUG: Credentails request cross realm ticket for " + "krbtgt/" + serviceRealm + "@" + localRealm);
    82           System.out.println(">>>DEBUG: Credentails request cross realm ticket for " + "krbtgt/" + serviceRealm + "@" + localRealm);
   126             return null;
   112             return null;
   127         }
   113         }
   128 
   114 
   129         int i = 0, k = 0;
   115         int i = 0, k = 0;
   130         Credentials cTgt = null, newTgt = null, theTgt = null;
   116         Credentials cTgt = null, newTgt = null, theTgt = null;
   131         ServiceName tempService = null;
   117         PrincipalName tempService = null;
   132         String realm = null, newTgtRealm = null, theTgtRealm = null;
   118         String realm = null, newTgtRealm = null, theTgtRealm = null;
   133 
   119 
   134         for (cTgt = ccreds, i = 0; i < realms.length;)
   120         for (cTgt = ccreds, i = 0; i < realms.length;)
   135         {
   121         {
   136             tempService = new ServiceName(PrincipalName.TGS_DEFAULT_SRV_NAME,
   122             tempService = PrincipalName.tgsService(serviceRealm, realms[i]);
   137                                           serviceRealm, realms[i]);
       
   138 
   123 
   139             if (DEBUG)
   124             if (DEBUG)
   140             {
   125             {
   141                 System.out.println(">>> Credentials acquireServiceCreds: main loop: [" + i +"] tempService=" + tempService);
   126                 System.out.println(">>> Credentials acquireServiceCreds: main loop: [" + i +"] tempService=" + tempService);
   142             }
   127             }
   162 
   147 
   163                 for (newTgt = null, k = realms.length - 1;
   148                 for (newTgt = null, k = realms.length - 1;
   164                      newTgt == null && k > i; k--)
   149                      newTgt == null && k > i; k--)
   165                 {
   150                 {
   166 
   151 
   167                     tempService = new ServiceName(
   152                     tempService = PrincipalName.tgsService(realms[k], realms[i]);
   168                                        PrincipalName.TGS_DEFAULT_SRV_NAME,
       
   169                                        realms[k], realms[i]);
       
   170                     if (DEBUG)
   153                     if (DEBUG)
   171                     {
   154                     {
   172                         System.out.println(">>> Credentials acquireServiceCreds: inner loop: [" + k +"] tempService=" + tempService);
   155                         System.out.println(">>> Credentials acquireServiceCreds: inner loop: [" + k +"] tempService=" + tempService);
   173                     }
   156                     }
   174 
   157 
   304 
   287 
   305    /*
   288    /*
   306     * This method does the real job to request the service credential.
   289     * This method does the real job to request the service credential.
   307     */
   290     */
   308     private static Credentials serviceCreds(
   291     private static Credentials serviceCreds(
   309             ServiceName service, Credentials ccreds)
   292             PrincipalName service, Credentials ccreds)
   310             throws KrbException, IOException {
   293             throws KrbException, IOException {
   311         return new KrbTgsReq(ccreds, service).sendAndGetCreds();
   294         return new KrbTgsReq(ccreds, service).sendAndGetCreds();
   312     }
   295     }
   313 }
   296 }