Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/security/jgss/wrapper/GSSCredElement.java
38923 views
/*1* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package sun.security.jgss.wrapper;2526import org.ietf.jgss.*;27import java.security.Provider;28import sun.security.jgss.GSSUtil;29import sun.security.jgss.spi.GSSCredentialSpi;30import sun.security.jgss.spi.GSSNameSpi;3132/**33* This class is essentially a wrapper class for the gss_cred_id_t34* structure of the native GSS library.35* @author Valerie Peng36* @since 1.637*/38public class GSSCredElement implements GSSCredentialSpi {3940private int usage;41long pCred; // Pointer to the gss_cred_id_t structure42private GSSNameElement name = null;43private GSSLibStub cStub;4445// Perform the necessary ServicePermission check on this cred46void doServicePermCheck() throws GSSException {47if (GSSUtil.isKerberosMech(cStub.getMech())) {48if (System.getSecurityManager() != null) {49if (isInitiatorCredential()) {50String tgsName = Krb5Util.getTGSName(name);51Krb5Util.checkServicePermission(tgsName, "initiate");52}53if (isAcceptorCredential() &&54name != GSSNameElement.DEF_ACCEPTOR) {55String krbName = name.getKrbName();56Krb5Util.checkServicePermission(krbName, "accept");57}58}59}60}6162// Construct delegation cred using the actual context mech and srcName63GSSCredElement(long pCredentials, GSSNameElement srcName, Oid mech)64throws GSSException {65pCred = pCredentials;66cStub = GSSLibStub.getInstance(mech);67usage = GSSCredential.INITIATE_ONLY;68name = srcName;69}7071GSSCredElement(GSSNameElement name, int lifetime, int usage,72GSSLibStub stub) throws GSSException {73cStub = stub;74this.usage = usage;7576if (name != null) { // Could be GSSNameElement.DEF_ACCEPTOR77this.name = name;78doServicePermCheck();79pCred = cStub.acquireCred(this.name.pName, lifetime, usage);80} else {81pCred = cStub.acquireCred(0, lifetime, usage);82this.name = new GSSNameElement(cStub.getCredName(pCred), cStub);83doServicePermCheck();84}85}8687public Provider getProvider() {88return SunNativeProvider.INSTANCE;89}9091public void dispose() throws GSSException {92name = null;93if (pCred != 0) {94pCred = cStub.releaseCred(pCred);95}96}9798public GSSNameElement getName() throws GSSException {99return (name == GSSNameElement.DEF_ACCEPTOR ?100null : name);101}102103public int getInitLifetime() throws GSSException {104if (isInitiatorCredential()) {105return cStub.getCredTime(pCred);106} else return 0;107}108109public int getAcceptLifetime() throws GSSException {110if (isAcceptorCredential()) {111return cStub.getCredTime(pCred);112} else return 0;113}114115public boolean isInitiatorCredential() {116return (usage != GSSCredential.ACCEPT_ONLY);117}118119public boolean isAcceptorCredential() {120return (usage != GSSCredential.INITIATE_ONLY);121}122123public Oid getMechanism() {124return cStub.getMech();125}126127public String toString() {128// No hex bytes available for native impl129return "N/A";130}131132protected void finalize() throws Throwable {133dispose();134}135136@Override137public GSSCredentialSpi impersonate(GSSNameSpi name) throws GSSException {138throw new GSSException(GSSException.FAILURE, -1,139"Not supported yet");140}141}142143144