get rid of all jdo jpox dependencies

Signed-off-by: olivier lamy <olamy@apache.org>
This commit is contained in:
olivier lamy 2016-12-31 10:21:49 +01:00
parent effc4a280b
commit 0537b8562e
31 changed files with 2 additions and 4718 deletions

88
pom.xml
View File

@ -387,35 +387,7 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.archiva.redback.components</groupId>
<artifactId>spring-jdo2</artifactId>
<version>2.2</version>
<exclusions>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xmlParserAPIs</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Other -->
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<!-- must run at xalan 2.7.0, as ealier versions embed an ancient version
of bcel, which iterferes with the ability of jpox/jdo to run -->
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<!-- Xalan 2.7.0 requires xml-apis version 1.3.02+ -->
<version>1.3.03</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
@ -543,45 +515,6 @@
<artifactId>redback-rest-services</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>jpox</groupId>
<artifactId>jpox</artifactId>
<version>1.1.9-1</version>
<scope>compile</scope>
<exclusions>
<!-- targeting JDK 1.4 we don't need this -->
<exclusion>
<groupId>javax.sql</groupId>
<artifactId>jdbc-stdext</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>javax.resource</groupId>
<artifactId>connector</artifactId>
</exclusion>
<exclusion>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>jpox</groupId>
<artifactId>jpox-ehcache</artifactId>
<version>1.1.9</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>ehcache</groupId>
<artifactId>ehcache</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
@ -697,22 +630,10 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jpox-maven-plugin</artifactId>
<version>1.1.7</version>
<dependencies>
<dependency>
<groupId>org.apache.bcel</groupId>
<artifactId>bcel</artifactId>
<version>6.0</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
@ -732,11 +653,6 @@
<pubScmUrl>scm:svn:https://svn.apache.org/repos/asf/archiva/site-content/redback/core</pubScmUrl>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.archiva.redback.components.modello</groupId>
<artifactId>jpox-modello-maven-plugin</artifactId>
<version>1.0</version>
</plugin>
<plugin>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-maven-plugin</artifactId>

View File

@ -29,7 +29,6 @@
<name>Redback :: Commons</name>
<packaging>pom</packaging>
<modules>
<module>redback-common-jdo</module>
<module>redback-common-ldap</module>
<module>redback-common-test-resources</module>
<module>redback-common-jpa</module>

View File

@ -1,116 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<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.apache.archiva.redback</groupId>
<artifactId>redback-common</artifactId>
<version>2.5-SNAPSHOT</version>
</parent>
<artifactId>redback-common-jdo</artifactId>
<packaging>bundle</packaging>
<name>Redback :: JDO Common API</name>
<dependencies>
<dependency>
<groupId>org.apache.archiva.redback.components</groupId>
<artifactId>spring-jdo2</artifactId>
</dependency>
<dependency>
<groupId>jpox</groupId>
<artifactId>jpox</artifactId>
<scope>compile</scope>
<exclusions>
<!-- targeting JDK 1.4 we don't need this -->
<exclusion>
<groupId>javax.sql</groupId>
<artifactId>jdbc-stdext</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>javax.resource</groupId>
<artifactId>connector</artifactId>
</exclusion>
<exclusion>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.archiva.redback</groupId>
<artifactId>redback-configuration</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>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Export-Package>
org.apache.archiva.redback.common.jdo*;version=${project.version};-split-package:=merge-first
</Export-Package>
<Import-Package>
javax.annotation,
javax.inject;version="[1,2)",
javax.jdo;version="[2,3)",
org.apache.archiva.redback.components.jdo;version=${project.version},
org.apache.archiva.redback.configuration;version=${project.version},
org.apache.commons.lang;version="[2.6,3)",
org.codehaus.plexus.interpolation;version="[1.9,2)",
org.jpox*;version="[1.1,2)",
org.springframework.stereotype;version="[3,4)",
org.slf4j;resolution:=optional
</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,132 +0,0 @@
package org.apache.archiva.redback.common.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.components.jdo.DefaultConfigurableJdoFactory;
import org.apache.archiva.redback.configuration.UserConfiguration;
import org.apache.commons.lang.StringUtils;
import org.codehaus.plexus.interpolation.InterpolationException;
import org.codehaus.plexus.interpolation.PropertiesBasedValueSource;
import org.codehaus.plexus.interpolation.StringSearchInterpolator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
/**
* UserConfigurableJdoFactory
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
*/
@Service("jdoFactory#users")
public class UserConfigurableJdoFactory
extends DefaultConfigurableJdoFactory
{
private Logger log = LoggerFactory.getLogger( getClass() );
private UserConfiguration userConfiguration;
@Inject
public UserConfigurableJdoFactory(
@Named( value = "userConfiguration#default" ) UserConfiguration userConfiguration )
{
this.userConfiguration = userConfiguration;
}
private String getConfigString( String key, String currentValue, String defaultValue )
{
String valueFromSysProps = System.getProperty( "redback." + key );
if ( StringUtils.isNotEmpty( valueFromSysProps ) )
{
return valueFromSysProps;
}
String value = null;
if ( StringUtils.isNotEmpty( currentValue ) )
{
value = userConfiguration.getString( key, currentValue );
}
else
{
value = userConfiguration.getString( key, defaultValue );
}
// do some interpolation as we can have some ${plexus.home} etc...
StringSearchInterpolator interpolator = new StringSearchInterpolator();
interpolator.addValueSource( new PropertiesBasedValueSource( System.getProperties() ) );
try
{
return interpolator.interpolate( value );
}
catch ( InterpolationException e )
{
// ignore interpolation issue
log.warn( "skip issue during interpolation {}", e.getMessage() );
return value;
}
}
@PostConstruct
public void initialize()
{
String jdbcDriverName =
getConfigString( "jdbc.driver.name", super.getDriverName(), "org.apache.derby.jdbc.EmbeddedDriver" );
String jdbcUrl =
getConfigString( "jdbc.url", super.getUrl(), "jdbc:derby:${plexus.home}/database;create=true" );
String jdbcUsername = getConfigString( "jdbc.username", super.getUserName(), "sa" );
String jdbcPassword = getConfigString( "jdbc.password", super.getPassword(), "" );
super.setDriverName( jdbcDriverName );
super.setUrl( jdbcUrl );
super.setUserName( jdbcUsername );
super.setPassword( jdbcPassword );
if ( StringUtils.isEmpty( super.persistenceManagerFactoryClass ) )
{
super.setPersistenceManagerFactoryClass( "org.jpox.PersistenceManagerFactoryImpl" );
}
if ( ( super.otherProperties == null ) || super.otherProperties.isEmpty() )
{
super.setProperty( "org.jpox.autoCreateSchema", "true" );
super.setProperty( "org.jpox.validateSchema", "false" );
super.setProperty( "org.jpox.validateTables", "false" );
super.setProperty( "org.jpox.validateConstraints", "false" );
super.setProperty( "org.jpox.transactionIsolation", "READ_COMMITTED" );
super.setProperty( "org.jpox.rdbms.dateTimezone", "JDK_DEFAULT_TIMEZONE" );
}
super.initialize();
}
public UserConfiguration getUserConfiguration()
{
return userConfiguration;
}
public void setUserConfiguration( UserConfiguration userConfiguration )
{
this.userConfiguration = userConfiguration;
}
}

View File

@ -1,113 +0,0 @@
package org.apache.archiva.redback.common.jdo.test;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.jdo.PersistenceManager;
import org.jpox.AbstractPersistenceManagerFactory;
import org.jpox.ClassLoaderResolver;
import org.jpox.plugin.ConfigurationElement;
import org.jpox.plugin.Extension;
import org.jpox.store.rdbms.RDBMSManager;
/**
* A extension to JPOX store manager that allows counting the SQL queries
*
* @author Carlos Sanchez
*/
public class StoreManagerDebug
extends RDBMSManager
{
private static int counter;
public StoreManagerDebug( ClassLoaderResolver clr, AbstractPersistenceManagerFactory pmf, String userName,
String password )
{
super( clr, pmf, userName, password );
}
/**
* This method will change JPOX store manager extension so it uses our class instead of whatever is configured in
* the plugin.xml
*
* @param pmf
*/
public static void setup( AbstractPersistenceManagerFactory pmf )
{
/* set our own Store Manager to allow counting SQL statements */
Extension[] extensions =
pmf.getPMFContext().getPluginManager().getExtensionPoint( "org.jpox.store_manager" ).getExtensions();
Extension e = extensions[0];
for ( ConfigurationElement element : e.getConfigurationElements() )
{
element.putAttribute( "class-name", StoreManagerDebug.class.getName() );
}
}
/**
* Get the currently configured store manager from JPOX. Will fail if
* {@link #setup(AbstractPersistenceManagerFactory)} is not called first.
*
* @param persistenceManager
* @return
*/
public static StoreManagerDebug getConfiguredStoreManager( PersistenceManager persistenceManager )
{
return (StoreManagerDebug) ( (org.jpox.PersistenceManager) persistenceManager ).getStoreManager();
}
@Override
public int[] executeStatementBatch( String stmt, PreparedStatement ps )
throws SQLException
{
counter++;
return super.executeStatementBatch( stmt, ps );
}
@Override
public ResultSet executeStatementQuery( String stmt, PreparedStatement ps )
throws SQLException
{
counter++;
return super.executeStatementQuery( stmt, ps );
}
@Override
public int executeStatementUpdate( String stmt, PreparedStatement ps )
throws SQLException
{
counter++;
return super.executeStatementUpdate( stmt, ps );
}
public void resetCounter()
{
counter = 0;
}
public int counter()
{
return counter;
}
}

View File

@ -1,35 +0,0 @@
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
default-lazy-init="true">
<bean name="jdoFactory#users" class="org.apache.archiva.redback.common.jdo.UserConfigurableJdoFactory">
<constructor-arg>
<ref bean="userConfiguration#default"/>
</constructor-arg>
<!--
<property name="config" ref="userConfiguration#default"/>
-->
</bean>
</beans>

View File

@ -1,170 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<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.apache.archiva.redback</groupId>
<artifactId>redback-keys-providers</artifactId>
<version>2.5-SNAPSHOT</version>
</parent>
<artifactId>redback-keys-jdo</artifactId>
<packaging>jar</packaging>
<name>Redback :: Key Management Provider :: JDO</name>
<dependencies>
<dependency>
<groupId>org.apache.archiva.redback</groupId>
<artifactId>redback-keys-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva.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.apache.archiva.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>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<configuration>
<version>1.0.1</version>
<packageWithVersion>false</packageWithVersion>
<models>
<model>src/main/mdo/keys.mdo</model>
</models>
</configuration>
<executions>
<execution>
<id>modello-java</id>
<goals>
<goal>java</goal>
<goal>stax-reader</goal>
<goal>stax-writer</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.archiva.redback.components.modello</groupId>
<artifactId>jpox-modello-maven-plugin</artifactId>
<configuration>
<version>1.0.1</version>
<packageWithVersion>false</packageWithVersion>
<models>
<model>src/main/mdo/keys.mdo</model>
</models>
</configuration>
<executions>
<execution>
<id>modello-jpox</id>
<goals>
<goal>jpox-metadata-class</goal>
</goals>
</execution>
<execution>
<id>jpox-jdo-mapping</id>
<goals>
<goal>jpox-jdo-mapping</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}/org/apache/archiva/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>

View File

@ -1,187 +0,0 @@
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.components.jdo.JdoFactory;
import org.apache.archiva.redback.components.jdo.RedbackJdoUtils;
import org.apache.archiva.redback.components.jdo.RedbackObjectNotFoundException;
import org.apache.archiva.redback.components.jdo.RedbackStoreException;
import org.apache.archiva.redback.keys.AuthenticationKey;
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>
*
*/
@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) RedbackJdoUtils.addObject( getPersistenceManager(), key );
}
public void eraseDatabase()
{
RedbackJdoUtils.removeAll( getPersistenceManager(), JdoAuthenticationKey.class );
RedbackJdoUtils.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) RedbackJdoUtils.getObjectById(
getPersistenceManager(), JdoAuthenticationKey.class, key );
if ( authkey == null )
{
throw new KeyNotFoundException( "Key [" + key + "] not found." );
}
assertNotExpired( authkey );
return authkey;
}
catch ( RedbackObjectNotFoundException e )
{
throw new KeyNotFoundException( e.getMessage() );
}
catch ( RedbackStoreException e )
{
throw new KeyManagerException(
"Unable to get " + JdoAuthenticationKey.class.getName() + "', key '" + key + "' from jdo store." );
}
}
public void deleteKey( AuthenticationKey authkey )
throws KeyManagerException
{
RedbackJdoUtils.removeObject( getPersistenceManager(), authkey );
}
public void deleteKey( String key )
throws KeyManagerException
{
try
{
AuthenticationKey authkey = findKey( key );
RedbackJdoUtils.removeObject( getPersistenceManager(), authkey );
}
catch ( KeyNotFoundException e )
{
// not found? nothing to do.
}
}
@SuppressWarnings( "unchecked" )
public List<AuthenticationKey> getAllKeys()
{
return RedbackJdoUtils.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;
}
}

View File

@ -1,89 +0,0 @@
<?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.
-->
<model>
<id>redback-keys-jdo</id>
<name>RedbackKeyManagementJdo</name>
<version>1.0.1</version>
<description>Archiva Redback :: Key Management JDO Store.</description>
<defaults>
<default>
<key>package</key>
<value>org.apache.archiva.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.apache.archiva.redback.keys.AuthenticationKey</interface>
</interfaces>
<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 xml.format="long">
<name>dateCreated</name>
<version>1.0.0+</version>
<type>Date</type>
</field>
<field xml.format="long">
<name>dateExpires</name>
<version>1.0.0+</version>
<type>Date</type>
</field>
</fields>
</class>
</classes>
</model>

View File

@ -1,32 +0,0 @@
<?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.apache.archiva.redback.keys.jdo"/>
</beans>

View File

@ -1,102 +0,0 @@
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.components.jdo.DefaultConfigurableJdoFactory;
import org.apache.archiva.redback.keys.KeyManager;
import org.apache.archiva.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>
*
*/
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/apache/archiva/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 );
}
}

View File

@ -1,48 +0,0 @@
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean name="jdoFactory#users" class="org.apache.archiva.redback.components.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#default" class="org.apache.archiva.redback.configuration.DefaultUserConfiguration">
<property name="registry" ref="test-conf"/>
</bean>
<bean name="commons-configuration" class="org.apache.archiva.redback.components.registry.commons.CommonsConfigurationRegistry">
</bean>
<alias name="commons-configuration" alias="test-conf"/>
</beans>

View File

@ -1,156 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<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.apache.archiva.redback</groupId>
<artifactId>redback-rbac-providers</artifactId>
<version>2.5-SNAPSHOT</version>
</parent>
<artifactId>redback-rbac-jdo</artifactId>
<packaging>bundle</packaging>
<name>Redback :: RBAC Provider :: JDO</name>
<dependencies>
<dependency>
<groupId>org.apache.archiva.redback</groupId>
<artifactId>redback-rbac-model</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.apache.archiva.redback</groupId>
<artifactId>redback-rbac-tests</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva.redback</groupId>
<artifactId>redback-common-jdo</artifactId>
</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>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jpox</groupId>
<artifactId>jpox-ehcache</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>ehcache</groupId>
<artifactId>ehcache</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<configuration>
<version>1.0.1</version>
<packageWithVersion>false</packageWithVersion>
<models>
<model>src/main/mdo/rbac-jdo.mdo</model>
</models>
</configuration>
<executions>
<execution>
<id>modello-java</id>
<goals>
<goal>java</goal>
<!-- TODO: Move these to plexus-security-authorization-rbac-model -->
<goal>stax-reader</goal>
<goal>stax-writer</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.archiva.redback.components.modello</groupId>
<artifactId>jpox-modello-maven-plugin</artifactId>
<configuration>
<version>1.0.1</version>
<packageWithVersion>false</packageWithVersion>
<models>
<model>src/main/mdo/rbac-jdo.mdo</model>
</models>
</configuration>
<executions>
<execution>
<id>modello-jpox</id>
<goals>
<goal>jpox-metadata-class</goal>
<goal>jpox-jdo-mapping</goal>
</goals>
</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>

View File

@ -1,711 +0,0 @@
package org.apache.archiva.redback.rbac.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.rbac.AbstractRBACManager;
import org.apache.archiva.redback.rbac.Operation;
import org.apache.archiva.redback.rbac.RBACManagerListener;
import org.apache.archiva.redback.rbac.RbacManagerException;
import org.apache.archiva.redback.rbac.RbacObjectInvalidException;
import org.apache.archiva.redback.rbac.RbacObjectNotFoundException;
import org.apache.archiva.redback.rbac.RbacPermanentException;
import org.apache.archiva.redback.rbac.Resource;
import org.apache.archiva.redback.rbac.Role;
import org.apache.archiva.redback.rbac.UserAssignment;
import org.apache.archiva.redback.rbac.Permission;
import org.apache.archiva.redback.rbac.RBACObjectAssertions;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.Transaction;
import java.util.Collection;
import java.util.List;
/**
* JdoRbacManager:
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @author Jesse McConnell
*
*/
@Service( "rbacManager#jdo" )
public class JdoRbacManager
extends AbstractRBACManager
implements RBACManagerListener
{
@Inject
private JdoTool jdo;
private boolean enableCache = true;
// private static final String ROLE_DETAIL = "role-child-detail";
private static final String ROLE_DETAIL = null;
// ----------------------------------------------------------------------
// Role methods
// ----------------------------------------------------------------------
/**
* Creates an implementation specific {@link Role}.
*
* Note: this method does not add the {@link Role} to the underlying store.
* a call to {@link #saveRole(Role)} is required to track the role created with this
* method call.
*
* @param name the name.
* @return the new {@link Role} object with an empty (non-null) {@link Role#getChildRoleNames()} object.
*/
public Role createRole( String name )
{
Role role;
try
{
role = getRole( name );
}
catch ( RbacManagerException e )
{
role = new JdoRole();
role.setName( name );
}
return role;
}
/**
* Method addRole
*
* @param role
*/
public Role saveRole( Role role )
throws RbacObjectInvalidException, RbacManagerException
{
RBACObjectAssertions.assertValid( role );
return jdo.saveObject( role, new String[]{ ROLE_DETAIL } );
}
public boolean roleExists( Role role )
{
return jdo.objectExists( role );
}
public boolean roleExists( String name )
{
try
{
return jdo.objectExistsById( JdoRole.class, name );
}
catch ( RbacManagerException e )
{
return false;
}
}
/**
* @param roleName
* @return
* @throws RbacObjectNotFoundException
* @throws RbacManagerException
*/
public Role getRole( String roleName )
throws RbacObjectNotFoundException, RbacManagerException
{
return jdo.getObjectById( JdoRole.class, roleName, ROLE_DETAIL );
}
/**
* Method getRoles
*/
@SuppressWarnings( "unchecked" )
public List<Role> getAllRoles()
throws RbacManagerException
{
return (List<Role>) jdo.getAllObjects( JdoRole.class );
}
public void removeRole( Role role )
throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException
{
RBACObjectAssertions.assertValid( role );
if ( role.isPermanent() )
{
throw new RbacPermanentException( "Unable to delete permanent role [" + role.getName() + "]" );
}
jdo.removeObject( role );
}
public void saveRoles( Collection<Role> roles )
throws RbacObjectInvalidException, RbacManagerException
{
if ( roles == null )
{
// Nothing to do.
return;
}
// This is done in JdoRbacManager as opposed to JdoTool as we need to assertValid() on each role and
// also wrap the entire collection into a single atomic save/makePersistent.
PersistenceManager pm = jdo.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try
{
tx.begin();
for ( Role role : roles )
{
if ( ( JDOHelper.getObjectId( role ) != null ) && !JDOHelper.isDetached( role ) )
{
// This is a fatal error that means we need to fix our code.
// Leave it as a JDOUserException, it's intentional.
throw new RbacManagerException( "Existing Role is not detached: " + role );
}
RBACObjectAssertions.assertValid( role );
pm.makePersistent( role );
}
tx.commit();
}
finally
{
jdo.rollbackIfActive( tx );
}
}
// ----------------------------------------------------------------------
// Permission methods
// ----------------------------------------------------------------------
/**
* Creates an implementation specific {@link Permission}.
*
* Note: this method does not add the {@link Permission} to the underlying store.
* a call to {@link #savePermission(Permission)} is required to track the permission created
* with this method call.
*
* @param name the name.
* @return the new Permission.
* @throws RbacManagerException
*/
public Permission createPermission( String name )
throws RbacManagerException
{
Permission permission;
try
{
permission = getPermission( name );
log.debug( "Create Permission [{}] Returning Existing.", name );
}
catch ( RbacObjectNotFoundException e )
{
permission = new JdoPermission();
permission.setName( name );
log.debug( "Create Permission [{}] New JdoPermission.", name );
}
return permission;
}
/**
* Creates an implementation specific {@link Permission} with specified {@link Operation},
* and {@link Resource} identifiers.
*
* Note: this method does not add the Permission, Operation, or Resource to the underlying store.
* a call to {@link #savePermission(Permission)} is required to track the permission, operation,
* or resource created with this method call.
*
* @param name the name.
* @param operationName the {@link Operation#setName(String)} value
* @param resourceIdentifier the {@link Resource#setIdentifier(String)} value
* @return the new Permission.
* @throws RbacManagerException
*/
public Permission createPermission( String name, String operationName, String resourceIdentifier )
throws RbacManagerException
{
Permission permission = new JdoPermission();
permission.setName( name );
Operation operation;
try
{
operation = getOperation( operationName );
}
catch ( RbacObjectNotFoundException e )
{
operation = new JdoOperation();
operation.setName( operationName );
}
permission.setOperation( operation );
Resource resource;
try
{
resource = getResource( resourceIdentifier );
}
catch ( RbacObjectNotFoundException e )
{
resource = new JdoResource();
resource.setIdentifier( resourceIdentifier );
}
permission.setResource( resource );
return permission;
}
public Permission savePermission( Permission permission )
throws RbacObjectInvalidException, RbacManagerException
{
RBACObjectAssertions.assertValid( permission );
return jdo.saveObject( permission, null );
}
public boolean permissionExists( Permission permission )
{
return jdo.objectExists( permission );
}
public boolean permissionExists( String name )
{
try
{
return jdo.objectExistsById( JdoPermission.class, name );
}
catch ( RbacManagerException e )
{
return false;
}
}
public Permission getPermission( String permissionName )
throws RbacObjectNotFoundException, RbacManagerException
{
return jdo.getObjectById( JdoPermission.class, permissionName, null );
}
@SuppressWarnings( "unchecked" )
public List<Permission> getAllPermissions()
throws RbacManagerException
{
return (List<Permission>) jdo.getAllObjects( JdoPermission.class );
}
public void removePermission( Permission permission )
throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException
{
RBACObjectAssertions.assertValid( permission );
if ( permission.isPermanent() )
{
throw new RbacPermanentException( "Unable to delete permanent permission [" + permission.getName() + "]" );
}
jdo.removeObject( permission );
}
// ----------------------------------------------------------------------
// Operation methods
// ----------------------------------------------------------------------
/**
* Creates an implementation specific {@link Operation}.
*
* Note: this method does not add the {@link Operation} to the underlying store.
* a call to {@link #saveOperation(Operation)} is required to track the operation created
* with this method call.
*
* @param name the name.
* @return the new Operation.
* @throws RbacManagerException
*/
public Operation createOperation( String name )
throws RbacManagerException
{
Operation operation;
try
{
operation = getOperation( name );
}
catch ( RbacObjectNotFoundException e )
{
operation = new JdoOperation();
operation.setName( name );
}
return operation;
}
public Operation saveOperation( Operation operation )
throws RbacObjectInvalidException, RbacManagerException
{
RBACObjectAssertions.assertValid( operation );
return jdo.saveObject( operation, null );
}
public boolean operationExists( Operation operation )
{
return jdo.objectExists( operation );
}
public boolean operationExists( String name )
{
try
{
return jdo.objectExistsById( JdoOperation.class, name );
}
catch ( RbacManagerException e )
{
return false;
}
}
public Operation getOperation( String operationName )
throws RbacObjectNotFoundException, RbacManagerException
{
return jdo.getObjectById( JdoOperation.class, operationName, null );
}
@SuppressWarnings( "unchecked" )
public List<Operation> getAllOperations()
throws RbacManagerException
{
return (List<Operation>) jdo.getAllObjects( JdoOperation.class );
}
public void removeOperation( Operation operation )
throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException
{
RBACObjectAssertions.assertValid( operation );
if ( operation.isPermanent() )
{
throw new RbacPermanentException( "Unable to delete permanent operation [" + operation.getName() + "]" );
}
jdo.removeObject( operation );
}
// ----------------------------------------------------------------------
// Resource methods
// ----------------------------------------------------------------------
/**
* Creates an implementation specific {@link Resource}.
*
* Note: this method does not add the {@link Resource} to the underlying store.
* a call to {@link #saveResource(Resource)} is required to track the resource created
* with this method call.
*
* @param identifier the identifier.
* @return the new Resource.
* @throws RbacManagerException
*/
public Resource createResource( String identifier )
throws RbacManagerException
{
Resource resource;
try
{
resource = getResource( identifier );
log.debug( "Create Resource [ {} ] Returning Existing.", identifier );
}
catch ( RbacObjectNotFoundException e )
{
resource = new JdoResource();
resource.setIdentifier( identifier );
log.debug( "Create Resource [ {} ] New JdoResource.", identifier );
}
return resource;
}
public Resource saveResource( Resource resource )
throws RbacObjectInvalidException, RbacManagerException
{
RBACObjectAssertions.assertValid( resource );
return jdo.saveObject( resource, null );
}
public boolean resourceExists( Resource resource )
{
return jdo.objectExists( resource );
}
public boolean resourceExists( String identifier )
{
try
{
return jdo.objectExistsById( JdoResource.class, identifier );
}
catch ( RbacManagerException e )
{
return false;
}
}
public Resource getResource( String resourceIdentifier )
throws RbacObjectNotFoundException, RbacManagerException
{
return jdo.getObjectById( JdoResource.class, resourceIdentifier, null );
}
@SuppressWarnings( "unchecked" )
public List<Resource> getAllResources()
throws RbacManagerException
{
return (List<Resource>) jdo.getAllObjects( JdoResource.class );
}
public void removeResource( Resource resource )
throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException
{
RBACObjectAssertions.assertValid( resource );
if ( resource.isPermanent() )
{
throw new RbacPermanentException(
"Unable to delete permanent resource [" + resource.getIdentifier() + "]" );
}
jdo.removeObject( resource );
}
// ----------------------------------------------------------------------
// User Assignment methods
// ----------------------------------------------------------------------
/**
* Creates an implementation specific {@link UserAssignment}.
*
* Note: this method does not add the {@link UserAssignment} to the underlying store.
* a call to {@link #saveUserAssignment(UserAssignment)} is required to track the user
* assignment created with this method call.
*
* @param principal the principal reference to the user.
* @return the new UserAssignment with an empty (non-null) {@link UserAssignment#getRoleNames()} object.
*/
public UserAssignment createUserAssignment( String principal )
{
UserAssignment ua;
try
{
ua = getUserAssignment( principal );
}
catch ( RbacManagerException e )
{
ua = new JdoUserAssignment();
ua.setPrincipal( principal );
}
return ua;
}
/**
* Method addUserAssignment
*
* @param userAssignment
*/
public UserAssignment saveUserAssignment( UserAssignment userAssignment )
throws RbacObjectInvalidException, RbacManagerException
{
RBACObjectAssertions.assertValid( "Save User Assignment", userAssignment );
fireRbacUserAssignmentSaved( userAssignment );
return jdo.saveObject( userAssignment, new String[]{ ROLE_DETAIL } );
}
public boolean userAssignmentExists( String principal )
{
try
{
return jdo.objectExistsById( JdoUserAssignment.class, principal );
}
catch ( RbacManagerException e )
{
return false;
}
}
public boolean userAssignmentExists( UserAssignment assignment )
{
return jdo.objectExists( assignment );
}
public UserAssignment getUserAssignment( String principal )
throws RbacObjectNotFoundException, RbacManagerException
{
return jdo.getObjectById( JdoUserAssignment.class, principal, ROLE_DETAIL );
}
/**
* Method getAssignments
*/
@SuppressWarnings( "unchecked" )
public List<UserAssignment> getAllUserAssignments()
throws RbacManagerException
{
return (List<UserAssignment>) jdo.getAllObjects( JdoUserAssignment.class );
}
/**
* Method getUserAssignmentsForRoles
*/
@SuppressWarnings( "unchecked" )
public List<UserAssignment> getUserAssignmentsForRoles( Collection<String> roleNames )
throws RbacManagerException
{
return (List<UserAssignment>) jdo.getUserAssignmentsForRoles( JdoUserAssignment.class, null, roleNames );
}
/**
* Method removeAssignment
*
* @param userAssignment
*/
public void removeUserAssignment( UserAssignment userAssignment )
throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException
{
RBACObjectAssertions.assertValid( userAssignment );
if ( userAssignment.isPermanent() )
{
throw new RbacPermanentException(
"Unable to delete permanent user assignment [" + userAssignment.getPrincipal() + "]" );
}
fireRbacUserAssignmentRemoved( userAssignment );
jdo.removeObject( userAssignment );
}
public void eraseDatabase()
{
// Must delete in order so that FK constraints don't get violated
jdo.removeAll( JdoRole.class );
jdo.removeAll( JdoPermission.class );
jdo.removeAll( JdoOperation.class );
jdo.removeAll( JdoResource.class );
jdo.removeAll( JdoUserAssignment.class );
jdo.removeAll( RbacJdoModelModelloMetadata.class );
}
@PostConstruct
public void initialize()
{
super.initialize();
jdo.setListener( this );
if ( enableCache )
{
jdo.enableCache( JdoRole.class );
jdo.enableCache( JdoOperation.class );
jdo.enableCache( JdoResource.class );
jdo.enableCache( JdoUserAssignment.class );
jdo.enableCache( JdoPermission.class );
}
}
public void rbacInit( boolean freshdb )
{
fireRbacInit( freshdb );
}
public void rbacPermissionRemoved( Permission permission )
{
fireRbacPermissionRemoved( permission );
}
public void rbacPermissionSaved( Permission permission )
{
fireRbacPermissionSaved( permission );
}
public void rbacRoleRemoved( Role role )
{
fireRbacRoleRemoved( role );
}
public void rbacRoleSaved( Role role )
{
fireRbacRoleSaved( role );
}
public void rbacUserAssignmentSaved( UserAssignment userAssignment )
{
fireRbacUserAssignmentSaved( userAssignment );
}
public void rbacUserAssignmentRemoved( UserAssignment userAssignment )
{
fireRbacUserAssignmentRemoved( userAssignment );
}
public JdoTool getJdo()
{
return jdo;
}
public void setJdo( JdoTool jdo )
{
this.jdo = jdo;
}
public boolean isEnableCache()
{
return enableCache;
}
public void setEnableCache( boolean enableCache )
{
this.enableCache = enableCache;
}
@Override
public boolean isFinalImplementation()
{
return true;
}
public String getDescriptionKey()
{
return "archiva.redback.rbacmanager.jdo";
}
public boolean isReadOnly()
{
return false;
}
}

View File

@ -1,500 +0,0 @@
package org.apache.archiva.redback.rbac.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.rbac.Permission;
import org.apache.archiva.redback.rbac.RBACManagerListener;
import org.apache.archiva.redback.rbac.RbacManagerException;
import org.apache.archiva.redback.rbac.RbacObjectNotFoundException;
import org.apache.archiva.redback.rbac.Role;
import org.apache.archiva.redback.components.jdo.JdoFactory;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.jdo.Extent;
import javax.jdo.JDOException;
import javax.jdo.JDOHelper;
import javax.jdo.JDOObjectNotFoundException;
import javax.jdo.JDOUserException;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import javax.jdo.Query;
import javax.jdo.Transaction;
import javax.jdo.datastore.DataStoreCache;
import javax.jdo.listener.DeleteLifecycleListener;
import javax.jdo.listener.InstanceLifecycleEvent;
import javax.jdo.listener.StoreLifecycleListener;
import javax.jdo.spi.Detachable;
import javax.jdo.spi.PersistenceCapable;
import java.io.PrintStream;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
/**
* JdoTool - RBAC JDO Tools.
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
*
*/
@Service("jdoTool")
public class JdoTool
implements DeleteLifecycleListener, StoreLifecycleListener
{
@Resource(name="jdoFactory#users")
private JdoFactory jdoFactory;
private PersistenceManagerFactory pmf;
private RBACManagerListener listener;
@PostConstruct
public void initialize()
{
pmf = jdoFactory.getPersistenceManagerFactory();
pmf.addInstanceLifecycleListener( this, null );
}
public static void dumpObjectState( PrintStream out, Object o )
{
final String STATE = "[STATE] ";
final String INDENT = " ";
if ( o == null )
{
out.println( STATE + "Object is null." );
return;
}
out.println( STATE + "Object " + o.getClass().getName() );
if ( !( o instanceof PersistenceCapable ) )
{
out.println( INDENT + "is NOT PersistenceCapable (not a jdo object?)" );
return;
}
out.println( INDENT + "is PersistenceCapable." );
if ( o instanceof Detachable )
{
out.println( INDENT + "is Detachable" );
}
out.println( INDENT + "is new : " + Boolean.toString( JDOHelper.isNew( o ) ) );
out.println( INDENT + "is transactional : " + Boolean.toString( JDOHelper.isTransactional( o ) ) );
out.println( INDENT + "is deleted : " + Boolean.toString( JDOHelper.isDeleted( o ) ) );
out.println( INDENT + "is detached : " + Boolean.toString( JDOHelper.isDetached( o ) ) );
out.println( INDENT + "is dirty : " + Boolean.toString( JDOHelper.isDirty( o ) ) );
out.println( INDENT + "is persistent : " + Boolean.toString( JDOHelper.isPersistent( o ) ) );
out.println( INDENT + "object id : " + JDOHelper.getObjectId( o ) );
}
public PersistenceManager getPersistenceManager()
{
PersistenceManager pm = pmf.getPersistenceManager();
pm.getFetchPlan().setMaxFetchDepth( -1 );
triggerInit();
return pm;
}
private boolean hasTriggeredInit = false;
@SuppressWarnings("unchecked")
public void triggerInit()
{
if ( !hasTriggeredInit )
{
hasTriggeredInit = true;
List<Role> roles = (List<Role>) getAllObjects( JdoRole.class );
listener.rbacInit( roles.isEmpty() );
}
}
public void enableCache( Class<?> clazz )
{
DataStoreCache cache = pmf.getDataStoreCache();
if ( cache.getClass().getName().equals( "org.jpox.cache.EhcacheClassBasedLevel2Cache" )
|| cache.getClass().getName().equals( "org.jpox.cache.EhcacheLevel2Cache" ) )
{
/* Ehcache adapters don't support pinAll, the caching is handled in the configuration */
return;
}
cache.pinAll( clazz, false ); // Pin all objects of type clazz from now on
}
public <T>T saveObject( T object )
{
return (T) saveObject( object, null );
}
public <T>T saveObject( T object, String[] fetchGroups )
{
PersistenceManager pm = getPersistenceManager();
Transaction tx = pm.currentTransaction();
try
{
tx.begin();
if ( ( JDOHelper.getObjectId( object ) != null ) && !JDOHelper.isDetached( object ) )
{
// This is a fatal error that means we need to fix our code.
// Leave it as a JDOUserException, it's intentional.
throw new JDOUserException( "Existing object is not detached: " + object, object );
}
if ( fetchGroups != null )
{
for ( int i = 0; i >= fetchGroups.length; i++ )
{
pm.getFetchPlan().addGroup( fetchGroups[i] );
}
}
pm.makePersistent( object );
object = (T) pm.detachCopy( object );
tx.commit();
return object;
}
finally
{
rollbackIfActive( tx );
}
}
public List<?> getAllObjects( Class<?> clazz )
{
return getAllObjects( clazz, null, null );
}
public List<?> getAllObjects( Class<?> clazz, String ordering )
{
return getAllObjects( clazz, ordering, null );
}
public List<?> getAllObjects( Class<?> clazz, String ordering, String fetchGroup )
{
PersistenceManager pm = getPersistenceManager();
Transaction tx = pm.currentTransaction();
try
{
tx.begin();
Extent extent = pm.getExtent( clazz, true );
Query query = pm.newQuery( extent );
if ( ordering != null )
{
query.setOrdering( ordering );
}
if ( fetchGroup != null )
{
pm.getFetchPlan().addGroup( fetchGroup );
}
List<?> result = (List<?>) query.execute();
result = (List<?>) pm.detachCopyAll( result );
tx.commit();
return result;
}
finally
{
rollbackIfActive( tx );
}
}
public List<?> getUserAssignmentsForRoles( Class<?> clazz, String ordering, Collection<String> roleNames )
{
PersistenceManager pm = getPersistenceManager();
Transaction tx = pm.currentTransaction();
try
{
tx.begin();
Extent extent = pm.getExtent( clazz, true );
Query query = pm.newQuery( extent );
if ( ordering != null )
{
query.setOrdering( ordering );
}
query.declareImports( "import java.lang.String" );
StringBuilder filter = new StringBuilder();
if ( roleNames.size() > 0 )
{
Iterator<String> i = roleNames.iterator();
filter.append( "this.roleNames.contains(\"" ).append( i.next() ).append( "\")" );
while ( i.hasNext() )
{
filter.append( " || this.roleNames.contains(\"" ).append( i.next() ).append( "\")" );
}
query.setFilter( filter.toString() );
}
List<?> result = (List<?>) query.execute();
result = (List<?>) pm.detachCopyAll( result );
tx.commit();
return result;
}
finally
{
rollbackIfActive( tx );
}
}
public <T>T getObjectById( Class<T> clazz, String id, String fetchGroup )
throws RbacObjectNotFoundException, RbacManagerException
{
if ( StringUtils.isEmpty( id ) )
{
throw new RbacObjectNotFoundException(
"Unable to get object '" + clazz.getName() + "' from jdo using null/empty id." );
}
PersistenceManager pm = getPersistenceManager();
Transaction tx = pm.currentTransaction();
try
{
tx.begin();
if ( fetchGroup != null )
{
pm.getFetchPlan().addGroup( fetchGroup );
}
Object objectId = pm.newObjectIdInstance( clazz, id );
Object object = pm.getObjectById( objectId );
object = pm.detachCopy( object );
tx.commit();
return (T) object;
}
catch ( JDOObjectNotFoundException e )
{
throw new RbacObjectNotFoundException( "Unable to find RBAC Object '" + id + "' of type " +
clazz.getName() + " using fetch-group '" + fetchGroup + "'", e, id );
}
catch ( JDOException e )
{
throw new RbacManagerException( "Error in JDO during get of RBAC object id '" + id + "' of type " +
clazz.getName() + " using fetch-group '" + fetchGroup + "'", e );
}
finally
{
rollbackIfActive( tx );
}
}
public boolean objectExists( Object object )
{
return ( JDOHelper.getObjectId( object ) != null );
}
public boolean objectExistsById( Class<?> clazz, String id )
throws RbacManagerException
{
try
{
Object o = getObjectById( clazz, id, null );
return ( o != null );
}
catch ( RbacObjectNotFoundException e )
{
return false;
}
}
public <T>T removeObject( T o )
throws RbacManagerException
{
if ( o == null )
{
throw new RbacManagerException( "Unable to remove null object" );
}
PersistenceManager pm = getPersistenceManager();
Transaction tx = pm.currentTransaction();
try
{
tx.begin();
o = (T) pm.getObjectById( pm.getObjectId( o ) );
pm.deletePersistent( o );
tx.commit();
return o;
}
finally
{
rollbackIfActive( tx );
}
}
public void rollbackIfActive( Transaction tx )
{
PersistenceManager pm = tx.getPersistenceManager();
try
{
if ( tx.isActive() )
{
tx.rollback();
}
}
finally
{
closePersistenceManager( pm );
}
}
public void closePersistenceManager( PersistenceManager pm )
{
try
{
pm.close();
}
catch ( JDOUserException e )
{
// ignore
}
}
public RBACManagerListener getListener()
{
return listener;
}
public void setListener( RBACManagerListener listener )
{
this.listener = listener;
}
public void postDelete( InstanceLifecycleEvent evt )
{
PersistenceCapable obj = ( (PersistenceCapable) evt.getSource() );
if ( obj == null )
{
// Do not track null objects.
// These events are typically a product of an internal lifecycle event.
return;
}
if ( obj instanceof Role )
{
listener.rbacRoleRemoved( (Role) obj );
}
else if ( obj instanceof Permission )
{
listener.rbacPermissionRemoved( (Permission) obj );
}
}
public void preDelete( InstanceLifecycleEvent evt )
{
// ignore
}
public void postStore( InstanceLifecycleEvent evt )
{
PersistenceCapable obj = ( (PersistenceCapable) evt.getSource() );
if ( obj instanceof Role )
{
listener.rbacRoleSaved( (Role) obj );
}
else if ( obj instanceof Permission )
{
listener.rbacPermissionSaved( (Permission) obj );
}
}
public void preStore( InstanceLifecycleEvent evt )
{
// ignore
}
public void removeAll( Class<?> aClass )
{
PersistenceManager pm = getPersistenceManager();
Transaction tx = pm.currentTransaction();
try
{
tx.begin();
Query query = pm.newQuery( aClass );
query.deletePersistentAll();
tx.commit();
}
finally
{
rollbackIfActive( tx );
}
}
public JdoFactory getJdoFactory()
{
return jdoFactory;
}
public void setJdoFactory( JdoFactory jdoFactory )
{
this.jdoFactory = jdoFactory;
}
}

View File

@ -1,337 +0,0 @@
<?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.
-->
<model jpox.mapping-in-package="true"
jpox.table-prefix="SECURITY_">
<!-- TODO: there is no reason this model is JDO specific. Shouldn't it be the basis for the various providers? It would dramatically reduce the code in -memory, for example -->
<id>rbac-jdo</id>
<name>RbacJdoModel</name>
<version>1.0.1</version>
<defaults>
<default>
<key>package</key>
<value>org.apache.archiva.redback.rbac.jdo</value>
</default>
</defaults>
<classes>
<class rootElement="true"
jpox.stashable="false">
<name>RbacDatabase</name>
<version>1.0.1+</version>
<fields>
<field jpox.column="RBAC_ROLES">
<name>roles</name>
<version>1.0.1+</version>
<association>
<type>JdoRole</type>
<multiplicity>*</multiplicity>
</association>
</field>
<field>
<name>permissions</name>
<version>1.0.1+</version>
<association>
<type>JdoPermission</type>
<multiplicity>*</multiplicity>
</association>
</field>
<field>
<name>operations</name>
<version>1.0.1+</version>
<association>
<type>JdoOperation</type>
<multiplicity>*</multiplicity>
</association>
</field>
<field>
<name>resources</name>
<version>1.0.1+</version>
<association>
<type>JdoResource</type>
<multiplicity>*</multiplicity>
</association>
</field>
<field>
<name>userAssignments</name>
<version>1.0.1+</version>
<association>
<type>JdoUserAssignment</type>
<multiplicity>*</multiplicity>
</association>
</field>
</fields>
</class>
<class jpox.stashable="true"
jpox.table="ROLES">
<name>JdoRole</name>
<version>1.0.0+</version>
<interfaces>
<interface>org.apache.archiva.redback.rbac.Role</interface>
</interfaces>
<superClass>org.apache.archiva.redback.rbac.AbstractRole</superClass>
<fields>
<field jpox.primary-key="true" jpox.value-strategy="off">
<name>name</name>
<version>1.0.0+</version>
<type>String</type>
<identifier>true</identifier>
</field>
<field>
<name>description</name>
<version>1.0.0+</version>
<type>String</type>
</field>
<field>
<name>assignable</name>
<version>1.0.0+</version>
<type>boolean</type>
<description>
true if this role is available to be assigned to a user
</description>
</field>
<field>
<name>permanent</name>
<version>1.0.0+</version>
<type>boolean</type>
<description>
true if this object is permanent.
</description>
</field>
<field jpox.persistence-modifier="persistent"
jpox.fetch-groups="role-child-detail"
jpox.join-table="ROLE_CHILDROLE_MAP">
<name>childRoleNames</name>
<version>1.0.0+</version>
<association stash.part="true"
jpox.join="true"
java.init="field"
jpox.dependent="false"
java.generate-break="false"
java.generate-create="false"
zjava.use-interface="org.apache.archiva.redback.rbac.Role">
<type>String</type>
<multiplicity>*</multiplicity>
</association>
<description>
roles that will inherit the permissions of this role
</description>
</field>
<field jpox.fetch-groups="role-child-detail"
jpox.join-table="ROLE_PERMISSION_MAP">
<name>permissions</name>
<version>1.0.0+</version>
<association stash.part="true"
xml.reference="true"
jpox.join="true"
jpox.dependent="false"
java.init="field"
java.generate-break="false"
java.generate-create="false"
java.use-interface="org.apache.archiva.redback.rbac.Permission">
<type>JdoPermission</type>
<multiplicity>*</multiplicity>
</association>
</field>
</fields>
</class>
<class jpox.stashable="true"
jpox.table="PERMISSIONS">
<name>JdoPermission</name>
<version>1.0.0+</version>
<interfaces>
<interface>org.apache.archiva.redback.rbac.Permission</interface>
</interfaces>
<fields>
<field jpox.primary-key="true" jpox.value-strategy="off">
<name>name</name>
<version>1.0.0+</version>
<type>String</type>
<identifier>true</identifier>
</field>
<field>
<name>description</name>
<version>1.0.0+</version>
<type>String</type>
</field>
<field>
<name>permanent</name>
<version>1.0.0+</version>
<type>boolean</type>
<description>
true if this object is permanent.
</description>
</field>
<field jpox.indexed="true"
jpox.persistence-modifier="persistent"
jpox.column="RBAC_OPERATION">
<name>operation</name>
<version>1.0.0+</version>
<association stash.part="true"
xml.reference="true"
java.use-interface="org.apache.archiva.redback.rbac.Operation"
jpox.dependent="false">
<type>JdoOperation</type>
<multiplicity>1</multiplicity>
</association>
</field>
<field jpox.indexed="true"
jpox.persistence-modifier="persistent"
jpox.column="RBAC_RESOURCE">
<name>resource</name>
<version>1.0.0+</version>
<association stash.part="true"
xml.reference="true"
java.use-interface="org.apache.archiva.redback.rbac.Resource"
jpox.dependent="false">
<type>JdoResource</type>
<multiplicity>1</multiplicity>
</association>
</field>
</fields>
</class>
<class jpox.stashable="true"
jpox.table="OPERATIONS">
<name>JdoOperation</name>
<version>1.0.0+</version>
<interfaces>
<interface>org.apache.archiva.redback.rbac.Operation</interface>
</interfaces>
<fields>
<field jpox.primary-key="true" jpox.value-strategy="off">
<name>name</name>
<version>1.0.0+</version>
<type>String</type>
<identifier>true</identifier>
</field>
<field>
<name>description</name>
<version>1.0.0+</version>
<type>String</type>
</field>
<field>
<name>permanent</name>
<version>1.0.0+</version>
<type>boolean</type>
<description>
true if this object is permanent.
</description>
</field>
<field>
<name>resourceRequired</name>
<version>1.0.0+</version>
<type>boolean</type>
<description>
true if the resource is required for authorization to be granted
</description>
</field>
</fields>
</class>
<class jpox.stashable="true"
jpox.table="RESOURCES">
<name>JdoResource</name>
<version>1.0.0+</version>
<description>
In RBAC terms, this is the entity which an operation is associated with that which permissions are based on.
</description>
<interfaces>
<interface>org.apache.archiva.redback.rbac.Resource</interface>
</interfaces>
<fields>
<field jpox.primary-key="true" jpox.value-strategy="off">
<name>identifier</name>
<version>1.0.0+</version>
<type>String</type>
<description>
The string identifier for a resource.
</description>
<identifier>true</identifier>
</field>
<field>
<name>pattern</name>
<version>1.0.0+</version>
<type>boolean</type>
<description>
true if the identifer is a pattern that is to be evaluated, for example x.* could match x.a or x.b and x.**
could match x.foo
</description>
</field>
<field>
<name>permanent</name>
<version>1.0.0+</version>
<type>boolean</type>
<description>
true if this object is permanent.
</description>
</field>
</fields>
</class>
<class jpox.stashable="true"
jpox.table="USER_ASSIGNMENTS">
<name>JdoUserAssignment</name>
<description>binding of a principal to a role</description>
<version>1.0.0+</version>
<interfaces>
<interface>org.apache.archiva.redback.rbac.UserAssignment</interface>
</interfaces>
<superClass>org.apache.archiva.redback.rbac.AbstractUserAssignment</superClass>
<fields>
<field jpox.primary-key="true" jpox.value-strategy="off">
<name>principal</name>
<version>1.0.0+</version>
<type>String</type>
<identifier>true</identifier>
</field>
<field jpox.column="LAST_UPDATED" xml.format="long">
<name>timestamp</name>
<version>1.0.0+</version>
<type>Date</type>
</field>
<field>
<name>permanent</name>
<version>1.0.0+</version>
<type>boolean</type>
<description>
true if this object is permanent.
</description>
</field>
<field java.adder="false"
jpox.persistence-modifier="persistent"
jpox.indexed="false"
jpox.join-table="USERASSIGNMENT_ROLENAMES">
<name>roleNames</name>
<version>1.0.0+</version>
<association stash.part="true"
jpox.join="true"
java.init="field"
java.generate-break="false"
java.generate-create="false">
<type>String</type>
<multiplicity>*</multiplicity>
</association>
</field>
</fields>
</class>
</classes>
</model>

View File

@ -1,34 +0,0 @@
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
default-lazy-init="true">
<bean name="rbacManager#jdo" class="org.apache.archiva.redback.rbac.jdo.JdoRbacManager" init-method="initialize">
<property name="jdo" ref="jdoTool"/>
</bean>
<bean id="jdoTool" class="org.apache.archiva.redback.rbac.jdo.JdoTool" init-method="initialize" lazy-init="true">
<property name="jdoFactory" ref="jdoFactory#users"/>
</bean>
</beans>

View File

@ -1,219 +0,0 @@
package org.apache.archiva.redback.rbac.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.common.jdo.test.StoreManagerDebug;
import org.apache.archiva.redback.components.jdo.DefaultConfigurableJdoFactory;
import org.apache.archiva.redback.rbac.RBACManager;
import org.apache.archiva.redback.rbac.RbacManagerException;
import org.apache.archiva.redback.tests.AbstractRbacManagerTestCase;
import org.jpox.AbstractPersistenceManagerFactory;
import org.jpox.SchemaTool;
import org.junit.Before;
import org.springframework.test.annotation.DirtiesContext;
import javax.inject.Inject;
import javax.inject.Named;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import java.io.File;
import java.net.URL;
import java.util.Map;
import java.util.Properties;
/**
* JdoRbacManagerTest:
*
* @author Jesse McConnell
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
*/
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class JdoRbacManagerTest
extends AbstractRbacManagerTestCase
{
private StoreManagerDebug storeManager;
@Inject
@Named(value = "jdoFactory#users")
DefaultConfigurableJdoFactory jdoFactory;
@Inject
@Named(value = "rbacManager#jdo")
RBACManager rbacManager;
public static int EVENTCOUNT = 2;
@Override
public void assertEventCount()
{
assertEquals( EVENTCOUNT, eventTracker.initCount );
}
/**
* Creates a new RbacStore which contains no data.
*/
@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(
System.getProperty( "jdo.test.driver", "org.hsqldb.jdbcDriver" ) ); //$NON-NLS-1$ //$NON-NLS-2$
jdoFactory.setUrl(
System.getProperty( "jdo.test.url", "jdbc:hsqldb:mem:" + getName() ) ); //$NON-NLS-1$ //$NON-NLS-2$
jdoFactory.setUserName( System.getProperty( "jdo.test.user", "sa" ) ); //$NON-NLS-1$
jdoFactory.setPassword( System.getProperty( "jdo.test.pass", "" ) ); //$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.autoCreateTables", "true" );
jdoFactory.setProperty( "javax.jdo.option.RetainValues", "true" );
jdoFactory.setProperty( "javax.jdo.option.RestoreValues", "true" );
// jdoFactory.setProperty( "org.jpox.autoCreateColumns", "true" );
jdoFactory.setProperty( "org.jpox.validateTables", "true" );
jdoFactory.setProperty( "org.jpox.validateColumns", "true" );
jdoFactory.setProperty( "org.jpox.validateConstraints", "true" );
/* Enable the level 2 Ehcache class-based cache */
jdoFactory.setProperty( "org.jpox.cache.level2", "true" );
jdoFactory.setProperty( "org.jpox.cache.level2.type", "ehcacheclassbased" );
jdoFactory.setProperty( "org.jpox.cache.level2.configurationFile", "/ehcache.xml" ); // ehcache config
jdoFactory.setProperty( "org.jpox.cache.level2.cacheName", "default" ); // default cache name
Properties properties = jdoFactory.getProperties();
for ( Map.Entry<Object, Object> entry : properties.entrySet() )
{
System.setProperty( (String) entry.getKey(), (String) entry.getValue() );
}
URL[] jdoFileUrls =
new URL[]{ getClass().getResource( "/org/apache/archiva/redback/rbac/jdo/package.jdo" ) }; //$NON-NLS-1$
if ( ( jdoFileUrls == null ) || ( jdoFileUrls[0] == null ) )
{
fail( "Unable to process test " + getName() + " - missing package.jdo." );
}
File propsFile = null; // intentional
boolean verbose = true;
PersistenceManagerFactory pmf = jdoFactory.getPersistenceManagerFactory();
assertNotNull( pmf );
/* set our own Store Manager to allow counting SQL statements */
StoreManagerDebug.setup( (AbstractPersistenceManagerFactory) pmf );
/* clean up the db */
SchemaTool.deleteSchemaTables( jdoFileUrls, new URL[]{ }, propsFile, verbose );
SchemaTool.createSchemaTables( jdoFileUrls, new URL[]{ }, propsFile, verbose, null );
PersistenceManager pm = pmf.getPersistenceManager();
pm.close();
setRbacManager( rbacManager );
/* save the store manager to access the queries executed */
JdoRbacManager rbacManager = (JdoRbacManager) getRbacManager();
storeManager = StoreManagerDebug.getConfiguredStoreManager( rbacManager.getJdo().getPersistenceManager() );
}
@Override
public void testGetAssignedRoles()
throws RbacManagerException
{
storeManager.resetCounter();
super.testGetAssignedRoles();
int counter = storeManager.counter();
/* without Level 2 cache: 15 queries */
/* with Level 2 cache: 8 queries */
assertEquals( "Number of SQL queries", 8, counter );
}
@Override
public void testGetAssignedPermissionsDeep()
throws RbacManagerException
{
super.testGetAssignedPermissionsDeep();
int counter = storeManager.counter();
/* without Level 2 cache: 26 queries */
/* with Level 2 cache: 10 queries */
assertEquals( "Number of SQL queries", 10, counter );
}
@Override
protected void afterSetup()
{
super.afterSetup();
storeManager.resetCounter();
}
@Override
public void testLargeApplicationInit()
throws RbacManagerException
{
this.clearCache();
super.testLargeApplicationInit();
}
@Override
public void testGetRolesDeep()
throws RbacManagerException
{
this.clearCache();
super.testGetRolesDeep();
}
@Override
public void testStoreInitialization()
throws Exception
{
this.clearCache();
rbacManager.eraseDatabase();
eventTracker.rbacInit( true );
super.testStoreInitialization();
assertEquals( EVENTCOUNT, eventTracker.initCount );
}
}

View File

@ -1,198 +0,0 @@
package org.apache.archiva.redback.rbac.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 java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import javax.xml.stream.XMLStreamException;
import junit.framework.TestCase;
import org.apache.archiva.redback.rbac.Operation;
import org.apache.archiva.redback.rbac.Permission;
import org.apache.archiva.redback.rbac.Resource;
import org.apache.archiva.redback.rbac.jdo.io.stax.RbacJdoModelStaxReader;
import org.apache.archiva.redback.rbac.jdo.io.stax.RbacJdoModelStaxWriter;
/**
* Test the StAX reader and writer generated.
*/
public class RbacJdoModelStaxTest
extends TestCase
{
@SuppressWarnings("unchecked")
public void testStax()
throws IOException, XMLStreamException
{
RbacDatabase database = new RbacDatabase();
JdoRole role = new JdoRole();
role.setAssignable( true );
role.setDescription( "descriptor" );
role.setName( "name" );
role.setPermanent( true );
role.addChildRoleName( "childRole1" );
role.addChildRoleName( "childRole2" );
JdoPermission permission = new JdoPermission();
permission.setDescription( "permDesc" );
permission.setName( "permName" );
JdoOperation operation = new JdoOperation();
operation.setDescription( "opDesc" );
operation.setName( "opName" );
operation.setPermanent( true );
operation.setResourceRequired( true );
permission.setOperation( operation );
database.addOperation( operation );
JdoResource resource = new JdoResource();
resource.setIdentifier( "resId" );
resource.setPattern( true );
resource.setPermanent( true );
permission.setResource( resource );
database.addResource( resource );
permission.setPermanent( true );
role.addPermission( permission );
database.addPermission( permission );
database.addRole( role );
JdoUserAssignment assignment = new JdoUserAssignment();
assignment.setPermanent( false );
assignment.setPrincipal( "principal" );
assignment.setTimestamp( new Date() );
assignment.addRoleName( "name" );
database.addUserAssignment( assignment );
StringWriter w = new StringWriter();
new RbacJdoModelStaxWriter().write( w, database );
RbacDatabase newDatabase = new RbacJdoModelStaxReader().read( new StringReader( w.toString() ) );
List<JdoRole> expectedRoles = database.getRoles();
List<JdoRole> roles = newDatabase.getRoles();
assertEquals( expectedRoles.size(), roles.size() );
for ( JdoRole r : roles )
{
boolean found = false;
for ( JdoRole expectedRole : expectedRoles )
{
if ( expectedRole.getName().equals( r.getName() ) )
{
found = true;
assertRole( expectedRole, r );
}
}
if ( !found )
{
fail( "Couldn't find role: " + r.getName() );
}
}
List<JdoUserAssignment> expectedUserAssignments = database.getUserAssignments();
List<JdoUserAssignment> userAssignments = newDatabase.getUserAssignments();
assertEquals( expectedUserAssignments.size(), userAssignments.size() );
for ( JdoUserAssignment a : userAssignments )
{
boolean found = false;
for ( JdoUserAssignment expectedAssignment : expectedUserAssignments )
{
if ( expectedAssignment.getPrincipal().equals( a.getPrincipal() ) )
{
found = true;
assertUserAssignment( expectedAssignment, a );
}
}
if ( !found )
{
fail( "Couldn't find assignment: " + a.getPrincipal() );
}
}
}
@SuppressWarnings("unchecked")
private void assertRole( JdoRole expectedRole, JdoRole role )
{
assertEquals( expectedRole.getDescription(), role.getDescription() );
assertPermissions( expectedRole.getPermissions(), role.getPermissions() );
assertEquals( expectedRole.getChildRoleNames(), role.getChildRoleNames() );
}
private void assertUserAssignment( JdoUserAssignment expectedAssignment, JdoUserAssignment assignment )
{
SimpleDateFormat sdf = new SimpleDateFormat( "EEE, d MMM yyyy HH:mm:ss Z", Locale.US );
assertNotNull( expectedAssignment.getTimestamp() );
assertNotNull( assignment.getTimestamp() );
assertEquals( sdf.format( expectedAssignment.getTimestamp() ), sdf.format( assignment.getTimestamp() ) );
assertEquals( expectedAssignment.getRoleNames(), assignment.getRoleNames() );
}
private void assertPermissions( List<Permission> expectedPermissions, List<Permission> permissions )
{
assertEquals( expectedPermissions.size(), permissions.size() );
for ( Permission permission : permissions )
{
boolean found = false;
for ( Permission expectedPermission : expectedPermissions )
{
if ( expectedPermission.getName().equals( permission.getName() ) )
{
found = true;
assertPermission( expectedPermission, permission );
}
}
if ( !found )
{
fail( "Couldn't find permission: " + permission.getName() );
}
}
}
private void assertPermission( Permission expectedPermission, Permission permission )
{
assertEquals( expectedPermission.getDescription(), permission.getDescription() );
assertOperation( expectedPermission.getOperation(), permission.getOperation() );
assertResource( expectedPermission.getResource(), permission.getResource() );
}
private void assertResource( Resource expectedResource, Resource resource )
{
assertEquals( expectedResource.getIdentifier(), resource.getIdentifier() );
}
private void assertOperation( Operation expectedOperation, Operation operation )
{
assertEquals( expectedOperation.getName(), operation.getName() );
assertEquals( expectedOperation.getDescription(), operation.getDescription() );
}
}

View File

@ -1,90 +0,0 @@
<?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.
-->
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">
<diskStore path="java.io.tmpdir" />
<!--
Redback EHCACHE config file that can be used with JPOX-Ehcache integration
For reference http://ehcache.sourceforge.net/documentation/configuration.html
-->
<!-- make default cache very short lived -->
<defaultCache
maxElementsInMemory="100"
maxElementsOnDisk="0"
eternal="false"
overflowToDisk="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LFU" />
<!--
cache Redback classes longer to avoid a lot of SQL queries
See REDBACK-227
-->
<cache name="org.apache.archiva.redback.rbac.jdo.JdoOperation"
maxElementsInMemory="10000"
maxElementsOnDisk="0"
eternal="false"
overflowToDisk="false"
timeToIdleSeconds="3000"
timeToLiveSeconds="6000"
memoryStoreEvictionPolicy="LFU" />
<cache name="org.apache.archiva.redback.rbac.jdo.JdoPermission"
maxElementsInMemory="10000"
maxElementsOnDisk="0"
eternal="false"
overflowToDisk="false"
timeToIdleSeconds="3000"
timeToLiveSeconds="6000"
memoryStoreEvictionPolicy="LFU" />
<cache name="org.apache.archiva.redback.rbac.jdo.JdoResource"
maxElementsInMemory="10000"
maxElementsOnDisk="0"
eternal="false"
overflowToDisk="false"
timeToIdleSeconds="3000"
timeToLiveSeconds="6000"
memoryStoreEvictionPolicy="LFU" />
<cache name="org.apache.archiva.redback.rbac.jdo.JdoRole"
maxElementsInMemory="10000"
maxElementsOnDisk="0"
eternal="false"
overflowToDisk="false"
timeToIdleSeconds="3000"
timeToLiveSeconds="6000"
memoryStoreEvictionPolicy="LFU" />
<cache name="org.apache.archiva.redback.rbac.jdo.JdoUserAssignment"
maxElementsInMemory="10000"
maxElementsOnDisk="0"
eternal="false"
overflowToDisk="false"
timeToIdleSeconds="3000"
timeToLiveSeconds="6000"
memoryStoreEvictionPolicy="LFU" />
</ehcache>

View File

@ -1,85 +0,0 @@
<?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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<bean name="jdoFactory#users" class="org.apache.archiva.redback.components.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>
<prop key="org.jpox.cache.level2">true</prop>
<prop key="org.jpox.cache.level2.type">ehcacheclassbased</prop>
<prop key="org.jpox.cache.level2.configurationFile">/ehcache.xml</prop>
<prop key="org.jpox.cache.level2.cacheName">defaultfake</prop>
</props>
</property>
</bean>
<!--
*** jpa init ***
Needed because of the dependency redback-user-cache -> redback-user-jpa
***
-->
<bean name="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="jpaVendorAdapter" >
<bean class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter" />
</property>
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence-hsqldb.xml" />
<property name="jpaPropertyMap">
<map>
<entry key="openjpa.ConnectionURL" value="jdbc:hsqldb:mem:redback_database" />
<entry key="openjpa.ConnectionDriverName" value="org.hsqldb.jdbcDriver" />
<entry key="openjpa.ConnectionUserName" value="sa" />
<entry key="openjpa.ConnectionPassword" value="" />
<entry key="openjpa.Log" value="DefaultLevel=TRACE, Runtime=TRACE, Tool=INFO, SQL=TRACE" />
<entry key="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
<entry key="openjpa.jdbc.MappingDefaults"
value="ForeignKeyDeleteAction=restrict,JoinForeignKeyDeleteAction=restrict"/>
</map>
</property>
</bean>
<bean name="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" >
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven />
<!-- **** jpa init *** -->
<bean name="userConfiguration#default" class="org.apache.archiva.redback.configuration.DefaultUserConfiguration">
<property name="registry" ref="test-conf"/>
</bean>
<bean name="commons-configuration" class="org.apache.archiva.redback.components.registry.commons.CommonsConfigurationRegistry">
</bean>
<alias name="commons-configuration" alias="test-conf"/>
</beans>

View File

@ -1,176 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<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.apache.archiva.redback</groupId>
<artifactId>redback-users-providers</artifactId>
<version>2.5-SNAPSHOT</version>
</parent>
<artifactId>redback-users-jdo</artifactId>
<packaging>jar</packaging>
<name>Redback :: Users Provider :: JDO</name>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva.redback</groupId>
<artifactId>redback-common-jdo</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva.redback</groupId>
<artifactId>redback-policy</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.apache.archiva.redback</groupId>
<artifactId>redback-users-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>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<configuration>
<version>1.0.1</version>
<packageWithVersion>false</packageWithVersion>
<models>
<model>src/main/mdo/user.mdo</model>
</models>
</configuration>
<executions>
<execution>
<id>modello-java</id>
<goals>
<goal>java</goal>
<goal>stax-reader</goal>
<goal>stax-writer</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.archiva.redback.components.modello</groupId>
<artifactId>jpox-modello-maven-plugin</artifactId>
<configuration>
<version>1.0.1</version>
<packageWithVersion>false</packageWithVersion>
<models>
<model>src/main/mdo/user.mdo</model>
</models>
</configuration>
<executions>
<execution>
<id>modello-jpox</id>
<goals>
<goal>jpox-metadata-class</goal>
</goals>
</execution>
<execution>
<id>jpox-jdo-mapping</id>
<goals>
<goal>jpox-jdo-mapping</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}/org/apache/archiva/redback/users/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>

View File

@ -1,466 +0,0 @@
package org.apache.archiva.redback.users.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.components.jdo.JdoFactory;
import org.apache.archiva.redback.components.jdo.RedbackJdoUtils;
import org.apache.archiva.redback.components.jdo.RedbackObjectNotFoundException;
import org.apache.archiva.redback.components.jdo.RedbackStoreException;
import org.apache.archiva.redback.policy.UserSecurityPolicy;
import org.apache.archiva.redback.users.AbstractUserManager;
import org.apache.archiva.redback.users.PermanentUserException;
import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException;
import org.apache.archiva.redback.users.UserQuery;
import org.codehaus.plexus.util.StringUtils;
import org.jpox.JDOClassLoaderResolver;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import javax.jdo.Extent;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import javax.jdo.Query;
import javax.jdo.Transaction;
import java.util.Date;
import java.util.List;
/**
* JdoUserManager
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
*/
@Service("userManager#jdo")
public class JdoUserManager
extends AbstractUserManager
{
@Inject
@Named(value = "jdoFactory#users")
private JdoFactory jdoFactory;
@Inject
private UserSecurityPolicy userSecurityPolicy;
private PersistenceManagerFactory pmf;
public String getId()
{
return "jdo";
}
public boolean isReadOnly()
{
return false;
}
public UserQuery createUserQuery()
{
return new JdoUserQuery();
}
// ------------------------------------------------------------------
public User createUser( String username, String fullname, String email )
{
User user = new JdoUser();
user.setUsername( username );
user.setFullName( fullname );
user.setEmail( email );
user.setAccountCreationDate( new Date() );
return user;
}
public List<User> getUsers()
{
return getAllObjectsDetached( null );
}
public List<User> getUsers( boolean orderAscending )
{
String ordering = orderAscending ? "username ascending" : "username descending";
return getAllObjectsDetached( ordering );
}
@SuppressWarnings("unchecked")
private List<User> getAllObjectsDetached( String ordering )
{
return RedbackJdoUtils.getAllObjectsDetached( getPersistenceManager(), JdoUser.class, ordering, (String) null );
}
public List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending )
{
return findUsers( "username", usernameKey, orderAscending );
}
public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
{
return findUsers( "fullName", fullNameKey, orderAscending );
}
public List<User> findUsersByEmailKey( String emailKey, boolean orderAscending )
{
return findUsers( "email", emailKey, orderAscending );
}
@SuppressWarnings("unchecked")
public List<User> findUsersByQuery( UserQuery userQuery )
{
JdoUserQuery uq = (JdoUserQuery) userQuery;
PersistenceManager pm = getPersistenceManager();
Transaction tx = pm.currentTransaction();
try
{
tx.begin();
Extent extent = pm.getExtent( JdoUser.class, true );
Query query = pm.newQuery( extent );
String ordering = uq.getOrdering();
query.setOrdering( ordering );
query.declareImports( "import java.lang.String" );
query.declareParameters( uq.getParameters() );
query.setFilter( uq.getFilter() );
query.setRange( uq.getFirstResult(),
uq.getMaxResults() < 0 ? Long.MAX_VALUE : uq.getFirstResult() + uq.getMaxResults() );
List<User> result = (List<User>) query.executeWithArray( uq.getSearchKeys() );
result = (List<User>) pm.detachCopyAll( result );
tx.commit();
return result;
}
finally
{
rollback( tx );
}
}
@SuppressWarnings("unchecked")
private List<User> findUsers( String searchField, String searchKey, boolean ascendingUsername )
{
PersistenceManager pm = getPersistenceManager();
Transaction tx = pm.currentTransaction();
try
{
tx.begin();
Extent extent = pm.getExtent( JdoUser.class, true );
Query query = pm.newQuery( extent );
String ordering = ascendingUsername ? "username ascending" : "username descending";
query.setOrdering( ordering );
query.declareImports( "import java.lang.String" );
query.declareParameters( "String searchKey" );
query.setFilter( "this." + searchField + ".toLowerCase().indexOf(searchKey.toLowerCase()) > -1" );
List<User> result = (List<User>) query.execute( searchKey );
result = (List<User>) pm.detachCopyAll( result );
tx.commit();
return result;
}
finally
{
rollback( tx );
}
}
public User addUser( User user )
throws UserManagerException
{
if ( !( user instanceof JdoUser ) )
{
throw new UserManagerException( "Unable to Add User. User object " + user.getClass().getName() +
" is not an instance of " + JdoUser.class.getName() );
}
if ( StringUtils.isEmpty( user.getUsername() ) )
{
throw new IllegalStateException(
Messages.getString( "user.manager.cannot.add.user.without.username" ) ); //$NON-NLS-1$
}
userSecurityPolicy.extensionChangePassword( user );
fireUserManagerUserAdded( user );
// TODO: find a better solution
// workaround for avoiding the admin from providing another password on the next login after the
// admin account has been created
// extensionChangePassword by default sets the password change status to false
if ( "admin".equals( user.getUsername() ) )
{
user.setPasswordChangeRequired( false );
}
else
{
user.setPasswordChangeRequired( true );
}
return (User) addObject( user );
}
public void deleteUser( String username )
throws UserManagerException
{
try
{
User user = findUser( username );
if ( user.isPermanent() )
{
throw new PermanentUserException( "Cannot delete permanent user [" + user.getUsername() + "]." );
}
fireUserManagerUserRemoved( user );
RedbackJdoUtils.removeObject( getPersistenceManager(), user );
}
catch ( UserNotFoundException e )
{
log.warn( "Unable to delete user {}, user not found.", username, e );
}
}
public void addUserUnchecked( User user )
throws UserManagerException
{
if ( !( user instanceof JdoUser ) )
{
throw new UserManagerException( "Unable to Add User. User object " + user.getClass().getName() +
" is not an instance of " + JdoUser.class.getName() );
}
if ( StringUtils.isEmpty( user.getUsername() ) )
{
throw new IllegalStateException(
Messages.getString( "user.manager.cannot.add.user.without.username" ) ); //$NON-NLS-1$
}
addObject( user );
}
public void eraseDatabase()
{
RedbackJdoUtils.removeAll( getPersistenceManager(), JdoUser.class );
RedbackJdoUtils.removeAll( getPersistenceManager(), UsersManagementModelloMetadata.class );
}
public User findUser( String username )
throws UserNotFoundException, UserManagerException
{
if ( StringUtils.isEmpty( username ) )
{
throw new UserNotFoundException( "User with empty username not found." );
}
return (User) getObjectById( username, null );
}
@Override
public User findUser( String username, boolean useCache )
throws UserNotFoundException, UserManagerException
{
return findUser( username );
}
public boolean userExists( String principal )
throws UserManagerException
{
try
{
findUser( principal );
return true;
}
catch ( UserNotFoundException ne )
{
return false;
}
}
public User updateUser( User user )
throws UserNotFoundException, UserManagerException
{
return updateUser( user, false );
}
public User updateUser( User user, boolean passwordChangeRequired )
throws UserNotFoundException, UserManagerException
{
if ( !( user instanceof JdoUser ) )
{
throw new UserManagerException( "Unable to Update User. User object " + user.getClass().getName() +
" is not an instance of " + JdoUser.class.getName() );
}
// If password is supplied, assume changing of password.
// TODO: Consider adding a boolean to the updateUser indicating a password change or not.
if ( StringUtils.isNotEmpty( user.getPassword() ) )
{
userSecurityPolicy.extensionChangePassword( user, passwordChangeRequired );
}
user = (User) updateObject( user );
fireUserManagerUserUpdated( user );
return user;
}
@PostConstruct
public void initialize()
{
JDOClassLoaderResolver d;
pmf = jdoFactory.getPersistenceManagerFactory();
}
public PersistenceManager getPersistenceManager()
{
PersistenceManager pm = pmf.getPersistenceManager();
pm.getFetchPlan().setMaxFetchDepth( -1 );
triggerInit();
return pm;
}
// ----------------------------------------------------------------------
// jdo utility methods
// ----------------------------------------------------------------------
private Object addObject( Object object )
{
return RedbackJdoUtils.addObject( getPersistenceManager(), object );
}
private Object getObjectById( String id, String fetchGroup )
throws UserNotFoundException, UserManagerException
{
try
{
return RedbackJdoUtils.getObjectById( getPersistenceManager(), JdoUser.class, id, fetchGroup );
}
catch ( RedbackObjectNotFoundException e )
{
throw new UserNotFoundException( e.getMessage() );
}
catch ( RedbackStoreException e )
{
throw new UserManagerException( "Unable to get object '" + JdoUser.class.getName() + "', id '" + id +
"', fetch-group '" + fetchGroup + "' from jdo store.", e );
}
}
private Object removeObject( Object o )
throws UserManagerException
{
if ( o == null )
{
throw new UserManagerException( "Unable to remove null object" );
}
RedbackJdoUtils.removeObject( getPersistenceManager(), o );
return o;
}
private Object updateObject( Object object )
throws UserNotFoundException, UserManagerException
{
try
{
return RedbackJdoUtils.updateObject( getPersistenceManager(), object );
}
catch ( RedbackStoreException e )
{
throw new UserManagerException(
"Unable to update the '" + object.getClass().getName() + "' object in the jdo database. Cause: " + e.getMessage(), e );
}
}
private void rollback( Transaction tx )
{
RedbackJdoUtils.rollbackIfActive( tx );
}
private boolean hasTriggeredInit = false;
public void triggerInit()
{
if ( !hasTriggeredInit )
{
hasTriggeredInit = true;
List<User> users = getAllObjectsDetached( null );
fireUserManagerInit( users.isEmpty() );
}
}
public JdoFactory getJdoFactory()
{
return jdoFactory;
}
public void setJdoFactory( JdoFactory jdoFactory )
{
this.jdoFactory = jdoFactory;
}
public UserSecurityPolicy getUserSecurityPolicy()
{
return userSecurityPolicy;
}
public boolean isFinalImplementation()
{
return true;
}
public String getDescriptionKey()
{
return "archiva.redback.usermanager.jdo";
}
}

View File

@ -1,136 +0,0 @@
package org.apache.archiva.redback.users.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.users.AbstractUserQuery;
import org.apache.archiva.redback.users.UserQuery;
import org.codehaus.plexus.util.StringUtils;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class JdoUserQuery
extends AbstractUserQuery
{
/**
* Create the ordering string for use in {@link javax.jdo.Query#setOrdering(String)}
*
* @return the created filter
*/
public String getOrdering()
{
StringBuilder ordering = new StringBuilder();
if ( UserQuery.ORDER_BY_EMAIL.equals( getOrderBy() ) )
{
ordering.append( "email" );
}
else if ( UserQuery.ORDER_BY_FULLNAME.equals( getOrderBy() ) )
{
ordering.append( "fullName" );
}
else
{
ordering.append( "username" );
}
ordering.append( " " ).append( isAscending() ? "ascending" : "descending" );
return ordering.toString();
}
/**
* Create and return the filter string for use in {@link javax.jdo.Query#setFilter(String)}
*
* @return the query filter
*/
public String getFilter()
{
Set<String> terms = new HashSet<String>();
if ( getUsername() != null )
{
terms.add( "this.username.toLowerCase().indexOf(usernameKey.toLowerCase()) > -1" );
}
if ( getFullName() != null )
{
terms.add( "this.fullName.toLowerCase().indexOf(fullNameKey.toLowerCase()) > -1" );
}
if ( getEmail() != null )
{
terms.add( "this.email.toLowerCase().indexOf(emailKey.toLowerCase()) > -1" );
}
return StringUtils.join( terms.iterator(), " && " );
}
/**
* Return an array of parameters for user in {@link javax.jdo.Query#executeWithArray(Object[])}
*
* @return the parameter array
*/
public String[] getSearchKeys()
{
List<String> keys = new ArrayList<String>();
if ( getUsername() != null )
{
keys.add( getUsername() );
}
if ( getFullName() != null )
{
keys.add( getFullName() );
}
if ( getEmail() != null )
{
keys.add( getEmail() );
}
return keys.toArray( new String[keys.size()] );
}
/**
* Returns the parameters for use in {@link javax.jdo.Query#declareParameters(String)}
*
* @return the parameter list
*/
public String getParameters()
{
List<String> params = new ArrayList<String>();
if ( getUsername() != null )
{
params.add( "String usernameKey" );
}
if ( getFullName() != null )
{
params.add( "String fullNameKey" );
}
if ( getEmail() != null )
{
params.add( "String emailKey" );
}
return StringUtils.join( params.iterator(), ", " );
}
}

View File

@ -1,94 +0,0 @@
package org.apache.archiva.redback.users.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 java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
/**
* Localized Message Handling.
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
*
*/
public class Messages
{
private static final String BUNDLE_NAME = "org.apache.archiva.redback.users.jdo"; //$NON-NLS-1$
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( BUNDLE_NAME );
/**
* Get a Message as-is from the Resource Bundle.
*
* @param key the key for the message to get.
* @return the value of the key, or "!key!" if the key is not found.
*/
public static String getString( String key )
{
try
{
return RESOURCE_BUNDLE.getString( key );
}
catch ( MissingResourceException e )
{
return '!' + key + '!';
}
}
/**
* Gets a Message from the Resource Bundle, with {1} and {2} style arguments.
*
* @param key the key for the message to get.
* @param arg the argument to pass in.
* @return the value of the key, or "!key!" if the key is not found.
*/
public static String getString( String key, Object arg )
{
return getString( key, new Object[] { arg } );
}
/**
* Gets a Message from the Resource Bundle, with {1} and {2} style arguments.
*
* @param key the key for the message to get.
* @param args the arguments to pass in.
* @return the value of the key, or "!key!" if the key is not found.
*/
public static String getString( String key, Object args[] )
{
try
{
String pattern = RESOURCE_BUNDLE.getString( key );
return MessageFormat.format( pattern, args );
}
catch ( MissingResourceException e )
{
return '!' + key + '!';
}
}
/**
* Prevent Instantiation.
*/
private Messages()
{
}
}

View File

@ -1,162 +0,0 @@
<?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.
-->
<model>
<id>redback-users-jdo</id>
<name>UsersManagement</name>
<version>1.0.1</version>
<description>Archiva Redback Users object model.</description>
<defaults>
<default>
<key>package</key>
<value>org.apache.archiva.redback.users.jdo</value>
</default>
</defaults>
<classes>
<class stash.storable="false" rootElement="true">
<name>UserDatabase</name>
<version>1.0.1+</version>
<fields>
<field>
<name>users</name>
<version>1.0.1+</version>
<association>
<type>JdoUser</type>
<multiplicity>*</multiplicity>
</association>
</field>
</fields>
</class>
<class stash.storable="true" jpox.use-identifiers-as-primary-key="false">
<name>JdoUser</name>
<version>1.0.0+</version>
<interfaces>
<interface>org.apache.archiva.redback.users.User</interface>
</interfaces>
<description></description>
<fields>
<field jpox.primary-key="true" jpox.value-strategy="off" jpox.persistence-modifier="persistent">
<name>username</name>
<version>1.0.0+</version>
<type>String</type>
<identifier>true</identifier>
</field>
<field jpox.column="USER_PASSWORD">
<name>password</name>
<version>1.0.0+</version>
<type>String</type>
<identifier>true</identifier>
</field>
<field>
<name>encodedPassword</name>
<version>1.0.0+</version>
<type>String</type>
<identifier>true</identifier>
</field>
<field>
<name>fullName</name>
<version>1.0.0+</version>
<type>String</type>
<identifier>true</identifier>
</field>
<field>
<name>email</name>
<version>1.0.0+</version>
<type>String</type>
<identifier>true</identifier>
</field>
<field xml.format="long">
<name>lastPasswordChange</name>
<version>1.0.0+</version>
<type>Date</type>
</field>
<field xml.format="long">
<name>lastLoginDate</name>
<version>1.0.0+</version>
<type>Date</type>
</field>
<field>
<name>countFailedLoginAttempts</name>
<version>1.0.0+</version>
<type>int</type>
</field>
<field>
<name>locked</name>
<version>1.0.0+</version>
<type>boolean</type>
<defaultValue>false</defaultValue>
<identifier>true</identifier>
</field>
<field>
<name>permanent</name>
<version>1.0.0+</version>
<type>boolean</type>
<defaultValue>false</defaultValue>
<identifier>true</identifier>
</field>
<field>
<name>validated</name>
<version>1.0.0+</version>
<type>boolean</type>
<defaultValue>false</defaultValue>
<identifier>true</identifier>
</field>
<field>
<name>passwordChangeRequired</name>
<version>1.0.0+</version>
<type>boolean</type>
<defaultValue>false</defaultValue>
<identifier>true</identifier>
</field>
<field>
<name>previousEncodedPasswords</name>
<version>1.0.0+</version>
<association stash.part="true">
<type>String</type>
<multiplicity>*</multiplicity>
</association>
</field>
<field xml.format="long">
<name>accountCreationDate</name>
<version>1.0.0+</version>
<type>Date</type>
</field>
</fields>
<codeSegments>
<codeSegment>
<version>1.0.0+</version>
<code><![CDATA[
public JdoUser()
{
// Intentionally initialize List to avoid JPOX NullPointerException Issues.
previousEncodedPasswords = new java.util.ArrayList<String>();
}
public String getUserManagerId()
{
return "jdo";
}
]]></code>
</codeSegment>
</codeSegments>
</class>
</classes>
</model>

View File

@ -1,33 +0,0 @@
<?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.apache.archiva.redback.users.jdo"/>
</beans>

View File

@ -1,18 +0,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.
user.manager.cannot.add.user.without.username=User.username must be supplied on an .addUser() request.
user.manager.cannot.add.user.without.password=User.password must be supplied on an .addUser() request.

View File

@ -1,117 +0,0 @@
package org.apache.archiva.redback.users.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.components.jdo.DefaultConfigurableJdoFactory;
import org.apache.archiva.redback.common.jdo.test.StoreManagerDebug;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.provider.test.AbstractUserManagerTestCase;
import org.jpox.AbstractPersistenceManagerFactory;
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;
/**
* JdoUserManagerTest
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
*/
public class JdoUserManagerTest
extends AbstractUserManagerTestCase
{
@Inject
@Named(value = "jdoFactory#users")
DefaultConfigurableJdoFactory jdoFactory;
@Inject
@Named(value = "userManager#jdo")
JdoUserManager jdoUserManager;
private StoreManagerDebug storeManager;
@Before
public void setUp()
throws Exception
{
super.setUp();
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$
Properties properties = jdoFactory.getProperties();
for ( Map.Entry<?, ?> entry : properties.entrySet() )
{
System.setProperty( (String) entry.getKey(), (String) entry.getValue() );
}
PersistenceManagerFactory pmf = jdoFactory.getPersistenceManagerFactory();
assertNotNull( pmf );
/* set our own Store Manager to allow counting SQL statements */
StoreManagerDebug.setup( (AbstractPersistenceManagerFactory) pmf );
SchemaTool.createSchemaTables(
new URL[]{ getClass().getResource( "/org/apache/archiva/redback/users/jdo/package.jdo" ) }, new URL[]{ },
null, false, null ); //$NON-NLS-1$
PersistenceManager pm = pmf.getPersistenceManager();
pm.close();
setUserManager( jdoUserManager );
/* save the store manager to access the queries executed */
JdoUserManager userManager = (JdoUserManager) getUserManager();
storeManager = StoreManagerDebug.getConfiguredStoreManager( userManager.getPersistenceManager() );
}
protected void assertCleanUserManager()
throws UserManagerException
{
// database cleanup
( (JdoUserManager) getUserManager() ).eraseDatabase();
super.assertCleanUserManager();
}
}

View File

@ -1,58 +0,0 @@
<?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.apache.archiva.redback.common.jdo.UserConfigurableJdoFactory">
<constructor-arg>
<ref bean="userConfiguration#default"/>
</constructor-arg>
<!--property name="userConfiguration" ref="userConfiguration#default"/-->
<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=""/>
</bean>
<bean name="userConfiguration#default" class="org.apache.archiva.redback.configuration.DefaultUserConfiguration">
<property name="registry" ref="test-conf"/>
</bean>
<bean name="commons-configuration" class="org.apache.archiva.redback.components.registry.commons.CommonsConfigurationRegistry">
<property name="properties">
<value>
<![CDATA[
<configuration>
<properties fileName="test.properties" config-name="properties"/>
</configuration>
]]>
</value>
</property>
</bean>
<alias name="commons-configuration" alias="test-conf"/>
</beans>

View File

@ -1,17 +0,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.
jdbc.driver.name=org.hsqldb.jdbcDriver