src/jdk.security.jgss/share/classes/com/sun/security/jgss/ExtendedGSSContextImpl.java
author bpb
Fri, 12 Jan 2018 11:06:24 -0800
changeset 48461 6a1c3a5e04f3
parent 47216 71c04702a3d5
permissions -rw-r--r--
4358774: Add null InputStream and OutputStream Reviewed-by: alanb, prappo, reinhapa, rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41372
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
     1
/*
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
     4
 *
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    10
 *
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    15
 * accompanied this code).
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    16
 *
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    20
 *
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    23
 * questions.
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    24
 */
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    25
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    26
package com.sun.security.jgss;
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    27
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    28
import org.ietf.jgss.*;
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    29
import sun.security.jgss.GSSContextImpl;
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    30
import sun.security.krb5.internal.AuthorizationData;
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    31
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    32
// The impl is almost identical to GSSContextImpl with only 2 differences:
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    33
// 1. It implements the extended interface
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    34
// 2. It translates result to data types here in inquireSecContext
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    35
class ExtendedGSSContextImpl extends GSSContextImpl
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    36
        implements ExtendedGSSContext {
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    37
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    38
    public ExtendedGSSContextImpl(GSSContextImpl old) {
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    39
        super(old);
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    40
    }
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    41
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    42
    @Override
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    43
    public Object inquireSecContext(InquireType type) throws GSSException {
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    44
        SecurityManager security = System.getSecurityManager();
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    45
        if (security != null) {
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    46
            security.checkPermission(
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    47
                    new InquireSecContextPermission(type.toString()));
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    48
        }
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    49
        Object output = super.inquireSecContext(type.name());
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    50
        if (output != null) {
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    51
            if (type == InquireType.KRB5_GET_AUTHZ_DATA) {
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    52
                AuthorizationData ad = (AuthorizationData) output;
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    53
                AuthorizationDataEntry[] authzData =
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    54
                        new AuthorizationDataEntry[ad.count()];
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    55
                for (int i = 0; i < ad.count(); i++) {
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    56
                    authzData[i] = new AuthorizationDataEntry(
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    57
                            ad.item(i).adType, ad.item(i).adData);
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    58
                }
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    59
                output = authzData;
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    60
            }
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    61
        }
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    62
        return output;
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    63
    }
893bf8209c04 8167181: Exported elements referring to inaccessible types in jdk.security.jgss
weijun
parents:
diff changeset
    64
}