← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7385: Refactored HibernateUserStore to use separate identifiable stores

 

------------------------------------------------------------
revno: 7385
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-06-25 20:07:55 +0200
message:
  Refactored HibernateUserStore to use separate identifiable stores
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentialsStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserCredentialsStore.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserAuthorityGroupTest.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserStoreTest.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentialsStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentialsStore.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentialsStore.java	2012-06-25 18:07:55 +0000
@@ -0,0 +1,177 @@
+package org.hisp.dhis.user;
+
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+import java.util.Date;
+
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+
+/**
+ * @author Lars Helge Overland
+ */
+public interface UserCredentialsStore
+{
+    String ID = UserCredentialsStore.class.getName();
+    
+    // -------------------------------------------------------------------------
+    // UserCredentials
+    // -------------------------------------------------------------------------
+
+    /**
+     * Adds a UserCredentials.
+     * 
+     * @param userCredentials the UserCredentials to add.
+     * @return the User which the UserCredentials is associated with.
+     */
+    User addUserCredentials( UserCredentials userCredentials );
+
+    /**
+     * Updates a UserCredentials.
+     * 
+     * @param userCredentials the UserCredentials to update.
+     */
+    void updateUserCredentials( UserCredentials userCredentials );
+
+    /**
+     * Retrieves the UserCredentials of the given User.
+     * 
+     * @param user the User.
+     * @return the UserCredentials.
+     */
+    UserCredentials getUserCredentials( User user );
+
+    /**
+     * Retrieves the UserCredentials associated with the User with the given
+     * name.
+     * 
+     * @param username the name of the User.
+     * @return the UserCredentials.
+     */
+    UserCredentials getUserCredentialsByUsername( String username );
+
+    /**
+     * Retrieves all UserCredentials.
+     * 
+     * @return a Collection of UserCredentials.
+     */
+    Collection<UserCredentials> getAllUserCredentials();
+
+    /**
+     * Deletes a UserCredentials.
+     * 
+     * @param userCredentials the UserCredentials.
+     */
+    void deleteUserCredentials( UserCredentials userCredentials );
+
+    Collection<UserCredentials> searchUsersByName( String key );
+
+    Collection<UserCredentials> getUsersBetween( int first, int max );
+
+    Collection<UserCredentials> getUsersBetweenByName( String name, int first, int max );
+
+    Collection<UserCredentials> getUsersWithoutOrganisationUnitBetween( int first, int max );
+
+    Collection<UserCredentials> getUsersWithoutOrganisationUnitBetweenByName( String name, int first, int max );
+
+    Collection<UserCredentials> getUsersByOrganisationUnitBetween( OrganisationUnit orgUnit, int first, int max );
+
+    Collection<UserCredentials> getUsersByOrganisationUnitBetweenByName( OrganisationUnit orgUnit, String name,
+        int first, int max );
+
+    Collection<UserCredentials> getInactiveUsers( Date date );
+    
+    Collection<UserCredentials> getInactiveUsers( Date date, int first, int max );
+
+    int getInactiveUsersCount( Date date );
+
+    int getActiveUsersCount( Date date );
+
+    int getUserCount();
+
+    int getUserCountByName( String name );
+
+    int getUsersWithoutOrganisationUnitCount();
+
+    int getUsersWithoutOrganisationUnitCountByName( String name );
+
+    int getUsersByOrganisationUnitCount( OrganisationUnit orgUnit );
+
+    int getUsersByOrganisationUnitCountByName( OrganisationUnit orgUnit, String name );
+
+    // -------------------------------------------------------------------------
+    // UserSettings
+    // -------------------------------------------------------------------------
+
+    /**
+     * Adds a UserSetting.
+     * 
+     * @param userSetting the UserSetting to add.
+     */
+    void addUserSetting( UserSetting userSetting );
+
+    /**
+     * Updates a UserSetting.
+     * 
+     * @param userSetting the UserSetting to update.
+     */
+    void updateUserSetting( UserSetting userSetting );
+
+    /**
+     * Retrieves the UserSetting associated with the given User for the given
+     * UserSetting name.
+     * 
+     * @param user the User.
+     * @param name the name of the UserSetting.
+     * @return the UserSetting.
+     */
+    UserSetting getUserSetting( User user, String name );
+
+    /**
+     * Retrieves all UserSettings for the given User.
+     * 
+     * @param user the User.
+     * @return a Collection of UserSettings.
+     */
+    Collection<UserSetting> getAllUserSettings( User user );
+
+    /**
+     * Deletes a UserSetting.
+     * 
+     * @param userSetting the UserSetting to delete.
+     */
+    void deleteUserSetting( UserSetting userSetting );
+    
+    /**
+     * Returns all UserSettings with the given name.
+     * 
+     * @param name the name.
+     * @return a Collection of UserSettings.
+     */
+    Collection<UserSetting> getUserSettings( String name );
+}

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java	2012-06-05 15:36:07 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java	2012-06-25 18:07:55 +0000
@@ -28,64 +28,18 @@
  */
 
 import java.util.Collection;
-import java.util.Date;
 
+import org.hisp.dhis.common.GenericIdentifiableObjectStore;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 
 /**
  * @author Nguyen Hong Duc
- * @version $Id: UserStore.java 5724 2008-09-18 14:37:01Z larshelg $
  */
 public interface UserStore
+    extends GenericIdentifiableObjectStore<User>
 {
     String ID = UserStore.class.getName();
 
-    // -------------------------------------------------------------------------
-    // User
-    // -------------------------------------------------------------------------
-
-    /**
-     * Adds a User.
-     * 
-     * @param user the User to add.
-     * @return the generated identifier.
-     */
-    int addUser( User user );
-
-    /**
-     * Updates a User.
-     * 
-     * @param user the User to update.
-     */
-    void updateUser( User user );
-
-    /**
-     * Retrieves the User with the given identifier.
-     *
-     * @param id the identifier of the User to retrieve.
-     * @return the User.
-     */
-    User getUser( int id );
-
-    /**
-     * Retrieves the User with the given unique identifier.
-     *
-     * @param uid the identifier of the User to retrieve.
-     * @return the User.
-     */
-    User getUser( String uid );
-
-    /**
-     * Returns a Collection of all Users.
-     * 
-     * @return a Collection of Users.
-     */
-    Collection<User> getAllUsers();
-
-    Collection<User> getAllUsersBetween(int first, int max);
-
-    Collection<User> getUsersByLastUpdated(Date lastUpdated);
-
     /**
      * Returns a Collection of the Users which are not associated with any
      * OrganisationUnits.
@@ -110,204 +64,4 @@
      * @return a Collection of Users.
      */
     Collection<User> getUsersByPhoneNumber( String phoneNumber );
-
-    /**
-     * Deletes a User.
-     * 
-     * @param user the User to delete.
-     */
-    void deleteUser( User user );
-
-    int getUserCount();
-
-    int getUserCountByName( String name );
-
-    int getUsersWithoutOrganisationUnitCount();
-
-    int getUsersWithoutOrganisationUnitCountByName( String name );
-
-    int getUsersByOrganisationUnitCount( OrganisationUnit orgUnit );
-
-    int getUsersByOrganisationUnitCountByName( OrganisationUnit orgUnit, String name );
-
-    // -------------------------------------------------------------------------
-    // UserCredentials
-    // -------------------------------------------------------------------------
-
-    /**
-     * Adds a UserCredentials.
-     * 
-     * @param userCredentials the UserCredentials to add.
-     * @return the User which the UserCredentials is associated with.
-     */
-    User addUserCredentials( UserCredentials userCredentials );
-
-    /**
-     * Updates a UserCredentials.
-     * 
-     * @param userCredentials the UserCredentials to update.
-     */
-    void updateUserCredentials( UserCredentials userCredentials );
-
-    /**
-     * Retrieves the UserCredentials of the given User.
-     * 
-     * @param user the User.
-     * @return the UserCredentials.
-     */
-    UserCredentials getUserCredentials( User user );
-
-    /**
-     * Retrieves the UserCredentials associated with the User with the given
-     * name.
-     * 
-     * @param username the name of the User.
-     * @return the UserCredentials.
-     */
-    UserCredentials getUserCredentialsByUsername( String username );
-
-    /**
-     * Retrieves all UserCredentials.
-     * 
-     * @return a Collection of UserCredentials.
-     */
-    Collection<UserCredentials> getAllUserCredentials();
-
-    /**
-     * Deletes a UserCredentials.
-     * 
-     * @param userCredentials the UserCredentials.
-     */
-    void deleteUserCredentials( UserCredentials userCredentials );
-
-    Collection<UserCredentials> searchUsersByName( String key );
-
-    Collection<UserCredentials> getUsersBetween( int first, int max );
-
-    Collection<UserCredentials> getUsersBetweenByName( String name, int first, int max );
-
-    Collection<UserCredentials> getUsersWithoutOrganisationUnitBetween( int first, int max );
-
-    Collection<UserCredentials> getUsersWithoutOrganisationUnitBetweenByName( String name, int first, int max );
-
-    Collection<UserCredentials> getUsersByOrganisationUnitBetween( OrganisationUnit orgUnit, int first, int max );
-
-    Collection<UserCredentials> getUsersByOrganisationUnitBetweenByName( OrganisationUnit orgUnit, String name,
-        int first, int max );
-
-    Collection<UserCredentials> getInactiveUsers( Date date );
-    
-    Collection<UserCredentials> getInactiveUsers( Date date, int first, int max );
-
-    int getInactiveUsersCount( Date date );
-
-    int getActiveUsersCount( Date date );
-
-    // -------------------------------------------------------------------------
-    // UserAuthorityGroup
-    // -------------------------------------------------------------------------
-
-    /**
-     * Adds a UserAuthorityGroup.
-     * 
-     * @param userAuthorityGroup the UserAuthorityGroup.
-     * @return the generated identifier.
-     */
-    int addUserAuthorityGroup( UserAuthorityGroup userAuthorityGroup );
-
-    /**
-     * Updates a UserAuthorityGroup.
-     * 
-     * @param userAuthorityGroup the UserAuthorityGroup.
-     */
-    void updateUserAuthorityGroup( UserAuthorityGroup userAuthorityGroup );
-
-    /**
-     * Retrieves the UserAuthorityGroup with the given identifier.
-     * 
-     * @param id the identifier of the UserAuthorityGroup to retrieve.
-     * @return the UserAuthorityGroup.
-     */
-    UserAuthorityGroup getUserAuthorityGroup( int id );
-
-    /**
-     * Retrieves the UserAuthorityGroup with the given identifier.
-     *
-     * @param uid the identifier of the UserAuthorityGroup to retrieve.
-     * @return the UserAuthorityGroup.
-     */
-    UserAuthorityGroup getUserAuthorityGroup( String uid );
-
-    /**
-     * Retrieves the UserAuthorityGroup with the given name.
-     * 
-     * @param name the name of the UserAuthorityGroup to retrieve.
-     * @return the UserAuthorityGroup.
-     */
-    UserAuthorityGroup getUserAuthorityGroupByName( String name );
-
-    /**
-     * Deletes a UserAuthorityGroup.
-     * 
-     * @param userAuthorityGroup the UserAuthorityGroup to delete.
-     */
-    void deleteUserAuthorityGroup( UserAuthorityGroup userAuthorityGroup );
-
-    /**
-     * Retrieves all UserAuthorityGroups.
-     * 
-     * @return a Collectio of UserAuthorityGroups.
-     */
-    Collection<UserAuthorityGroup> getAllUserAuthorityGroups();
-
-    // -------------------------------------------------------------------------
-    // UserSettings
-    // -------------------------------------------------------------------------
-
-    /**
-     * Adds a UserSetting.
-     * 
-     * @param userSetting the UserSetting to add.
-     */
-    void addUserSetting( UserSetting userSetting );
-
-    /**
-     * Updates a UserSetting.
-     * 
-     * @param userSetting the UserSetting to update.
-     */
-    void updateUserSetting( UserSetting userSetting );
-
-    /**
-     * Retrieves the UserSetting associated with the given User for the given
-     * UserSetting name.
-     * 
-     * @param user the User.
-     * @param name the name of the UserSetting.
-     * @return the UserSetting.
-     */
-    UserSetting getUserSetting( User user, String name );
-
-    /**
-     * Retrieves all UserSettings for the given User.
-     * 
-     * @param user the User.
-     * @return a Collection of UserSettings.
-     */
-    Collection<UserSetting> getAllUserSettings( User user );
-
-    /**
-     * Deletes a UserSetting.
-     * 
-     * @param userSetting the UserSetting to delete.
-     */
-    void deleteUserSetting( UserSetting userSetting );
-    
-    /**
-     * Returns all UserSettings with the given name.
-     * 
-     * @param name the name.
-     * @return a Collection of UserSettings.
-     */
-    Collection<UserSetting> getUserSettings( String name );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java	2012-06-05 15:36:07 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java	2012-06-25 18:07:55 +0000
@@ -1,20 +1,5 @@
 package org.hisp.dhis.user;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.hisp.dhis.common.GenericIdentifiableObjectStore;
-import org.hisp.dhis.dataset.DataSet;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.period.PeriodType;
-import org.hisp.dhis.system.filter.UserCredentialsCanUpdateFilter;
-import org.hisp.dhis.system.util.AuditLogUtil;
-import org.hisp.dhis.system.util.Filter;
-import org.hisp.dhis.system.util.FilterUtils;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.io.Serializable;
-import java.util.*;
-
 /*
  * Copyright (c) 2004-2012, University of Oslo
  * All rights reserved.
@@ -42,9 +27,27 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.io.Serializable;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.common.GenericIdentifiableObjectStore;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.system.filter.UserCredentialsCanUpdateFilter;
+import org.hisp.dhis.system.util.AuditLogUtil;
+import org.hisp.dhis.system.util.Filter;
+import org.hisp.dhis.system.util.FilterUtils;
+import org.springframework.transaction.annotation.Transactional;
+
 /**
  * @author Chau Thu Tran
- * @version $Id$
  */
 @Transactional
 public class DefaultUserService
@@ -63,11 +66,18 @@
         this.userStore = userStore;
     }
 
-    private GenericIdentifiableObjectStore<UserAuthorityGroup> userRoleStore;
+    private UserCredentialsStore userCredentialsStore;
+    
+    public void setUserCredentialsStore( UserCredentialsStore userCredentialsStore )
+    {
+        this.userCredentialsStore = userCredentialsStore;
+    }
 
-    public void setUserRoleStore( GenericIdentifiableObjectStore<UserAuthorityGroup> userRoleStore )
+    private GenericIdentifiableObjectStore<UserAuthorityGroup> userAuthorityGroupStore;
+    
+    public void setUserAuthorityGroupStore( GenericIdentifiableObjectStore<UserAuthorityGroup> userAuthorityGroupStore )
     {
-        this.userRoleStore = userRoleStore;
+        this.userAuthorityGroupStore = userAuthorityGroupStore;
     }
 
     private CurrentUserService currentUserService;
@@ -101,7 +111,7 @@
 
     public boolean isLastSuperUser( UserCredentials userCredentials )
     {
-        Collection<UserCredentials> users = userStore.getAllUserCredentials();
+        Collection<UserCredentials> users = userCredentialsStore.getAllUserCredentials();
 
         for ( UserCredentials user : users )
         {
@@ -126,7 +136,7 @@
 
     public boolean isLastSuperRole( UserAuthorityGroup userAuthorityGroup )
     {
-        Collection<UserAuthorityGroup> groups = userStore.getAllUserAuthorityGroups();
+        Collection<UserAuthorityGroup> groups = userAuthorityGroupStore.getAll();
 
         for ( UserAuthorityGroup group : groups )
         {
@@ -148,12 +158,12 @@
         log.info( AuditLogUtil.logMessage( currentUserService.getCurrentUsername(), AuditLogUtil.ACTION_ADD, User.class
             .getSimpleName(), user.getName() ) );
 
-        return userStore.addUser( user );
+        return userStore.save( user );
     }
 
     public void deleteUser( User user )
     {
-        userStore.deleteUser( user );
+        userStore.delete( user );
 
         log.info( AuditLogUtil.logMessage( currentUserService.getCurrentUsername(), AuditLogUtil.ACTION_DELETE,
             User.class.getSimpleName(), user.getName() ) );
@@ -161,7 +171,7 @@
 
     public void updateUser( User user )
     {
-        userStore.updateUser( user );
+        userStore.update( user );
 
         log.info( AuditLogUtil.logMessage( currentUserService.getCurrentUsername(), AuditLogUtil.ACTION_EDIT,
             User.class.getSimpleName(), user.getName() ) );
@@ -169,39 +179,39 @@
 
     public Collection<User> getAllUsers()
     {
-        return userStore.getAllUsers();
+        return userStore.getAll();
     }
 
     @Override
     public Collection<User> getAllUsersBetween( int first, int max )
     {
-        return userStore.getAllUsersBetween( first, max );
+        return userStore.getBetween( first, max );
     }
 
     @Override
     public Collection<User> getUsersByLastUpdated( Date lastUpdated )
     {
-        return userStore.getUsersByLastUpdated( lastUpdated );
+        return userStore.getByLastUpdated( lastUpdated );
     }
 
     public User getUser( int userId )
     {
-        return userStore.getUser( userId );
+        return userStore.get( userId );
     }
 
     public User getUser( String uid )
     {
-        return userStore.getUser( uid );
+        return userStore.getByUid( uid );
     }
 
     public int getUserCount()
     {
-        return userStore.getUserCount();
+        return userStore.getCount();
     }
 
     public int getUserCountByName( String userName )
     {
-        return userStore.getUserCountByName( userName );
+        return userStore.getCountByName( userName );
     }
 
     public Collection<UserCredentials> getUsers( final Collection<Integer> identifiers, User user )
@@ -222,23 +232,23 @@
 
     public Collection<UserCredentials> getUsersByOrganisationUnitBetween( OrganisationUnit unit, int first, int max )
     {
-        return userStore.getUsersByOrganisationUnitBetween( unit, first, max );
+        return userCredentialsStore.getUsersByOrganisationUnitBetween( unit, first, max );
     }
 
     public Collection<UserCredentials> getUsersByOrganisationUnitBetweenByName( OrganisationUnit unit, String userName,
         int first, int max )
     {
-        return userStore.getUsersByOrganisationUnitBetweenByName( unit, userName, first, max );
+        return userCredentialsStore.getUsersByOrganisationUnitBetweenByName( unit, userName, first, max );
     }
 
     public int getUsersByOrganisationUnitCount( OrganisationUnit unit )
     {
-        return userStore.getUsersByOrganisationUnitCount( unit );
+        return userCredentialsStore.getUsersByOrganisationUnitCount( unit );
     }
 
     public int getUsersByOrganisationUnitCountByName( OrganisationUnit unit, String userName )
     {
-        return userStore.getUsersByOrganisationUnitCountByName( unit, userName );
+        return userCredentialsStore.getUsersByOrganisationUnitCountByName( unit, userName );
     }
 
     public Collection<User> getUsersByPhoneNumber( String phoneNumber )
@@ -253,12 +263,12 @@
 
     public int getUsersWithoutOrganisationUnitCount()
     {
-        return userStore.getUsersWithoutOrganisationUnitCount();
+        return userCredentialsStore.getUsersWithoutOrganisationUnitCount();
     }
 
     public int getUsersWithoutOrganisationUnitCountByName( String userName )
     {
-        return userStore.getUsersWithoutOrganisationUnitCountByName( userName );
+        return userCredentialsStore.getUsersWithoutOrganisationUnitCountByName( userName );
     }
 
     // -------------------------------------------------------------------------
@@ -267,57 +277,57 @@
 
     public int addUserAuthorityGroup( UserAuthorityGroup userAuthorityGroup )
     {
-        return userStore.addUserAuthorityGroup( userAuthorityGroup );
+        return userAuthorityGroupStore.save( userAuthorityGroup );
     }
 
     public void updateUserAuthorityGroup( UserAuthorityGroup userAuthorityGroup )
     {
-        userStore.updateUserAuthorityGroup( userAuthorityGroup );
+        userAuthorityGroupStore.update( userAuthorityGroup );
     }
 
     public void deleteUserAuthorityGroup( UserAuthorityGroup userAuthorityGroup )
     {
-        userStore.deleteUserAuthorityGroup( userAuthorityGroup );
+        userAuthorityGroupStore.delete( userAuthorityGroup );
     }
 
     public Collection<UserAuthorityGroup> getAllUserAuthorityGroups()
     {
-        return userStore.getAllUserAuthorityGroups();
+        return userAuthorityGroupStore.getAll();
     }
 
-    public UserAuthorityGroup getUserAuthorityGroup( int userAuthorityGroupId )
+    public UserAuthorityGroup getUserAuthorityGroup( int id )
     {
-        return userStore.getUserAuthorityGroup( userAuthorityGroupId );
+        return userAuthorityGroupStore.get( id );
     }
 
     public UserAuthorityGroup getUserAuthorityGroup( String uid )
     {
-        return userStore.getUserAuthorityGroup( uid );
+        return userAuthorityGroupStore.getByUid( uid );
     }
 
-    public UserAuthorityGroup getUserAuthorityGroupByName( String userAuthorityGroupName )
+    public UserAuthorityGroup getUserAuthorityGroupByName( String name )
     {
-        return userStore.getUserAuthorityGroupByName( userAuthorityGroupName );
+        return userAuthorityGroupStore.getByName( name );
     }
 
     public Collection<UserAuthorityGroup> getUserRolesBetween( int first, int max )
     {
-        return userRoleStore.getBetween( first, max );
+        return userAuthorityGroupStore.getBetween( first, max );
     }
 
     public Collection<UserAuthorityGroup> getUserRolesBetweenByName( String name, int first, int max )
     {
-        return userRoleStore.getBetweenByName( name, first, max );
+        return userAuthorityGroupStore.getBetweenByName( name, first, max );
     }
 
     public int getUserRoleCount()
     {
-        return userRoleStore.getCount();
+        return userAuthorityGroupStore.getCount();
     }
 
     public int getUserRoleCountByName( String name )
     {
-        return userRoleStore.getCountByName( name );
+        return userAuthorityGroupStore.getCountByName( name );
     }
 
     public void assignDataSetToUserRole( DataSet dataSet )
@@ -343,57 +353,57 @@
 
     public User addUserCredentials( UserCredentials userCredentials )
     {
-        return userStore.addUserCredentials( userCredentials );
+        return userCredentialsStore.addUserCredentials( userCredentials );
     }
 
     public void updateUserCredentials( UserCredentials userCredentials )
     {
-        userStore.updateUserCredentials( userCredentials );
+        userCredentialsStore.updateUserCredentials( userCredentials );
     }
 
     public void deleteUserCredentials( UserCredentials userCredentials )
     {
-        userStore.deleteUserCredentials( userCredentials );
+        userCredentialsStore.deleteUserCredentials( userCredentials );
     }
 
     public Collection<UserCredentials> getAllUserCredentials()
     {
-        return userStore.getAllUserCredentials();
+        return userCredentialsStore.getAllUserCredentials();
     }
 
     public UserCredentials getUserCredentials( User user )
     {
-        return userStore.getUserCredentials( user );
+        return userCredentialsStore.getUserCredentials( user );
     }
 
     public UserCredentials getUserCredentialsByUsername( String username )
     {
-        return userStore.getUserCredentialsByUsername( username );
+        return userCredentialsStore.getUserCredentialsByUsername( username );
     }
 
     public Collection<UserCredentials> getUsersBetween( int first, int max )
     {
-        return userStore.getUsersBetween( first, max );
+        return userCredentialsStore.getUsersBetween( first, max );
     }
 
     public Collection<UserCredentials> getUsersBetweenByName( String username, int first, int max )
     {
-        return userStore.getUsersBetweenByName( username, first, max );
+        return userCredentialsStore.getUsersBetweenByName( username, first, max );
     }
 
     public Collection<UserCredentials> getUsersWithoutOrganisationUnitBetween( int first, int max )
     {
-        return userStore.getUsersWithoutOrganisationUnitBetween( first, max );
+        return userCredentialsStore.getUsersWithoutOrganisationUnitBetween( first, max );
     }
 
     public Collection<UserCredentials> getUsersWithoutOrganisationUnitBetweenByName( String username, int first, int max )
     {
-        return userStore.getUsersWithoutOrganisationUnitBetweenByName( username, first, max );
+        return userCredentialsStore.getUsersWithoutOrganisationUnitBetweenByName( username, first, max );
     }
 
     public Collection<UserCredentials> searchUsersByName( String username )
     {
-        return userStore.searchUsersByName( username );
+        return userCredentialsStore.searchUsersByName( username );
     }
 
     public void setLastLogin( String username )
@@ -408,7 +418,7 @@
         Calendar cal = PeriodType.createCalendarInstance();
         cal.add( Calendar.MONTH, (months * -1) );
 
-        return userStore.getInactiveUsers( cal.getTime() );
+        return userCredentialsStore.getInactiveUsers( cal.getTime() );
     }
 
     public Collection<UserCredentials> getInactiveUsers( int months, int first, int max )
@@ -416,7 +426,7 @@
         Calendar cal = PeriodType.createCalendarInstance();
         cal.add( Calendar.MONTH, (months * -1) );
 
-        return userStore.getInactiveUsers( cal.getTime(), first, max );
+        return userCredentialsStore.getInactiveUsers( cal.getTime(), first, max );
     }
 
     public int getInactiveUsersCount( int months )
@@ -424,7 +434,7 @@
         Calendar cal = PeriodType.createCalendarInstance();
         cal.add( Calendar.MONTH, (months * -1) );
 
-        return userStore.getInactiveUsersCount( cal.getTime() );
+        return userCredentialsStore.getInactiveUsersCount( cal.getTime() );
     }
 
     public int getActiveUsersCount( int days )
@@ -432,7 +442,7 @@
         Calendar cal = PeriodType.createCalendarInstance();
         cal.add( Calendar.DAY_OF_YEAR, (days * -1) );
 
-        return userStore.getActiveUsersCount( cal.getTime() );
+        return userCredentialsStore.getActiveUsersCount( cal.getTime() );
     }
 
     // -------------------------------------------------------------------------
@@ -441,34 +451,34 @@
 
     public void addUserSetting( UserSetting userSetting )
     {
-        userStore.addUserSetting( userSetting );
+        userCredentialsStore.addUserSetting( userSetting );
     }
 
     public void updateUserSetting( UserSetting userSetting )
     {
-        userStore.updateUserSetting( userSetting );
+        userCredentialsStore.updateUserSetting( userSetting );
     }
 
     public void deleteUserSetting( UserSetting userSetting )
     {
-        userStore.deleteUserSetting( userSetting );
+        userCredentialsStore.deleteUserSetting( userSetting );
     }
 
     public Collection<UserSetting> getAllUserSettings( User user )
     {
-        return userStore.getAllUserSettings( user );
+        return userCredentialsStore.getAllUserSettings( user );
     }
 
     public UserSetting getUserSetting( User user, String name )
     {
-        return userStore.getUserSetting( user, name );
+        return userCredentialsStore.getUserSetting( user, name );
     }
 
     public Map<User, Serializable> getUserSettings( String name, Serializable defaultValue )
     {
         Map<User, Serializable> map = new HashMap<User, Serializable>();
 
-        for ( UserSetting setting : userStore.getUserSettings( name ) )
+        for ( UserSetting setting : userCredentialsStore.getUserSettings( name ) )
         {
             map.put( setting.getUser(), setting.getValue() != null ? setting.getValue() : defaultValue );
         }

=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserCredentialsStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserCredentialsStore.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserCredentialsStore.java	2012-06-25 18:07:55 +0000
@@ -0,0 +1,373 @@
+package org.hisp.dhis.user.hibernate;
+
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+
+import org.hibernate.Criteria;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Projections;
+import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserCredentials;
+import org.hisp.dhis.user.UserCredentialsStore;
+import org.hisp.dhis.user.UserService;
+import org.hisp.dhis.user.UserSetting;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class HibernateUserCredentialsStore
+    implements UserCredentialsStore
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private SessionFactory sessionFactory;
+
+    public void setSessionFactory( SessionFactory sessionFactory )
+    {
+        this.sessionFactory = sessionFactory;
+    }
+    
+    private UserService userService;
+
+    public void setUserService( UserService userService )
+    {
+        this.userService = userService;
+    }
+
+    // -------------------------------------------------------------------------
+    // UserCredentials
+    // -------------------------------------------------------------------------
+
+    public User addUserCredentials( UserCredentials userCredentials )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        int id = (Integer) session.save( userCredentials );
+
+        return userService.getUser( id );
+    }
+
+    public void updateUserCredentials( UserCredentials userCredentials )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        session.update( userCredentials );
+    }
+
+    public UserCredentials getUserCredentials( User user )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        return (UserCredentials) session.get( UserCredentials.class, user.getId() );
+    }
+
+    public UserCredentials getUserCredentialsByUsername( String username )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Query query = session.createQuery( "from UserCredentials uc where uc.username = :username" );
+
+        query.setString( "username", username );
+        query.setCacheable( true );
+
+        return (UserCredentials) query.uniqueResult();
+    }
+
+    @SuppressWarnings( "unchecked" )
+    public Collection<UserCredentials> getAllUserCredentials()
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        return session.createCriteria( UserCredentials.class ).list();
+    }
+
+    public void deleteUserCredentials( UserCredentials userCredentials )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        session.delete( userCredentials );
+    }
+
+    public int getUserCount()
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Query query = session.createQuery( "select count(*) from UserCredentials" );
+
+        Number rs = (Number) query.uniqueResult();
+
+        return rs != null ? rs.intValue() : 0;
+    }
+
+    @SuppressWarnings( "unchecked" )
+    public Collection<UserCredentials> searchUsersByName( String key )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Criteria criteria = session.createCriteria( UserCredentials.class );
+
+        criteria.add( Restrictions.ilike( "username", "%" + key + "%" ) );
+        criteria.addOrder( Order.asc( "username" ) );
+
+        return criteria.list();
+    }
+
+    public int getUserCountByName( String name )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Criteria criteria = session.createCriteria( UserCredentials.class );
+
+        criteria.add( Restrictions.ilike( "username", "%" + name + "%" ) );
+
+        criteria.setProjection( Projections.rowCount() );
+
+        Number rs = (Number) criteria.uniqueResult();
+
+        return rs != null ? rs.intValue() : 0;
+    }
+
+    @SuppressWarnings( "unchecked" )
+    public Collection<UserCredentials> getUsersBetween( int first, int max )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        return session.createQuery( "from UserCredentials order by username" ).setFirstResult( first ).setMaxResults(
+            max ).list();
+    }
+
+    @SuppressWarnings( "unchecked" )
+    public Collection<UserCredentials> getUsersBetweenByName( String name, int first, int max )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Criteria criteria = session.createCriteria( UserCredentials.class );
+
+        criteria.add( Restrictions.ilike( "username", "%" + name + "%" ) );
+        criteria.addOrder( Order.asc( "username" ) );
+        criteria.setFirstResult( first );
+        criteria.setMaxResults( max );
+
+        return criteria.list();
+    }
+
+    public Collection<UserCredentials> getUsersByOrganisationUnitBetween( OrganisationUnit orgUnit, int first, int max )
+    {
+        return getBlockUser( toUserCredentials( orgUnit.getUsers() ), first, max );
+    }
+
+    public Collection<UserCredentials> getUsersByOrganisationUnitBetweenByName( OrganisationUnit orgUnit, String name,
+        int first, int max )
+    {
+        return getBlockUser( findByName( toUserCredentials( orgUnit.getUsers() ), name ), first, max );
+    }
+
+    public int getUsersByOrganisationUnitCount( OrganisationUnit orgUnit )
+    {
+        return orgUnit.getUsers().size();
+    }
+
+    public int getUsersByOrganisationUnitCountByName( OrganisationUnit orgUnit, String name )
+    {
+        return findByName( toUserCredentials( orgUnit.getUsers() ), name ).size();
+    }
+
+    public Collection<UserCredentials> getUsersWithoutOrganisationUnitBetween( int first, int max )
+    {
+        return getBlockUser( toUserCredentials( userService.getUsersWithoutOrganisationUnit() ), first, max );
+    }
+
+    public Collection<UserCredentials> getUsersWithoutOrganisationUnitBetweenByName( String name, int first, int max )
+    {
+        return getBlockUser( findByName( toUserCredentials( userService.getUsersWithoutOrganisationUnit() ), name ), first, max );
+    }
+
+    public int getUsersWithoutOrganisationUnitCount()
+    {
+        return userService.getUsersWithoutOrganisationUnit().size();
+    }
+
+    public int getUsersWithoutOrganisationUnitCountByName( String name )
+    {
+        return findByName( toUserCredentials( userService.getUsersWithoutOrganisationUnit() ), name ).size();
+    }
+
+    @SuppressWarnings( "unchecked" )
+    public Collection<UserCredentials> getInactiveUsers( Date date )
+    {
+        Criteria criteria = sessionFactory.getCurrentSession().createCriteria( UserCredentials.class );
+        criteria.add( Restrictions.lt( "lastLogin", date ) );
+
+        return criteria.list();
+    }
+
+    @SuppressWarnings( "unchecked" )
+    public Collection<UserCredentials> getInactiveUsers( Date date, int first, int max )
+    {
+        Criteria criteria = sessionFactory.getCurrentSession().createCriteria( UserCredentials.class );
+        criteria.add( Restrictions.lt( "lastLogin", date ) );
+        criteria.setFirstResult( first );
+        criteria.setMaxResults( max );
+
+        return criteria.list();
+    }
+
+    public int getInactiveUsersCount( Date date )
+    {
+        Criteria criteria = sessionFactory.getCurrentSession().createCriteria( UserCredentials.class );
+        criteria.add( Restrictions.lt( "lastLogin", date ) );
+        criteria.setProjection( Projections.rowCount() );
+
+        Number rs = (Number) criteria.uniqueResult();
+
+        return rs != null ? rs.intValue() : 0;
+    }
+
+    public int getActiveUsersCount( Date date )
+    {
+        Criteria criteria = sessionFactory.getCurrentSession().createCriteria( UserCredentials.class );
+        criteria.add( Restrictions.ge( "lastLogin", date ) );
+        criteria.setProjection( Projections.rowCount() );
+
+        Number rs = (Number) criteria.uniqueResult();
+
+        return rs != null ? rs.intValue() : 0;
+    }
+
+    // -------------------------------------------------------------------------
+    // UserSettings
+    // -------------------------------------------------------------------------
+
+    public void addUserSetting( UserSetting userSetting )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        session.save( userSetting );
+    }
+
+    public void updateUserSetting( UserSetting userSetting )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        session.update( userSetting );
+    }
+
+    public UserSetting getUserSetting( User user, String name )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Query query = session.createQuery( "from UserSetting us where us.user = :user and us.name = :name" );
+
+        query.setEntity( "user", user );
+        query.setString( "name", name );
+        query.setCacheable( true );
+
+        return (UserSetting) query.uniqueResult();
+    }
+
+    @SuppressWarnings( "unchecked" )
+    public Collection<UserSetting> getAllUserSettings( User user )
+    {
+        Session session = sessionFactory.getCurrentSession();
+        Query query = session.createQuery( "from UserSetting us where us.user = :user" );
+        query.setEntity( "user", user );
+
+        return query.list();
+    }
+
+    @SuppressWarnings( "unchecked" )
+    public Collection<UserSetting> getUserSettings( String name )
+    {
+        Session session = sessionFactory.getCurrentSession();
+        Query query = session.createQuery( "from UserSetting us where us.name = :name" );
+        query.setString( "name", name );
+
+        return query.list();
+    }
+
+    public void deleteUserSetting( UserSetting userSetting )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        session.delete( userSetting );
+    }
+
+    // -------------------------------------------------------------------------
+    // Supportive methods
+    // -------------------------------------------------------------------------
+
+    private Collection<UserCredentials> findByName( Collection<UserCredentials> users, String key )
+    {
+        List<UserCredentials> returnList = new ArrayList<UserCredentials>();
+
+        for ( UserCredentials user : users )
+        {
+            if ( user != null )
+            {
+                if ( user.getUsername().toLowerCase().contains( key.toLowerCase() ) )
+                {
+                    returnList.add( user );
+                }
+            }
+        }
+
+        return returnList;
+    }
+
+    private List<UserCredentials> getBlockUser( Collection<UserCredentials> usersList, int startPos, int pageSize )
+    {
+        List<UserCredentials> elementList = new ArrayList<UserCredentials>( usersList );
+
+        int toIndex = Math.min( startPos + pageSize, elementList.size() );
+
+        return elementList.subList( startPos, toIndex );
+    }
+
+    private List<UserCredentials> toUserCredentials( Collection<User> users )
+    {
+        List<UserCredentials> credentials = new ArrayList<UserCredentials>();
+
+        for ( User user : users )
+        {
+            credentials.add( user.getUserCredentials() );
+        }
+
+        return credentials;
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java	2012-06-24 12:54:56 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java	2012-06-25 18:07:55 +0000
@@ -27,104 +27,28 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import org.hibernate.Criteria;
+import java.util.Collection;
+import java.util.Iterator;
+
 import org.hibernate.Query;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.criterion.Order;
-import org.hibernate.criterion.Projections;
-import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.user.*;
-
-import java.util.*;
+import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserStore;
 
 /**
  * @author Nguyen Hong Duc
  */
 public class HibernateUserStore
-    implements UserStore
+    extends HibernateIdentifiableObjectStore<User> implements UserStore
 {
     // -------------------------------------------------------------------------
-    // Dependencies
-    // -------------------------------------------------------------------------
-
-    private SessionFactory sessionFactory;
-
-    public void setSessionFactory( SessionFactory sessionFactory )
-    {
-        this.sessionFactory = sessionFactory;
-    }
-
-    // -------------------------------------------------------------------------
-    // User
-    // -------------------------------------------------------------------------
-
-    public int addUser( User user )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        return (Integer) session.save( user );
-    }
-
-    public void updateUser( User user )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        session.update( user );
-    }
-
-    public User getUser( int id )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        return (User) session.get( User.class, id );
-    }
-
-    public User getUser( String uid )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        Criteria criteria = session.createCriteria( User.class );
-        criteria.add( Restrictions.like( "uid", uid ) );
-
-        return (User) criteria.uniqueResult();
-    }
-
-    @SuppressWarnings( "unchecked" )
-    public Collection<User> getAllUsers()
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        return session.createQuery( "from User" ).list();
-    }
-
-    @Override
-    @SuppressWarnings("unchecked")
-    public Collection<User> getAllUsersBetween( int first, int max )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        Query query = session.createQuery( "from User" );
-        query.setFirstResult( first );
-        query.setMaxResults( max );
-
-        return query.list();
-    }
-
-    @Override
-    @SuppressWarnings("unchecked")
-    public Collection<User> getUsersByLastUpdated( Date lastUpdated )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        Criteria criteria = session.createCriteria( User.class );
-        return criteria.add( Restrictions.ge( "lastUpdated", lastUpdated ) ).list();
-    }
+    // UserStore implementation
+    // -------------------------------------------------------------------------
 
     public Collection<User> getUsersWithoutOrganisationUnit()
     {
-        Collection<User> users = getAllUsers();
+        Collection<User> users = getAll();
 
         Iterator<User> iterator = users.iterator();
 
@@ -150,378 +74,6 @@
         return query.list();
     }
 
-    public void deleteUser( User user )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        session.delete( user );
-    }
-
-    // -------------------------------------------------------------------------
-    // UserCredentials
-    // -------------------------------------------------------------------------
-
-    public User addUserCredentials( UserCredentials userCredentials )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        int id = (Integer) session.save( userCredentials );
-
-        return getUser( id );
-    }
-
-    public void updateUserCredentials( UserCredentials userCredentials )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        session.update( userCredentials );
-    }
-
-    public UserCredentials getUserCredentials( User user )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        return (UserCredentials) session.get( UserCredentials.class, user.getId() );
-    }
-
-    public UserCredentials getUserCredentialsByUsername( String username )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        Query query = session.createQuery( "from UserCredentials uc where uc.username = :username" );
-
-        query.setString( "username", username );
-        query.setCacheable( true );
-
-        return (UserCredentials) query.uniqueResult();
-    }
-
-    @SuppressWarnings( "unchecked" )
-    public Collection<UserCredentials> getAllUserCredentials()
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        return session.createCriteria( UserCredentials.class ).list();
-    }
-
-    public void deleteUserCredentials( UserCredentials userCredentials )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        session.delete( userCredentials );
-    }
-
-    public int getUserCount()
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        Query query = session.createQuery( "select count(*) from UserCredentials" );
-
-        Number rs = (Number) query.uniqueResult();
-
-        return rs != null ? rs.intValue() : 0;
-    }
-
-    @SuppressWarnings( "unchecked" )
-    public Collection<UserCredentials> searchUsersByName( String key )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        Criteria criteria = session.createCriteria( UserCredentials.class );
-
-        criteria.add( Restrictions.ilike( "username", "%" + key + "%" ) );
-        criteria.addOrder( Order.asc( "username" ) );
-
-        return criteria.list();
-    }
-
-    public int getUserCountByName( String name )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        Criteria criteria = session.createCriteria( UserCredentials.class );
-
-        criteria.add( Restrictions.ilike( "username", "%" + name + "%" ) );
-
-        criteria.setProjection( Projections.rowCount() );
-
-        Number rs = (Number) criteria.uniqueResult();
-
-        return rs != null ? rs.intValue() : 0;
-    }
-
-    @SuppressWarnings( "unchecked" )
-    public Collection<UserCredentials> getUsersBetween( int first, int max )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        return session.createQuery( "from UserCredentials order by username" ).setFirstResult( first ).setMaxResults(
-            max ).list();
-    }
-
-    @SuppressWarnings( "unchecked" )
-    public Collection<UserCredentials> getUsersBetweenByName( String name, int first, int max )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        Criteria criteria = session.createCriteria( UserCredentials.class );
-
-        criteria.add( Restrictions.ilike( "username", "%" + name + "%" ) );
-        criteria.addOrder( Order.asc( "username" ) );
-        criteria.setFirstResult( first );
-        criteria.setMaxResults( max );
-
-        return criteria.list();
-    }
-
-    public Collection<UserCredentials> getUsersByOrganisationUnitBetween( OrganisationUnit orgUnit, int first, int max )
-    {
-        return getBlockUser( toUserCredentials( orgUnit.getUsers() ), first, max );
-    }
-
-    public Collection<UserCredentials> getUsersByOrganisationUnitBetweenByName( OrganisationUnit orgUnit, String name,
-        int first, int max )
-    {
-        return getBlockUser( findByName( toUserCredentials( orgUnit.getUsers() ), name ), first, max );
-    }
-
-    public int getUsersByOrganisationUnitCount( OrganisationUnit orgUnit )
-    {
-        return orgUnit.getUsers().size();
-    }
-
-    public int getUsersByOrganisationUnitCountByName( OrganisationUnit orgUnit, String name )
-    {
-        return findByName( toUserCredentials( orgUnit.getUsers() ), name ).size();
-    }
-
-    public Collection<UserCredentials> getUsersWithoutOrganisationUnitBetween( int first, int max )
-    {
-        return getBlockUser( toUserCredentials( getUsersWithoutOrganisationUnit() ), first, max );
-    }
-
-    public Collection<UserCredentials> getUsersWithoutOrganisationUnitBetweenByName( String name, int first, int max )
-    {
-        return getBlockUser( findByName( toUserCredentials( getUsersWithoutOrganisationUnit() ), name ), first, max );
-    }
-
-    public int getUsersWithoutOrganisationUnitCount()
-    {
-        return getUsersWithoutOrganisationUnit().size();
-    }
-
-    public int getUsersWithoutOrganisationUnitCountByName( String name )
-    {
-        return findByName( toUserCredentials( getUsersWithoutOrganisationUnit() ), name ).size();
-    }
-
-    @SuppressWarnings( "unchecked" )
-    public Collection<UserCredentials> getInactiveUsers( Date date )
-    {
-        Criteria criteria = sessionFactory.getCurrentSession().createCriteria( UserCredentials.class );
-        criteria.add( Restrictions.lt( "lastLogin", date ) );
-
-        return criteria.list();
-    }
-
-    @SuppressWarnings( "unchecked" )
-    public Collection<UserCredentials> getInactiveUsers( Date date, int first, int max )
-    {
-        Criteria criteria = sessionFactory.getCurrentSession().createCriteria( UserCredentials.class );
-        criteria.add( Restrictions.lt( "lastLogin", date ) );
-        criteria.setFirstResult( first );
-        criteria.setMaxResults( max );
-
-        return criteria.list();
-    }
-
-    public int getInactiveUsersCount( Date date )
-    {
-        Criteria criteria = sessionFactory.getCurrentSession().createCriteria( UserCredentials.class );
-        criteria.add( Restrictions.lt( "lastLogin", date ) );
-        criteria.setProjection( Projections.rowCount() );
-
-        Number rs = (Number) criteria.uniqueResult();
-
-        return rs != null ? rs.intValue() : 0;
-    }
-
-    public int getActiveUsersCount( Date date )
-    {
-        Criteria criteria = sessionFactory.getCurrentSession().createCriteria( UserCredentials.class );
-        criteria.add( Restrictions.ge( "lastLogin", date ) );
-        criteria.setProjection( Projections.rowCount() );
-
-        Number rs = (Number) criteria.uniqueResult();
-
-        return rs != null ? rs.intValue() : 0;
-    }
-
-    // -------------------------------------------------------------------------
-    // UserAuthorityGroup
-    // -------------------------------------------------------------------------
-
-    public int addUserAuthorityGroup( UserAuthorityGroup userAuthorityGroup )
-    {
-        Session session = sessionFactory.getCurrentSession();
-        userAuthorityGroup.setAutoFields();
-
-        return (Integer) session.save( userAuthorityGroup );
-    }
-
-    public void updateUserAuthorityGroup( UserAuthorityGroup userAuthorityGroup )
-    {
-        Session session = sessionFactory.getCurrentSession();
-        userAuthorityGroup.setAutoFields();
-
-        session.update( userAuthorityGroup );
-    }
-
-    public UserAuthorityGroup getUserAuthorityGroup( int id )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        return (UserAuthorityGroup) session.get( UserAuthorityGroup.class, id );
-    }
-
-    public UserAuthorityGroup getUserAuthorityGroup( String uid )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        Criteria criteria = session.createCriteria( UserAuthorityGroup.class );
-
-        criteria.add( Restrictions.eq( "uid", uid ) );
-
-        return (UserAuthorityGroup) criteria.uniqueResult();
-    }
-
-    public UserAuthorityGroup getUserAuthorityGroupByName( String name )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        Criteria criteria = session.createCriteria( UserAuthorityGroup.class );
-
-        criteria.add( Restrictions.eq( "name", name ) );
-
-        return (UserAuthorityGroup) criteria.uniqueResult();
-    }
-
-    @SuppressWarnings( "unchecked" )
-    public Collection<UserAuthorityGroup> getAllUserAuthorityGroups()
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        return session.createQuery( "from UserAuthorityGroup" ).list();
-    }
-
-    public void deleteUserAuthorityGroup( UserAuthorityGroup userAuthorityGroup )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        session.delete( userAuthorityGroup );
-    }
-
-    // -------------------------------------------------------------------------
-    // UserSettings
-    // -------------------------------------------------------------------------
-
-    public void addUserSetting( UserSetting userSetting )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        session.save( userSetting );
-    }
-
-    public void updateUserSetting( UserSetting userSetting )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        session.update( userSetting );
-    }
-
-    public UserSetting getUserSetting( User user, String name )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        Query query = session.createQuery( "from UserSetting us where us.user = :user and us.name = :name" );
-
-        query.setEntity( "user", user );
-        query.setString( "name", name );
-        query.setCacheable( true );
-
-        return (UserSetting) query.uniqueResult();
-    }
-
-    @SuppressWarnings( "unchecked" )
-    public Collection<UserSetting> getAllUserSettings( User user )
-    {
-        Session session = sessionFactory.getCurrentSession();
-        Query query = session.createQuery( "from UserSetting us where us.user = :user" );
-        query.setEntity( "user", user );
-
-        return query.list();
-    }
-
-    @SuppressWarnings( "unchecked" )
-    public Collection<UserSetting> getUserSettings( String name )
-    {
-        Session session = sessionFactory.getCurrentSession();
-        Query query = session.createQuery( "from UserSetting us where us.name = :name" );
-        query.setString( "name", name );
-
-        return query.list();
-    }
-
-    public void deleteUserSetting( UserSetting userSetting )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        session.delete( userSetting );
-    }
-
-    // -------------------------------------------------------------------------
-    // Supportive methods
-    // -------------------------------------------------------------------------
-
-    private Collection<UserCredentials> findByName( Collection<UserCredentials> users, String key )
-    {
-        List<UserCredentials> returnList = new ArrayList<UserCredentials>();
-
-        for ( UserCredentials user : users )
-        {
-            if ( user != null )
-            {
-                if ( user.getUsername().toLowerCase().contains( key.toLowerCase() ) )
-                {
-                    returnList.add( user );
-                }
-            }
-        }
-
-        return returnList;
-    }
-
-    private List<UserCredentials> getBlockUser( Collection<UserCredentials> usersList, int startPos, int pageSize )
-    {
-        List<UserCredentials> elementList = new ArrayList<UserCredentials>( usersList );
-
-        int toIndex = Math.min( startPos + pageSize, elementList.size() );
-
-        return elementList.subList( startPos, toIndex );
-    }
-
-    private List<UserCredentials> toUserCredentials( Collection<User> users )
-    {
-        List<UserCredentials> credentials = new ArrayList<UserCredentials>();
-
-        for ( User user : users )
-        {
-            credentials.add( user.getUserCredentials() );
-        }
-
-        return credentials;
-    }
-
     @SuppressWarnings( "unchecked" )
     public Collection<User> getUsersByOrganisationUnits( Collection<OrganisationUnit> orgunits )
     {

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2012-06-24 09:35:28 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2012-06-25 18:07:55 +0000
@@ -198,6 +198,13 @@
 
   <bean id="org.hisp.dhis.user.UserStore" class="org.hisp.dhis.user.hibernate.HibernateUserStore">
     <property name="sessionFactory" ref="sessionFactory" />
+    <property name="clazz" value="org.hisp.dhis.user.User" />
+	<property name="cacheable" value="true" />
+  </bean>
+
+  <bean id="org.hisp.dhis.user.UserCredentialsStore" class="org.hisp.dhis.user.hibernate.HibernateUserCredentialsStore">
+    <property name="sessionFactory" ref="sessionFactory" />
+	<property name="userService" ref="org.hisp.dhis.user.UserService" />
   </bean>
 
   <bean id="org.hisp.dhis.user.UserGroupStore" class="org.hisp.dhis.hibernate.HibernateGenericStore">
@@ -223,7 +230,7 @@
     <property name="statementManager" ref="statementManager" />
   </bean>
 
-  <bean id="org.hisp.dhis.user.UserAuthorityGroupStore" class="org.hisp.dhis.hibernate.HibernateGenericStore">
+  <bean id="org.hisp.dhis.user.UserAuthorityGroupStore" class="org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore">
     <property name="clazz" value="org.hisp.dhis.user.UserAuthorityGroup" />
     <property name="sessionFactory" ref="sessionFactory" />
   </bean>
@@ -448,7 +455,8 @@
 
   <bean id="org.hisp.dhis.user.UserService" class="org.hisp.dhis.user.DefaultUserService">
     <property name="userStore" ref="org.hisp.dhis.user.UserStore" />
-    <property name="userRoleStore" ref="org.hisp.dhis.user.UserAuthorityGroupStore" />
+	<property name="userCredentialsStore" ref="org.hisp.dhis.user.UserCredentialsStore" />
+    <property name="userAuthorityGroupStore" ref="org.hisp.dhis.user.UserAuthorityGroupStore" />
     <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
   </bean>
 

=== added file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserAuthorityGroupTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserAuthorityGroupTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserAuthorityGroupTest.java	2012-06-25 18:07:55 +0000
@@ -0,0 +1,82 @@
+package org.hisp.dhis.user;
+
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import static junit.framework.Assert.assertEquals;
+
+import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.common.GenericIdentifiableObjectStore;
+import org.junit.Test;
+
+public class UserAuthorityGroupTest
+    extends DhisSpringTest
+{
+    private GenericIdentifiableObjectStore<UserAuthorityGroup> userAuthorityGroupStore;
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public void setUpTest() throws Exception
+    {
+        userAuthorityGroupStore = (GenericIdentifiableObjectStore<UserAuthorityGroup>) getBean( "org.hisp.dhis.user.UserAuthorityGroupStore" );
+    }
+    
+    @Test
+    public void testBasicUserAuthorityGroup()
+        throws Exception
+    {
+        String name = "UserAuthorityGroup";
+        String name1 = "UserAuthorityGroup1";
+        String name2 = "UserAuthorityGroup2";
+
+        // Test addUserAuthorityGroup
+        UserAuthorityGroup userAuthorityGroup = new UserAuthorityGroup();
+        userAuthorityGroup.setName( name );
+        userAuthorityGroupStore.save( userAuthorityGroup );
+        assertEquals( userAuthorityGroupStore.get( userAuthorityGroup.getId() ).getName(), name );
+
+        // Test updateUserAuthorityGroup
+        userAuthorityGroup.setName( name1 );
+        userAuthorityGroupStore.update( userAuthorityGroup );
+        assertEquals( userAuthorityGroup.getName(), name1 );
+
+        // Test getUserAuthorityGroup
+        assertEquals( userAuthorityGroupStore.get( userAuthorityGroup.getId() ).getName(), name1 );
+        assertEquals( userAuthorityGroupStore.get( userAuthorityGroup.getId() ).getClass(), userAuthorityGroup
+            .getClass() );
+
+        // Test getAllUserAuthorityGroups
+        UserAuthorityGroup userAuthorityGroup2 = new UserAuthorityGroup();
+        userAuthorityGroup2.setName( name2 );
+        userAuthorityGroupStore.save( userAuthorityGroup2 );
+
+        // Test deleteUserAuthorityGroup
+        assertEquals( userAuthorityGroupStore.getAll().size(), 2 );
+        userAuthorityGroupStore.delete( userAuthorityGroup2 );
+        assertEquals( userAuthorityGroupStore.getAll().size(), 1 );
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserStoreTest.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserStoreTest.java	2012-06-25 18:07:55 +0000
@@ -48,6 +48,8 @@
     extends DhisSpringTest
 {
     private UserStore userStore;
+    
+    private UserCredentialsStore userCredentialsStore;
 
     private OrganisationUnitService organisationUnitService;
 
@@ -56,6 +58,8 @@
         throws Exception
     {
         userStore = (UserStore) getBean( UserStore.ID );
+        
+        userCredentialsStore = (UserCredentialsStore) getBean( UserCredentialsStore.ID );
 
         organisationUnitService = (OrganisationUnitService) getBean( OrganisationUnitService.ID );
     }
@@ -83,25 +87,25 @@
         user.setFirstName( userName );
 
         // Test addUser
-        int id = userStore.addUser( user );
-        assertEquals( userStore.getUser( id ).getSurname(), userName );
-        assertEquals( userStore.getUser( id ).getFirstName(), userName );
-        assertEquals( 1, userStore.getAllUsers().size(), 1 );
+        int id = userStore.save( user );
+        assertEquals( userStore.get( id ).getSurname(), userName );
+        assertEquals( userStore.get( id ).getFirstName(), userName );
+        assertEquals( 1, userStore.getAll().size(), 1 );
         assertEquals( 1, userStore.getUsersWithoutOrganisationUnit().size() );
 
         // Test updateUser
         user.setSurname( "User1" );
         user.setOrganisationUnits( units1 );
-        userStore.updateUser( user );
+        userStore.update( user );
         
-        assertEquals( userStore.getUser( id ).getSurname(), "User1" );
+        assertEquals( userStore.get( id ).getSurname(), "User1" );
         assertEquals( 0, userStore.getUsersWithoutOrganisationUnit().size() );
 
         // Test getUser
-        assertEquals( userStore.getUser( user.getId() ).getSurname(), "User1" );
-        assertEquals( userStore.getUser( user.getId() ).getFirstName(), userName );
-        assertEquals( 2, userStore.getUser( user.getId() ).getOrganisationUnits().size() );
-        assertEquals( userStore.getUser( user.getId() ).getId(), id );
+        assertEquals( userStore.get( user.getId() ).getSurname(), "User1" );
+        assertEquals( userStore.get( user.getId() ).getFirstName(), userName );
+        assertEquals( 2, userStore.get( user.getId() ).getOrganisationUnits().size() );
+        assertEquals( userStore.get( user.getId() ).getId(), id );
 
         // Test getAllUsers
         User user2 = new User();
@@ -111,9 +115,9 @@
         user2.setSurname( "User2" );
         user2.setFirstName( "User2" );
         user2.setOrganisationUnits( units2 );
-        userStore.addUser( user2 );
+        userStore.save( user2 );
 
-        assertEquals( userStore.getAllUsers().size(), 2 );
+        assertEquals( userStore.getAll().size(), 2 );
         
         assertEquals( 0, userStore.getUsersWithoutOrganisationUnit().size() );
 
@@ -128,13 +132,13 @@
         units3.add(unit3);
         
         user.setOrganisationUnits( units3 );
-        userStore.addUser( user3 );
+        userStore.save( user3 );
 
-        assertEquals( userStore.getAllUsers().size(), 3 );
+        assertEquals( userStore.getAll().size(), 3 );
         // delete User3
-        assertEquals( userStore.getUser( user3.getId() ).getSurname(), "User3" );
-        userStore.deleteUser( user3 );
-        assertEquals( userStore.getAllUsers().size(), 2 );
+        assertEquals( userStore.get( user3.getId() ).getSurname(), "User3" );
+        userStore.delete( user3 );
+        assertEquals( userStore.getAll().size(), 2 );
     }
 
     @Test
@@ -150,86 +154,44 @@
         User user = new User();
         user.setSurname( username );
         user.setFirstName( username );
-        userStore.addUser( user );
+        userStore.save( user );
 
         UserCredentials userCredentials = new UserCredentials();
         userCredentials.setUser( user );
         userCredentials.setUsername( username );
         userCredentials.setPassword( password );
 
-        userStore.addUserCredentials( userCredentials );
+        userCredentialsStore.addUserCredentials( userCredentials );
 
-        assertEquals( userStore.getUserCredentials( user ).getUser().getId(), user.getId() );
-        assertEquals( userStore.getUserCredentials( user ).getUsername(), username );
-        assertEquals( userStore.getUserCredentials( user ).getPassword(), password );
+        assertEquals( userCredentialsStore.getUserCredentials( user ).getUser().getId(), user.getId() );
+        assertEquals( userCredentialsStore.getUserCredentials( user ).getUsername(), username );
+        assertEquals( userCredentialsStore.getUserCredentials( user ).getPassword(), password );
 
         // Test updateUserCredentials
         userCredentials.setUser( user );
         userCredentials.setUsername( someone );
         userCredentials.setPassword( iloveyou );
 
-        userStore.updateUserCredentials( userCredentials );
-        assertEquals( userStore.getUserCredentials( user ).getUsername(), someone );
-        assertEquals( userStore.getUserCredentials( user ).getPassword(), iloveyou );
+        userCredentialsStore.updateUserCredentials( userCredentials );
+        assertEquals( userCredentialsStore.getUserCredentials( user ).getUsername(), someone );
+        assertEquals( userCredentialsStore.getUserCredentials( user ).getPassword(), iloveyou );
 
         // Test getUserCredentials
-        assertEquals( userStore.getUserCredentials( user ).getUsername(), someone );
-        assertEquals( userStore.getUserCredentials( user ).getPassword(), iloveyou );
+        assertEquals( userCredentialsStore.getUserCredentials( user ).getUsername(), someone );
+        assertEquals( userCredentialsStore.getUserCredentials( user ).getPassword(), iloveyou );
 
         // Test getUserCredentialsByUsername
         // System.out.println( userStore.getUserCredentialsByUsername( someone
         // ).getPassword() );
-        assertEquals( userStore.getUserCredentialsByUsername( someone ).getPassword(), userCredentials.getPassword() );
-        assertEquals( userStore.getUserCredentialsByUsername( someone ).getClass(), userCredentials.getClass() );
+        assertEquals( userCredentialsStore.getUserCredentialsByUsername( someone ).getPassword(), userCredentials.getPassword() );
+        assertEquals( userCredentialsStore.getUserCredentialsByUsername( someone ).getClass(), userCredentials.getClass() );
 
         // Test deleteUserCredentials
         // Before delete
-        assertNotNull( userStore.getUserCredentials( user ) );
-        userStore.deleteUserCredentials( userStore.getUserCredentials( user ) );
+        assertNotNull( userCredentialsStore.getUserCredentials( user ) );
+        userCredentialsStore.deleteUserCredentials( userCredentialsStore.getUserCredentials( user ) );
         // After delete
-        assertNull( userStore.getUserCredentials( user ) );
-    }
-
-    @Test
-    public void testBasicUserAuthorityGroup()
-        throws Exception
-    {
-        String name = "UserAuthorityGroup";
-        String name1 = "UserAuthorityGroup1";
-        String name2 = "UserAuthorityGroup2";
-
-        // Test addUserAuthorityGroup
-        UserAuthorityGroup userAuthorityGroup = new UserAuthorityGroup();
-        userAuthorityGroup.setName( name );
-        userStore.addUserAuthorityGroup( userAuthorityGroup );
-        assertEquals( userStore.getUserAuthorityGroup( userAuthorityGroup.getId() ).getName(), name );
-
-        // Test updateUserAuthorityGroup
-        userAuthorityGroup.setName( name1 );
-        userStore.updateUserAuthorityGroup( userAuthorityGroup );
-        assertEquals( userAuthorityGroup.getName(), name1 );
-
-        // Test getUserAuthorityGroup
-        assertEquals( userStore.getUserAuthorityGroup( userAuthorityGroup.getId() ).getName(), name1 );
-        assertEquals( userStore.getUserAuthorityGroup( userAuthorityGroup.getId() ).getClass(), userAuthorityGroup
-            .getClass() );
-
-        // Test getAllUserAuthorityGroups
-        UserAuthorityGroup userAuthorityGroup2 = new UserAuthorityGroup();
-        userAuthorityGroup2.setName( name2 );
-        userStore.addUserAuthorityGroup( userAuthorityGroup2 );
-
-        assertEquals( userStore.getAllUserAuthorityGroups().size(), 2 );
-        for ( int i = 1; i <= userStore.getAllUserAuthorityGroups().size(); i++ )
-        {
-            // System.out.println( "UserAuthorityGroup" + i );
-            assertEquals( userStore.getUserAuthorityGroup( i ).getName(), "UserAuthorityGroup" + i );
-        }
-
-        // Test deleteUserAuthorityGroup
-        assertEquals( userStore.getAllUserAuthorityGroups().size(), 2 );
-        userStore.deleteUserAuthorityGroup( userAuthorityGroup2 );
-        assertEquals( userStore.getAllUserAuthorityGroups().size(), 1 );
+        assertNull( userCredentialsStore.getUserCredentials( user ) );
     }
 
     @Test
@@ -245,39 +207,39 @@
         User user = new User();
         user.setSurname( userName );
         user.setFirstName( userName );
-        userStore.addUser( user );
+        userStore.save( user );
 
         UserSetting userSetting = new UserSetting();
         userSetting.setUser( user );
         userSetting.setName( name );
         userSetting.setValue( value );
 
-        userStore.addUserSetting( userSetting );
-        assertEquals( userStore.getUserSetting( user, name ).getName(), userSetting.getName() );
+        userCredentialsStore.addUserSetting( userSetting );
+        assertEquals( userCredentialsStore.getUserSetting( user, name ).getName(), userSetting.getName() );
 
         // Test updateUserSetting
         userSetting.setValue( value1 );
         // System.out.println( userSetting.getName() );
-        userStore.updateUserSetting( userSetting );
+        userCredentialsStore.updateUserSetting( userSetting );
         // System.out.println( userSetting.getName() );
-        assertEquals( value1, userStore.getUserSetting( user, name ).getValue() );
+        assertEquals( value1, userCredentialsStore.getUserSetting( user, name ).getValue() );
 
         // Test getUserSetting
-        assertEquals( userStore.getUserSetting( userSetting.getUser(), name ).getName(), name );
-        assertEquals( userStore.getUserSetting( userSetting.getUser(), name ).getUser().getId(), user.getId() );
-        assertEquals( userStore.getUserSetting( userSetting.getUser(), name ).getValue(), value1 );
+        assertEquals( userCredentialsStore.getUserSetting( userSetting.getUser(), name ).getName(), name );
+        assertEquals( userCredentialsStore.getUserSetting( userSetting.getUser(), name ).getUser().getId(), user.getId() );
+        assertEquals( userCredentialsStore.getUserSetting( userSetting.getUser(), name ).getValue(), value1 );
 
         // Test getAllUserSettings
-        assertEquals( userStore.getAllUserSettings( user ).size(), 1 );
-        for ( int i = 1; i <= userStore.getAllUserSettings( user ).size(); i++ )
+        assertEquals( userCredentialsStore.getAllUserSettings( user ).size(), 1 );
+        for ( int i = 1; i <= userCredentialsStore.getAllUserSettings( user ).size(); i++ )
         {
             // System.out.println( "UserSettings" + i );
-            assertEquals( userStore.getUserSetting( user, name ).getValue(), "value" + i );
+            assertEquals( userCredentialsStore.getUserSetting( user, name ).getValue(), "value" + i );
         }
 
         // Test deleteUserSetting
-        assertEquals( userStore.getAllUserSettings( user ).size(), 1 );
-        userStore.deleteUserSetting( userStore.getUserSetting( user, name ) );
-        assertEquals( userStore.getAllUserSettings( user ).size(), 0 );
+        assertEquals( userCredentialsStore.getAllUserSettings( user ).size(), 1 );
+        userCredentialsStore.deleteUserSetting( userCredentialsStore.getUserSetting( user, name ) );
+        assertEquals( userCredentialsStore.getAllUserSettings( user ).size(), 0 );
     }
 }