Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id A3E6E200BFE for ; Sun, 1 Jan 2017 09:21:11 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id A1FD3160B20; Sun, 1 Jan 2017 08:21:11 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 336B7160B44 for ; Sun, 1 Jan 2017 09:21:09 +0100 (CET) Received: (qmail 88556 invoked by uid 500); 1 Jan 2017 08:21:08 -0000 Mailing-List: contact commits-help@archiva.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@archiva.apache.org Delivered-To: mailing list commits@archiva.apache.org Received: (qmail 88359 invoked by uid 99); 1 Jan 2017 08:21:08 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 01 Jan 2017 08:21:08 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 16EE3DFD9D; Sun, 1 Jan 2017 08:21:08 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: olamy@apache.org To: commits@archiva.apache.org Date: Sun, 01 Jan 2017 08:21:11 -0000 Message-Id: In-Reply-To: <77b02694c4be4c569e41be46c001112f@git.apache.org> References: <77b02694c4be4c569e41be46c001112f@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [4/5] archiva-redback-core git commit: get rid of all jdo jpox dependencies archived-at: Sun, 01 Jan 2017 08:21:11 -0000 http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0537b856/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/java/org/apache/archiva/redback/rbac/jdo/JdoTool.java ---------------------------------------------------------------------- diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/java/org/apache/archiva/redback/rbac/jdo/JdoTool.java b/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/java/org/apache/archiva/redback/rbac/jdo/JdoTool.java deleted file mode 100644 index 2d4233e..0000000 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/java/org/apache/archiva/redback/rbac/jdo/JdoTool.java +++ /dev/null @@ -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 Joakim Erdfelt - * - */ -@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 roles = (List) 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 saveObject( T object ) - { - return (T) saveObject( object, null ); - } - - public 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 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 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 getObjectById( Class 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 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; - } -} http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0537b856/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/mdo/rbac-jdo.mdo ---------------------------------------------------------------------- diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/mdo/rbac-jdo.mdo b/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/mdo/rbac-jdo.mdo deleted file mode 100644 index ebd9ecc..0000000 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/mdo/rbac-jdo.mdo +++ /dev/null @@ -1,337 +0,0 @@ - - - - - - rbac-jdo - RbacJdoModel - 1.0.1 - - - package - org.apache.archiva.redback.rbac.jdo - - - - - RbacDatabase - 1.0.1+ - - - roles - 1.0.1+ - - JdoRole - * - - - - permissions - 1.0.1+ - - JdoPermission - * - - - - operations - 1.0.1+ - - JdoOperation - * - - - - resources - 1.0.1+ - - JdoResource - * - - - - userAssignments - 1.0.1+ - - JdoUserAssignment - * - - - - - - - JdoRole - 1.0.0+ - - org.apache.archiva.redback.rbac.Role - - org.apache.archiva.redback.rbac.AbstractRole - - - name - 1.0.0+ - String - true - - - description - 1.0.0+ - String - - - assignable - 1.0.0+ - boolean - - true if this role is available to be assigned to a user - - - - permanent - 1.0.0+ - boolean - - true if this object is permanent. - - - - childRoleNames - 1.0.0+ - - String - * - - - roles that will inherit the permissions of this role - - - - permissions - 1.0.0+ - - JdoPermission - * - - - - - - - JdoPermission - 1.0.0+ - - org.apache.archiva.redback.rbac.Permission - - - - name - 1.0.0+ - String - true - - - description - 1.0.0+ - String - - - permanent - 1.0.0+ - boolean - - true if this object is permanent. - - - - operation - 1.0.0+ - - JdoOperation - 1 - - - - resource - 1.0.0+ - - JdoResource - 1 - - - - - - - JdoOperation - 1.0.0+ - - org.apache.archiva.redback.rbac.Operation - - - - name - 1.0.0+ - String - true - - - description - 1.0.0+ - String - - - permanent - 1.0.0+ - boolean - - true if this object is permanent. - - - - resourceRequired - 1.0.0+ - boolean - - true if the resource is required for authorization to be granted - - - - - - - JdoResource - 1.0.0+ - - In RBAC terms, this is the entity which an operation is associated with that which permissions are based on. - - - org.apache.archiva.redback.rbac.Resource - - - - identifier - 1.0.0+ - String - - The string identifier for a resource. - - true - - - pattern - 1.0.0+ - boolean - - 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 - - - - permanent - 1.0.0+ - boolean - - true if this object is permanent. - - - - - - - JdoUserAssignment - binding of a principal to a role - 1.0.0+ - - org.apache.archiva.redback.rbac.UserAssignment - - org.apache.archiva.redback.rbac.AbstractUserAssignment - - - principal - 1.0.0+ - String - true - - - timestamp - 1.0.0+ - Date - - - permanent - 1.0.0+ - boolean - - true if this object is permanent. - - - - roleNames - 1.0.0+ - - String - * - - - - - - http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0537b856/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/resources/META-INF/spring-context.xml ---------------------------------------------------------------------- diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/resources/META-INF/spring-context.xml b/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/resources/META-INF/spring-context.xml deleted file mode 100644 index 2a3dec1..0000000 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/resources/META-INF/spring-context.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0537b856/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/java/org/apache/archiva/redback/rbac/jdo/JdoRbacManagerTest.java ---------------------------------------------------------------------- diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/java/org/apache/archiva/redback/rbac/jdo/JdoRbacManagerTest.java b/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/java/org/apache/archiva/redback/rbac/jdo/JdoRbacManagerTest.java deleted file mode 100644 index 0572706..0000000 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/java/org/apache/archiva/redback/rbac/jdo/JdoRbacManagerTest.java +++ /dev/null @@ -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 Joakim Erdfelt - */ -@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 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 ); - } - - -} http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0537b856/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/java/org/apache/archiva/redback/rbac/jdo/RbacJdoModelStaxTest.java ---------------------------------------------------------------------- diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/java/org/apache/archiva/redback/rbac/jdo/RbacJdoModelStaxTest.java b/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/java/org/apache/archiva/redback/rbac/jdo/RbacJdoModelStaxTest.java deleted file mode 100644 index cde20d6..0000000 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/java/org/apache/archiva/redback/rbac/jdo/RbacJdoModelStaxTest.java +++ /dev/null @@ -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 expectedRoles = database.getRoles(); - List 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 expectedUserAssignments = database.getUserAssignments(); - List 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 expectedPermissions, List 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() ); - } -} http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0537b856/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/resources/ehcache.xml ---------------------------------------------------------------------- diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/resources/ehcache.xml b/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/resources/ehcache.xml deleted file mode 100644 index 34e6626..0000000 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/resources/ehcache.xml +++ /dev/null @@ -1,90 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0537b856/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/resources/spring-context.xml ---------------------------------------------------------------------- diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/resources/spring-context.xml b/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/resources/spring-context.xml deleted file mode 100644 index 34e8738..0000000 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/resources/spring-context.xml +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - - - - - - - - - JDK_DEFAULT_TIMEZONE - true - true - ehcacheclassbased - /ehcache.xml - defaultfake - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0537b856/redback-users/redback-users-providers/redback-users-jdo/pom.xml ---------------------------------------------------------------------- diff --git a/redback-users/redback-users-providers/redback-users-jdo/pom.xml b/redback-users/redback-users-providers/redback-users-jdo/pom.xml deleted file mode 100644 index 9b889a6..0000000 --- a/redback-users/redback-users-providers/redback-users-jdo/pom.xml +++ /dev/null @@ -1,176 +0,0 @@ - - - - - 4.0.0 - - - org.apache.archiva.redback - redback-users-providers - 2.5-SNAPSHOT - - - redback-users-jdo - jar - Redback :: Users Provider :: JDO - - - - org.codehaus.plexus - plexus-utils - - - org.apache.archiva.redback - redback-common-jdo - - - org.apache.archiva.redback - redback-policy - - - org.springframework - spring-context-support - - - javax.annotation - jsr250-api - - - org.apache.archiva.redback - redback-users-tests - test - - - org.hsqldb - hsqldb - test - - - net.java.dev.stax-utils - stax-utils - 20060502 - - - com.bea.xml - jsr173-ri - - - - - - org.slf4j - slf4j-simple - test - - - org.slf4j - jul-to-slf4j - test - - - - - - - org.apache.felix - maven-bundle-plugin - - - bundle-manifest - process-classes - - manifest - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - - - - org.codehaus.modello - modello-maven-plugin - - 1.0.1 - false - - src/main/mdo/user.mdo - - - - - modello-java - - java - stax-reader - stax-writer - - - - - - org.apache.archiva.redback.components.modello - jpox-modello-maven-plugin - - 1.0.1 - false - - src/main/mdo/user.mdo - - - - - modello-jpox - - jpox-metadata-class - - - - jpox-jdo-mapping - - jpox-jdo-mapping - - - ${project.build.outputDirectory}/org/apache/archiva/redback/users/jdo - - - - - - org.codehaus.mojo - jpox-maven-plugin - - - - enhance - - - - - - - - http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0537b856/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/JdoUserManager.java ---------------------------------------------------------------------- diff --git a/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/JdoUserManager.java b/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/JdoUserManager.java deleted file mode 100644 index 2369a16..0000000 --- a/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/JdoUserManager.java +++ /dev/null @@ -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 Joakim Erdfelt - */ -@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 getUsers() - { - return getAllObjectsDetached( null ); - } - - public List getUsers( boolean orderAscending ) - { - String ordering = orderAscending ? "username ascending" : "username descending"; - - return getAllObjectsDetached( ordering ); - } - - @SuppressWarnings("unchecked") - private List getAllObjectsDetached( String ordering ) - { - return RedbackJdoUtils.getAllObjectsDetached( getPersistenceManager(), JdoUser.class, ordering, (String) null ); - } - - public List findUsersByUsernameKey( String usernameKey, boolean orderAscending ) - { - return findUsers( "username", usernameKey, orderAscending ); - } - - public List findUsersByFullNameKey( String fullNameKey, boolean orderAscending ) - { - return findUsers( "fullName", fullNameKey, orderAscending ); - } - - public List findUsersByEmailKey( String emailKey, boolean orderAscending ) - { - return findUsers( "email", emailKey, orderAscending ); - } - - @SuppressWarnings("unchecked") - public List 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 result = (List) query.executeWithArray( uq.getSearchKeys() ); - - result = (List) pm.detachCopyAll( result ); - - tx.commit(); - - return result; - } - finally - { - rollback( tx ); - } - } - - @SuppressWarnings("unchecked") - private List 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 result = (List) query.execute( searchKey ); - - result = (List) 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 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"; - } -} http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0537b856/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/JdoUserQuery.java ---------------------------------------------------------------------- diff --git a/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/JdoUserQuery.java b/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/JdoUserQuery.java deleted file mode 100644 index 2a06caa..0000000 --- a/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/JdoUserQuery.java +++ /dev/null @@ -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 terms = new HashSet(); - - 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 keys = new ArrayList(); - - 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 params = new ArrayList(); - - 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(), ", " ); - } -} http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0537b856/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/Messages.java ---------------------------------------------------------------------- diff --git a/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/Messages.java b/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/Messages.java deleted file mode 100644 index d067548..0000000 --- a/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/Messages.java +++ /dev/null @@ -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 Joakim Erdfelt - * - */ -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() - { - } -} http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0537b856/redback-users/redback-users-providers/redback-users-jdo/src/main/mdo/user.mdo ---------------------------------------------------------------------- diff --git a/redback-users/redback-users-providers/redback-users-jdo/src/main/mdo/user.mdo b/redback-users/redback-users-providers/redback-users-jdo/src/main/mdo/user.mdo deleted file mode 100644 index b7ca9bb..0000000 --- a/redback-users/redback-users-providers/redback-users-jdo/src/main/mdo/user.mdo +++ /dev/null @@ -1,162 +0,0 @@ - - - - - redback-users-jdo - UsersManagement - 1.0.1 - Archiva Redback Users object model. - - - package - org.apache.archiva.redback.users.jdo - - - - - - UserDatabase - 1.0.1+ - - - users - 1.0.1+ - - JdoUser - * - - - - - - JdoUser - 1.0.0+ - - org.apache.archiva.redback.users.User - - - - - username - 1.0.0+ - String - true - - - password - 1.0.0+ - String - true - - - encodedPassword - 1.0.0+ - String - true - - - fullName - 1.0.0+ - String - true - - - email - 1.0.0+ - String - true - - - lastPasswordChange - 1.0.0+ - Date - - - lastLoginDate - 1.0.0+ - Date - - - countFailedLoginAttempts - 1.0.0+ - int - - - locked - 1.0.0+ - boolean - false - true - - - permanent - 1.0.0+ - boolean - false - true - - - validated - 1.0.0+ - boolean - false - true - - - passwordChangeRequired - 1.0.0+ - boolean - false - true - - - previousEncodedPasswords - 1.0.0+ - - String - * - - - - accountCreationDate - 1.0.0+ - Date - - - - - 1.0.0+ - (); - } - public String getUserManagerId() - { - return "jdo"; - } - - ]]> - - - - -