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;
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;
--- /dev/null
+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;
+ }
+ }
+}
--- /dev/null
+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;
+ }
+}
--- /dev/null
+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() );
+ }
+ }
+}
--- /dev/null
+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;
+ }
+
+}
+++ /dev/null
-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;
- }
- }
-}
+++ /dev/null
-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;
- }
-}
+++ /dev/null
-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() );
- }
- }
-}
+++ /dev/null
-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;
- }
-
-}
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
--- /dev/null
+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 );
+ }
+}
+++ /dev/null
-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 );
- }
-}