--- /dev/null
+package org.apache.archiva.redback.keys.jdo;
+
+/*
+ * 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 org.apache.archiva.redback.keys.AuthenticationKey;
+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.apache.archiva.redback.keys.AbstractKeyManager;
+import org.apache.archiva.redback.keys.KeyManagerException;
+import org.apache.archiva.redback.keys.KeyNotFoundException;
+import org.codehaus.plexus.redback.keys.jdo.JdoAuthenticationKey;
+import org.codehaus.plexus.redback.keys.jdo.RedbackKeyManagementJdoModelloMetadata;
+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;
+ }
+}
+++ /dev/null
-package org.codehaus.plexus.redback.keys.jdo;
-
-/*
- * 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 org.apache.archiva.redback.keys.AuthenticationKey;
-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.apache.archiva.redback.keys.AbstractKeyManager;
-import org.apache.archiva.redback.keys.KeyManagerException;
-import org.apache.archiva.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;
- }
-}
default-lazy-init="true">
<context:annotation-config />
- <context:component-scan base-package="org.codehaus.plexus.redback.keys.jdo"/>
+ <context:component-scan base-package="org.apache.archiva.redback.keys.jdo"/>
</beans>
\ No newline at end of file
--- /dev/null
+package org.apache.archiva.redback.keys.jdo;
+
+/*
+ * 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 org.apache.archiva.redback.keys.KeyManager;
+import org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory;
+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 );
+ }
+
+}
+++ /dev/null
-package org.codehaus.plexus.redback.keys.jdo;
-
-/*
- * 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 org.apache.archiva.redback.keys.KeyManager;
-import org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory;
-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 );
- }
-
-}
-->
<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">
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean name="jdoFactory#users" class="org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory">
<property name="driverName" value="org.hsqldb.jdbcDriver"/>