← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4058: Replaced custom method in UserDetailsService with one from UserService.

 

------------------------------------------------------------
revno: 4058
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2011-07-02 13:06:16 +0200
message:
  Replaced custom method in UserDetailsService with one from UserService.
renamed:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/hibernate/HibernateUserDetailsService.java => dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/DefaultUserDetailsService.java
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/security.xml
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/DefaultUserDetailsService.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
=== renamed file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/hibernate/HibernateUserDetailsService.java' => 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/DefaultUserDetailsService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/hibernate/HibernateUserDetailsService.java	2010-10-29 12:19:15 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/DefaultUserDetailsService.java	2011-07-02 11:06:16 +0000
@@ -1,4 +1,4 @@
-package org.hisp.dhis.security.hibernate;
+package org.hisp.dhis.security;
 
 /*
  * Copyright (c) 2004-2010, University of Oslo
@@ -31,12 +31,9 @@
 import java.util.HashSet;
 import java.util.Set;
 
-import org.hibernate.Criteria;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.user.UserAuthorityGroup;
 import org.hisp.dhis.user.UserCredentials;
+import org.hisp.dhis.user.UserService;
 import org.springframework.dao.DataAccessException;
 import org.springframework.security.core.GrantedAuthority;
 import org.springframework.security.core.authority.GrantedAuthorityImpl;
@@ -47,14 +44,9 @@
 import org.springframework.transaction.annotation.Transactional;
 
 /**
- * Creates and returns org.acegisecurity.userdetails.UserDetails objects based
- * on requests from the Acegi framework. The returned UserDetails objects
- * contain the username, password and authorities of the requested users.
- * 
  * @author Torgeir Lorange Ostby
- * @version $Id: HibernateUserDetailsService.java 3109 2007-03-19 17:05:21Z torgeilo $
  */
-public class HibernateUserDetailsService
+public class DefaultUserDetailsService
     implements UserDetailsService
 {
     public static final String ID = UserDetailsService.class.getName();
@@ -63,11 +55,11 @@
     // Dependencies
     // -------------------------------------------------------------------------
 
-    private SessionFactory sessionFactory;
-
-    public void setSessionFactory( SessionFactory sessionFactory )
+    private UserService userService;
+    
+    public void setUserService( UserService userService )
     {
-        this.sessionFactory = sessionFactory;
+        this.userService = userService;
     }
 
     // -------------------------------------------------------------------------
@@ -78,7 +70,12 @@
     public final UserDetails loadUserByUsername( String username )
         throws UsernameNotFoundException, DataAccessException
     {
-        UserCredentials credentials = loadUserCredentials( username );
+        UserCredentials credentials = userService.getUserCredentialsByUsername( username );
+
+        if ( credentials == null )
+        {
+            throw new UsernameNotFoundException( "Username does not exist" );
+        }
 
         return new User( credentials.getUsername(), credentials.getPassword(), true,
             true, true, true, getGrantedAuthorities( credentials ) );
@@ -102,22 +99,4 @@
 
         return authorities;
     }
-
-    private UserCredentials loadUserCredentials( String username )
-        throws UsernameNotFoundException
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        Criteria criteria = session.createCriteria( UserCredentials.class );
-        criteria.add( Restrictions.eq( "username", username ) );
-
-        UserCredentials userCredentials = (UserCredentials) criteria.uniqueResult();
-
-        if ( userCredentials == null )
-        {
-            throw new UsernameNotFoundException( "Username doesn't exist" );
-        }
-
-        return userCredentials;
-    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/security.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/security.xml	2011-06-23 14:44:17 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/security.xml	2011-07-02 11:06:16 +0000
@@ -8,8 +8,8 @@
   <bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" />
   <bean id="usernameSaltSource" class="org.hisp.dhis.security.DefaultUsernameSaltSource" />
 
-  <bean id="userDetailsService" class="org.hisp.dhis.security.hibernate.HibernateUserDetailsService">
-    <property name="sessionFactory" ref="sessionFactory" />
+  <bean id="userDetailsService" class="org.hisp.dhis.security.DefaultUserDetailsService">
+    <property name="userService" ref="org.hisp.dhis.user.UserService" />
   </bean>
 
   <bean id="org.hisp.dhis.security.PasswordManager" class="org.hisp.dhis.security.spring.SpringSecurityPasswordManager">