1 package org.apache.maven.wagon.shared.http;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.http.HttpHost;
23 import org.apache.http.auth.AuthScope;
24
25
26
27
28 public class BasicAuthScope
29 {
30 private String host;
31
32 private String port;
33
34 private String realm;
35
36
37
38
39 public String getHost()
40 {
41 return host;
42 }
43
44
45
46
47 public void setHost( String host )
48 {
49 this.host = host;
50 }
51
52
53
54
55 public String getRealm()
56 {
57 return realm;
58 }
59
60
61
62
63 public void setRealm( String realm )
64 {
65 this.realm = realm;
66 }
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81 public AuthScope getScope( String host, int port )
82 {
83 if ( getHost() != null
84 && "ANY".compareTo( getHost() ) == 0
85 && getPort() != null
86 && "ANY".compareTo( getPort() ) == 0
87 && getRealm() != null
88 && "ANY".compareTo( getRealm() ) == 0 )
89 {
90 return AuthScope.ANY;
91 }
92 String scopeHost = host;
93 if ( getHost() != null )
94 {
95 if ( "ANY".compareTo( getHost() ) == 0 )
96 {
97 scopeHost = AuthScope.ANY_HOST;
98 }
99 else
100 {
101 scopeHost = getHost();
102 }
103 }
104
105 int scopePort = port > -1 ? port : AuthScope.ANY_PORT;
106
107
108
109 if ( getPort() != null )
110 {
111 if ( "ANY".compareTo( getPort() ) == 0 )
112 {
113 scopePort = AuthScope.ANY_PORT;
114 }
115 else
116 {
117 scopePort = Integer.parseInt( getPort() );
118 }
119 }
120
121 String scopeRealm = AuthScope.ANY_REALM;
122 if ( getRealm() != null )
123 {
124 if ( "ANY".compareTo( getRealm() ) != 0 )
125 {
126 scopeRealm = getRealm();
127 }
128 else
129 {
130 scopeRealm = getRealm();
131 }
132 }
133
134 return new AuthScope( scopeHost, scopePort, scopeRealm );
135 }
136
137
138
139
140 public String getPort()
141 {
142 return port;
143 }
144
145
146
147
148 public void setPort( String port )
149 {
150 this.port = port;
151 }
152
153
154
155
156
157
158
159
160
161
162
163
164 public AuthScope getScope( HttpHost targetHost )
165 {
166 return getScope( targetHost.getHostName(), targetHost.getPort() );
167 }
168 }