This project has retired. For details please refer to its
Attic page.
CachedKeyManager xref
1 package org.apache.archiva.redback.keys.cached;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.List;
23
24 import javax.inject.Inject;
25 import javax.inject.Named;
26
27 import org.apache.archiva.redback.components.cache.Cache;
28 import org.apache.archiva.redback.keys.AbstractKeyManager;
29 import org.apache.archiva.redback.keys.AuthenticationKey;
30 import org.apache.archiva.redback.keys.KeyManager;
31 import org.apache.archiva.redback.keys.KeyManagerException;
32 import org.apache.archiva.redback.keys.KeyNotFoundException;
33 import org.springframework.stereotype.Service;
34
35
36
37
38
39
40 @Service("keyManager#cached")
41 public class CachedKeyManager
42 extends AbstractKeyManager
43 implements KeyManager
44 {
45 @Inject
46 @Named(value = "keyManager#jdo")
47 private KeyManager keyImpl;
48
49 @Inject
50 @Named(value = "cache#keys")
51 private Cache<String, AuthenticationKey> keysCache;
52
53 public AuthenticationKey addKey( AuthenticationKey key )
54 {
55 if ( key != null )
56 {
57 keysCache.remove( key.getKey() );
58 }
59 return this.keyImpl.addKey( key );
60 }
61
62 public AuthenticationKey createKey( String principal, String purpose, int expirationMinutes )
63 throws KeyManagerException
64 {
65 AuthenticationKey authkey = this.keyImpl.createKey( principal, purpose, expirationMinutes );
66 keysCache.remove( authkey.getKey() );
67 return authkey;
68 }
69
70 public void deleteKey( AuthenticationKey key )
71 throws KeyManagerException
72 {
73 keysCache.remove( key.getKey() );
74 this.keyImpl.deleteKey( key );
75 }
76
77 public void deleteKey( String key )
78 throws KeyManagerException
79 {
80 keysCache.remove( key );
81 this.keyImpl.deleteKey( key );
82 }
83
84 public void eraseDatabase()
85 {
86 try
87 {
88 this.keyImpl.eraseDatabase();
89 }
90 finally
91 {
92 this.keysCache.clear();
93 }
94 }
95
96 public AuthenticationKey findKey( String key )
97 throws KeyNotFoundException, KeyManagerException
98 {
99 try
100 {
101 AuthenticationKey authkey = keysCache.get( key );
102 if ( authkey != null )
103 {
104 assertNotExpired( authkey );
105 return authkey;
106 }
107 else
108 {
109 authkey = this.keyImpl.findKey( key );
110 keysCache.put( key, authkey );
111 return authkey;
112 }
113 }
114 catch ( KeyNotFoundException knfe )
115 {
116
117
118 keysCache.remove( key );
119 throw knfe;
120 }
121 }
122
123 public List<AuthenticationKey> getAllKeys()
124 {
125 log.debug( "NOT CACHED - .getAllKeys()" );
126 return this.keyImpl.getAllKeys();
127 }
128
129 public String getId()
130 {
131 return "Cached Key Manager [" + this.keyImpl.getId() + "]";
132 }
133
134 public KeyManager getKeyImpl()
135 {
136 return keyImpl;
137 }
138
139 public void setKeyImpl( KeyManager keyImpl )
140 {
141 this.keyImpl = keyImpl;
142 }
143
144 public Cache getKeysCache()
145 {
146 return keysCache;
147 }
148
149 public void setKeysCache( Cache keysCache )
150 {
151 this.keysCache = keysCache;
152 }
153 }