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

13 files changed:
redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/admin/AbstractUserCredentialsActionTest.java
redback-integrations/redback-struts2/redback-struts2-integration/src/test/java/org/codehaus/plexus/redback/struts2/action/admin/UserEditActionTest.java
redback-users/redback-users-providers/redback-users-memory/src/main/java/org/apache/archiva/redback/users/memory/MemoryUserManager.java [new file with mode: 0644]
redback-users/redback-users-providers/redback-users-memory/src/main/java/org/apache/archiva/redback/users/memory/SimpleUser.java [new file with mode: 0644]
redback-users/redback-users-providers/redback-users-memory/src/main/java/org/apache/archiva/redback/users/memory/SimpleUserQuery.java [new file with mode: 0644]
redback-users/redback-users-providers/redback-users-memory/src/main/java/org/apache/archiva/redback/users/memory/util/UserSorter.java [new file with mode: 0644]
redback-users/redback-users-providers/redback-users-memory/src/main/java/org/codehaus/plexus/redback/users/memory/MemoryUserManager.java [deleted file]
redback-users/redback-users-providers/redback-users-memory/src/main/java/org/codehaus/plexus/redback/users/memory/SimpleUser.java [deleted file]
redback-users/redback-users-providers/redback-users-memory/src/main/java/org/codehaus/plexus/redback/users/memory/SimpleUserQuery.java [deleted file]
redback-users/redback-users-providers/redback-users-memory/src/main/java/org/codehaus/plexus/redback/users/memory/util/UserSorter.java [deleted file]
redback-users/redback-users-providers/redback-users-memory/src/main/resources/META-INF/spring-context.xml
redback-users/redback-users-providers/redback-users-memory/src/test/java/org/apache/archiva/redback/users/MemoryUserManagerTest.java [new file with mode: 0644]
redback-users/redback-users-providers/redback-users-memory/src/test/java/org/codehaus/plexus/redback/users/MemoryUserManagerTest.java [deleted file]

index b64a558d8e0faccdb4b43abda2a799f48ea27bdf..2a08c1b4cdeab1eefc56d31c5e952f017414c7de 100644 (file)
@@ -37,7 +37,7 @@ import org.codehaus.plexus.redback.system.SecuritySystem;
 import org.codehaus.plexus.redback.system.SecuritySystemConstants;
 import org.apache.archiva.redback.users.User;
 import org.apache.archiva.redback.users.UserNotFoundException;
-import org.codehaus.plexus.redback.users.memory.SimpleUser;
+import org.apache.archiva.redback.users.memory.SimpleUser;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.runner.RunWith;
index 8a0d7399518507d11586bf0dfee65b9172ae1f65..a87aedf1fce18aa57d48639c1662d5f4147d950e 100644 (file)
@@ -33,7 +33,7 @@ import org.codehaus.plexus.redback.rbac.Role;
 import org.codehaus.plexus.redback.system.DefaultSecuritySession;
 import org.codehaus.plexus.redback.system.SecuritySession;
 import org.codehaus.plexus.redback.system.SecuritySystemConstants;
-import org.codehaus.plexus.redback.users.memory.SimpleUser;
+import org.apache.archiva.redback.users.memory.SimpleUser;
 import org.codehaus.redback.integration.model.AdminEditUserCredentials;
 import org.junit.After;
 import org.junit.Before;
diff --git a/redback-users/redback-users-providers/redback-users-memory/src/main/java/org/apache/archiva/redback/users/memory/MemoryUserManager.java b/redback-users/redback-users-providers/redback-users-memory/src/main/java/org/apache/archiva/redback/users/memory/MemoryUserManager.java
new file mode 100644 (file)
index 0000000..125168b
--- /dev/null
@@ -0,0 +1,335 @@
+package org.apache.archiva.redback.users.memory;
+
+/*
+ * 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.User;
+import org.apache.archiva.redback.users.UserManager;
+import org.codehaus.plexus.redback.policy.UserSecurityPolicy;
+import org.apache.archiva.redback.users.AbstractUserManager;
+import org.apache.archiva.redback.users.PermanentUserException;
+import org.apache.archiva.redback.users.UserQuery;
+import org.apache.archiva.redback.users.UserNotFoundException;
+import org.apache.archiva.redback.users.memory.util.UserSorter;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.annotation.Resource;
+
+/**
+ * @version $Id$
+ */
+@Service("userManager#memory")
+public class MemoryUserManager
+    extends AbstractUserManager
+    implements UserManager
+{
+    @Resource
+    private UserSecurityPolicy userSecurityPolicy;
+
+    public String getId()
+    {
+        Properties props = new Properties();
+        URL url = this
+            .getClass()
+            .getResource(
+                "META-INF/maven/org/codehaus/plexus/redback/redback-users-memory/pom.properties" );
+
+        if ( url != null )
+        {
+            try
+            {
+                props.load( url.openStream() );
+                return "MemoryUserManager - " + props.getProperty( "version" );
+            }
+            catch ( IOException e )
+            {
+                // Fall thru
+            }
+        }
+        return "MemoryUserManager - (unknown version)";
+    }
+    
+    public boolean isReadOnly()
+    {
+        return false;
+    }
+
+    public UserQuery createUserQuery()
+    {
+        return new SimpleUserQuery();
+    }
+
+    public List<User> findUsersByQuery( UserQuery query )
+    {
+        SimpleUserQuery uq = (SimpleUserQuery) query;
+
+        List<User> list = new ArrayList<User>();
+
+        for ( Iterator<User> i = users.values().iterator(); i.hasNext(); )
+        {
+            SimpleUser user = (SimpleUser) i.next();
+            boolean matches = uq.matches( user );
+            if ( matches )
+            {
+                list.add( user );
+            }
+        }
+
+        Collections.sort( list, uq.getComparator() );
+
+        List<User> cutList = new ArrayList<User>();
+
+        for ( long i = query.getFirstResult();
+              i < list.size() && ( query.getMaxResults() == -1 || i < query.getFirstResult() + uq.getMaxResults() );
+              i++ )
+        {
+            cutList.add( list.get( (int) i ) );
+        }
+        return cutList;
+    }
+
+    private Map<Object, User> users = new HashMap<Object, User>();
+
+    public User addUser( User user )
+    {
+        saveUser( user );
+        fireUserManagerUserAdded( user );
+
+        // If there exists no encoded password, then this is a new user setup 
+        if ( StringUtils.isEmpty( user.getEncodedPassword() ) )
+        {
+            userSecurityPolicy.extensionChangePassword( user );
+        }
+
+        return user;
+    }
+
+    private void saveUser( User user )
+    {
+        triggerInit();
+        users.put( user.getPrincipal(), user );
+    }
+
+    public User updateUser( User user )
+    {
+        return updateUser( user, false );
+    }
+
+    public User updateUser( User user, boolean passwordChangeRequired )
+    {
+        if ( StringUtils.isNotEmpty( user.getPassword() ) )
+        {
+            userSecurityPolicy.extensionChangePassword( user, passwordChangeRequired );
+        }
+
+        saveUser( user );
+
+        fireUserManagerUserUpdated( user );
+
+        return user;
+    }
+
+    public User findUser( Object principal )
+        throws UserNotFoundException
+    {
+        triggerInit();
+        User user = users.get( principal );
+
+        if ( user == null )
+        {
+            throw new UserNotFoundException( "Cannot find the user with the principal '" + principal + "'." );
+        }
+
+        return user;
+    }
+
+    public boolean userExists( Object principal )
+    {
+        try
+        {
+            findUser( principal );
+            return true;
+        }
+        catch ( UserNotFoundException ne )
+        {
+            return false;
+        }
+    }
+
+    public void deleteUser( Object principal )
+        throws UserNotFoundException
+    {
+        deleteUser( principal.toString() );
+    }
+
+    public User createUser( String username, String fullName, String emailAddress )
+    {
+        User user = new SimpleUser();
+        user.setUsername( username );
+        user.setFullName( fullName );
+        user.setEmail( emailAddress );
+
+        return user;
+    }
+
+    public void deleteUser( String username )
+        throws UserNotFoundException
+    {
+        User user = findUser( username );
+
+        if ( user.isPermanent() )
+        {
+            throw new PermanentUserException( "Cannot delete permanent user." );
+        }
+
+        users.remove( user.getPrincipal() );
+
+        fireUserManagerUserRemoved( user );
+    }
+
+    public void addUserUnchecked( User user )
+    {
+        addUser( user );
+    }
+
+    public void eraseDatabase()
+    {
+        users.clear();
+    }
+
+    public User findUser( String username )
+        throws UserNotFoundException
+    {
+        triggerInit();
+        User user = null;
+
+        Iterator<User> it = users.values().iterator();
+        while ( it.hasNext() )
+        {
+            User u = it.next();
+            if ( u.getUsername().equals( username ) )
+            {
+                user = u;
+            }
+        }
+
+        if ( user == null )
+        {
+            throw new UserNotFoundException( "Unable to find user '" + username + "'" );
+        }
+
+        return user;
+    }
+
+    public List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending )
+    {
+        triggerInit();
+
+        List<User> userList = new ArrayList<User>();
+
+        Iterator<User> it = users.values().iterator();
+        while ( it.hasNext() )
+        {
+            User u = it.next();
+            if ( u.getUsername().indexOf( usernameKey ) > -1 )
+            {
+                userList.add( u );
+            }
+        }
+
+        Collections.sort( userList, new UserSorter( orderAscending ) );
+
+        return userList;
+    }
+
+    public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
+    {
+        triggerInit();
+
+        List<User> userList = new ArrayList<User>();
+
+        Iterator<User> it = users.values().iterator();
+        while ( it.hasNext() )
+        {
+            User u = it.next();
+            if ( u.getFullName().indexOf( fullNameKey ) > -1 )
+            {
+                userList.add( u );
+            }
+        }
+
+        Collections.sort( userList, new UserSorter( orderAscending ) );
+
+        return userList;
+    }
+
+    public List<User> findUsersByEmailKey( String emailKey, boolean orderAscending )
+    {
+        triggerInit();
+
+        List<User> userList = new ArrayList<User>();
+
+        Iterator<User> it = users.values().iterator();
+        while ( it.hasNext() )
+        {
+            User u = it.next();
+            if ( u.getEmail().indexOf( emailKey ) > -1 )
+            {
+                userList.add( u );
+            }
+        }
+
+        Collections.sort( userList, new UserSorter( orderAscending ) );
+
+        return userList;
+    }
+
+    public List<User> getUsers()
+    {
+        triggerInit();
+        return new ArrayList<User>( users.values() );
+    }
+
+    public List<User> getUsers( boolean ascendingUsername )
+    {
+        return getUsers();
+    }
+
+    private boolean hasTriggeredInit = false;
+
+    public void triggerInit()
+    {
+        if ( !hasTriggeredInit )
+        {
+            fireUserManagerInit( users.isEmpty() );
+            hasTriggeredInit = true;
+        }
+    }
+}
diff --git a/redback-users/redback-users-providers/redback-users-memory/src/main/java/org/apache/archiva/redback/users/memory/SimpleUser.java b/redback-users/redback-users-providers/redback-users-memory/src/main/java/org/apache/archiva/redback/users/memory/SimpleUser.java
new file mode 100644 (file)
index 0000000..2f37a4c
--- /dev/null
@@ -0,0 +1,223 @@
+package org.apache.archiva.redback.users.memory;
+
+/*
+ * 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.User;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * A Simple User record.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ */
+public class SimpleUser
+    implements User, Serializable
+{
+    private String username;
+
+    private String password;
+
+    private String email;
+
+    private String fullName;
+
+    private String encodedPassword;
+
+    private Date lastPasswordChange;
+
+    private Date lastLoginDate;
+
+    private int countFailedLoginAttempts = 0;
+
+    private boolean locked = false;
+
+    private boolean permanent = false;
+
+    private boolean validated = false;
+
+    private List<String> previousEncodedPasswords;
+
+    private Date accountCreationDate;
+
+    private boolean passwordChangeRequired;
+
+    public SimpleUser()
+    {
+        // no op
+    }
+
+    public void addPreviousEncodedPassword( String encodedPassword )
+    {
+        getPreviousEncodedPasswords().add( encodedPassword );
+    }
+
+    public Date getAccountCreationDate()
+    {
+        return accountCreationDate;
+    }
+
+    public int getCountFailedLoginAttempts()
+    {
+        return countFailedLoginAttempts;
+    }
+
+    public String getEmail()
+    {
+        return email;
+    }
+
+    public String getEncodedPassword()
+    {
+        return encodedPassword;
+    }
+
+    public String getFullName()
+    {
+        return fullName;
+    }
+
+    public Date getLastLoginDate()
+    {
+        return lastLoginDate;
+    }
+
+    public Date getLastPasswordChange()
+    {
+        return lastPasswordChange;
+    }
+
+    public String getPassword()
+    {
+        return password;
+    }
+
+    public List<String> getPreviousEncodedPasswords()
+    {
+        if ( previousEncodedPasswords == null )
+        {
+            previousEncodedPasswords = new ArrayList<String>();
+        }
+        return previousEncodedPasswords;
+    }
+
+    public Object getPrincipal()
+    {
+        return username;
+    }
+
+    public String getUsername()
+    {
+        return username;
+    }
+
+    public boolean isLocked()
+    {
+        return locked;
+    }
+
+    public void setAccountCreationDate( Date accountCreationDate )
+    {
+        this.accountCreationDate = accountCreationDate;
+    }
+
+    public void setCountFailedLoginAttempts( int countFailedLoginAttempts )
+    {
+        this.countFailedLoginAttempts = countFailedLoginAttempts;
+    }
+
+    public void setEmail( String email )
+    {
+        this.email = email;
+    }
+
+    public void setEncodedPassword( String encodedPassword )
+    {
+        this.encodedPassword = encodedPassword;
+    }
+
+    public void setFullName( String fullName )
+    {
+        this.fullName = fullName;
+    }
+
+    public void setLastLoginDate( Date lastLoginDate )
+    {
+        this.lastLoginDate = lastLoginDate;
+    }
+
+    public void setLastPasswordChange( Date lastPasswordChange )
+    {
+        this.lastPasswordChange = lastPasswordChange;
+    }
+
+    public void setLocked( boolean locked )
+    {
+        this.locked = locked;
+    }
+
+    public void setPassword( String password )
+    {
+        this.password = password;
+    }
+
+    public void setPreviousEncodedPasswords( List<String> previousEncodedPasswords )
+    {
+        this.previousEncodedPasswords = previousEncodedPasswords;
+    }
+
+    public void setUsername( String username )
+    {
+        this.username = username;
+    }
+
+    public boolean isPasswordChangeRequired()
+    {
+        return passwordChangeRequired;
+    }
+
+    public void setPasswordChangeRequired( boolean passwordChangeRequired )
+    {
+        this.passwordChangeRequired = passwordChangeRequired;
+    }
+
+    public boolean isPermanent()
+    {
+        return permanent;
+    }
+
+    public void setPermanent( boolean permanent )
+    {
+        this.permanent = permanent;
+    }
+
+    public boolean isValidated()
+    {
+        return validated;
+    }
+
+    public void setValidated( boolean validated )
+    {
+        this.validated = validated;
+    }
+}
diff --git a/redback-users/redback-users-providers/redback-users-memory/src/main/java/org/apache/archiva/redback/users/memory/SimpleUserQuery.java b/redback-users/redback-users-providers/redback-users-memory/src/main/java/org/apache/archiva/redback/users/memory/SimpleUserQuery.java
new file mode 100644 (file)
index 0000000..70b2bbb
--- /dev/null
@@ -0,0 +1,94 @@
+package org.apache.archiva.redback.users.memory;
+
+/*
+ * 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.User;
+
+import java.util.Comparator;
+
+public class SimpleUserQuery
+    extends AbstractUserQuery
+{
+
+    /**
+     * Returns true if this user should be considered a match of the current query
+     *
+     * @param user
+     * @return
+     */
+    public boolean matches( User user )
+    {
+        if ( getUsername() != null && user.getUsername() != null &&
+            user.getUsername().toLowerCase().indexOf( getUsername().toLowerCase() ) == -1 )
+        {
+            return false;
+        }
+        else if ( getFullName() != null && user.getFullName() != null &&
+            user.getFullName().toLowerCase().indexOf( getFullName().toLowerCase() ) == -1 )
+        {
+            return false;
+        }
+        else if ( getEmail() != null && user.getEmail() != null &&
+            user.getEmail().toLowerCase().indexOf( getEmail().toLowerCase() ) == -1 )
+        {
+            return false;
+        }
+        else
+        {
+            return true;
+        }
+
+    }
+
+    /**
+     * Returns a comparator used for sorting a collection of User objects based on the ordering set
+     * on this UserQuery's {@link #setOrderBy(String)} and {@link #setAscending(boolean)}. 
+     * @return
+     */
+    public Comparator<User> getComparator()
+    {
+        return new Comparator<User>()
+        {
+            public int compare( User user1, User user2 )
+            {
+                return ( isAscending() ? 1 : -1 ) * compareUsers( user1, user2 );
+            }
+        };
+    }
+
+    private int compareUsers( User user, User user1 )
+    {
+        if ( ORDER_BY_EMAIL.equals( getOrderBy() ) )
+        {
+            return user.getEmail() == null ? -1
+                : user1.getEmail() == null ? 1 : user.getEmail().compareTo( user1.getEmail() );
+        }
+        else if ( ORDER_BY_FULLNAME.equals( getOrderBy() ) )
+        {
+            return user.getFullName() == null ? -1
+                : user1.getFullName() == null ? 1 : user.getFullName().compareTo( user1.getFullName() );
+        }
+        else
+        {
+            return user.getUsername().compareTo( user1.getUsername() );
+        }
+    }
+}
diff --git a/redback-users/redback-users-providers/redback-users-memory/src/main/java/org/apache/archiva/redback/users/memory/util/UserSorter.java b/redback-users/redback-users-providers/redback-users-memory/src/main/java/org/apache/archiva/redback/users/memory/util/UserSorter.java
new file mode 100644 (file)
index 0000000..7f46c51
--- /dev/null
@@ -0,0 +1,88 @@
+package org.apache.archiva.redback.users.memory.util;
+
+/*
+ * 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.User;
+
+import java.util.Comparator;
+
+/**
+ * UserSorter
+ */
+public class UserSorter
+    implements Comparator<User>
+{
+    private boolean ascending;
+
+    public UserSorter()
+    {
+        this.ascending = true;
+    }
+
+    public UserSorter( boolean ascending )
+    {
+        this.ascending = ascending;
+    }
+
+    public int compare( User o1, User o2 )
+    {
+        if ( ( o1 == null ) && ( o2 == null ) )
+        {
+            return 0;
+        }
+
+        if ( ( o1 == null ) && ( o2 != null ) )
+        {
+            return -1;
+        }
+
+        if ( ( o1 != null ) && ( o2 != null ) )
+        {
+            return 1;
+        }
+
+        User u1 = null;
+        User u2 = null;
+
+        if ( isAscending() )
+        {
+            u1 = o1;
+            u2 = o2;
+        }
+        else
+        {
+            u1 = o2;
+            u2 = o1;
+        }
+
+        return u1.getUsername().compareTo( u2.getUsername() );
+    }
+
+    public boolean isAscending()
+    {
+        return ascending;
+    }
+
+    public void setAscending( boolean ascending )
+    {
+        this.ascending = ascending;
+    }
+
+}
diff --git a/redback-users/redback-users-providers/redback-users-memory/src/main/java/org/codehaus/plexus/redback/users/memory/MemoryUserManager.java b/redback-users/redback-users-providers/redback-users-memory/src/main/java/org/codehaus/plexus/redback/users/memory/MemoryUserManager.java
deleted file mode 100644 (file)
index 8362567..0000000
+++ /dev/null
@@ -1,335 +0,0 @@
-package org.codehaus.plexus.redback.users.memory;
-
-/*
- * 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.User;
-import org.apache.archiva.redback.users.UserManager;
-import org.codehaus.plexus.redback.policy.UserSecurityPolicy;
-import org.apache.archiva.redback.users.AbstractUserManager;
-import org.apache.archiva.redback.users.PermanentUserException;
-import org.apache.archiva.redback.users.UserQuery;
-import org.apache.archiva.redback.users.UserNotFoundException;
-import org.codehaus.plexus.redback.users.memory.util.UserSorter;
-import org.apache.commons.lang.StringUtils;
-import org.springframework.stereotype.Service;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import javax.annotation.Resource;
-
-/**
- * @version $Id$
- */
-@Service("userManager#memory")
-public class MemoryUserManager
-    extends AbstractUserManager
-    implements UserManager
-{
-    @Resource
-    private UserSecurityPolicy userSecurityPolicy;
-
-    public String getId()
-    {
-        Properties props = new Properties();
-        URL url = this
-            .getClass()
-            .getResource(
-                "META-INF/maven/org/codehaus/plexus/redback/redback-users-memory/pom.properties" );
-
-        if ( url != null )
-        {
-            try
-            {
-                props.load( url.openStream() );
-                return "MemoryUserManager - " + props.getProperty( "version" );
-            }
-            catch ( IOException e )
-            {
-                // Fall thru
-            }
-        }
-        return "MemoryUserManager - (unknown version)";
-    }
-    
-    public boolean isReadOnly()
-    {
-        return false;
-    }
-
-    public UserQuery createUserQuery()
-    {
-        return new SimpleUserQuery();
-    }
-
-    public List<User> findUsersByQuery( UserQuery query )
-    {
-        SimpleUserQuery uq = (SimpleUserQuery) query;
-
-        List<User> list = new ArrayList<User>();
-
-        for ( Iterator<User> i = users.values().iterator(); i.hasNext(); )
-        {
-            SimpleUser user = (SimpleUser) i.next();
-            boolean matches = uq.matches( user );
-            if ( matches )
-            {
-                list.add( user );
-            }
-        }
-
-        Collections.sort( list, uq.getComparator() );
-
-        List<User> cutList = new ArrayList<User>();
-
-        for ( long i = query.getFirstResult();
-              i < list.size() && ( query.getMaxResults() == -1 || i < query.getFirstResult() + uq.getMaxResults() );
-              i++ )
-        {
-            cutList.add( list.get( (int) i ) );
-        }
-        return cutList;
-    }
-
-    private Map<Object, User> users = new HashMap<Object, User>();
-
-    public User addUser( User user )
-    {
-        saveUser( user );
-        fireUserManagerUserAdded( user );
-
-        // If there exists no encoded password, then this is a new user setup 
-        if ( StringUtils.isEmpty( user.getEncodedPassword() ) )
-        {
-            userSecurityPolicy.extensionChangePassword( user );
-        }
-
-        return user;
-    }
-
-    private void saveUser( User user )
-    {
-        triggerInit();
-        users.put( user.getPrincipal(), user );
-    }
-
-    public User updateUser( User user )
-    {
-        return updateUser( user, false );
-    }
-
-    public User updateUser( User user, boolean passwordChangeRequired )
-    {
-        if ( StringUtils.isNotEmpty( user.getPassword() ) )
-        {
-            userSecurityPolicy.extensionChangePassword( user, passwordChangeRequired );
-        }
-
-        saveUser( user );
-
-        fireUserManagerUserUpdated( user );
-
-        return user;
-    }
-
-    public User findUser( Object principal )
-        throws UserNotFoundException
-    {
-        triggerInit();
-        User user = users.get( principal );
-
-        if ( user == null )
-        {
-            throw new UserNotFoundException( "Cannot find the user with the principal '" + principal + "'." );
-        }
-
-        return user;
-    }
-
-    public boolean userExists( Object principal )
-    {
-        try
-        {
-            findUser( principal );
-            return true;
-        }
-        catch ( UserNotFoundException ne )
-        {
-            return false;
-        }
-    }
-
-    public void deleteUser( Object principal )
-        throws UserNotFoundException
-    {
-        deleteUser( principal.toString() );
-    }
-
-    public User createUser( String username, String fullName, String emailAddress )
-    {
-        User user = new SimpleUser();
-        user.setUsername( username );
-        user.setFullName( fullName );
-        user.setEmail( emailAddress );
-
-        return user;
-    }
-
-    public void deleteUser( String username )
-        throws UserNotFoundException
-    {
-        User user = findUser( username );
-
-        if ( user.isPermanent() )
-        {
-            throw new PermanentUserException( "Cannot delete permanent user." );
-        }
-
-        users.remove( user.getPrincipal() );
-
-        fireUserManagerUserRemoved( user );
-    }
-
-    public void addUserUnchecked( User user )
-    {
-        addUser( user );
-    }
-
-    public void eraseDatabase()
-    {
-        users.clear();
-    }
-
-    public User findUser( String username )
-        throws UserNotFoundException
-    {
-        triggerInit();
-        User user = null;
-
-        Iterator<User> it = users.values().iterator();
-        while ( it.hasNext() )
-        {
-            User u = it.next();
-            if ( u.getUsername().equals( username ) )
-            {
-                user = u;
-            }
-        }
-
-        if ( user == null )
-        {
-            throw new UserNotFoundException( "Unable to find user '" + username + "'" );
-        }
-
-        return user;
-    }
-
-    public List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending )
-    {
-        triggerInit();
-
-        List<User> userList = new ArrayList<User>();
-
-        Iterator<User> it = users.values().iterator();
-        while ( it.hasNext() )
-        {
-            User u = it.next();
-            if ( u.getUsername().indexOf( usernameKey ) > -1 )
-            {
-                userList.add( u );
-            }
-        }
-
-        Collections.sort( userList, new UserSorter( orderAscending ) );
-
-        return userList;
-    }
-
-    public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
-    {
-        triggerInit();
-
-        List<User> userList = new ArrayList<User>();
-
-        Iterator<User> it = users.values().iterator();
-        while ( it.hasNext() )
-        {
-            User u = it.next();
-            if ( u.getFullName().indexOf( fullNameKey ) > -1 )
-            {
-                userList.add( u );
-            }
-        }
-
-        Collections.sort( userList, new UserSorter( orderAscending ) );
-
-        return userList;
-    }
-
-    public List<User> findUsersByEmailKey( String emailKey, boolean orderAscending )
-    {
-        triggerInit();
-
-        List<User> userList = new ArrayList<User>();
-
-        Iterator<User> it = users.values().iterator();
-        while ( it.hasNext() )
-        {
-            User u = it.next();
-            if ( u.getEmail().indexOf( emailKey ) > -1 )
-            {
-                userList.add( u );
-            }
-        }
-
-        Collections.sort( userList, new UserSorter( orderAscending ) );
-
-        return userList;
-    }
-
-    public List<User> getUsers()
-    {
-        triggerInit();
-        return new ArrayList<User>( users.values() );
-    }
-
-    public List<User> getUsers( boolean ascendingUsername )
-    {
-        return getUsers();
-    }
-
-    private boolean hasTriggeredInit = false;
-
-    public void triggerInit()
-    {
-        if ( !hasTriggeredInit )
-        {
-            fireUserManagerInit( users.isEmpty() );
-            hasTriggeredInit = true;
-        }
-    }
-}
diff --git a/redback-users/redback-users-providers/redback-users-memory/src/main/java/org/codehaus/plexus/redback/users/memory/SimpleUser.java b/redback-users/redback-users-providers/redback-users-memory/src/main/java/org/codehaus/plexus/redback/users/memory/SimpleUser.java
deleted file mode 100644 (file)
index ac4aa4b..0000000
+++ /dev/null
@@ -1,223 +0,0 @@
-package org.codehaus.plexus.redback.users.memory;
-
-/*
- * 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.User;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-/**
- * A Simple User record.
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- */
-public class SimpleUser
-    implements User, Serializable
-{
-    private String username;
-
-    private String password;
-
-    private String email;
-
-    private String fullName;
-
-    private String encodedPassword;
-
-    private Date lastPasswordChange;
-
-    private Date lastLoginDate;
-
-    private int countFailedLoginAttempts = 0;
-
-    private boolean locked = false;
-
-    private boolean permanent = false;
-
-    private boolean validated = false;
-
-    private List<String> previousEncodedPasswords;
-
-    private Date accountCreationDate;
-
-    private boolean passwordChangeRequired;
-
-    public SimpleUser()
-    {
-        // no op
-    }
-
-    public void addPreviousEncodedPassword( String encodedPassword )
-    {
-        getPreviousEncodedPasswords().add( encodedPassword );
-    }
-
-    public Date getAccountCreationDate()
-    {
-        return accountCreationDate;
-    }
-
-    public int getCountFailedLoginAttempts()
-    {
-        return countFailedLoginAttempts;
-    }
-
-    public String getEmail()
-    {
-        return email;
-    }
-
-    public String getEncodedPassword()
-    {
-        return encodedPassword;
-    }
-
-    public String getFullName()
-    {
-        return fullName;
-    }
-
-    public Date getLastLoginDate()
-    {
-        return lastLoginDate;
-    }
-
-    public Date getLastPasswordChange()
-    {
-        return lastPasswordChange;
-    }
-
-    public String getPassword()
-    {
-        return password;
-    }
-
-    public List<String> getPreviousEncodedPasswords()
-    {
-        if ( previousEncodedPasswords == null )
-        {
-            previousEncodedPasswords = new ArrayList<String>();
-        }
-        return previousEncodedPasswords;
-    }
-
-    public Object getPrincipal()
-    {
-        return username;
-    }
-
-    public String getUsername()
-    {
-        return username;
-    }
-
-    public boolean isLocked()
-    {
-        return locked;
-    }
-
-    public void setAccountCreationDate( Date accountCreationDate )
-    {
-        this.accountCreationDate = accountCreationDate;
-    }
-
-    public void setCountFailedLoginAttempts( int countFailedLoginAttempts )
-    {
-        this.countFailedLoginAttempts = countFailedLoginAttempts;
-    }
-
-    public void setEmail( String email )
-    {
-        this.email = email;
-    }
-
-    public void setEncodedPassword( String encodedPassword )
-    {
-        this.encodedPassword = encodedPassword;
-    }
-
-    public void setFullName( String fullName )
-    {
-        this.fullName = fullName;
-    }
-
-    public void setLastLoginDate( Date lastLoginDate )
-    {
-        this.lastLoginDate = lastLoginDate;
-    }
-
-    public void setLastPasswordChange( Date lastPasswordChange )
-    {
-        this.lastPasswordChange = lastPasswordChange;
-    }
-
-    public void setLocked( boolean locked )
-    {
-        this.locked = locked;
-    }
-
-    public void setPassword( String password )
-    {
-        this.password = password;
-    }
-
-    public void setPreviousEncodedPasswords( List<String> previousEncodedPasswords )
-    {
-        this.previousEncodedPasswords = previousEncodedPasswords;
-    }
-
-    public void setUsername( String username )
-    {
-        this.username = username;
-    }
-
-    public boolean isPasswordChangeRequired()
-    {
-        return passwordChangeRequired;
-    }
-
-    public void setPasswordChangeRequired( boolean passwordChangeRequired )
-    {
-        this.passwordChangeRequired = passwordChangeRequired;
-    }
-
-    public boolean isPermanent()
-    {
-        return permanent;
-    }
-
-    public void setPermanent( boolean permanent )
-    {
-        this.permanent = permanent;
-    }
-
-    public boolean isValidated()
-    {
-        return validated;
-    }
-
-    public void setValidated( boolean validated )
-    {
-        this.validated = validated;
-    }
-}
diff --git a/redback-users/redback-users-providers/redback-users-memory/src/main/java/org/codehaus/plexus/redback/users/memory/SimpleUserQuery.java b/redback-users/redback-users-providers/redback-users-memory/src/main/java/org/codehaus/plexus/redback/users/memory/SimpleUserQuery.java
deleted file mode 100644 (file)
index 5eb50c7..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-package org.codehaus.plexus.redback.users.memory;
-
-/*
- * 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.User;
-
-import java.util.Comparator;
-
-public class SimpleUserQuery
-    extends AbstractUserQuery
-{
-
-    /**
-     * Returns true if this user should be considered a match of the current query
-     *
-     * @param user
-     * @return
-     */
-    public boolean matches( User user )
-    {
-        if ( getUsername() != null && user.getUsername() != null &&
-            user.getUsername().toLowerCase().indexOf( getUsername().toLowerCase() ) == -1 )
-        {
-            return false;
-        }
-        else if ( getFullName() != null && user.getFullName() != null &&
-            user.getFullName().toLowerCase().indexOf( getFullName().toLowerCase() ) == -1 )
-        {
-            return false;
-        }
-        else if ( getEmail() != null && user.getEmail() != null &&
-            user.getEmail().toLowerCase().indexOf( getEmail().toLowerCase() ) == -1 )
-        {
-            return false;
-        }
-        else
-        {
-            return true;
-        }
-
-    }
-
-    /**
-     * Returns a comparator used for sorting a collection of User objects based on the ordering set
-     * on this UserQuery's {@link #setOrderBy(String)} and {@link #setAscending(boolean)}. 
-     * @return
-     */
-    public Comparator<User> getComparator()
-    {
-        return new Comparator<User>()
-        {
-            public int compare( User user1, User user2 )
-            {
-                return ( isAscending() ? 1 : -1 ) * compareUsers( user1, user2 );
-            }
-        };
-    }
-
-    private int compareUsers( User user, User user1 )
-    {
-        if ( ORDER_BY_EMAIL.equals( getOrderBy() ) )
-        {
-            return user.getEmail() == null ? -1
-                : user1.getEmail() == null ? 1 : user.getEmail().compareTo( user1.getEmail() );
-        }
-        else if ( ORDER_BY_FULLNAME.equals( getOrderBy() ) )
-        {
-            return user.getFullName() == null ? -1
-                : user1.getFullName() == null ? 1 : user.getFullName().compareTo( user1.getFullName() );
-        }
-        else
-        {
-            return user.getUsername().compareTo( user1.getUsername() );
-        }
-    }
-}
diff --git a/redback-users/redback-users-providers/redback-users-memory/src/main/java/org/codehaus/plexus/redback/users/memory/util/UserSorter.java b/redback-users/redback-users-providers/redback-users-memory/src/main/java/org/codehaus/plexus/redback/users/memory/util/UserSorter.java
deleted file mode 100644 (file)
index 40dd340..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-package org.codehaus.plexus.redback.users.memory.util;
-
-/*
- * 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.User;
-
-import java.util.Comparator;
-
-/**
- * UserSorter
- */
-public class UserSorter
-    implements Comparator<User>
-{
-    private boolean ascending;
-
-    public UserSorter()
-    {
-        this.ascending = true;
-    }
-
-    public UserSorter( boolean ascending )
-    {
-        this.ascending = ascending;
-    }
-
-    public int compare( User o1, User o2 )
-    {
-        if ( ( o1 == null ) && ( o2 == null ) )
-        {
-            return 0;
-        }
-
-        if ( ( o1 == null ) && ( o2 != null ) )
-        {
-            return -1;
-        }
-
-        if ( ( o1 != null ) && ( o2 != null ) )
-        {
-            return 1;
-        }
-
-        User u1 = null;
-        User u2 = null;
-
-        if ( isAscending() )
-        {
-            u1 = o1;
-            u2 = o2;
-        }
-        else
-        {
-            u1 = o2;
-            u2 = o1;
-        }
-
-        return u1.getUsername().compareTo( u2.getUsername() );
-    }
-
-    public boolean isAscending()
-    {
-        return ascending;
-    }
-
-    public void setAscending( boolean ascending )
-    {
-        this.ascending = ascending;
-    }
-
-}
index 9694a882912d095d703d5e932bb676da5ad5342b..26fa471a7778546fb88d1a9264f286eeb2cc254e 100644 (file)
@@ -28,6 +28,6 @@
        default-lazy-init="true">
 
   <context:annotation-config />
-  <context:component-scan base-package="org.codehaus.plexus.redback.users.memory"/>
+  <context:component-scan base-package="org.apache.archiva.redback.users.memory"/>
  
 </beans>
\ No newline at end of file
diff --git a/redback-users/redback-users-providers/redback-users-memory/src/test/java/org/apache/archiva/redback/users/MemoryUserManagerTest.java b/redback-users/redback-users-providers/redback-users-memory/src/test/java/org/apache/archiva/redback/users/MemoryUserManagerTest.java
new file mode 100644 (file)
index 0000000..0befa96
--- /dev/null
@@ -0,0 +1,49 @@
+package org.apache.archiva.redback.users;
+
+/*
+ * 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.UserManager;
+import org.apache.archiva.redback.users.memory.MemoryUserManager;
+import org.codehaus.plexus.redback.users.provider.test.AbstractUserManagerTestCase;
+import org.junit.Before;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+/**
+ * {@link MemoryUserManager} test:
+ * 
+ * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
+ */
+public class MemoryUserManagerTest
+    extends AbstractUserManagerTestCase
+{
+
+    @Inject @Named(value = "userManager#memory")
+    UserManager userManager;
+
+    @Before
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+        setUserManager( userManager );
+    }
+}
diff --git a/redback-users/redback-users-providers/redback-users-memory/src/test/java/org/codehaus/plexus/redback/users/MemoryUserManagerTest.java b/redback-users/redback-users-providers/redback-users-memory/src/test/java/org/codehaus/plexus/redback/users/MemoryUserManagerTest.java
deleted file mode 100644 (file)
index 792b349..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-package org.codehaus.plexus.redback.users;
-
-/*
- * 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.UserManager;
-import org.codehaus.plexus.redback.users.memory.MemoryUserManager;
-import org.codehaus.plexus.redback.users.provider.test.AbstractUserManagerTestCase;
-import org.junit.Before;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-/**
- * {@link MemoryUserManager} test:
- * 
- * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
- */
-public class MemoryUserManagerTest
-    extends AbstractUserManagerTestCase
-{
-
-    @Inject @Named(value = "userManager#memory")
-    UserManager userManager;
-
-    @Before
-    public void setUp()
-        throws Exception
-    {
-        super.setUp();
-        setUserManager( userManager );
-    }
-}