1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.client.util;
20
21 import java.net.URI;
22
23 import org.eclipse.jetty.client.HttpClient;
24 import org.eclipse.jetty.client.api.Authentication;
25
26 public abstract class AbstractAuthentication implements Authentication
27 {
28 private final URI uri;
29 private final String realm;
30
31 public AbstractAuthentication(URI uri, String realm)
32 {
33 this.uri = uri;
34 this.realm = realm;
35 }
36
37 public abstract String getType();
38
39 public URI getURI()
40 {
41 return uri;
42 }
43
44 public String getRealm()
45 {
46 return realm;
47 }
48
49 @Override
50 public boolean matches(String type, URI uri, String realm)
51 {
52 if (!getType().equalsIgnoreCase(type))
53 return false;
54
55 if (!this.realm.equals(realm))
56 return false;
57
58 return matchesURI(this.uri, uri);
59 }
60
61 public static boolean matchesURI(URI uri1, URI uri2)
62 {
63 String scheme = uri1.getScheme();
64 if (uri1.getScheme().equalsIgnoreCase(scheme))
65 {
66 if (uri1.getHost().equalsIgnoreCase(uri2.getHost()))
67 {
68
69 int thisPort = HttpClient.normalizePort(scheme, uri1.getPort());
70 int thatPort = HttpClient.normalizePort(scheme, uri2.getPort());
71 if (thisPort == thatPort)
72 {
73
74 return uri2.getPath().startsWith(uri1.getPath());
75 }
76 }
77 }
78 return false;
79 }
80 }