J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 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 it |
| 5 | * under the terms of the GNU General Public License version 2 only, as |
| 6 | * published by the Free Software Foundation. Sun designates this |
| 7 | * particular file as subject to the "Classpath" exception as provided |
| 8 | * by Sun in the LICENSE file that accompanied this code. |
| 9 | * |
| 10 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 | * version 2 for more details (a copy is included in the LICENSE file that |
| 14 | * accompanied this code). |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License version |
| 17 | * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 21 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 22 | * have any questions. |
| 23 | */ |
| 24 | |
| 25 | /* |
| 26 | * |
| 27 | * (C) Copyright IBM Corp. 1999 All Rights Reserved. |
| 28 | * Copyright 1997 The Open Group Research Institute. All rights reserved. |
| 29 | */ |
| 30 | |
| 31 | package sun.security.krb5.internal.ccache; |
| 32 | |
| 33 | import sun.security.krb5.*; |
| 34 | import sun.security.krb5.internal.*; |
| 35 | import java.util.StringTokenizer; |
| 36 | import java.util.Vector; |
| 37 | import java.io.IOException; |
| 38 | import java.io.File; |
| 39 | import java.io.FileInputStream; |
| 40 | import java.io.FileOutputStream; |
| 41 | import java.io.BufferedReader; |
| 42 | import java.io.InputStreamReader; |
| 43 | |
| 44 | /** |
| 45 | * CredentialsCache stores credentials(tickets, session keys, etc) in a semi-permanent store |
| 46 | * for later use by different program. |
| 47 | * |
| 48 | * @author Yanni Zhang |
| 49 | */ |
| 50 | public abstract class CredentialsCache { |
| 51 | static CredentialsCache singleton = null; |
| 52 | static String cacheName; |
| 53 | private static boolean DEBUG = Krb5.DEBUG; |
| 54 | |
| 55 | public static CredentialsCache getInstance(PrincipalName principal) { |
| 56 | return FileCredentialsCache.acquireInstance(principal, null); |
| 57 | } |
| 58 | |
| 59 | public static CredentialsCache getInstance(String cache) { |
| 60 | if ((cache.length() >= 5) && cache.substring(0, 5).equalsIgnoreCase("FILE:")) { |
| 61 | return FileCredentialsCache.acquireInstance(null, cache.substring(5)); |
| 62 | } |
| 63 | // XXX else, memory credential cache |
| 64 | // default is file credential cache. |
| 65 | return FileCredentialsCache.acquireInstance(null, cache); |
| 66 | } |
| 67 | |
| 68 | public static CredentialsCache getInstance(PrincipalName principal, |
| 69 | String cache) { |
| 70 | |
| 71 | // XXX Modify this to use URL framework of the JDK |
| 72 | if (cache != null && |
| 73 | (cache.length() >= 5) && |
| 74 | cache.regionMatches(true, 0, "FILE:", 0, 5)) { |
| 75 | return FileCredentialsCache.acquireInstance(principal, |
| 76 | cache.substring(5)); |
| 77 | } |
| 78 | |
| 79 | // When cache is null, read the default cache. |
| 80 | // XXX else ..we haven't provided support for memory credential cache |
| 81 | // yet. (supported in native code) |
| 82 | // default is file credentials cache. |
| 83 | return FileCredentialsCache.acquireInstance(principal, cache); |
| 84 | |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Gets the default credentials cache. |
| 89 | */ |
| 90 | public static CredentialsCache getInstance() { |
| 91 | // Default credentials cache is file-based. |
| 92 | return FileCredentialsCache.acquireInstance(); |
| 93 | } |
| 94 | |
| 95 | public static CredentialsCache create(PrincipalName principal, String name) { |
| 96 | if (name == null) { |
| 97 | throw new RuntimeException("cache name error"); |
| 98 | } |
| 99 | if ((name.length() >= 5) |
| 100 | && name.regionMatches(true, 0, "FILE:", 0, 5)) { |
| 101 | name = name.substring(5); |
| 102 | return (FileCredentialsCache.New(principal, name)); |
| 103 | } |
| 104 | // else return file credentials cache |
| 105 | // default is file credentials cache. |
| 106 | return (FileCredentialsCache.New(principal, name)); |
| 107 | } |
| 108 | |
| 109 | public static CredentialsCache create(PrincipalName principal) { |
| 110 | // create a default credentials cache for a specified principal |
| 111 | return (FileCredentialsCache.New(principal)); |
| 112 | } |
| 113 | |
| 114 | public static String cacheName() { |
| 115 | return cacheName; |
| 116 | } |
| 117 | |
| 118 | public abstract PrincipalName getPrimaryPrincipal(); |
| 119 | public abstract void update(Credentials c); |
| 120 | public abstract void save() throws IOException, KrbException; |
| 121 | public abstract Credentials[] getCredsList(); |
| 122 | public abstract Credentials getDefaultCreds(); |
| 123 | public abstract Credentials getCreds(PrincipalName sname, Realm srealm) ; |
| 124 | public abstract Credentials getCreds(LoginOptions options, PrincipalName sname, Realm srealm) ; |
| 125 | } |