]> source.dussan.org Git - archiva.git/commitdiff
package move to o.a.a.r module redback-users-jdo
authorOlivier Lamy <olamy@apache.org>
Sat, 7 Apr 2012 18:03:25 +0000 (18:03 +0000)
committerOlivier Lamy <olamy@apache.org>
Sat, 7 Apr 2012 18:03:25 +0000 (18:03 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1310809 13f79535-47bb-0310-9956-ffa450edef68

13 files changed:
redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/JdoUserManager.java [new file with mode: 0644]
redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/JdoUserQuery.java [new file with mode: 0644]
redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/Messages.java [new file with mode: 0644]
redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/JdoUserManager.java [deleted file]
redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/JdoUserQuery.java [deleted file]
redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/Messages.java [deleted file]
redback-users/redback-users-providers/redback-users-jdo/src/main/resources/META-INF/spring-context.xml
redback-users/redback-users-providers/redback-users-jdo/src/main/resources/org/apache/archiva/redback/users/jdo/messages.properties [new file with mode: 0644]
redback-users/redback-users-providers/redback-users-jdo/src/main/resources/org/codehaus/plexus/redback/users/jdo/messages.properties [deleted file]
redback-users/redback-users-providers/redback-users-jdo/src/test/java/org/apache/archiva/redback/users/jdo/JdoUserManagerTest.java [new file with mode: 0644]
redback-users/redback-users-providers/redback-users-jdo/src/test/java/org/codehaus/plexus/redback/users/jdo/JdoUserManagerTest.java [deleted file]
redback-users/redback-users-providers/redback-users-jdo/src/test/resources/org/apache/archiva/redback/config-defaults.properties [new file with mode: 0644]
redback-users/redback-users-providers/redback-users-jdo/src/test/resources/org/codehaus/plexus/redback/config-defaults.properties [deleted file]

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
new file mode 100644 (file)
index 0000000..054ad41
--- /dev/null
@@ -0,0 +1,491 @@
+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.AbstractUserManager;
+import org.apache.archiva.redback.users.User;
+import org.apache.archiva.redback.users.UserManagerException;
+import org.apache.archiva.redback.users.UserNotFoundException;
+import org.codehaus.plexus.jdo.JdoFactory;
+import org.codehaus.plexus.jdo.PlexusJdoUtils;
+import org.codehaus.plexus.jdo.PlexusObjectNotFoundException;
+import org.codehaus.plexus.jdo.PlexusStoreException;
+import org.codehaus.plexus.redback.policy.UserSecurityPolicy;
+import org.apache.archiva.redback.users.PermanentUserException;
+import org.apache.archiva.redback.users.UserQuery;
+import org.codehaus.plexus.redback.users.jdo.JdoUser;
+import org.codehaus.plexus.redback.users.jdo.UsersManagementModelloMetadata;
+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>
+ * @version $Id$
+ */
+@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 UserManager - " + this.getClass().getName();
+    }
+
+
+    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 PlexusJdoUtils.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 )
+    {
+        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( Object principal )
+    {
+        try
+        {
+            User user = findUser( principal );
+
+            if ( user.isPermanent() )
+            {
+                throw new PermanentUserException( "Cannot delete permanent user [" + user.getUsername() + "]." );
+            }
+
+            fireUserManagerUserRemoved( user );
+
+            removeObject( user );
+        }
+        catch ( UserNotFoundException e )
+        {
+            log.warn( "Unable to delete user " + principal + ", user not found.", e );
+        }
+    }
+
+    public void deleteUser( String username )
+    {
+        try
+        {
+            User user = findUser( username );
+
+            if ( user.isPermanent() )
+            {
+                throw new PermanentUserException( "Cannot delete permanent user [" + user.getUsername() + "]." );
+            }
+
+            fireUserManagerUserRemoved( user );
+
+            PlexusJdoUtils.removeObject( getPersistenceManager(), user );
+        }
+        catch ( UserNotFoundException e )
+        {
+            log.warn( "Unable to delete user " + username + ", user not found.", e );
+        }
+    }
+
+    public void addUserUnchecked( User user )
+    {
+        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()
+    {
+        PlexusJdoUtils.removeAll( getPersistenceManager(), JdoUser.class );
+        PlexusJdoUtils.removeAll( getPersistenceManager(), UsersManagementModelloMetadata.class );
+    }
+
+    public User findUser( Object principal )
+        throws UserNotFoundException
+    {
+        if ( principal == null )
+        {
+            throw new UserNotFoundException( "Unable to find user based on null principal." );
+        }
+
+        try
+        {
+            return (User) PlexusJdoUtils.getObjectById( getPersistenceManager(), JdoUser.class, principal.toString(),
+                                                        null );
+        }
+        catch ( PlexusObjectNotFoundException e )
+        {
+            throw new UserNotFoundException( "Unable to find user: " + e.getMessage(), e );
+        }
+        catch ( PlexusStoreException e )
+        {
+            throw new UserNotFoundException( "Unable to find user: " + e.getMessage(), e );
+        }
+    }
+
+    public User findUser( String username )
+        throws UserNotFoundException
+    {
+        if ( StringUtils.isEmpty( username ) )
+        {
+            throw new UserNotFoundException( "User with empty username not found." );
+        }
+
+        return (User) getObjectById( username, null );
+    }
+
+    public boolean userExists( Object principal )
+    {
+        try
+        {
+            findUser( principal );
+            return true;
+        }
+        catch ( UserNotFoundException ne )
+        {
+            return false;
+        }
+    }
+
+    public User updateUser( User user )
+        throws UserNotFoundException
+    {
+        return updateUser( user, false );
+    }
+
+    public User updateUser( User user, boolean passwordChangeRequired )
+        throws UserNotFoundException
+    {
+        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 );
+        }
+
+        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 PlexusJdoUtils.addObject( getPersistenceManager(), object );
+    }
+
+    private Object getObjectById( String id, String fetchGroup )
+        throws UserNotFoundException, UserManagerException
+    {
+        try
+        {
+            return PlexusJdoUtils.getObjectById( getPersistenceManager(), JdoUser.class, id, fetchGroup );
+        }
+        catch ( PlexusObjectNotFoundException e )
+        {
+            throw new UserNotFoundException( e.getMessage() );
+        }
+        catch ( PlexusStoreException e )
+        {
+            throw new UserManagerException( "Unable to get object '" + JdoUser.class.getName() + "', id '" + id +
+                "', fetch-group '" + fetchGroup + "' from jdo store." );
+        }
+    }
+
+    private Object removeObject( Object o )
+    {
+        if ( o == null )
+        {
+            throw new UserManagerException( "Unable to remove null object" );
+        }
+
+        PlexusJdoUtils.removeObject( getPersistenceManager(), o );
+        return o;
+    }
+
+    private Object updateObject( Object object )
+        throws UserNotFoundException, UserManagerException
+    {
+        try
+        {
+            return PlexusJdoUtils.updateObject( getPersistenceManager(), object );
+        }
+        catch ( PlexusStoreException e )
+        {
+            throw new UserManagerException(
+                "Unable to update the '" + object.getClass().getName() + "' object in the jdo database.", e );
+        }
+    }
+
+    private void rollback( Transaction tx )
+    {
+        PlexusJdoUtils.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;
+    }
+}
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
new file mode 100644 (file)
index 0000000..77933e9
--- /dev/null
@@ -0,0 +1,136 @@
+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()
+    {
+        StringBuffer ordering = new StringBuffer();
+
+        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 (String[]) keys.toArray( new String[0] );
+    }
+
+    /**
+     * 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(), ", " );
+    }
+}
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
new file mode 100644 (file)
index 0000000..ee99ae1
--- /dev/null
@@ -0,0 +1,94 @@
+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>
+ * @version $Id$
+ */
+public class Messages
+{
+    private static final String BUNDLE_NAME = "org.codehaus.plexus.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()
+    {
+    }
+}
diff --git a/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/JdoUserManager.java b/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/JdoUserManager.java
deleted file mode 100644 (file)
index 14ee716..0000000
+++ /dev/null
@@ -1,489 +0,0 @@
-package org.codehaus.plexus.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.AbstractUserManager;
-import org.apache.archiva.redback.users.User;
-import org.apache.archiva.redback.users.UserManagerException;
-import org.apache.archiva.redback.users.UserNotFoundException;
-import org.codehaus.plexus.jdo.JdoFactory;
-import org.codehaus.plexus.jdo.PlexusJdoUtils;
-import org.codehaus.plexus.jdo.PlexusObjectNotFoundException;
-import org.codehaus.plexus.jdo.PlexusStoreException;
-import org.codehaus.plexus.redback.policy.UserSecurityPolicy;
-import org.apache.archiva.redback.users.PermanentUserException;
-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>
- * @version $Id$
- */
-@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 UserManager - " + this.getClass().getName();
-    }
-
-
-    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 PlexusJdoUtils.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 )
-    {
-        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( Object principal )
-    {
-        try
-        {
-            User user = findUser( principal );
-
-            if ( user.isPermanent() )
-            {
-                throw new PermanentUserException( "Cannot delete permanent user [" + user.getUsername() + "]." );
-            }
-
-            fireUserManagerUserRemoved( user );
-
-            removeObject( user );
-        }
-        catch ( UserNotFoundException e )
-        {
-            log.warn( "Unable to delete user " + principal + ", user not found.", e );
-        }
-    }
-
-    public void deleteUser( String username )
-    {
-        try
-        {
-            User user = findUser( username );
-
-            if ( user.isPermanent() )
-            {
-                throw new PermanentUserException( "Cannot delete permanent user [" + user.getUsername() + "]." );
-            }
-
-            fireUserManagerUserRemoved( user );
-
-            PlexusJdoUtils.removeObject( getPersistenceManager(), user );
-        }
-        catch ( UserNotFoundException e )
-        {
-            log.warn( "Unable to delete user " + username + ", user not found.", e );
-        }
-    }
-
-    public void addUserUnchecked( User user )
-    {
-        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()
-    {
-        PlexusJdoUtils.removeAll( getPersistenceManager(), JdoUser.class );
-        PlexusJdoUtils.removeAll( getPersistenceManager(), UsersManagementModelloMetadata.class );
-    }
-
-    public User findUser( Object principal )
-        throws UserNotFoundException
-    {
-        if ( principal == null )
-        {
-            throw new UserNotFoundException( "Unable to find user based on null principal." );
-        }
-
-        try
-        {
-            return (User) PlexusJdoUtils.getObjectById( getPersistenceManager(), JdoUser.class, principal.toString(),
-                                                        null );
-        }
-        catch ( PlexusObjectNotFoundException e )
-        {
-            throw new UserNotFoundException( "Unable to find user: " + e.getMessage(), e );
-        }
-        catch ( PlexusStoreException e )
-        {
-            throw new UserNotFoundException( "Unable to find user: " + e.getMessage(), e );
-        }
-    }
-
-    public User findUser( String username )
-        throws UserNotFoundException
-    {
-        if ( StringUtils.isEmpty( username ) )
-        {
-            throw new UserNotFoundException( "User with empty username not found." );
-        }
-
-        return (User) getObjectById( username, null );
-    }
-
-    public boolean userExists( Object principal )
-    {
-        try
-        {
-            findUser( principal );
-            return true;
-        }
-        catch ( UserNotFoundException ne )
-        {
-            return false;
-        }
-    }
-
-    public User updateUser( User user )
-        throws UserNotFoundException
-    {
-        return updateUser( user, false );
-    }
-
-    public User updateUser( User user, boolean passwordChangeRequired )
-        throws UserNotFoundException
-    {
-        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 );
-        }
-
-        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 PlexusJdoUtils.addObject( getPersistenceManager(), object );
-    }
-
-    private Object getObjectById( String id, String fetchGroup )
-        throws UserNotFoundException, UserManagerException
-    {
-        try
-        {
-            return PlexusJdoUtils.getObjectById( getPersistenceManager(), JdoUser.class, id, fetchGroup );
-        }
-        catch ( PlexusObjectNotFoundException e )
-        {
-            throw new UserNotFoundException( e.getMessage() );
-        }
-        catch ( PlexusStoreException e )
-        {
-            throw new UserManagerException( "Unable to get object '" + JdoUser.class.getName() + "', id '" + id +
-                "', fetch-group '" + fetchGroup + "' from jdo store." );
-        }
-    }
-
-    private Object removeObject( Object o )
-    {
-        if ( o == null )
-        {
-            throw new UserManagerException( "Unable to remove null object" );
-        }
-
-        PlexusJdoUtils.removeObject( getPersistenceManager(), o );
-        return o;
-    }
-
-    private Object updateObject( Object object )
-        throws UserNotFoundException, UserManagerException
-    {
-        try
-        {
-            return PlexusJdoUtils.updateObject( getPersistenceManager(), object );
-        }
-        catch ( PlexusStoreException e )
-        {
-            throw new UserManagerException(
-                "Unable to update the '" + object.getClass().getName() + "' object in the jdo database.", e );
-        }
-    }
-
-    private void rollback( Transaction tx )
-    {
-        PlexusJdoUtils.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;
-    }
-}
diff --git a/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/JdoUserQuery.java b/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/JdoUserQuery.java
deleted file mode 100644 (file)
index 1b29114..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-package org.codehaus.plexus.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()
-    {
-        StringBuffer ordering = new StringBuffer();
-
-        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 (String[]) keys.toArray( new String[0] );
-    }
-
-    /**
-     * 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(), ", " );
-    }
-}
diff --git a/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/Messages.java b/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/Messages.java
deleted file mode 100644 (file)
index 26fed4b..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-package org.codehaus.plexus.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>
- * @version $Id$
- */
-public class Messages
-{
-    private static final String BUNDLE_NAME = "org.codehaus.plexus.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()
-    {
-    }
-}
index cc2328dfe004a60e6fce72b395040390ce5a5ed0..522f90b457d29fe992ff7930d5bc5c86e1ed571d 100644 (file)
@@ -28,6 +28,6 @@
         default-lazy-init="true">
 
   <context:annotation-config />
-  <context:component-scan base-package="org.codehaus.plexus.redback.users.jdo"/>
+  <context:component-scan base-package="org.apache.archiva.redback.users.jdo"/>
 
 </beans>
\ No newline at end of file
diff --git a/redback-users/redback-users-providers/redback-users-jdo/src/main/resources/org/apache/archiva/redback/users/jdo/messages.properties b/redback-users/redback-users-providers/redback-users-jdo/src/main/resources/org/apache/archiva/redback/users/jdo/messages.properties
new file mode 100644 (file)
index 0000000..a05e400
--- /dev/null
@@ -0,0 +1,18 @@
+# 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.
diff --git a/redback-users/redback-users-providers/redback-users-jdo/src/main/resources/org/codehaus/plexus/redback/users/jdo/messages.properties b/redback-users/redback-users-providers/redback-users-jdo/src/main/resources/org/codehaus/plexus/redback/users/jdo/messages.properties
deleted file mode 100644 (file)
index a05e400..0000000
+++ /dev/null
@@ -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.
diff --git a/redback-users/redback-users-providers/redback-users-jdo/src/test/java/org/apache/archiva/redback/users/jdo/JdoUserManagerTest.java b/redback-users/redback-users-providers/redback-users-jdo/src/test/java/org/apache/archiva/redback/users/jdo/JdoUserManagerTest.java
new file mode 100644 (file)
index 0000000..970a279
--- /dev/null
@@ -0,0 +1,120 @@
+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.jdo.JdoUserManager;
+import org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory;
+import org.codehaus.plexus.redback.common.jdo.test.StoreManagerDebug;
+import org.codehaus.plexus.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>
+ * @version $Id$
+ */
+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/codehaus/plexus/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()
+    {
+        // database cleanup
+        ( (JdoUserManager) getUserManager()).eraseDatabase();
+
+
+
+        super.assertCleanUserManager();
+    }
+
+
+}
diff --git a/redback-users/redback-users-providers/redback-users-jdo/src/test/java/org/codehaus/plexus/redback/users/jdo/JdoUserManagerTest.java b/redback-users/redback-users-providers/redback-users-jdo/src/test/java/org/codehaus/plexus/redback/users/jdo/JdoUserManagerTest.java
deleted file mode 100644 (file)
index 7bee0c8..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-package org.codehaus.plexus.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.codehaus.plexus.jdo.DefaultConfigurableJdoFactory;
-import org.codehaus.plexus.redback.common.jdo.test.StoreManagerDebug;
-import org.codehaus.plexus.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>
- * @version $Id$
- */
-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/codehaus/plexus/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()
-    {
-        // database cleanup
-        ( (JdoUserManager) getUserManager()).eraseDatabase();
-
-
-
-        super.assertCleanUserManager();
-    }
-
-
-}
diff --git a/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/org/apache/archiva/redback/config-defaults.properties b/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/org/apache/archiva/redback/config-defaults.properties
new file mode 100644 (file)
index 0000000..4aa5a48
--- /dev/null
@@ -0,0 +1,128 @@
+# 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.
+
+# --------------------------------------------------------------------
+# Application Configuration
+
+application.timestamp=EEE d MMM yyyy HH:mm:ss Z
+
+# --------------------------------------------------------------------
+# JDBC Setup
+
+jdbc.driver.name=org.hsqldb.jdbcDriver
+jdbc.url=jdbc:hsqldb:mem:redback-test
+jdbc.username=sa
+jdbc.password=
+
+# --------------------------------------------------------------------
+# Email Settings
+
+email.jndiSessionName=java:comp/env/mail/Session
+email.smtp.host=localhost
+email.smtp.port=25
+email.smtp.ssl.enabled=false
+email.smtp.tls.enabled=false
+email.smtp.username=
+email.smtp.password=
+
+#TODO: move description elsewhere, remove bad default
+# All emails sent by the system will be from the following address
+#email.from.address=${user.name}@localhost
+# All emails sent by the system will be from the following user name (used in conjunction with address)
+#email.from.name=Unconfigured Username
+
+# If all email addresses (from new user registration) require an account validation email. 
+email.validation.required=true
+# Timeout (in minutes) for the key generated for an email validation to remain valid.
+# 2880 minutes = 48 hours
+email.validation.timeout=2880
+# The subject line for the email message.
+email.validation.subject=Welcome
+
+#TODO: move description elsewhere, remove bad default
+# Get the Feedback to use for any outgoing emails.
+# NOTE: if feedback.path starts with a "/" it is appended to the end of the value provided in application.url
+# This value can be in the format/syntax of "/feedback.action" or even "mailto:feedback@application.com"
+#email.feedback.path=/feedback.action
+
+#Set the application base URL. The default is to derive it from the HTTP request
+#application.url=http://myurl.mycompany.com
+
+# --------------------------------------------------------------------
+# Auto Login Settings
+
+security.rememberme.enabled=true
+# Timeout in minutes ( 525600 minutes = 1 year )
+security.rememberme.timeout=525600
+
+# Single Sign On
+# Timeout in minutes
+security.signon.timeout=30
+
+# --------------------------------------------------------------------
+# Default Username Values
+redback.default.admin=admin
+
+# --------------------------------------------------------------------
+# Security Policies
+
+#security.policy.password.encoder=
+security.policy.password.previous.count=6
+security.policy.password.expiration.enabled=true
+security.policy.password.expiration.days=90
+security.policy.password.expiration.notify.days=10
+security.policy.allowed.login.attempt=10
+
+# turn off the perclick enforcement of various security policies, slightly
+# more heavyweight since it will ensure that the User object on each click
+# is up to date
+security.policy.strict.enforcement.enabled=true
+security.policy.strict.force.password.change.enabled=true
+
+# --------------------------------------------------------------------
+# Password Rules
+security.policy.password.rule.alphanumeric.enabled=false
+security.policy.password.rule.alphacount.enabled=true
+security.policy.password.rule.alphacount.minimum=1
+security.policy.password.rule.characterlength.enabled=true
+security.policy.password.rule.characterlength.minimum=1
+security.policy.password.rule.characterlength.maximum=24
+security.policy.password.rule.musthave.enabled=true
+security.policy.password.rule.numericalcount.enabled=true
+security.policy.password.rule.numericalcount.minimum=1
+security.policy.password.rule.reuse.enabled=true
+security.policy.password.rule.nowhitespace.enabled=true
+
+# --------------------------------------------------------------------
+# ldap settings
+#
+ldap.bind.authenticator.enabled=false
+
+# ldap options for configuration via properties file
+#ldap.config.hostname=
+#ldap.config.port=
+#ldap.config.base.dn=
+#ldap.config.context.factory=
+#ldap.config.bind.dn=
+#ldap.config.password=
+#ldap.config.authentication.method=
+
+# config parameter for the ConfigurableUserManager
+user.manager.impl=cached
+
+
+
diff --git a/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/org/codehaus/plexus/redback/config-defaults.properties b/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/org/codehaus/plexus/redback/config-defaults.properties
deleted file mode 100644 (file)
index 4aa5a48..0000000
+++ /dev/null
@@ -1,128 +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.
-
-# --------------------------------------------------------------------
-# Application Configuration
-
-application.timestamp=EEE d MMM yyyy HH:mm:ss Z
-
-# --------------------------------------------------------------------
-# JDBC Setup
-
-jdbc.driver.name=org.hsqldb.jdbcDriver
-jdbc.url=jdbc:hsqldb:mem:redback-test
-jdbc.username=sa
-jdbc.password=
-
-# --------------------------------------------------------------------
-# Email Settings
-
-email.jndiSessionName=java:comp/env/mail/Session
-email.smtp.host=localhost
-email.smtp.port=25
-email.smtp.ssl.enabled=false
-email.smtp.tls.enabled=false
-email.smtp.username=
-email.smtp.password=
-
-#TODO: move description elsewhere, remove bad default
-# All emails sent by the system will be from the following address
-#email.from.address=${user.name}@localhost
-# All emails sent by the system will be from the following user name (used in conjunction with address)
-#email.from.name=Unconfigured Username
-
-# If all email addresses (from new user registration) require an account validation email. 
-email.validation.required=true
-# Timeout (in minutes) for the key generated for an email validation to remain valid.
-# 2880 minutes = 48 hours
-email.validation.timeout=2880
-# The subject line for the email message.
-email.validation.subject=Welcome
-
-#TODO: move description elsewhere, remove bad default
-# Get the Feedback to use for any outgoing emails.
-# NOTE: if feedback.path starts with a "/" it is appended to the end of the value provided in application.url
-# This value can be in the format/syntax of "/feedback.action" or even "mailto:feedback@application.com"
-#email.feedback.path=/feedback.action
-
-#Set the application base URL. The default is to derive it from the HTTP request
-#application.url=http://myurl.mycompany.com
-
-# --------------------------------------------------------------------
-# Auto Login Settings
-
-security.rememberme.enabled=true
-# Timeout in minutes ( 525600 minutes = 1 year )
-security.rememberme.timeout=525600
-
-# Single Sign On
-# Timeout in minutes
-security.signon.timeout=30
-
-# --------------------------------------------------------------------
-# Default Username Values
-redback.default.admin=admin
-
-# --------------------------------------------------------------------
-# Security Policies
-
-#security.policy.password.encoder=
-security.policy.password.previous.count=6
-security.policy.password.expiration.enabled=true
-security.policy.password.expiration.days=90
-security.policy.password.expiration.notify.days=10
-security.policy.allowed.login.attempt=10
-
-# turn off the perclick enforcement of various security policies, slightly
-# more heavyweight since it will ensure that the User object on each click
-# is up to date
-security.policy.strict.enforcement.enabled=true
-security.policy.strict.force.password.change.enabled=true
-
-# --------------------------------------------------------------------
-# Password Rules
-security.policy.password.rule.alphanumeric.enabled=false
-security.policy.password.rule.alphacount.enabled=true
-security.policy.password.rule.alphacount.minimum=1
-security.policy.password.rule.characterlength.enabled=true
-security.policy.password.rule.characterlength.minimum=1
-security.policy.password.rule.characterlength.maximum=24
-security.policy.password.rule.musthave.enabled=true
-security.policy.password.rule.numericalcount.enabled=true
-security.policy.password.rule.numericalcount.minimum=1
-security.policy.password.rule.reuse.enabled=true
-security.policy.password.rule.nowhitespace.enabled=true
-
-# --------------------------------------------------------------------
-# ldap settings
-#
-ldap.bind.authenticator.enabled=false
-
-# ldap options for configuration via properties file
-#ldap.config.hostname=
-#ldap.config.port=
-#ldap.config.base.dn=
-#ldap.config.context.factory=
-#ldap.config.bind.dn=
-#ldap.config.password=
-#ldap.config.authentication.method=
-
-# config parameter for the ConfigurableUserManager
-user.manager.impl=cached
-
-
-