KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > jayasoft > ivy > url > CredentialsStore


1 package fr.jayasoft.ivy.url;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Map JavaDoc;
5
6 import fr.jayasoft.ivy.util.Credentials;
7 import fr.jayasoft.ivy.util.Message;
8
9 /**
10  *
11  * @author Christian Riege
12  * @author Xavier Hanin
13  */

14 public class CredentialsStore {
15     /**
16      * A Map of Credentials objects keyed by the 'key' of the Credentials.
17      */

18     private final static Map JavaDoc keyring = new HashMap JavaDoc();
19     public final static CredentialsStore INSTANCE = new CredentialsStore();
20     
21     private CredentialsStore() {
22     }
23
24     public void addCredentials(String JavaDoc realm, String JavaDoc host, String JavaDoc userName, String JavaDoc passwd) {
25         if (userName == null) {
26             return;
27         }
28         Credentials c = new Credentials(realm, host, userName, passwd);
29         Message.debug("credentials added: "+c);
30         keyring.put(c.getKey(), c);
31         // add also with host only, to be able to find credential with host only
32
// (useful for httpclient especially)
33
keyring.put(c.getHost(), c);
34     }
35
36     public Credentials getCredentials(String JavaDoc realm, String JavaDoc host) {
37         return (Credentials) keyring.get(Credentials.buildKey(realm, host));
38     }
39
40 }
41
Popular Tags