src/java.security.jgss/windows/classes/sun/security/krb5/internal/tools/KinitOptions.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 27946 jdk/src/java.security.jgss/windows/classes/sun/security/krb5/internal/tools/KinitOptions.java@9f99b93cbbb2
child 48543 7067fe4e054e
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 13247
diff changeset
     2
 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *  (C) Copyright IBM Corp. 1999 All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *  Copyright 1997 The Open Group Research Institute.  All rights reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
package sun.security.krb5.internal.tools;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.security.krb5.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.security.krb5.internal.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.security.krb5.internal.ccache.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.IOException;
27946
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
    37
import java.time.Instant;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.FileInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * Maintains user-specific options or default settings when the user requests
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * a KDC ticket using Kinit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @author Yanni Zhang
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @author Ram Marti
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
class KinitOptions {
27946
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
    48
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
    49
    // 1. acquire, 2. renew, 3. validate
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
    50
    public int action = 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    // forwardable and proxiable flags have two states:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    // -1 - flag set to be not forwardable or proxiable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    // 1 - flag set to be forwardable or proxiable.
27946
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
    55
    public short forwardable = 0;
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
    56
    public short proxiable = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public KerberosTime lifetime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public KerberosTime renewable_lifetime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public String target_service;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public String keytab_file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public String cachename;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private PrincipalName principal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public String realm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    char[] password = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public boolean keytab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private boolean DEBUG = Krb5.DEBUG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private boolean includeAddresses = true; // default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private boolean useKeytab = false; // default = false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private String ktabName; // keytab file name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public KinitOptions() throws RuntimeException, RealmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        // no args were specified in the command line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        // use default values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        cachename = FileCredentialsCache.getDefaultCacheName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        if (cachename == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            throw new RuntimeException("default cache name error");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        principal = getDefaultPrincipal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public void setKDCRealm(String r) throws RealmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        realm = r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public String getKDCRealm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        if (realm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            if (principal != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                return principal.getRealmString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public KinitOptions(String[] args)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        throws KrbException, RuntimeException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        // currently we provide support for -f -p -c principal options
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        String p = null; // store principal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        for (int i = 0; i < args.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            if (args[i].equals("-f")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                forwardable = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            } else if (args[i].equals("-p")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                proxiable = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            } else if (args[i].equals("-c")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                if (args[i + 1].startsWith("-")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                    throw new IllegalArgumentException("input format " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                                                       " not correct: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                                                       " -c  option " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                                                       "must be followed " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                                                       "by the cache name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                cachename = args[++i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                if ((cachename.length() >= 5) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                    cachename.substring(0, 5).equalsIgnoreCase("FILE:")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                    cachename = cachename.substring(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            } else if (args[i].equals("-A")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                includeAddresses = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            } else if (args[i].equals("-k")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                useKeytab = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            } else if (args[i].equals("-t")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                if (ktabName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                    throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                        ("-t option/keytab file name repeated");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                } else if (i + 1 < args.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                    ktabName = args[++i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                    throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                        ("-t option requires keytab file name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                useKeytab = true;
27946
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   134
            } else if (args[i].equals("-R")) {
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   135
                action = 2;
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   136
            } else if (args[i].equals("-l")) {
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   137
                lifetime = getTime(Config.duration(args[++i]));
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   138
            } else if (args[i].equals("-r")) {
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   139
                renewable_lifetime = getTime(Config.duration(args[++i]));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            } else if (args[i].equalsIgnoreCase("-help")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                printHelp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                System.exit(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            } else if (p == null) { // Haven't yet processed a "principal"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                p = args[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                    principal = new PrincipalName(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                    throw new IllegalArgumentException("invalid " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                                                       "Principal name: " + p +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                                                       e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            } else if (this.password == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                // Have already processed a Principal, this must be a password
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                password = args[i].toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                throw new IllegalArgumentException("too many parameters");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        // we should get cache name before getting the default principal name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (cachename == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            cachename = FileCredentialsCache.getDefaultCacheName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            if (cachename == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                throw new RuntimeException("default cache name error");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        if (principal == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            principal = getDefaultPrincipal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    PrincipalName getDefaultPrincipal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        // get default principal name from the cachename if it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        // available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            CCacheInputStream cis =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                new CCacheInputStream(new FileInputStream(cachename));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            int version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            if ((version = cis.readVersion()) ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                    FileCCacheConstants.KRB5_FCC_FVNO_4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                cis.readTag();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                if (version == FileCCacheConstants.KRB5_FCC_FVNO_1 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                        version == FileCCacheConstants.KRB5_FCC_FVNO_2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                    cis.setNativeByteOrder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            PrincipalName p = cis.readPrincipal(version);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            cis.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                System.out.println(">>>KinitOptions principal name from "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                                   "the cache is :" + p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            return p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            // ignore any exceptions; we will use the user name as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            // principal name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        } catch (RealmException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        String username = System.getProperty("user.name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            System.out.println(">>>KinitOptions default username is :"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                               + username);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 5506
diff changeset
   213
        try {
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 5506
diff changeset
   214
            PrincipalName p = new PrincipalName(username);
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 5506
diff changeset
   215
            return p;
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 5506
diff changeset
   216
        } catch (RealmException e) {
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 5506
diff changeset
   217
            // ignore exception , return null
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 5506
diff changeset
   218
            if (DEBUG) {
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 5506
diff changeset
   219
                System.out.println ("Exception in getting principal " +
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 5506
diff changeset
   220
                                    "name " + e.getMessage());
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 5506
diff changeset
   221
                e.printStackTrace();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    void printHelp() {
27946
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   229
        System.out.println("Usage:\n\n1. Initial ticket request:\n" +
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   230
                "    kinit [-A] [-f] [-p] [-c cachename] " +
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   231
                "[-l lifetime] [-r renewable_time]\n" +
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   232
                "          [[-k [-t keytab_file_name]] [principal] " +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                           "[password]");
27946
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   234
        System.out.println("2. Renew a ticket:\n" +
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   235
                "    kinit -R [-c cachename] [principal]");
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   236
        System.out.println("\nAvailable options to " +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                           "Kerberos 5 ticket request:");
27946
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   238
        System.out.println("\t-A   do not include addresses");
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   239
        System.out.println("\t-f   forwardable");
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   240
        System.out.println("\t-p   proxiable");
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   241
        System.out.println("\t-c   cache name " +
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   242
                "(i.e., FILE:\\d:\\myProfiles\\mykrb5cache)");
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   243
        System.out.println("\t-l   lifetime");
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   244
        System.out.println("\t-r   renewable time " +
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   245
                "(total lifetime a ticket can be renewed)");
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   246
        System.out.println("\t-k   use keytab");
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   247
        System.out.println("\t-t   keytab file name");
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   248
        System.out.println("\tprincipal   the principal name "+
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   249
                "(i.e., qweadf@ATHENA.MIT.EDU qweadf)");
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   250
        System.out.println("\tpassword    the principal's Kerberos password");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public boolean getAddressOption() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        return includeAddresses;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public boolean useKeytabFile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return useKeytab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public String keytabFileName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        return ktabName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public PrincipalName getPrincipal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        return principal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
27946
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   268
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   269
    private KerberosTime getTime(int s) {
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   270
        return new KerberosTime(Instant.now().plusSeconds(s));
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   271
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
}