You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ol...@apache.org on 2012/04/06 11:59:32 UTC
svn commit: r1310268 [28/42] - in /archiva/redback/redback-core/trunk: ./
redback-authentication/ redback-authentication/redback-authentication-api/
redback-authentication/redback-authentication-api/src/
redback-authentication/redback-authentication-ap...
Added: archiva/redback/redback-core/trunk/redback-keys/redback-authentication-keys/src/main/java/org/codehaus/plexus/redback/authentication/keystore/KeyStoreAuthenticator.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-authentication-keys/src/main/java/org/codehaus/plexus/redback/authentication/keystore/KeyStoreAuthenticator.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-authentication-keys/src/main/java/org/codehaus/plexus/redback/authentication/keystore/KeyStoreAuthenticator.java (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-authentication-keys/src/main/java/org/codehaus/plexus/redback/authentication/keystore/KeyStoreAuthenticator.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,114 @@
+package org.codehaus.plexus.redback.authentication.keystore;
+
+/*
+* Copyright 2005 The Codehaus.
+*
+* Licensed 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 javax.annotation.Resource;
+
+import org.codehaus.plexus.redback.authentication.AuthenticationDataSource;
+import org.codehaus.plexus.redback.authentication.AuthenticationException;
+import org.codehaus.plexus.redback.authentication.AuthenticationResult;
+import org.codehaus.plexus.redback.authentication.Authenticator;
+import org.codehaus.plexus.redback.authentication.TokenBasedAuthenticationDataSource;
+import org.codehaus.plexus.redback.keys.AuthenticationKey;
+import org.codehaus.plexus.redback.keys.KeyManager;
+import org.codehaus.plexus.redback.keys.KeyManagerException;
+import org.codehaus.plexus.redback.keys.KeyNotFoundException;
+import org.codehaus.plexus.redback.policy.AccountLockedException;
+import org.codehaus.plexus.redback.policy.MustChangePasswordException;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.redback.users.UserManager;
+import org.codehaus.plexus.redback.users.UserNotFoundException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+/**
+ * KeyStoreAuthenticator:
+ *
+ * @author: Jesse McConnell <je...@codehaus.org>
+ * @version: $Id$
+ *
+ */
+@Service("authenticator#keystore")
+public class KeyStoreAuthenticator
+ implements Authenticator
+{
+ private Logger log = LoggerFactory.getLogger( getClass() );
+
+ @Resource(name="keyManager#cached")
+ private KeyManager keystore;
+
+ @Resource(name="userManager#configurable")
+ private UserManager userManager;
+
+ public String getId()
+ {
+ return "$Id$";
+ }
+
+ public AuthenticationResult authenticate( AuthenticationDataSource source )
+ throws AccountLockedException, AuthenticationException, MustChangePasswordException
+ {
+ TokenBasedAuthenticationDataSource dataSource = (TokenBasedAuthenticationDataSource) source;
+
+ String key = dataSource.getToken();
+ try
+ {
+ AuthenticationKey authKey = keystore.findKey( key );
+
+ // if we find a key (exception was probably thrown if not) then we should be authentic
+ if ( authKey != null )
+ {
+ User user = userManager.findUser( dataSource.getPrincipal() );
+
+ if ( user.isLocked() )
+ {
+ throw new AccountLockedException( "Account " + source.getPrincipal() + " is locked.", user );
+ }
+
+ if ( user.isPasswordChangeRequired() && source.isEnforcePasswordChange() )
+ {
+ throw new MustChangePasswordException( "Password expired.", user );
+ }
+
+ return new AuthenticationResult( true, dataSource.getPrincipal(), null );
+ }
+ else
+ {
+ return new AuthenticationResult( false, dataSource.getPrincipal(), new AuthenticationException("unable to find key") );
+ }
+ }
+ catch ( KeyNotFoundException ne )
+ {
+ return new AuthenticationResult( false, null, ne );
+ }
+ catch ( KeyManagerException ke )
+ {
+ throw new AuthenticationException( "underlaying keymanager issue", ke );
+ }
+ catch ( UserNotFoundException e )
+ {
+ log.warn( "Login for user " + source.getPrincipal() + " failed. user not found." );
+ return new AuthenticationResult( false, null, e );
+ }
+ }
+
+ public boolean supportsDataSource( AuthenticationDataSource source )
+ {
+ return source instanceof TokenBasedAuthenticationDataSource;
+ }
+}
\ No newline at end of file
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-authentication-keys/src/main/java/org/codehaus/plexus/redback/authentication/keystore/KeyStoreAuthenticator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-authentication-keys/src/main/java/org/codehaus/plexus/redback/authentication/keystore/KeyStoreAuthenticator.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-authentication-keys/src/main/resources/META-INF/spring-context.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-authentication-keys/src/main/resources/META-INF/spring-context.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-authentication-keys/src/main/resources/META-INF/spring-context.xml (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-authentication-keys/src/main/resources/META-INF/spring-context.xml Fri Apr 6 09:58:14 2012
@@ -0,0 +1,34 @@
+<?xml version="1.0"?>
+
+<!--
+ ~ 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.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-3.0.xsd"
+ default-lazy-init="true">
+
+ <context:annotation-config />
+ <context:component-scan
+ base-package="org.codehaus.plexus.redback.authentication.keystore"/>
+
+</beans>
\ No newline at end of file
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-authentication-keys/src/main/resources/META-INF/spring-context.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-authentication-keys/src/main/resources/META-INF/spring-context.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/pom.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/pom.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/pom.xml (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/pom.xml Fri Apr 6 09:58:14 2012
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2006 The Codehaus.
+ ~
+ ~ Licensed 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.codehaus.redback</groupId>
+ <artifactId>redback-keys</artifactId>
+ <version>1.5-SNAPSHOT</version>
+ </parent>
+ <artifactId>redback-keys-api</artifactId>
+ <name>Redback :: Key Management API</name>
+ <packaging>jar</packaging>
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-digest</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-component-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/pom.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/AbstractKeyManager.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/AbstractKeyManager.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/AbstractKeyManager.java (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/AbstractKeyManager.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,171 @@
+package org.codehaus.plexus.redback.keys;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+import java.util.Calendar;
+import java.util.List;
+import java.util.Random;
+import java.util.TimeZone;
+
+import org.codehaus.plexus.digest.Hex;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * AbstractKeyManager
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public abstract class AbstractKeyManager
+ implements KeyManager
+{
+ protected Logger log = LoggerFactory.getLogger( getClass() );
+
+ private static final int KEY_LENGTH = 16;
+
+ private static final boolean SECURE = true;
+
+ private boolean randomMode = SECURE;
+
+ private SecureRandom secureRandom;
+
+ private Random random;
+
+ /**
+ * Generate a UUID using <a href="http://www.ietf.org/rfc/rfc4122.txt">RFC 4122</a> UUID generation of a
+ * type 4 or randomly generated UUID.
+ *
+ * @return the 32 character long UUID string.
+ * @throws KeyManagerException
+ */
+ protected String generateUUID()
+ throws KeyManagerException
+ {
+ byte vfour[] = new byte[KEY_LENGTH];
+
+ if ( isRandomMode() == SECURE )
+ {
+ if ( secureRandom == null )
+ {
+ try
+ {
+ secureRandom = SecureRandom.getInstance( "SHA1PRNG" );
+ }
+ catch ( NoSuchAlgorithmException e )
+ {
+ setRandomMode( !SECURE );
+ log.warn( "Unable to use SecureRandom", e );
+ }
+ }
+
+ if ( isRandomMode() == SECURE )
+ {
+ secureRandom.nextBytes( vfour );
+ }
+ }
+
+ if ( isRandomMode() != SECURE )
+ {
+ if ( random == null )
+ {
+ random = new Random();
+ }
+
+ random.nextBytes( vfour );
+ }
+
+ vfour[6] &= 0x0F;
+ vfour[6] |= ( 4 << 4 );
+ vfour[8] &= 0x3F;
+ vfour[8] |= 0x80;
+
+ return Hex.encode( vfour );
+ }
+
+ /**
+ * Tests the key to see if it is expired or not.
+ *
+ * If the key is expired, a call to {@link #removeExpiredKey(AuthenticationKey)} is issued,
+ * and a {@link KeyNotFoundException} is thrown.
+ *
+ * @param authkey the key to test.
+ * @throws KeyNotFoundException if the key is expired.
+ * @throws KeyManagerException if there was a problem removing the key.
+ */
+ protected void assertNotExpired( AuthenticationKey authkey )
+ throws KeyNotFoundException, KeyManagerException
+ {
+ if ( authkey.getDateExpires() == null )
+ {
+ // No expiration means a permanent entry.
+ return;
+ }
+
+ // Test for expiration.
+ Calendar now = getNowGMT();
+ Calendar expiration = getNowGMT();
+ expiration.setTime( authkey.getDateExpires() );
+
+ if ( now.after( expiration ) )
+ {
+ deleteKey( authkey );
+ throw new KeyNotFoundException( "Key [" + authkey.getKey() + "] has expired." );
+ }
+ }
+
+ protected Calendar getNowGMT()
+ {
+ return Calendar.getInstance( TimeZone.getTimeZone( "GMT" ) );
+ }
+
+ public void setRandomMode( boolean randomMode )
+ {
+ this.randomMode = randomMode;
+ }
+
+ public boolean isRandomMode()
+ {
+ return randomMode;
+ }
+
+ public void removeExpiredKeys()
+ throws KeyManagerException
+ {
+ List<AuthenticationKey> allKeys = getAllKeys();
+
+ Calendar now = getNowGMT();
+ Calendar expiration = getNowGMT();
+
+ log.info( "Removing expired keys." );
+ for ( AuthenticationKey authkey : allKeys )
+ {
+ if ( authkey.getDateExpires() != null )
+ {
+ expiration.setTime( authkey.getDateExpires() );
+
+ if ( now.after( expiration ) )
+ {
+ deleteKey( authkey );
+ }
+ }
+ }
+ log.info( "Expired keys removed." );
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/AbstractKeyManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/AbstractKeyManager.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/AuthenticationKey.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/AuthenticationKey.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/AuthenticationKey.java (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/AuthenticationKey.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,50 @@
+package org.codehaus.plexus.redback.keys;
+
+/*
+ * Copyright 2001-2006 The Codehaus.
+ *
+ * Licensed 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.Date;
+
+/**
+ * AuthenticationKey is an object representing a key established to
+ * automatically authenticate a user without the user providing typical
+ * login credentials.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public interface AuthenticationKey
+{
+ public Date getDateCreated();
+ public Date getDateExpires();
+ public String getForPrincipal();
+ public String getKey();
+
+ /**
+ * A String representation of what the purpose of existence is for this key.
+ *
+ * Examples: "selfservice password reset", "inter system communications", "remember me"
+ *
+ * @return
+ */
+ public String getPurpose();
+
+ public void setDateCreated( Date dateCreated );
+ public void setDateExpires( Date dateExpires );
+ public void setForPrincipal( String forPrincipal );
+ public void setKey( String key );
+ public void setPurpose( String requestedFrom );
+}
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/AuthenticationKey.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/AuthenticationKey.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/KeyManager.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/KeyManager.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/KeyManager.java (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/KeyManager.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,91 @@
+package org.codehaus.plexus.redback.keys;
+
+/*
+ * Copyright 2001-2006 The Codehaus.
+ *
+ * Licensed 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;
+
+/**
+ * KeyManager
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public interface KeyManager
+{
+
+
+ /**
+ * String identifying the key manager implementation.
+ *
+ * @return the key manager implementation id.
+ */
+ String getId();
+
+ /**
+ * Attempt to find a specific key in the store.
+ * <p/>
+ * NOTE: Implementations of this interface should never return an expired key.
+ *
+ * @param key the key to find.
+ * @return the actual key found.
+ * @throws KeyNotFoundException when the requested, unexpired, key cannot be found.
+ * @throws KeyManagerException when there is a fundamental problem with the KeyManager implementation.
+ */
+ AuthenticationKey findKey( String key )
+ throws KeyNotFoundException, KeyManagerException;
+
+ /**
+ * Create a key (and save it to the store) for the specified principal.
+ *
+ * @param principal the principal to generate the key for.
+ * @param purpose the purpose of the key. (Example: "selfservice password reset", "new user validation",
+ * "remember me") This is a purely informational field .
+ * @param expirationMinutes the amount in minutes until this key expires. (-1 means no expiration)
+ * @return the key created
+ * @throws KeyManagerException if there is a fundamental problem with the KeyManager implementation.
+ */
+ AuthenticationKey createKey( String principal, String purpose, int expirationMinutes )
+ throws KeyManagerException;
+
+ /**
+ * Delete a key from the underlying store.
+ *
+ * @param key the key to delete.
+ */
+ void deleteKey( AuthenticationKey key )
+ throws KeyManagerException;
+
+ /**
+ * Delete a key from the underlying store.
+ *
+ * @param key the key to delete.
+ */
+ void deleteKey( String key )
+ throws KeyManagerException;
+
+ List<AuthenticationKey> getAllKeys();
+
+ AuthenticationKey addKey( AuthenticationKey key );
+
+ void eraseDatabase();
+
+ /**
+ * Remove all keys that are expired.
+ */
+ void removeExpiredKeys()
+ throws KeyManagerException;
+}
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/KeyManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/KeyManager.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/KeyManagerException.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/KeyManagerException.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/KeyManagerException.java (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/KeyManagerException.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,49 @@
+package org.codehaus.plexus.redback.keys;
+
+/*
+ * Copyright 2001-2006 The Codehaus.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * KeyManagerException
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class KeyManagerException
+ extends Exception
+{
+
+ public KeyManagerException()
+ {
+ super();
+ }
+
+ public KeyManagerException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+
+ public KeyManagerException( String message )
+ {
+ super( message );
+ }
+
+ public KeyManagerException( Throwable cause )
+ {
+ super( cause );
+ }
+
+}
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/KeyManagerException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/KeyManagerException.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/KeyNotFoundException.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/KeyNotFoundException.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/KeyNotFoundException.java (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/KeyNotFoundException.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,48 @@
+package org.codehaus.plexus.redback.keys;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * KeyNotFoundException
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class KeyNotFoundException
+ extends KeyManagerException
+{
+ public KeyNotFoundException()
+ {
+ super();
+ }
+
+ public KeyNotFoundException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+
+ public KeyNotFoundException( String message )
+ {
+ super( message );
+ }
+
+ public KeyNotFoundException( Throwable cause )
+ {
+ super( cause );
+ }
+
+}
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/KeyNotFoundException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/main/java/org/codehaus/plexus/redback/keys/KeyNotFoundException.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/test/java/org/codehaus/plexus/redback/keys/KeyManagerTest.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/test/java/org/codehaus/plexus/redback/keys/KeyManagerTest.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/test/java/org/codehaus/plexus/redback/keys/KeyManagerTest.java (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/test/java/org/codehaus/plexus/redback/keys/KeyManagerTest.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,91 @@
+package org.codehaus.plexus.redback.keys;
+
+/*
+ * Copyright 2001-2006 The Codehaus.
+ *
+ * Licensed 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 junit.framework.TestCase;
+
+public class KeyManagerTest
+ extends TestCase
+{
+ private final class AbstractKeyManagerExtension
+ extends AbstractKeyManager
+ {
+ public AuthenticationKey addKey( AuthenticationKey key )
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public AuthenticationKey createKey( String principal, String purpose, int expirationMinutes )
+ throws KeyManagerException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void deleteKey( AuthenticationKey key )
+ throws KeyManagerException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void deleteKey( String key )
+ throws KeyManagerException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void eraseDatabase()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public AuthenticationKey findKey( String key )
+ throws KeyNotFoundException, KeyManagerException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public List<AuthenticationKey> getAllKeys()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getId()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ }
+
+ public void testUUID()
+ throws KeyManagerException
+ {
+ AbstractKeyManager manager = new AbstractKeyManagerExtension();
+
+ // verifies we can get the provider after change not to require Sun one
+ assertNotNull( manager.generateUUID() );
+ assertTrue( manager.isRandomMode() );
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/test/java/org/codehaus/plexus/redback/keys/KeyManagerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-api/src/test/java/org/codehaus/plexus/redback/keys/KeyManagerTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/pom.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/pom.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/pom.xml (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/pom.xml Fri Apr 6 09:58:14 2012
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2006 The Codehaus.
+ ~
+ ~ Licensed 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.codehaus.redback</groupId>
+ <artifactId>redback-keys</artifactId>
+ <version>1.5-SNAPSHOT</version>
+ </parent>
+ <artifactId>redback-keys-providers</artifactId>
+ <name>Redback :: Key Management Providers</name>
+ <packaging>pom</packaging>
+ <modules>
+ <module>redback-keys-jdo</module>
+ <module>redback-keys-memory</module>
+ <module>redback-keys-cached</module>
+ </modules>
+</project>
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/pom.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/pom.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/pom.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/pom.xml (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/pom.xml Fri Apr 6 09:58:14 2012
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2006 The Codehaus.
+ ~
+ ~ Licensed 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.codehaus.redback</groupId>
+ <artifactId>redback-keys-providers</artifactId>
+ <version>1.5-SNAPSHOT</version>
+ </parent>
+ <artifactId>redback-keys-cached</artifactId>
+ <name>Redback :: Key Management Provider :: Cached</name>
+ <packaging>jar</packaging>
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.redback</groupId>
+ <artifactId>redback-keys-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.redback.components.cache</groupId>
+ <artifactId>spring-cache-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.redback.components.cache</groupId>
+ <artifactId>spring-cache-ehcache</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.ehcache</groupId>
+ <artifactId>ehcache-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.redback</groupId>
+ <artifactId>redback-keys-jdo</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context-support</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>jsr250-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.redback</groupId>
+ <artifactId>redback-keys-tests</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.redback</groupId>
+ <artifactId>redback-keys-memory</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/pom.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/src/main/java/org/codehaus/plexus/redback/keys/cached/CachedKeyManager.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/src/main/java/org/codehaus/plexus/redback/keys/cached/CachedKeyManager.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/src/main/java/org/codehaus/plexus/redback/keys/cached/CachedKeyManager.java (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/src/main/java/org/codehaus/plexus/redback/keys/cached/CachedKeyManager.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,150 @@
+package org.codehaus.plexus.redback.keys.cached;
+
+/*
+ * Copyright 2001-2006 The Codehaus.
+ *
+ * Licensed 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.annotation.Resource;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.codehaus.plexus.cache.Cache;
+import org.codehaus.plexus.redback.keys.AbstractKeyManager;
+import org.codehaus.plexus.redback.keys.AuthenticationKey;
+import org.codehaus.plexus.redback.keys.KeyManager;
+import org.codehaus.plexus.redback.keys.KeyManagerException;
+import org.codehaus.plexus.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;
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/src/main/java/org/codehaus/plexus/redback/keys/cached/CachedKeyManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/src/main/java/org/codehaus/plexus/redback/keys/cached/CachedKeyManager.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/src/main/resources/META-INF/spring-context.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/src/main/resources/META-INF/spring-context.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/src/main/resources/META-INF/spring-context.xml (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/src/main/resources/META-INF/spring-context.xml Fri Apr 6 09:58:14 2012
@@ -0,0 +1,45 @@
+<?xml version="1.0"?>
+
+<!--
+ ~ 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.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-3.0.xsd"
+ default-lazy-init="true">
+
+ <context:annotation-config />
+ <context:component-scan
+ base-package="org.codehaus.plexus.redback.keys.cached"/>
+
+ <bean name="cache#keys" class="org.codehaus.plexus.cache.ehcache.EhcacheCache"
+ init-method="initialize">
+ <property name="diskPersistent" value="false"/>
+ <property name="eternal" value="false"/>
+ <property name="maxElementsInMemory" value="1000"/>
+ <property name="memoryEvictionPolicy" value="LRU"/>
+ <property name="name" value="usersCache"/>
+ <property name="timeToIdleSeconds" value="1800"/>
+ <property name="timeToLiveSeconds" value="14400"/>
+ </bean>
+
+</beans>
\ No newline at end of file
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/src/main/resources/META-INF/spring-context.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/src/main/resources/META-INF/spring-context.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/src/test/java/org/codehaus/plexus/redback/keys/cached/CachedKeyManagerTest.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/src/test/java/org/codehaus/plexus/redback/keys/cached/CachedKeyManagerTest.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/src/test/java/org/codehaus/plexus/redback/keys/cached/CachedKeyManagerTest.java (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/src/test/java/org/codehaus/plexus/redback/keys/cached/CachedKeyManagerTest.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,58 @@
+package org.codehaus.plexus.redback.keys.cached;
+
+/*
+ * Copyright 2001-2006 The Codehaus.
+ *
+ * Licensed 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.codehaus.plexus.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();
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/src/test/java/org/codehaus/plexus/redback/keys/cached/CachedKeyManagerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/src/test/java/org/codehaus/plexus/redback/keys/cached/CachedKeyManagerTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/src/test/resources/spring-context.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/src/test/resources/spring-context.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/src/test/resources/spring-context.xml (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/src/test/resources/spring-context.xml Fri Apr 6 09:58:14 2012
@@ -0,0 +1,63 @@
+<?xml version="1.0"?>
+
+<!--
+ ~ 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.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+
+ <bean name="jdoFactory#users" class="org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory">
+ <property name="driverName" value="org.hsqldb.jdbcDriver"/>
+ <property name="url" value="jdbc:hsqldb:mem:redback-users-tests" />
+ <property name="userName" value="sa"/>
+ <property name="password" value=""/>
+ <property name="persistenceManagerFactoryClass" value="org.jpox.PersistenceManagerFactoryImpl"/>
+ <property name="otherProperties">
+ <props>
+ <prop key="org.jpox.rdbms.dateTimezone">JDK_DEFAULT_TIMEZONE</prop>
+ <prop key="org.jpox.autoCreateTables">true</prop>
+ </props>
+ </property>
+ </bean>
+
+ <bean name="userConfiguration" class="org.codehaus.plexus.redback.configuration.UserConfiguration">
+ <property name="registry" ref="test-conf"/>
+ </bean>
+
+ <bean name="commons-configuration" class="org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry">
+ </bean>
+
+ <alias name="commons-configuration" alias="test-conf"/>
+
+ <bean name="cache#keys" class="org.codehaus.plexus.cache.ehcache.EhcacheCache"
+ init-method="initialize">
+ <property name="diskPersistent" value="false"/>
+ <property name="eternal" value="false"/>
+ <property name="maxElementsInMemory" value="1000"/>
+ <property name="memoryEvictionPolicy" value="LRU"/>
+ <property name="name" value="usersCache"/>
+ <property name="timeToIdleSeconds" value="1800"/>
+ <property name="timeToLiveSeconds" value="14400"/>
+ </bean>
+
+</beans>
\ No newline at end of file
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/src/test/resources/spring-context.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-cached/src/test/resources/spring-context.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/pom.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/pom.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/pom.xml (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/pom.xml Fri Apr 6 09:58:14 2012
@@ -0,0 +1,138 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2006 The Codehaus.
+ ~
+ ~ Licensed 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.codehaus.redback</groupId>
+ <artifactId>redback-keys-providers</artifactId>
+ <version>1.5-SNAPSHOT</version>
+ </parent>
+ <artifactId>redback-keys-jdo</artifactId>
+ <name>Redback :: Key Management Provider :: JDO</name>
+ <packaging>jar</packaging>
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.redback</groupId>
+ <artifactId>redback-keys-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codehaus.redback</groupId>
+ <artifactId>redback-common-jdo</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context-support</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>jsr250-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codehaus.redback</groupId>
+ <artifactId>redback-keys-tests</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>net.java.dev.stax-utils</groupId>
+ <artifactId>stax-utils</artifactId>
+ <version>20060502</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.bea.xml</groupId>
+ <artifactId>jsr173-ri</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>javax.xml.stream</groupId>
+ <artifactId>stax-api</artifactId>
+ <version>1.0-2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>wstx-asl</artifactId>
+ <version>3.2.0</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>stax</groupId>
+ <artifactId>stax-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.modello</groupId>
+ <artifactId>modello-maven-plugin</artifactId>
+ <version>1.0-alpha-15</version>
+ <configuration>
+ <version>1.0.1</version>
+ <packageWithVersion>false</packageWithVersion>
+ <model>src/main/mdo/keys.mdo</model>
+ </configuration>
+ <executions>
+ <execution>
+ <id>modello-java</id>
+ <goals>
+ <goal>java</goal>
+ <goal>jpox-metadata-class</goal>
+ <goal>stax-reader</goal>
+ <goal>stax-writer</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>jpox-jdo-mapping</id>
+ <goals>
+ <goal>jpox-jdo-mapping</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${basedir}/target/classes/org/codehaus/plexus/redback/keys/jdo</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>jpox-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>enhance</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/pom.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/java/org/codehaus/plexus/redback/keys/jdo/JdoKeyManager.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/java/org/codehaus/plexus/redback/keys/jdo/JdoKeyManager.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/java/org/codehaus/plexus/redback/keys/jdo/JdoKeyManager.java (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/java/org/codehaus/plexus/redback/keys/jdo/JdoKeyManager.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,185 @@
+package org.codehaus.plexus.redback.keys.jdo;
+
+/*
+ * Copyright 2001-2006 The Codehaus.
+ *
+ * Licensed 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 org.codehaus.plexus.jdo.JdoFactory;
+import org.codehaus.plexus.jdo.PlexusJdoUtils;
+import org.codehaus.plexus.jdo.PlexusObjectNotFoundException;
+import org.codehaus.plexus.jdo.PlexusStoreException;
+import org.codehaus.plexus.redback.keys.AbstractKeyManager;
+import org.codehaus.plexus.redback.keys.AuthenticationKey;
+import org.codehaus.plexus.redback.keys.KeyManagerException;
+import org.codehaus.plexus.redback.keys.KeyNotFoundException;
+import org.codehaus.plexus.util.StringUtils;
+import org.jpox.PersistenceManagerFactoryImpl;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.jdo.PersistenceManager;
+import javax.jdo.PersistenceManagerFactory;
+import java.util.Calendar;
+import java.util.List;
+
+/**
+ * JdoKeyManager
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Service( "keyManager#jdo" )
+public class JdoKeyManager
+ extends AbstractKeyManager
+{
+ @Inject
+ @Named( value = "jdoFactory#users" )
+ private JdoFactory jdoFactory;
+
+ private PersistenceManagerFactory pmf;
+
+ public AuthenticationKey createKey( String principal, String purpose, int expirationMinutes )
+ throws KeyManagerException
+ {
+ JdoAuthenticationKey authkey = new JdoAuthenticationKey();
+ authkey.setKey( super.generateUUID() );
+ authkey.setForPrincipal( principal );
+ authkey.setPurpose( purpose );
+
+ Calendar now = getNowGMT();
+ authkey.setDateCreated( now.getTime() );
+
+ if ( expirationMinutes >= 0 )
+ {
+ Calendar expiration = getNowGMT();
+ expiration.add( Calendar.MINUTE, expirationMinutes );
+ authkey.setDateExpires( expiration.getTime() );
+ }
+
+ return addKey( authkey );
+ }
+
+ public AuthenticationKey addKey( AuthenticationKey key )
+ {
+ return (AuthenticationKey) PlexusJdoUtils.addObject( getPersistenceManager(), key );
+ }
+
+ public void eraseDatabase()
+ {
+ PlexusJdoUtils.removeAll( getPersistenceManager(), JdoAuthenticationKey.class );
+ PlexusJdoUtils.removeAll( getPersistenceManager(), RedbackKeyManagementJdoModelloMetadata.class );
+ }
+
+ public AuthenticationKey findKey( String key )
+ throws KeyNotFoundException, KeyManagerException
+ {
+ if ( StringUtils.isEmpty( key ) )
+ {
+ throw new KeyNotFoundException( "Empty key not found." );
+ }
+
+ try
+ {
+ JdoAuthenticationKey authkey = (JdoAuthenticationKey) PlexusJdoUtils.getObjectById( getPersistenceManager(),
+ JdoAuthenticationKey.class,
+ key );
+
+ if ( authkey == null )
+ {
+ throw new KeyNotFoundException( "Key [" + key + "] not found." );
+ }
+ assertNotExpired( authkey );
+
+ return authkey;
+ }
+ catch ( PlexusObjectNotFoundException e )
+ {
+ throw new KeyNotFoundException( e.getMessage() );
+ }
+ catch ( PlexusStoreException e )
+ {
+ throw new KeyManagerException(
+ "Unable to get " + JdoAuthenticationKey.class.getName() + "', key '" + key + "' from jdo store." );
+ }
+ }
+
+ public void deleteKey( AuthenticationKey authkey )
+ throws KeyManagerException
+ {
+ PlexusJdoUtils.removeObject( getPersistenceManager(), authkey );
+ }
+
+ public void deleteKey( String key )
+ throws KeyManagerException
+ {
+ try
+ {
+ AuthenticationKey authkey = findKey( key );
+ PlexusJdoUtils.removeObject( getPersistenceManager(), authkey );
+ }
+ catch ( KeyNotFoundException e )
+ {
+ // not found? nothing to do.
+ }
+ }
+
+ @SuppressWarnings( "unchecked" )
+ public List<AuthenticationKey> getAllKeys()
+ {
+ return PlexusJdoUtils.getAllObjectsDetached( getPersistenceManager(), JdoAuthenticationKey.class );
+ }
+
+ @PostConstruct
+ public void initialize()
+ {
+ pmf = jdoFactory.getPersistenceManagerFactory();
+
+ if ( pmf instanceof PersistenceManagerFactoryImpl )
+ {
+ PersistenceManagerFactoryImpl jpoxpmf = (PersistenceManagerFactoryImpl) pmf;
+ if ( !StringUtils.equals( "JDK_DEFAULT_TIMEZONE", jpoxpmf.getDateTimezone() ) )
+ {
+ throw new RuntimeException( "The JdoFactory property 'org.jpox.rdbms.dateTimezone' MUST BE "
+ + "Set to 'JDK_DEFAULT_TIMEZONE' in order for jpox and JdoKeyManager to operate correctly." );
+ }
+ }
+ }
+
+ private PersistenceManager getPersistenceManager()
+ {
+ PersistenceManager pm = pmf.getPersistenceManager();
+
+ pm.getFetchPlan().setMaxFetchDepth( 5 );
+
+ return pm;
+ }
+
+ public String getId()
+ {
+ return "JDO Key Manager - " + this.getClass().getName();
+ }
+
+ public JdoFactory getJdoFactory()
+ {
+ return jdoFactory;
+ }
+
+ public void setJdoFactory( JdoFactory jdoFactory )
+ {
+ this.jdoFactory = jdoFactory;
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/java/org/codehaus/plexus/redback/keys/jdo/JdoKeyManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/java/org/codehaus/plexus/redback/keys/jdo/JdoKeyManager.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/mdo/keys.mdo
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/mdo/keys.mdo?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/mdo/keys.mdo (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/mdo/keys.mdo Fri Apr 6 09:58:14 2012
@@ -0,0 +1,74 @@
+<?xml version="1.0"?>
+
+<model>
+ <id>redback-keys-jdo</id>
+ <name>RedbackKeyManagementJdo</name>
+ <version>1.0.1</version>
+ <description>Plexus Redback :: Key Management JDO Store.</description>
+ <defaults>
+ <default>
+ <key>package</key>
+ <value>org.codehaus.plexus.redback.keys.jdo</value>
+ </default>
+ </defaults>
+
+ <classes>
+ <class stash.storable="false" rootElement="true">
+ <name>AuthenticationKeyDatabase</name>
+ <version>1.0.1+</version>
+ <fields>
+ <field jpox.column="AUTH_KEYS">
+ <name>keys</name>
+ <version>1.0.1+</version>
+ <association>
+ <type>JdoAuthenticationKey</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ </field>
+ </fields>
+ </class>
+ <class stash.storable="true" jpox.use-identifiers-as-primary-key="false">
+ <name>JdoAuthenticationKey</name>
+ <version>1.0.0+</version>
+ <interfaces>
+ <interface>org.codehaus.plexus.redback.keys.AuthenticationKey</interface>
+ </interfaces>
+ <description>
+ @plexus.component role="org.codehaus.plexus.redback.keys.AuthenticationKey"
+ role-hint="jdo"
+ </description>
+ <fields>
+ <field jpox.primary-key="true"
+ jpox.value-strategy="off"
+ jpox.persistence-modifier="persistent"
+ jpox.column="AUTHKEY">
+ <name>key</name>
+ <version>1.0.0+</version>
+ <type>String</type>
+ <identifier>true</identifier>
+ </field>
+ <field>
+ <name>forPrincipal</name>
+ <version>1.0.0+</version>
+ <type>String</type>
+ <identifier>true</identifier>
+ </field>
+ <field>
+ <name>purpose</name>
+ <version>1.0.0+</version>
+ <type>String</type>
+ </field>
+ <field>
+ <name>dateCreated</name>
+ <version>1.0.0+</version>
+ <type>Date</type>
+ </field>
+ <field>
+ <name>dateExpires</name>
+ <version>1.0.0+</version>
+ <type>Date</type>
+ </field>
+ </fields>
+ </class>
+ </classes>
+</model>
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/mdo/keys.mdo
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/mdo/keys.mdo
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/resources/META-INF/spring-context.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/resources/META-INF/spring-context.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/resources/META-INF/spring-context.xml (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/resources/META-INF/spring-context.xml Fri Apr 6 09:58:14 2012
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+
+<!--
+ ~ 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.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-3.0.xsd"
+ default-lazy-init="true">
+
+ <context:annotation-config />
+ <context:component-scan base-package="org.codehaus.plexus.redback.keys.jdo"/>
+</beans>
\ No newline at end of file
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/resources/META-INF/spring-context.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/resources/META-INF/spring-context.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/test/java/org/codehaus/plexus/redback/keys/jdo/JdoKeyManagerTest.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/test/java/org/codehaus/plexus/redback/keys/jdo/JdoKeyManagerTest.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/test/java/org/codehaus/plexus/redback/keys/jdo/JdoKeyManagerTest.java (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/test/java/org/codehaus/plexus/redback/keys/jdo/JdoKeyManagerTest.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,99 @@
+package org.codehaus.plexus.redback.keys.jdo;
+
+/*
+ * Copyright 2001-2006 The Codehaus.
+ *
+ * Licensed 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 org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory;
+import org.codehaus.plexus.redback.keys.KeyManager;
+import org.codehaus.plexus.redback.keys.KeyManagerTestCase;
+import org.jpox.SchemaTool;
+import org.junit.Before;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.jdo.PersistenceManager;
+import javax.jdo.PersistenceManagerFactory;
+import java.net.URL;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * JdoKeyManagerTest
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class JdoKeyManagerTest
+ extends KeyManagerTestCase
+{
+
+ @Inject
+ @Named(value = "jdoFactory#users")
+ DefaultConfigurableJdoFactory jdoFactory;
+
+ @Inject @Named(value = "keyManager#jdo")
+ KeyManager keyManager;
+
+
+ @Before
+ public void setUp()
+ throws Exception
+ {
+
+ super.setUp();
+
+ assertEquals( DefaultConfigurableJdoFactory.class.getName(), jdoFactory.getClass().getName() );
+
+ jdoFactory.setPersistenceManagerFactoryClass( "org.jpox.PersistenceManagerFactoryImpl" ); //$NON-NLS-1$
+
+ jdoFactory.setDriverName( "org.hsqldb.jdbcDriver" ); //$NON-NLS-1$
+
+ jdoFactory.setUrl( "jdbc:hsqldb:mem:" + getName() ); //$NON-NLS-1$
+
+ jdoFactory.setUserName( "sa" ); //$NON-NLS-1$
+
+ jdoFactory.setPassword( "" ); //$NON-NLS-1$
+
+ jdoFactory.setProperty( "org.jpox.transactionIsolation", "READ_COMMITTED" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+ jdoFactory.setProperty( "org.jpox.poid.transactionIsolation", "READ_COMMITTED" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+ jdoFactory.setProperty( "org.jpox.autoCreateSchema", "true" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+ jdoFactory.setProperty( "org.jpox.rdbms.dateTimezone", "JDK_DEFAULT_TIMEZONE" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+ Properties properties = jdoFactory.getProperties();
+
+ for ( Map.Entry<Object,Object> entry : properties.entrySet() )
+ {
+ System.setProperty( (String) entry.getKey(), (String) entry.getValue() );
+ }
+
+ SchemaTool.createSchemaTables( new URL[] { getClass()
+ .getResource( "/org/codehaus/plexus/redback/keys/jdo/package.jdo" ) }, new URL[] {}, null, false, null ); //$NON-NLS-1$
+
+ PersistenceManagerFactory pmf = jdoFactory.getPersistenceManagerFactory();
+
+ assertNotNull( pmf );
+
+ PersistenceManager pm = pmf.getPersistenceManager();
+
+ pm.close();
+ keyManager.eraseDatabase();
+ setKeyManager( keyManager );
+ }
+
+}
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/test/java/org/codehaus/plexus/redback/keys/jdo/JdoKeyManagerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/test/java/org/codehaus/plexus/redback/keys/jdo/JdoKeyManagerTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/test/resources/spring-context.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/test/resources/spring-context.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/test/resources/spring-context.xml (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/test/resources/spring-context.xml Fri Apr 6 09:58:14 2012
@@ -0,0 +1,51 @@
+<?xml version="1.0"?>
+
+<!--
+ ~ 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.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+
+ <bean name="jdoFactory#users" class="org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory">
+ <property name="driverName" value="org.hsqldb.jdbcDriver"/>
+ <property name="url" value="jdbc:hsqldb:mem:redback-users-tests" />
+ <property name="userName" value="sa"/>
+ <property name="password" value=""/>
+ <property name="persistenceManagerFactoryClass" value="org.jpox.PersistenceManagerFactoryImpl"/>
+ <property name="otherProperties">
+ <props>
+ <prop key="org.jpox.rdbms.dateTimezone">JDK_DEFAULT_TIMEZONE</prop>
+ </props>
+ </property>
+ </bean>
+
+ <bean name="userConfiguration" class="org.codehaus.plexus.redback.configuration.UserConfiguration">
+ <property name="registry" ref="test-conf"/>
+ </bean>
+
+ <bean name="commons-configuration" class="org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry">
+ </bean>
+
+ <alias name="commons-configuration" alias="test-conf"/>
+
+</beans>
\ No newline at end of file
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/test/resources/spring-context.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-jdo/src/test/resources/spring-context.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/pom.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/pom.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/pom.xml (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/pom.xml Fri Apr 6 09:58:14 2012
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2006 The Codehaus.
+ ~
+ ~ Licensed 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.codehaus.redback</groupId>
+ <artifactId>redback-keys-providers</artifactId>
+ <version>1.5-SNAPSHOT</version>
+ </parent>
+ <artifactId>redback-keys-memory</artifactId>
+ <name>Redback :: Key Management Provider :: Memory</name>
+ <packaging>jar</packaging>
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.redback</groupId>
+ <artifactId>redback-keys-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context-support</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>jsr250-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.redback</groupId>
+ <artifactId>redback-keys-tests</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/pom.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/codehaus/plexus/redback/keys/memory/MemoryAuthenticationKey.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/codehaus/plexus/redback/keys/memory/MemoryAuthenticationKey.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/codehaus/plexus/redback/keys/memory/MemoryAuthenticationKey.java (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/codehaus/plexus/redback/keys/memory/MemoryAuthenticationKey.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,106 @@
+package org.codehaus.plexus.redback.keys.memory;
+
+/*
+ * Copyright 2001-2006 The Codehaus.
+ *
+ * Licensed 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 org.codehaus.plexus.redback.keys.AuthenticationKey;
+
+import java.util.Date;
+
+/**
+ * MemoryAuthenticationKey
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class MemoryAuthenticationKey
+ implements AuthenticationKey
+{
+ private String key;
+
+ private String forPrincipal;
+
+ private String purpose;
+
+ private Date dateCreated;
+
+ private Date dateExpires;
+
+ public Date getDateCreated()
+ {
+ return dateCreated;
+ }
+
+ public Date getDateExpires()
+ {
+ return dateExpires;
+ }
+
+ public String getForPrincipal()
+ {
+ return forPrincipal;
+ }
+
+ public String getKey()
+ {
+ return key;
+ }
+
+ public String getPurpose()
+ {
+ return purpose;
+ }
+
+ public void setDateCreated( Date dateCreated )
+ {
+ this.dateCreated = dateCreated;
+ }
+
+ public void setDateExpires( Date dateExpires )
+ {
+ this.dateExpires = dateExpires;
+ }
+
+ public void setForPrincipal( String forPrincipal )
+ {
+ this.forPrincipal = forPrincipal;
+ }
+
+ public void setKey( String key )
+ {
+ this.key = key;
+ }
+
+ public void setPurpose( String purpose )
+ {
+ this.purpose = purpose;
+ }
+
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer();
+
+ sb.append( "MemoryAuthenticationKey[" );
+ sb.append( "key=" ).append( key );
+ sb.append( ",forPrincipal=" ).append( forPrincipal );
+ sb.append( ",purpose=" ).append( purpose );
+ sb.append( ",dateCreated=" ).append( dateCreated );
+ sb.append( ",dateExpired=" ).append( dateExpires );
+ sb.append( ']' );
+
+ return sb.toString();
+ }
+}