1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.transport.apache;
20
21 import java.io.Closeable;
22
23 import org.apache.http.client.protocol.HttpClientContext;
24
25
26
27
28
29
30
31 final class SharingHttpContext extends HttpClientContext implements Closeable {
32
33 private final LocalState state;
34
35 private final SharingAuthCache authCache;
36
37 SharingHttpContext(LocalState state) {
38 this.state = state;
39 authCache = new SharingAuthCache(state);
40 super.setAttribute(HttpClientContext.AUTH_CACHE, authCache);
41 }
42
43 @Override
44 public Object getAttribute(String id) {
45 if (HttpClientContext.USER_TOKEN.equals(id)) {
46 return state.getUserToken();
47 }
48 return super.getAttribute(id);
49 }
50
51 @Override
52 public void setAttribute(String id, Object obj) {
53 if (HttpClientContext.USER_TOKEN.equals(id)) {
54 state.setUserToken(obj);
55 } else {
56 super.setAttribute(id, obj);
57 }
58 }
59
60 @Override
61 public Object removeAttribute(String id) {
62 if (HttpClientContext.USER_TOKEN.equals(id)) {
63 state.setUserToken(null);
64 return null;
65 }
66 return super.removeAttribute(id);
67 }
68
69 @Override
70 public void close() {
71 authCache.clear();
72 }
73 }