src/java.security.jgss/share/classes/sun/security/krb5/internal/util/KerberosString.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 25859 jdk/src/java.security.jgss/share/classes/sun/security/krb5/internal/util/KerberosString.java@3317bb8137f4
child 49555 12fe57c319e1
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:
3949
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3949
diff changeset
     2
 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
3949
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
     4
 *
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
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: 3949
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
3949
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3949
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
3949
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    10
 *
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    15
 * accompanied this code).
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    16
 *
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3949
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3949
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3949
diff changeset
    23
 * questions.
3949
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    24
 */
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    25
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    26
package sun.security.krb5.internal.util;
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    27
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    28
import java.io.IOException;
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    29
import java.security.AccessController;
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    30
import sun.security.action.GetBooleanAction;
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    31
import sun.security.util.DerValue;
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    32
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    33
/**
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    34
 * Implements the ASN.1 KerberosString type.
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    35
 *
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    36
 * <pre>
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    37
 * KerberosString  ::= GeneralString (IA5String)
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    38
 * </pre>
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    39
 *
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    40
 * This definition reflects the Network Working Group RFC 4120
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    41
 * specification available at
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    42
 * <a href="http://www.ietf.org/rfc/rfc4120.txt">
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    43
 * http://www.ietf.org/rfc/rfc4120.txt</a>.
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    44
 */
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    45
public final class KerberosString {
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    46
    /**
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    47
     * RFC 4120 defines KerberosString as GeneralString (IA5String), which
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    48
     * only includes ASCII characters. However, other implementations have been
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    49
     * known to use GeneralString to contain UTF-8 encoding. To interop
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    50
     * with these implementations, the following system property is defined.
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    51
     * When set as true, KerberosString is encoded as UTF-8. Note that this
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    52
     * only affects the byte encoding, the tag of the ASN.1 type is still
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    53
     * GeneralString.
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    54
     */
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    55
    public static final boolean MSNAME = AccessController.doPrivileged(
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    56
            new GetBooleanAction("sun.security.krb5.msinterop.kstring"));
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    57
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    58
    private final String s;
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    59
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    60
    public KerberosString(String s) {
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    61
        this.s = s;
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    62
    }
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    63
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    64
    public KerberosString(DerValue der) throws IOException {
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    65
        if (der.tag != DerValue.tag_GeneralString) {
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    66
            throw new IOException(
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    67
                "KerberosString's tag is incorrect: " + der.tag);
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    68
        }
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    69
        s = new String(der.getDataBytes(), MSNAME?"UTF8":"ASCII");
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    70
    }
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    71
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    72
    public String toString() {
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    73
        return s;
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    74
    }
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    75
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    76
    public DerValue toDerValue() throws IOException {
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    77
        // No need to cache the result since this method is
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    78
        // only called once.
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    79
        return new DerValue(DerValue.tag_GeneralString,
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    80
                s.getBytes(MSNAME?"UTF8":"ASCII"));
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    81
    }
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff changeset
    82
}