History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/sun/security/jgss/wrapper/GSSCredElement.java (1 of 18352 files). Show all

Unified · Split

java/pkg/sun/security/jgss/wrapper/GSSCredElement.java+135−0
@@ -0,0 +1,135 @@
1/*
2 * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25package sun.security.jgss.wrapper;
26
27import org.ietf.jgss.*;
28import java.security.Provider;
29import sun.security.jgss.GSSUtil;
30import sun.security.jgss.spi.GSSCredentialSpi;
31
32/**
33 * This class is essentially a wrapper class for the gss_cred_id_t
34 * structure of the native GSS library.
35 * @author Valerie Peng
36 * @since 1.6
37 */
38public class GSSCredElement implements GSSCredentialSpi {
39
40 private int usage;
41 long pCred; // Pointer to the gss_cred_id_t structure
42 private GSSNameElement name = null;
43 private GSSLibStub cStub;
44
45 // Perform the necessary ServicePermission check on this cred
46 void doServicePermCheck() throws GSSException {
47 if (GSSUtil.isKerberosMech(cStub.getMech())) {
48 if (System.getSecurityManager() != null) {
49 if (isInitiatorCredential()) {
50 String tgsName = Krb5Util.getTGSName(name);
51 Krb5Util.checkServicePermission(tgsName, "initiate");
52 }
53 if (isAcceptorCredential() &&
54 name != GSSNameElement.DEF_ACCEPTOR) {
55 String krbName = name.getKrbName();
56 Krb5Util.checkServicePermission(krbName, "accept");
57 }
58 }
59 }
60 }
61
62 // Construct delegation cred using the actual context mech and srcName
63 GSSCredElement(long pCredentials, GSSNameElement srcName, Oid mech)
64 throws GSSException {
65 pCred = pCredentials;
66 cStub = GSSLibStub.getInstance(mech);
67 usage = GSSCredential.INITIATE_ONLY;
68 name = srcName;
69 }
70
71 GSSCredElement(GSSNameElement name, int lifetime, int usage,
72 GSSLibStub stub) throws GSSException {
73 cStub = stub;
74 this.usage = usage;
75
76 if (name != null) { // Could be GSSNameElement.DEF_ACCEPTOR
77 this.name = name;
78 doServicePermCheck();
79 pCred = cStub.acquireCred(this.name.pName, lifetime, usage);
80 } else {
81 pCred = cStub.acquireCred(0, lifetime, usage);
82 this.name = new GSSNameElement(cStub.getCredName(pCred), cStub);
83 doServicePermCheck();
84 }
85 }
86
87 public Provider getProvider() {
88 return SunNativeProvider.INSTANCE;
89 }
90
91 public void dispose() throws GSSException {
92 name = null;
93 if (pCred != 0) {
94 pCred = cStub.releaseCred(pCred);
95 }
96 }
97
98 public GSSNameElement getName() throws GSSException {
99 return (name == GSSNameElement.DEF_ACCEPTOR ?
100 null : name);
101 }
102
103 public int getInitLifetime() throws GSSException {
104 if (isInitiatorCredential()) {
105 return cStub.getCredTime(pCred);
106 } else return 0;
107 }
108
109 public int getAcceptLifetime() throws GSSException {
110 if (isAcceptorCredential()) {
111 return cStub.getCredTime(pCred);
112 } else return 0;
113 }
114
115 public boolean isInitiatorCredential() {
116 return (usage != GSSCredential.ACCEPT_ONLY);
117 }
118
119 public boolean isAcceptorCredential() {
120 return (usage != GSSCredential.INITIATE_ONLY);
121 }
122
123 public Oid getMechanism() {
124 return cStub.getMech();
125 }
126
127 public String toString() {
128 // No hex bytes available for native impl
129 return "N/A";
130 }
131
132 protected void finalize() throws Throwable {
133 dispose();
134 }
135}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t