<component>
<role>org.apache.archiva.redback.keys.KeyManager</role>
<role-hint>cached</role-hint>
- <implementation>org.codehaus.plexus.redback.keys.cached.CachedKeyManager</implementation>
+ <implementation>org.apache.archiva.redback.keys.cached.CachedKeyManager</implementation>
<description>CachedKeyManager</description>
<requirements>
<requirement>
<component>
<role>org.apache.archiva.redback.keys.KeyManager</role>
<role-hint>cached</role-hint>
- <implementation>org.codehaus.plexus.redback.keys.cached.CachedKeyManager</implementation>
+ <implementation>org.apache.archiva.redback.keys.cached.CachedKeyManager</implementation>
<description>CachedKeyManager</description>
<requirements>
<requirement>
</component>
-->
- <bean name="keyManager#cached" class="org.codehaus.plexus.redback.keys.cached.CachedKeyManager">
+ <bean name="keyManager#cached" class="org.apache.archiva.redback.keys.cached.CachedKeyManager">
<property name="keyImpl" ref="keyManager#memory"/>
</bean>
<!--
<component>
<role>org.apache.archiva.redback.keys.KeyManager</role>
<role-hint>cached</role-hint>
- <implementation>org.codehaus.plexus.redback.keys.cached.CachedKeyManager</implementation>
+ <implementation>org.apache.archiva.redback.keys.cached.CachedKeyManager</implementation>
<description>CachedKeyManager</description>
<requirements>
<requirement>
--- /dev/null
+package org.apache.archiva.redback.keys.cached;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.List;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.codehaus.plexus.cache.Cache;
+import org.apache.archiva.redback.keys.AbstractKeyManager;
+import org.apache.archiva.redback.keys.AuthenticationKey;
+import org.apache.archiva.redback.keys.KeyManager;
+import org.apache.archiva.redback.keys.KeyManagerException;
+import org.apache.archiva.redback.keys.KeyNotFoundException;
+import org.springframework.stereotype.Service;
+
+/**
+ * CachedKeyManager
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Service("keyManager#cached")
+public class CachedKeyManager
+ extends AbstractKeyManager
+ implements KeyManager
+{
+ @Inject @Named(value="keyManager#jdo")
+ private KeyManager keyImpl;
+
+ @Inject @Named(value="cache#keys")
+ private Cache keysCache;
+
+ public AuthenticationKey addKey( AuthenticationKey key )
+ {
+ if ( key != null )
+ {
+ keysCache.remove( key.getKey() );
+ }
+ return this.keyImpl.addKey( key );
+ }
+
+ public AuthenticationKey createKey( String principal, String purpose, int expirationMinutes )
+ throws KeyManagerException
+ {
+ AuthenticationKey authkey = this.keyImpl.createKey( principal, purpose, expirationMinutes );
+ keysCache.remove( authkey.getKey() );
+ return authkey;
+ }
+
+ public void deleteKey( AuthenticationKey key )
+ throws KeyManagerException
+ {
+ keysCache.remove( key.getKey() );
+ this.keyImpl.deleteKey( key );
+ }
+
+ public void deleteKey( String key )
+ throws KeyManagerException
+ {
+ keysCache.remove( key );
+ this.keyImpl.deleteKey( key );
+ }
+
+ public void eraseDatabase()
+ {
+ try
+ {
+ this.keyImpl.eraseDatabase();
+ }
+ finally
+ {
+ this.keysCache.clear();
+ }
+ }
+
+ public AuthenticationKey findKey( String key )
+ throws KeyNotFoundException, KeyManagerException
+ {
+ try
+ {
+ AuthenticationKey authkey = (AuthenticationKey) keysCache.get( key );
+ if ( authkey != null )
+ {
+ assertNotExpired( authkey );
+ return authkey;
+ }
+ else
+ {
+ authkey = this.keyImpl.findKey( key );
+ keysCache.put( key,authkey );
+ return authkey;
+ }
+ }
+ catch ( KeyNotFoundException knfe )
+ {
+ // this is done to remove keys that have been expired.
+ // TODO: need to make a listener for the key manager.
+ keysCache.remove( key );
+ throw knfe;
+ }
+ }
+
+ public List<AuthenticationKey> getAllKeys()
+ {
+ log.debug( "NOT CACHED - .getAllKeys()" );
+ return this.keyImpl.getAllKeys();
+ }
+
+ public String getId()
+ {
+ return "Cached Key Manager [" + this.keyImpl.getId() + "]";
+ }
+
+ public KeyManager getKeyImpl()
+ {
+ return keyImpl;
+ }
+
+ public void setKeyImpl( KeyManager keyImpl )
+ {
+ this.keyImpl = keyImpl;
+ }
+
+ public Cache getKeysCache()
+ {
+ return keysCache;
+ }
+
+ public void setKeysCache( Cache keysCache )
+ {
+ this.keysCache = keysCache;
+ }
+}
+++ /dev/null
-package org.codehaus.plexus.redback.keys.cached;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.List;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import org.codehaus.plexus.cache.Cache;
-import org.apache.archiva.redback.keys.AbstractKeyManager;
-import org.apache.archiva.redback.keys.AuthenticationKey;
-import org.apache.archiva.redback.keys.KeyManager;
-import org.apache.archiva.redback.keys.KeyManagerException;
-import org.apache.archiva.redback.keys.KeyNotFoundException;
-import org.springframework.stereotype.Service;
-
-/**
- * CachedKeyManager
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-@Service("keyManager#cached")
-public class CachedKeyManager
- extends AbstractKeyManager
- implements KeyManager
-{
- @Inject @Named(value="keyManager#jdo")
- private KeyManager keyImpl;
-
- @Inject @Named(value="cache#keys")
- private Cache keysCache;
-
- public AuthenticationKey addKey( AuthenticationKey key )
- {
- if ( key != null )
- {
- keysCache.remove( key.getKey() );
- }
- return this.keyImpl.addKey( key );
- }
-
- public AuthenticationKey createKey( String principal, String purpose, int expirationMinutes )
- throws KeyManagerException
- {
- AuthenticationKey authkey = this.keyImpl.createKey( principal, purpose, expirationMinutes );
- keysCache.remove( authkey.getKey() );
- return authkey;
- }
-
- public void deleteKey( AuthenticationKey key )
- throws KeyManagerException
- {
- keysCache.remove( key.getKey() );
- this.keyImpl.deleteKey( key );
- }
-
- public void deleteKey( String key )
- throws KeyManagerException
- {
- keysCache.remove( key );
- this.keyImpl.deleteKey( key );
- }
-
- public void eraseDatabase()
- {
- try
- {
- this.keyImpl.eraseDatabase();
- }
- finally
- {
- this.keysCache.clear();
- }
- }
-
- public AuthenticationKey findKey( String key )
- throws KeyNotFoundException, KeyManagerException
- {
- try
- {
- AuthenticationKey authkey = (AuthenticationKey) keysCache.get( key );
- if ( authkey != null )
- {
- assertNotExpired( authkey );
- return authkey;
- }
- else
- {
- authkey = this.keyImpl.findKey( key );
- keysCache.put( key,authkey );
- return authkey;
- }
- }
- catch ( KeyNotFoundException knfe )
- {
- // this is done to remove keys that have been expired.
- // TODO: need to make a listener for the key manager.
- keysCache.remove( key );
- throw knfe;
- }
- }
-
- public List<AuthenticationKey> getAllKeys()
- {
- log.debug( "NOT CACHED - .getAllKeys()" );
- return this.keyImpl.getAllKeys();
- }
-
- public String getId()
- {
- return "Cached Key Manager [" + this.keyImpl.getId() + "]";
- }
-
- public KeyManager getKeyImpl()
- {
- return keyImpl;
- }
-
- public void setKeyImpl( KeyManager keyImpl )
- {
- this.keyImpl = keyImpl;
- }
-
- public Cache getKeysCache()
- {
- return keysCache;
- }
-
- public void setKeysCache( Cache keysCache )
- {
- this.keysCache = keysCache;
- }
-}
<context:annotation-config />
<context:component-scan
- base-package="org.codehaus.plexus.redback.keys.cached"/>
+ base-package="org.apache.archiva.redback.keys.cached"/>
<bean name="cache#keys" class="org.codehaus.plexus.cache.ehcache.EhcacheCache"
init-method="initialize">
--- /dev/null
+package org.apache.archiva.redback.keys.cached;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import net.sf.ehcache.CacheManager;
+import org.apache.archiva.redback.keys.KeyManager;
+import org.apache.archiva.redback.keys.cached.CachedKeyManager;
+import org.codehaus.plexus.redback.keys.KeyManagerTestCase;
+import org.junit.Before;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+/**
+ * CachedKeyManagerTest
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class CachedKeyManagerTest
+ extends KeyManagerTestCase
+{
+
+ @Inject
+ @Named( value = "keyManager#cached" )
+ KeyManager manager;
+
+ @Before
+ public void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ setKeyManager( manager );
+
+ assertTrue( manager instanceof CachedKeyManager );
+ }
+
+ protected void tearDown()
+ throws Exception
+ {
+ CacheManager.getInstance().removalAll();
+ super.tearDown();
+ }
+}
+++ /dev/null
-package org.codehaus.plexus.redback.keys.cached;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import net.sf.ehcache.CacheManager;
-import org.apache.archiva.redback.keys.KeyManager;
-import org.codehaus.plexus.redback.keys.KeyManagerTestCase;
-import org.junit.Before;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-/**
- * CachedKeyManagerTest
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public class CachedKeyManagerTest
- extends KeyManagerTestCase
-{
-
- @Inject
- @Named( value = "keyManager#cached" )
- KeyManager manager;
-
- @Before
- public void setUp()
- throws Exception
- {
- super.setUp();
-
- setKeyManager( manager );
-
- assertTrue( manager instanceof CachedKeyManager );
- }
-
- protected void tearDown()
- throws Exception
- {
- CacheManager.getInstance().removalAll();
- super.tearDown();
- }
-}