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
24 import org.apache.http.client.protocol.ClientContext;
25 import org.apache.http.protocol.BasicHttpContext;
26
27
28
29
30
31
32
33 final class SharingHttpContext
34 extends BasicHttpContext
35 implements Closeable
36 {
37
38 private final LocalState state;
39
40 private final SharingAuthCache authCache;
41
42 SharingHttpContext( LocalState state )
43 {
44 this.state = state;
45 authCache = new SharingAuthCache( state );
46 super.setAttribute( ClientContext.AUTH_CACHE, authCache );
47 }
48
49 @Override
50 public Object getAttribute( String id )
51 {
52 if ( ClientContext.USER_TOKEN.equals( id ) )
53 {
54 return state.getUserToken();
55 }
56 return super.getAttribute( id );
57 }
58
59 @Override
60 public void setAttribute( String id, Object obj )
61 {
62 if ( ClientContext.USER_TOKEN.equals( id ) )
63 {
64 state.setUserToken( obj );
65 }
66 else
67 {
68 super.setAttribute( id, obj );
69 }
70 }
71
72 @Override
73 public Object removeAttribute( String id )
74 {
75 if ( ClientContext.USER_TOKEN.equals( id ) )
76 {
77 state.setUserToken( null );
78 return null;
79 }
80 return super.removeAttribute( id );
81 }
82
83 public void close()
84 {
85 authCache.clear();
86 }
87
88 }