1 package org.eclipse.aether.transport.http;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.Closeable;
23 import java.util.concurrent.ConcurrentHashMap;
24 import java.util.concurrent.ConcurrentMap;
25
26 import org.apache.http.HttpHost;
27 import org.apache.http.auth.AuthScheme;
28 import org.apache.http.conn.ClientConnectionManager;
29 import org.eclipse.aether.RepositorySystemSession;
30 import org.eclipse.aether.repository.RemoteRepository;
31 import org.eclipse.aether.transport.http.GlobalState.CompoundKey;
32
33
34
35
36
37 final class LocalState
38 implements Closeable
39 {
40
41 private final GlobalState global;
42
43 private final ClientConnectionManager connMgr;
44
45 private final CompoundKey userTokenKey;
46
47 private volatile Object userToken;
48
49 private final CompoundKey expectContinueKey;
50
51 private volatile Boolean expectContinue;
52
53 private volatile Boolean webDav;
54
55 private final ConcurrentMap<HttpHost, AuthSchemePool> authSchemePools;
56
57 LocalState( RepositorySystemSession session, RemoteRepository repo, SslConfig sslConfig )
58 {
59 global = GlobalState.get( session );
60 userToken = this;
61 if ( global == null )
62 {
63 connMgr = GlobalState.newConnectionManager( sslConfig );
64 userTokenKey = null;
65 expectContinueKey = null;
66 authSchemePools = new ConcurrentHashMap<>();
67 }
68 else
69 {
70 connMgr = global.getConnectionManager( sslConfig );
71 userTokenKey = new CompoundKey( repo.getId(), repo.getUrl(), repo.getAuthentication(), repo.getProxy() );
72 expectContinueKey = new CompoundKey( repo.getUrl(), repo.getProxy() );
73 authSchemePools = global.getAuthSchemePools();
74 }
75 }
76
77 public ClientConnectionManager getConnectionManager()
78 {
79 return connMgr;
80 }
81
82 public Object getUserToken()
83 {
84 if ( userToken == this )
85 {
86 userToken = ( global != null ) ? global.getUserToken( userTokenKey ) : null;
87 }
88 return userToken;
89 }
90
91 public void setUserToken( Object userToken )
92 {
93 this.userToken = userToken;
94 if ( global != null )
95 {
96 global.setUserToken( userTokenKey, userToken );
97 }
98 }
99
100 public boolean isExpectContinue()
101 {
102 if ( expectContinue == null )
103 {
104 expectContinue =
105 !Boolean.FALSE.equals( ( global != null ) ? global.getExpectContinue( expectContinueKey ) : null );
106 }
107 return expectContinue;
108 }
109
110 public void setExpectContinue( boolean enabled )
111 {
112 expectContinue = enabled;
113 if ( global != null )
114 {
115 global.setExpectContinue( expectContinueKey, enabled );
116 }
117 }
118
119 public Boolean getWebDav()
120 {
121 return webDav;
122 }
123
124 public void setWebDav( boolean webDav )
125 {
126 this.webDav = webDav;
127 }
128
129 public AuthScheme getAuthScheme( HttpHost host )
130 {
131 AuthSchemePool pool = authSchemePools.get( host );
132 if ( pool != null )
133 {
134 return pool.get();
135 }
136 return null;
137 }
138
139 public void setAuthScheme( HttpHost host, AuthScheme authScheme )
140 {
141 AuthSchemePool pool = authSchemePools.get( host );
142 if ( pool == null )
143 {
144 AuthSchemePool p = new AuthSchemePool();
145 pool = authSchemePools.putIfAbsent( host, p );
146 if ( pool == null )
147 {
148 pool = p;
149 }
150 }
151 pool.put( authScheme );
152 }
153
154 public void close()
155 {
156 if ( global == null )
157 {
158 connMgr.shutdown();
159 }
160 }
161
162 }