0N/A/*
2362N/A * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.net.www.protocol.http;
0N/A
0N/Aimport java.io.IOException;
0N/Aimport java.net.URL;
0N/Aimport java.util.Hashtable;
0N/Aimport java.util.LinkedList;
0N/Aimport java.util.ListIterator;
0N/Aimport java.util.Enumeration;
0N/Aimport java.util.HashMap;
0N/A
0N/A/**
0N/A * @author Michael McMahon
0N/A */
0N/A
0N/Apublic class AuthCacheImpl implements AuthCache {
0N/A HashMap hashtable;
0N/A
0N/A public AuthCacheImpl () {
0N/A hashtable = new HashMap ();
0N/A }
0N/A
0N/A public void setMap (HashMap map) {
0N/A hashtable = map;
0N/A }
0N/A
0N/A // put a value in map according to primary key + secondary key which
0N/A // is the path field of AuthenticationInfo
0N/A
0N/A public synchronized void put (String pkey, AuthCacheValue value) {
0N/A LinkedList list = (LinkedList) hashtable.get (pkey);
0N/A String skey = value.getPath();
0N/A if (list == null) {
0N/A list = new LinkedList ();
0N/A hashtable.put (pkey, list);
0N/A }
0N/A // Check if the path already exists or a super-set of it exists
0N/A ListIterator iter = list.listIterator();
0N/A while (iter.hasNext()) {
0N/A AuthenticationInfo inf = (AuthenticationInfo)iter.next();
0N/A if (inf.path == null || inf.path.startsWith (skey)) {
0N/A iter.remove ();
0N/A }
0N/A }
0N/A iter.add (value);
0N/A }
0N/A
0N/A // get a value from map checking both primary
0N/A // and secondary (urlpath) key
0N/A
0N/A public synchronized AuthCacheValue get (String pkey, String skey) {
0N/A AuthenticationInfo result = null;
0N/A LinkedList list = (LinkedList) hashtable.get (pkey);
0N/A if (list == null || list.size() == 0) {
0N/A return null;
0N/A }
0N/A if (skey == null) {
0N/A // list should contain only one element
0N/A return (AuthenticationInfo)list.get (0);
0N/A }
0N/A ListIterator iter = list.listIterator();
0N/A while (iter.hasNext()) {
0N/A AuthenticationInfo inf = (AuthenticationInfo)iter.next();
0N/A if (skey.startsWith (inf.path)) {
0N/A return inf;
0N/A }
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A public synchronized void remove (String pkey, AuthCacheValue entry) {
0N/A LinkedList list = (LinkedList) hashtable.get (pkey);
0N/A if (list == null) {
0N/A return;
0N/A }
0N/A if (entry == null) {
0N/A list.clear();
0N/A return;
0N/A }
0N/A ListIterator iter = list.listIterator ();
0N/A while (iter.hasNext()) {
0N/A AuthenticationInfo inf = (AuthenticationInfo)iter.next();
0N/A if (entry.equals(inf)) {
0N/A iter.remove ();
0N/A }
0N/A }
0N/A }
0N/A}