You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ol...@apache.org on 2012/04/06 11:59:32 UTC

svn commit: r1310268 [40/42] - in /archiva/redback/redback-core/trunk: ./ redback-authentication/ redback-authentication/redback-authentication-api/ redback-authentication/redback-authentication-api/src/ redback-authentication/redback-authentication-ap...

Added: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/JdoUserManager.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/JdoUserManager.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/JdoUserManager.java (added)
+++ archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/JdoUserManager.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,487 @@
+package org.codehaus.plexus.redback.users.jdo;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import 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.codehaus.plexus.redback.users.AbstractUserManager;
+import org.codehaus.plexus.redback.users.PermanentUserException;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.redback.users.UserManagerException;
+import org.codehaus.plexus.redback.users.UserNotFoundException;
+import org.codehaus.plexus.redback.users.UserQuery;
+import org.codehaus.plexus.util.StringUtils;
+import org.jpox.JDOClassLoaderResolver;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+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;
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/JdoUserManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/JdoUserManager.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/JdoUserQuery.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/JdoUserQuery.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/JdoUserQuery.java (added)
+++ archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/JdoUserQuery.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,133 @@
+package org.codehaus.plexus.redback.users.jdo;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.codehaus.plexus.redback.users.AbstractUserQuery;
+import org.codehaus.plexus.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(), ", " );
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/JdoUserQuery.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/JdoUserQuery.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/Messages.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/Messages.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/Messages.java (added)
+++ archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/Messages.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,91 @@
+package org.codehaus.plexus.redback.users.jdo;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.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()
+    {
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/Messages.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/codehaus/plexus/redback/users/jdo/Messages.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/mdo/user.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/mdo/user.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/mdo/user.xml (added)
+++ archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/mdo/user.xml Fri Apr  6 09:58:14 2012
@@ -0,0 +1,143 @@
+<?xml version="1.0" ?>
+<model>
+  <id>redback-users-jdo</id>
+  <name>UsersManagement</name>
+  <version>1.0.1</version>
+  <description>Plexus Redback Users object model.</description>
+  <defaults>
+    <default>
+      <key>package</key>
+      <value>org.codehaus.plexus.redback.users.jdo</value>
+    </default>
+  </defaults>
+
+  <classes>
+    <class stash.storable="false" rootElement="true">
+      <name>UserDatabase</name>
+      <version>1.0.1+</version>
+      <fields>
+        <field>
+          <name>users</name>
+          <version>1.0.1+</version>
+          <association>
+            <type>JdoUser</type>
+            <multiplicity>*</multiplicity>
+          </association>
+        </field>
+      </fields>
+    </class>
+    <class stash.storable="true" jpox.use-identifiers-as-primary-key="false">
+      <name>JdoUser</name>
+      <version>1.0.0+</version>
+      <interfaces>
+        <interface>org.codehaus.plexus.redback.users.User</interface>
+      </interfaces>
+      <description></description>
+      <fields>
+        <field jpox.primary-key="true" jpox.value-strategy="off" jpox.persistence-modifier="persistent">
+          <name>username</name>
+          <version>1.0.0+</version>
+          <type>String</type>
+          <identifier>true</identifier>
+        </field>
+        <field jpox.column="USER_PASSWORD">
+          <name>password</name>
+          <version>1.0.0+</version>
+          <type>String</type>
+          <identifier>true</identifier>
+        </field>
+        <field>
+          <name>encodedPassword</name>
+          <version>1.0.0+</version>
+          <type>String</type>
+          <identifier>true</identifier>
+        </field>
+        <field>
+          <name>fullName</name>
+          <version>1.0.0+</version>
+          <type>String</type>
+          <identifier>true</identifier>
+        </field>
+        <field>
+          <name>email</name>
+          <version>1.0.0+</version>
+          <type>String</type>
+          <identifier>true</identifier>
+        </field>
+        <field>
+          <name>lastPasswordChange</name>
+          <version>1.0.0+</version>
+          <type>Date</type>
+        </field>
+        <field>
+          <name>lastLoginDate</name>
+          <version>1.0.0+</version>
+          <type>Date</type>
+        </field>
+        <field>
+          <name>countFailedLoginAttempts</name>
+          <version>1.0.0+</version>
+          <type>int</type>
+        </field>
+        <field>
+          <name>locked</name>
+          <version>1.0.0+</version>
+          <type>boolean</type>
+          <defaultValue>false</defaultValue>
+          <identifier>true</identifier>
+        </field>
+        <field>
+          <name>permanent</name>
+          <version>1.0.0+</version>
+          <type>boolean</type>
+          <defaultValue>false</defaultValue>
+          <identifier>true</identifier>
+        </field>
+        <field>
+          <name>validated</name>
+          <version>1.0.0+</version>
+          <type>boolean</type>
+          <defaultValue>false</defaultValue>
+          <identifier>true</identifier>
+        </field>
+        <field>
+          <name>passwordChangeRequired</name>
+          <version>1.0.0+</version>
+          <type>boolean</type>
+          <defaultValue>false</defaultValue>
+          <identifier>true</identifier>
+        </field>
+        <field>
+          <name>previousEncodedPasswords</name>
+          <version>1.0.0+</version>
+          <association stash.part="true">
+            <type>String</type>
+            <multiplicity>*</multiplicity>
+          </association>
+        </field>
+        <field>
+          <name>accountCreationDate</name>
+          <version>1.0.0+</version>
+          <type>Date</type>
+        </field>
+      </fields>
+      <codeSegments>
+        <codeSegment>
+          <version>1.0.0+</version>
+          <code><![CDATA[
+              public JdoUser()
+              {
+                 // Intentionally initialize List to avoid JPOX NullPointerException Issues.
+              	 previousEncodedPasswords = new java.util.ArrayList();
+              }
+
+              public Object getPrincipal()
+              {
+                 return username;
+              }
+          ]]></code>
+        </codeSegment>
+      </codeSegments>
+    </class>
+  </classes>
+</model>

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/mdo/user.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/mdo/user.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/resources/META-INF/spring-context.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/resources/META-INF/spring-context.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/resources/META-INF/spring-context.xml (added)
+++ archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/resources/META-INF/spring-context.xml Fri Apr  6 09:58:14 2012
@@ -0,0 +1,33 @@
+<?xml version="1.0"?>
+
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~   http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:context="http://www.springframework.org/schema/context"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans
+           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+           http://www.springframework.org/schema/context 
+           http://www.springframework.org/schema/context/spring-context-3.0.xsd"
+        default-lazy-init="true">
+
+  <context:annotation-config />
+  <context:component-scan base-package="org.codehaus.plexus.redback.users.jdo"/>
+
+</beans>
\ No newline at end of file

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/resources/META-INF/spring-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/resources/META-INF/spring-context.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/resources/org/codehaus/plexus/redback/users/jdo/messages.properties
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/resources/org/codehaus/plexus/redback/users/jdo/messages.properties?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/resources/org/codehaus/plexus/redback/users/jdo/messages.properties (added)
+++ archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/resources/org/codehaus/plexus/redback/users/jdo/messages.properties Fri Apr  6 09:58:14 2012
@@ -0,0 +1,2 @@
+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.

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/resources/org/codehaus/plexus/redback/users/jdo/messages.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/main/resources/org/codehaus/plexus/redback/users/jdo/messages.properties
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/test/java/org/codehaus/plexus/redback/users/jdo/JdoUserManagerTest.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/test/java/org/codehaus/plexus/redback/users/jdo/JdoUserManagerTest.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/test/java/org/codehaus/plexus/redback/users/jdo/JdoUserManagerTest.java (added)
+++ archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/test/java/org/codehaus/plexus/redback/users/jdo/JdoUserManagerTest.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,120 @@
+package org.codehaus.plexus.redback.users.jdo;
+
+/*
+ * Copyright 2001-2006 The Codehaus.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory;
+import org.codehaus.plexus.redback.common.jdo.test.StoreManagerDebug;
+import org.codehaus.plexus.redback.users.UserManager;
+import org.codehaus.plexus.redback.users.UserNotFoundException;
+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.Arrays;
+import java.util.List;
+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();
+    }
+
+
+}

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/test/java/org/codehaus/plexus/redback/users/jdo/JdoUserManagerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/test/java/org/codehaus/plexus/redback/users/jdo/JdoUserManagerTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/org/codehaus/plexus/redback/config-defaults.properties
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/org/codehaus/plexus/redback/config-defaults.properties?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/org/codehaus/plexus/redback/config-defaults.properties (added)
+++ archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/org/codehaus/plexus/redback/config-defaults.properties Fri Apr  6 09:58:14 2012
@@ -0,0 +1,127 @@
+#
+# Copyright 2006 The Codehaus.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+#      http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# --------------------------------------------------------------------
+# 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
+
+
+

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/org/codehaus/plexus/redback/config-defaults.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/org/codehaus/plexus/redback/config-defaults.properties
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/spring-context.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/spring-context.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/spring-context.xml (added)
+++ archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/spring-context.xml Fri Apr  6 09:58:14 2012
@@ -0,0 +1,55 @@
+<?xml version="1.0"?>
+
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~   http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:context="http://www.springframework.org/schema/context"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans
+           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+           http://www.springframework.org/schema/context 
+           http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+
+  <bean name="jdoFactory#users" class="org.codehaus.plexus.redback.common.jdo.UserConfigurableJdoFactory">
+    <property name="config" ref="userConfiguration"/>
+    <property name="driverName" value="org.hsqldb.jdbcDriver"/>
+    <property name="url" value="jdbc:hsqldb:mem:redback-users-tests" />
+    <property name="userName" value="sa"/>
+    <property name="password" value=""/>
+  </bean>
+
+  <bean name="userConfiguration" class="org.codehaus.plexus.redback.configuration.UserConfiguration">
+    <property name="registry" ref="test-conf"/>
+  </bean>
+
+  <bean name="commons-configuration" class="org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry">
+    <property name="properties">
+      <value>
+        <![CDATA[
+          <configuration>
+            <properties fileName="test.properties" config-name="properties"/>
+          </configuration>
+        ]]>
+      </value>
+    </property>
+  </bean>
+
+  <alias name="commons-configuration" alias="test-conf"/>
+
+</beans>
\ No newline at end of file

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/spring-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/spring-context.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/test.properties
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/test.properties?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/test.properties (added)
+++ archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/test.properties Fri Apr  6 09:58:14 2012
@@ -0,0 +1 @@
+jdbc.driver.name=org.hsqldb.jdbcDriver
\ No newline at end of file

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/test.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/test.properties
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/pom.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/pom.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/pom.xml (added)
+++ archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/pom.xml Fri Apr  6 09:58:14 2012
@@ -0,0 +1,95 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  
+  <parent>
+    <groupId>org.codehaus.redback</groupId>
+    <artifactId>redback-users-providers</artifactId>
+    <version>1.5-SNAPSHOT</version>
+  </parent>
+  
+  <artifactId>redback-users-ldap</artifactId>
+  
+  <name>Redback :: Users Provider :: LDAP</name>
+  
+  <dependencies>
+    <dependency>
+      <groupId>org.codehaus.redback</groupId>
+      <artifactId>redback-users-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.redback</groupId>
+      <artifactId>redback-policy</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.redback</groupId>
+      <artifactId>redback-common-ldap</artifactId> 
+    </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-context-support</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.redback.components.cache</groupId>
+      <artifactId>spring-cache-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.redback.components.cache</groupId>
+      <artifactId>spring-cache-ehcache</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>javax.annotation</groupId>
+      <artifactId>jsr250-api</artifactId>
+    </dependency>    
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.codehaus.redback.components</groupId>
+      <artifactId>spring-apacheds</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.sonatype.plugins</groupId>
+        <artifactId>port-allocator-maven-plugin</artifactId>
+        <version>1.1</version>
+        <executions>
+          <execution>
+            <id>allocate-ldap-port</id>
+            <phase>process-classes</phase>
+            <goals>
+              <goal>allocate-ports</goal>
+            </goals>
+            <configuration>
+              <ports>
+                <port>
+                  <name>ldapPort</name>
+                  <portNumber>10390</portNumber>
+                </port>
+              </ports>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <systemPropertyVariables>
+            <ldapPort>${ldapPort}</ldapPort>
+            <basedir>${basedir}</basedir>
+          </systemPropertyVariables>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+  
+</project>

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/codehaus/plexus/redback/users/ldap/LdapUserManager.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/codehaus/plexus/redback/users/ldap/LdapUserManager.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/codehaus/plexus/redback/users/ldap/LdapUserManager.java (added)
+++ archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/codehaus/plexus/redback/users/ldap/LdapUserManager.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,498 @@
+package org.codehaus.plexus.redback.users.ldap;
+/*
+ * Copyright 2001-2007 The Codehaus.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+import org.codehaus.plexus.redback.common.ldap.LdapUser;
+import org.codehaus.plexus.redback.common.ldap.MappingException;
+import org.codehaus.plexus.redback.common.ldap.UserMapper;
+import org.codehaus.plexus.redback.common.ldap.connection.LdapConnection;
+import org.codehaus.plexus.redback.common.ldap.connection.LdapConnectionFactory;
+import org.codehaus.plexus.redback.common.ldap.connection.LdapException;
+import org.codehaus.plexus.redback.users.AbstractUserManager;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.redback.users.UserNotFoundException;
+import org.codehaus.plexus.redback.users.UserQuery;
+import org.codehaus.plexus.redback.users.ldap.ctl.LdapController;
+import org.codehaus.plexus.redback.users.ldap.ctl.LdapControllerException;
+import org.codehaus.plexus.redback.users.ldap.service.LdapCacheService;
+import org.springframework.stereotype.Service;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.naming.directory.DirContext;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author <a href="jesse@codehaus.org"> jesse
+ * @version "$Id$"
+ */
+@Service( "userManager#ldap" )
+public class LdapUserManager
+    extends AbstractUserManager
+{
+    @Inject
+    @Named( value = "ldapConnectionFactory#configurable" )
+    private LdapConnectionFactory connectionFactory;
+
+    @Inject
+    private LdapController controller;
+
+    @Inject
+    @Named( value = "userMapper#ldap" )
+    private UserMapper mapper;
+
+    @Inject
+    private LdapCacheService ldapCacheService;
+
+    private User guestUser;
+
+    public boolean isReadOnly()
+    {
+        return true;
+    }
+
+    public User addUser( User user )
+    {
+        return addUser( user, true );
+    }
+
+    public void addUserUnchecked( User user )
+    {
+        addUser( user, false );
+    }
+
+    private User addUser( User user, boolean checked )
+    {
+        if ( user == null )
+        {
+            return null;
+        }
+
+        if ( GUEST_USERNAME.equals( user.getUsername() ) )
+        {
+            guestUser = user;
+            return guestUser;
+        }
+
+        LdapConnection ldapConnection = getLdapConnection();
+        try
+        {
+            DirContext context = ldapConnection.getDirContext();
+            controller.createUser( user, context, checked );
+        }
+        catch ( LdapControllerException e )
+        {
+            log.error( "Error mapping user: " + user.getPrincipal() + " to LDAP attributes.", e );
+        }
+        catch ( MappingException e )
+        {
+            log.error( "Error mapping user: " + user.getPrincipal() + " to LDAP attributes.", e );
+        }
+        finally
+        {
+            closeLdapConnection( ldapConnection );
+        }
+        return user;
+    }
+
+    public User createUser( String username, String fullName, String emailAddress )
+    {
+        return mapper.newUserInstance( username, fullName, emailAddress );
+    }
+
+    public UserQuery createUserQuery()
+    {
+        return new LdapUserQuery();
+    }
+
+    public void deleteUser( Object principal )
+        throws UserNotFoundException
+    {
+        if ( principal != null )
+        {
+            clearFromCache( principal.toString() );
+        }
+
+        LdapConnection ldapConnection = getLdapConnection();
+        try
+        {
+            DirContext context = ldapConnection.getDirContext();
+            controller.removeUser( principal, context );
+        }
+        catch ( LdapControllerException e )
+        {
+            log.error( "Failed to delete user: {}", principal, e );
+        }
+        finally
+        {
+            closeLdapConnection( ldapConnection );
+        }
+    }
+
+    public void deleteUser( String username )
+        throws UserNotFoundException
+    {
+        if ( username != null )
+        {
+            clearFromCache( username );
+        }
+
+        LdapConnection ldapConnection = getLdapConnection();
+        try
+        {
+            DirContext context = ldapConnection.getDirContext();
+            controller.removeUser( username, context );
+        }
+        catch ( LdapControllerException e )
+        {
+            log.error( "Failed to delete user: " + username, e );
+        }
+        finally
+        {
+            closeLdapConnection( ldapConnection );
+        }
+    }
+
+    public void eraseDatabase()
+    {
+        // TODO Implement erase!
+    }
+
+    public User findUser( String username )
+        throws UserNotFoundException
+    {
+        if ( username == null )
+        {
+            throw new UserNotFoundException( "Unable to find user based on null username." );
+        }
+
+        if ( GUEST_USERNAME.equals( username ) )
+        {
+            return getGuestUser();
+        }
+
+        // REDBACK-289/MRM-1488
+        // look for the user in the cache first
+        LdapUser ldapUser = ldapCacheService.getUser( username );
+        if ( ldapUser != null )
+        {
+            log.debug( "User {} found in cache.", username );
+            return ldapUser;
+        }
+
+        LdapConnection ldapConnection = getLdapConnection();
+        try
+        {
+            DirContext context = ldapConnection.getDirContext();
+            User user = controller.getUser( username, context );
+            if ( user == null )
+            {
+                throw new UserNotFoundException( "user with name " + username + " not found " );
+            }
+
+            // REDBACK-289/MRM-1488
+            log.debug( "Adding user {} to cache..", username );
+
+            ldapCacheService.addUser( (LdapUser) user );
+
+            return user;
+        }
+        catch ( LdapControllerException e )
+        {
+            log.error( "Failed to find user: {}", username, e );
+            return null;
+        }
+        catch ( MappingException e )
+        {
+            log.error( "Failed to map user: {}", username, e );
+            return null;
+        }
+        finally
+        {
+            closeLdapConnection( ldapConnection );
+        }
+    }
+
+    public User getGuestUser()
+        throws UserNotFoundException
+    {
+        if ( guestUser == null )
+        {
+            throw new UserNotFoundException( "Guest user doesn't exist." );
+        }
+        return guestUser;
+    }
+
+    public User findUser( Object principal )
+        throws UserNotFoundException
+    {
+        if ( principal == null )
+        {
+            throw new UserNotFoundException( "Unable to find user based on null principal." );
+        }
+
+        if ( GUEST_USERNAME.equals( principal.toString() ) )
+        {
+            return getGuestUser();
+        }
+
+        // REDBACK-289/MRM-1488
+        // look for the user in the cache first
+        LdapUser ldapUser = ldapCacheService.getUser( principal.toString() );
+        if ( ldapUser != null )
+        {
+            log.debug( "User {} found in cache.", principal );
+            return ldapUser;
+        }
+
+        LdapConnection ldapConnection = getLdapConnection();
+        try
+        {
+            DirContext context = ldapConnection.getDirContext();
+
+            User user = controller.getUser( principal, context );
+
+            // REDBACK-289/MRM-1488
+            log.debug( "Adding user {} to cache..", principal );
+
+            ldapCacheService.addUser( (LdapUser) user );
+
+            return user;
+        }
+        catch ( LdapControllerException e )
+        {
+            log.error( "Failed to find user: {}", principal, e );
+            return null;
+        }
+        catch ( MappingException e )
+        {
+            log.error( "Failed to map user: {}", principal, e );
+            return null;
+        }
+        finally
+        {
+            closeLdapConnection( ldapConnection );
+        }
+    }
+
+    public List<User> findUsersByEmailKey( String emailKey, boolean orderAscending )
+    {
+        LdapUserQuery query = new LdapUserQuery();
+        query.setEmail( emailKey );
+        query.setOrderBy( UserQuery.ORDER_BY_EMAIL );
+        query.setAscending( orderAscending );
+        return findUsersByQuery( query );
+    }
+
+    public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
+    {
+        LdapUserQuery query = new LdapUserQuery();
+        query.setFullName( fullNameKey );
+        query.setOrderBy( UserQuery.ORDER_BY_FULLNAME );
+        query.setAscending( orderAscending );
+        return findUsersByQuery( query );
+    }
+
+    public List<User> findUsersByQuery( UserQuery query )
+    {
+        if ( query == null )
+        {
+            return Collections.emptyList();
+        }
+
+        LdapConnection ldapConnection = getLdapConnection();
+        try
+        {
+            DirContext context = ldapConnection.getDirContext();
+            return controller.getUsersByQuery( (LdapUserQuery) query, context );
+        }
+        catch ( LdapControllerException e )
+        {
+            log.error( "Failed to find user", e );
+            return null;
+        }
+        catch ( MappingException e )
+        {
+            log.error( "Failed to map user", e );
+            return null;
+        }
+        finally
+        {
+            closeLdapConnection( ldapConnection );
+        }
+    }
+
+    /**
+     * @see org.codehaus.plexus.redback.users.UserManager#findUsersByUsernameKey(java.lang.String, boolean)
+     */
+    public List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending )
+    {
+        LdapUserQuery query = new LdapUserQuery();
+        query.setUsername( usernameKey );
+        query.setOrderBy( UserQuery.ORDER_BY_USERNAME );
+        query.setAscending( orderAscending );
+        return findUsersByQuery( query );
+    }
+
+    public String getId()
+    {
+        return "LDAP User-Manager: " + getClass().getName();
+    }
+
+    /**
+     * @see org.codehaus.plexus.redback.users.UserManager#getUsers()
+     */
+    public List<User> getUsers()
+    {
+        LdapConnection ldapConnection = getLdapConnection();
+        try
+        {
+            DirContext context = ldapConnection.getDirContext();
+            List<User> users = new ArrayList<User>( controller.getUsers( context ) );
+            //We add the guest user because it isn't in LDAP
+            try
+            {
+                User u = getGuestUser();
+                if ( u != null )
+                {
+                    users.add( u );
+                }
+            }
+            catch ( UserNotFoundException e )
+            {
+                //Nothing to do
+            }
+            return users;
+        }
+        catch ( Exception e )
+        {
+            log.error( e.getMessage(), e );
+        }
+        finally
+        {
+            closeLdapConnection( ldapConnection );
+        }
+        return Collections.emptyList();
+    }
+
+    public List<User> getUsers( boolean orderAscending )
+    {
+        return getUsers();
+    }
+
+    public User updateUser( User user )
+        throws UserNotFoundException
+    {
+        return updateUser( user, false );
+    }
+
+    public User updateUser( User user, boolean passwordChangeRequired )
+        throws UserNotFoundException
+    {
+        if ( user != null )
+        {
+            clearFromCache( user.getUsername() );
+        }
+
+        LdapConnection ldapConnection = getLdapConnection();
+        try
+        {
+            DirContext context = ldapConnection.getDirContext();
+            controller.updateUser( user, context );
+        }
+        catch ( LdapControllerException e )
+        {
+            log.error( "Failed to update user: " + user.getPrincipal(), e );
+        }
+        catch ( MappingException e )
+        {
+            log.error( "Failed to update user: " + user.getPrincipal(), e );
+        }
+        finally
+        {
+            closeLdapConnection( ldapConnection );
+        }
+        return user;
+    }
+
+    public boolean userExists( Object principal )
+    {
+        if ( principal == null )
+        {
+            return false;
+        }
+
+        // REDBACK-289/MRM-1488
+        // look for the user in the cache first
+        LdapUser ldapUser = ldapCacheService.getUser( principal.toString() );
+        if ( ldapUser != null )
+        {
+            log.debug( "User {} found in cache.", principal );
+            return true;
+        }
+
+        LdapConnection ldapConnection = getLdapConnection();
+        try
+        {
+            DirContext context = ldapConnection.getDirContext();
+            return controller.userExists( principal, context );
+        }
+        catch ( LdapControllerException e )
+        {
+            log.warn( "Failed to search for user: " + principal, e );
+            return false;
+        }
+        finally
+        {
+            closeLdapConnection( ldapConnection );
+        }
+    }
+
+    private LdapConnection getLdapConnection()
+    {
+        try
+        {
+            return connectionFactory.getConnection();
+        }
+        catch ( LdapException e )
+        {
+            log.warn( "failed to get a ldap connection " + e.getMessage(), e );
+            throw new RuntimeException( "failed to get a ldap connection " + e.getMessage(), e );
+        }
+    }
+
+    private void closeLdapConnection( LdapConnection ldapConnection )
+    {
+        if ( ldapConnection != null )
+        {
+            ldapConnection.close();
+        }
+    }
+
+    // REDBACK-289/MRM-1488
+    private void clearFromCache( String username )
+    {
+        log.debug( "Removing user {} from cache..", username );
+        ldapCacheService.removeUser( username );
+
+        log.debug( "Removing userDn for user {} from cache..", username );
+        ldapCacheService.removeLdapUserDn( username );
+    }
+
+}

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/codehaus/plexus/redback/users/ldap/LdapUserManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/codehaus/plexus/redback/users/ldap/LdapUserManager.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/codehaus/plexus/redback/users/ldap/LdapUserQuery.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/codehaus/plexus/redback/users/ldap/LdapUserQuery.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/codehaus/plexus/redback/users/ldap/LdapUserQuery.java (added)
+++ archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/codehaus/plexus/redback/users/ldap/LdapUserQuery.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,60 @@
+package org.codehaus.plexus.redback.users.ldap;
+
+/*
+ * Copyright 2001-2007 The Codehaus.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.codehaus.plexus.redback.common.ldap.UserMapper;
+import org.codehaus.plexus.redback.users.AbstractUserQuery;
+
+public class LdapUserQuery
+    extends AbstractUserQuery
+{
+
+    public void setFirstResult( int firstResult )
+    {
+        super.setFirstResult( firstResult );
+        throw new UnsupportedOperationException( "Result limiting is not yet supported for LDAP." );
+    }
+
+    public void setMaxResults( int maxResults )
+    {
+        super.setMaxResults( maxResults );
+        throw new UnsupportedOperationException( "Result limiting is not yet supported for LDAP." );
+    }
+
+    public void setOrderBy( String orderBy )
+    {
+        super.setOrderBy( orderBy );
+        throw new UnsupportedOperationException( "Free-form ordering is not yet supported for LDAP." );
+    }
+    
+    public String getLdapFilter( UserMapper mapper )
+    {
+        String filter = "";
+        if (this.getEmail() != null )
+        {
+            filter += "(" + mapper.getEmailAddressAttribute() + "=" + this.getEmail() + ")";
+        }
+        if ( this.getFullName() != null )
+        {
+            filter += "(" + mapper.getUserFullNameAttribute() + "=" + this.getFullName() + ")";
+        }
+        filter += "(" + mapper.getUserIdAttribute() + "=" + ( this.getUsername() != null ? this.getUsername() : "*" ) + ")";
+        
+        return filter;
+    }
+
+}

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/codehaus/plexus/redback/users/ldap/LdapUserQuery.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/codehaus/plexus/redback/users/ldap/LdapUserQuery.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/codehaus/plexus/redback/users/ldap/ctl/DefaultLdapController.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/codehaus/plexus/redback/users/ldap/ctl/DefaultLdapController.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/codehaus/plexus/redback/users/ldap/ctl/DefaultLdapController.java (added)
+++ archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/codehaus/plexus/redback/users/ldap/ctl/DefaultLdapController.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,298 @@
+package org.codehaus.plexus.redback.users.ldap.ctl;
+
+/*
+ * Copyright 2001-2007 The Codehaus.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import javax.annotation.Resource;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import org.codehaus.plexus.redback.common.ldap.LdapUser;
+import org.codehaus.plexus.redback.common.ldap.LdapUserMapper;
+import org.codehaus.plexus.redback.common.ldap.MappingException;
+import org.codehaus.plexus.redback.common.ldap.UserMapper;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.redback.users.UserManager;
+import org.codehaus.plexus.redback.users.ldap.LdapUserQuery;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author <a href="jesse@codehaus.org"> jesse
+ * @version "$Id$"
+ */
+@Service
+public class DefaultLdapController
+    implements LdapController
+{
+
+    private Logger log = LoggerFactory.getLogger( getClass() );
+
+    @Inject
+    @Named(value = "userMapper#ldap")
+    private UserMapper mapper;
+
+    /**
+	 * @see org.codehaus.plexus.redback.users.ldap.ctl.LdapControllerI#removeUser(java.lang.Object, javax.naming.directory.DirContext)
+	 */
+    public void removeUser( Object principal, DirContext context )
+        throws LdapControllerException
+    {
+
+    }
+
+    /**
+	 * @see org.codehaus.plexus.redback.users.ldap.ctl.LdapControllerI#updateUser(org.codehaus.plexus.redback.users.User, javax.naming.directory.DirContext)
+	 */
+    public void updateUser( User user, DirContext context )
+        throws LdapControllerException, MappingException
+    {
+
+    }
+
+    /**
+	 * @see org.codehaus.plexus.redback.users.ldap.ctl.LdapControllerI#userExists(java.lang.Object, javax.naming.directory.DirContext)
+	 */
+    public boolean userExists( Object key, DirContext context )
+        throws LdapControllerException
+    {
+        NamingEnumeration<SearchResult> results = null;
+        try
+        {
+            results = searchUsers( key, context );
+            return results.hasMoreElements();
+        }
+        catch ( NamingException e )
+        {
+            throw new LdapControllerException( "Error searching for the existence of user: " + key, e );
+        }
+        finally
+        {
+            if ( results != null )
+                try
+                {
+                    results.close();
+                }
+                catch ( NamingException e )
+                {
+                    log.warn( "Error closing search results", e );
+                }
+        }
+    }
+
+    protected NamingEnumeration<SearchResult> searchUsers( Object key, DirContext context )
+        throws NamingException
+    {
+        LdapUserQuery query = new LdapUserQuery();
+        query.setUsername( "" + key );
+        return searchUsers( context, null, query );
+    }
+
+    protected NamingEnumeration<SearchResult> searchUsers( DirContext context )
+        throws NamingException
+    {
+        return searchUsers( context, null, null );
+    }
+
+    protected NamingEnumeration<SearchResult> searchUsers( DirContext context, String[] returnAttributes )
+        throws NamingException
+    {
+        return searchUsers( context, returnAttributes, null );
+    }
+
+    protected NamingEnumeration<SearchResult> searchUsers( DirContext context, String[] returnAttributes, LdapUserQuery query )
+        throws NamingException
+    {
+        if ( query == null )
+        {
+            query = new LdapUserQuery();
+        }
+        SearchControls ctls = new SearchControls();
+
+        ctls.setDerefLinkFlag( true );
+        ctls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+        ctls.setReturningAttributes( mapper.getReturningAttributes() );
+        ctls.setCountLimit( ( ( LdapUserMapper ) mapper ).getMaxResultCount() );
+
+        String finalFilter = "(&(objectClass=" + mapper.getUserObjectClass() + ")" +
+            ( mapper.getUserFilter() != null ? mapper.getUserFilter() : "" ) + query.getLdapFilter(mapper) + ")";
+
+        log.info( "Searching for users with filter: \'{}\'" + " from base dn: {}",finalFilter, mapper.getUserBaseDn() );
+
+        return context.search( mapper.getUserBaseDn(), finalFilter, ctls );
+    }
+
+    /**
+	 * @see org.codehaus.plexus.redback.users.ldap.ctl.LdapControllerI#getUsers(javax.naming.directory.DirContext)
+	 */
+    public Collection<User> getUsers( DirContext context )
+        throws LdapControllerException, MappingException
+    {
+        NamingEnumeration<SearchResult> results = null;
+        try
+        {
+            results = searchUsers( context, null, null );
+            Set<User> users = new LinkedHashSet<User>();
+
+            while ( results.hasMoreElements() )
+            {
+                SearchResult result = results.nextElement();
+
+                users.add( mapper.getUser( result.getAttributes() ) );
+            }
+
+            return users;
+        }
+        catch ( NamingException e )
+        {
+            String message = "Failed to retrieve ldap information for users.";
+
+            throw new LdapControllerException( message, e );
+        }
+        finally
+        {
+            if ( results != null )
+                try
+                {
+                    results.close();
+                }
+                catch ( NamingException e )
+                {
+                    log.warn( "failed to close search results", e );
+                }
+        }
+    }
+    
+   /**
+    * @see org.codehaus.plexus.redback.users.ldap.ctl.LdapControllerI#getUsersByQuery(org.codehaus.plexus.redback.users.ldap.LdapUserQuery, javax.naming.directory.DirContext)
+    */
+   public List<User> getUsersByQuery( LdapUserQuery query, DirContext context )
+       throws LdapControllerException, MappingException
+   {
+       NamingEnumeration<SearchResult> results = null;
+       try
+       {
+           results = searchUsers( context, null, query );
+           List<User> users = new LinkedList<User>();
+
+           while ( results.hasMoreElements() )
+           {
+               SearchResult result = results.nextElement();
+
+               users.add( mapper.getUser( result.getAttributes() ) );
+           }
+
+           return users;
+       }
+       catch ( NamingException e )
+       {
+           String message = "Failed to retrieve ldap information for users.";
+
+           throw new LdapControllerException( message, e );
+       }
+       finally
+        {
+            if ( results != null )
+                try
+                {
+                    results.close();
+                }
+                catch ( NamingException e )
+                {
+                    log.warn( "failed to close search results", e );
+                }
+        }
+   }
+
+    /**
+	 * @see org.codehaus.plexus.redback.users.ldap.ctl.LdapControllerI#createUser(org.codehaus.plexus.redback.users.User, javax.naming.directory.DirContext, boolean)
+	 */
+    public void createUser( User user, DirContext context, boolean encodePasswordIfChanged )
+        throws LdapControllerException, MappingException
+    {
+        if ( user == null )
+        {
+            return;
+        }
+        if ( user.getUsername().equals( UserManager.GUEST_USERNAME ) )
+        {
+            //We don't store guest
+            return;
+        }
+
+    }
+
+    /**
+	 * @see org.codehaus.plexus.redback.users.ldap.ctl.LdapControllerI#getUser(java.lang.Object, javax.naming.directory.DirContext)
+	 */
+    public LdapUser getUser( Object key, DirContext context )
+        throws LdapControllerException, MappingException
+    {
+        String username = key.toString();
+
+        log.info( "Searching for user: {}", username );
+        LdapUserQuery query = new LdapUserQuery();
+        query.setUsername( username );
+
+        NamingEnumeration<SearchResult> result = null;
+        try
+        {
+            result = searchUsers( context, null, query );
+
+            if ( result.hasMoreElements() )
+            {
+                SearchResult next = result.nextElement();
+
+                return mapper.getUser( next.getAttributes() );
+            }
+            else
+            {
+                return null;
+            }
+        }
+        catch ( NamingException e )
+        {
+            String message = "Failed to retrieve information for user: " + username;
+
+            throw new LdapControllerException( message, e );
+        }
+        finally
+        {
+            if ( result != null )
+                try
+                {
+                    result.close();
+                }
+                catch ( NamingException e )
+                {
+                    log.warn( "failed to close search results", e );
+                }
+        }
+    }
+
+}

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/codehaus/plexus/redback/users/ldap/ctl/DefaultLdapController.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/codehaus/plexus/redback/users/ldap/ctl/DefaultLdapController.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/codehaus/plexus/redback/users/ldap/ctl/LdapController.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/codehaus/plexus/redback/users/ldap/ctl/LdapController.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/codehaus/plexus/redback/users/ldap/ctl/LdapController.java (added)
+++ archiva/redback/redback-core/trunk/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/codehaus/plexus/redback/users/ldap/ctl/LdapController.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,54 @@
+package org.codehaus.plexus.redback.users.ldap.ctl;
+
+/*
+ * Copyright 2001-2007 The Codehaus.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.codehaus.plexus.redback.common.ldap.LdapUser;
+import org.codehaus.plexus.redback.common.ldap.MappingException;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.redback.users.ldap.LdapUserQuery;
+
+import javax.naming.directory.DirContext;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @version $Id$
+ */
+public interface LdapController
+{
+
+    void removeUser( Object principal, DirContext context )
+        throws LdapControllerException;
+
+    void updateUser( User user, DirContext context )
+        throws LdapControllerException, MappingException;
+
+    boolean userExists( Object key, DirContext context )
+        throws LdapControllerException;
+
+    Collection<User> getUsers( DirContext context )
+        throws LdapControllerException, MappingException;
+
+    void createUser( User user, DirContext context, boolean encodePasswordIfChanged )
+        throws LdapControllerException, MappingException;
+
+    LdapUser getUser( Object key, DirContext context )
+        throws LdapControllerException, MappingException;
+
+    List<User> getUsersByQuery( LdapUserQuery query, DirContext context )
+        throws LdapControllerException, MappingException;
+}