KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > jayasoft > ivy > util > Credentials


1 package fr.jayasoft.ivy.util;
2
3 /**
4  *
5  * @author Christian Riege
6  * @author Xavier Hanin
7  */

8 public class Credentials {
9     private String JavaDoc _realm;
10     private String JavaDoc _host;
11     private String JavaDoc _userName;
12     private String JavaDoc _passwd;
13     
14     public Credentials(String JavaDoc realm, String JavaDoc host, String JavaDoc userName, String JavaDoc passwd) {
15         _realm = realm;
16         _host = host;
17         _userName = userName;
18         _passwd = passwd;
19     }
20     
21     public String JavaDoc getHost() {
22         return _host;
23     }
24     public String JavaDoc getPasswd() {
25         return _passwd;
26     }
27     public String JavaDoc getRealm() {
28         return _realm;
29     }
30     public String JavaDoc getUserName() {
31         return _userName;
32     }
33
34     public static String JavaDoc buildKey(String JavaDoc realm, String JavaDoc host) {
35         if (realm == null || "".equals(realm.trim())) {
36             return host;
37         } else {
38             return realm + "@" + host;
39         }
40     }
41
42     public String JavaDoc toString() {
43         return getKey() + " " + getUserName() + "/" + getPasswd();
44     }
45
46     public boolean equals(Object JavaDoc o) {
47         if(o == null) {
48             return false;
49         }
50
51         if(o instanceof Credentials) {
52             Credentials c = (Credentials) o;
53             return getKey().equals(c.getKey());
54         }
55
56         return false;
57     }
58     
59     public int hashCode() {
60         return getKey().hashCode();
61     }
62     
63     public String JavaDoc getKey() {
64         return buildKey(_realm, _host);
65     }
66 }
67
Popular Tags