------------------------------------------------------------
revno: 13303
committer: Morten Olav Hansen <morte...@gmail.com>
branch nick: dhis2
timestamp: Wed 2013-12-18 13:58:19 +0100
message:
  add new field to userCredentials, passwordLastUpdated, will be used to handle 
password expiry
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java
  
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.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/main/resources/org/hisp/dhis/user/hibernate/UserCredentials.hbm.xml


--
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
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java	2013-10-01 13:32:53 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java	2013-12-18 12:58:19 +0000
@@ -42,8 +42,10 @@
 import org.hisp.dhis.common.view.ExportView;
 import org.hisp.dhis.dataset.DataSet;
 
+import java.util.Calendar;
 import java.util.Collection;
 import java.util.Date;
+import java.util.GregorianCalendar;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -76,6 +78,11 @@
     private String password;
 
     /**
+     * Date when password was changed.
+     */
+    private Date passwordLastUpdated;
+
+    /**
      * Set of user roles.
      */
     @Scanned
@@ -120,6 +127,7 @@
     {
         this.lastLogin = new Date();
         this.created = new Date();
+        this.passwordLastUpdated = new Date();
     }
 
     // -------------------------------------------------------------------------
@@ -293,9 +301,9 @@
      * Returns false if any of the given token or code arguments are not equal to
      * the respective properties the the credentials. Returns true otherwise.
      *
-     * @param token  the restore token.
-     * @param code   the restore code.
-     * @param date the expiry date.
+     * @param token the restore token.
+     * @param code  the restore code.
+     * @param date  the expiry date.
      * @return true or false.
      */
     public boolean canRestore( String token, String code, Date date )
@@ -377,6 +385,16 @@
         this.password = password;
     }
 
+    public Date getPasswordLastUpdated()
+    {
+        return passwordLastUpdated;
+    }
+
+    public void setPasswordLastUpdated( Date passwordLastUpdated )
+    {
+        this.passwordLastUpdated = passwordLastUpdated;
+    }
+
     @JsonProperty
     @JsonSerialize(contentAs = BaseIdentifiableObject.class)
     @JsonView({ DetailedView.class, ExportView.class })

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java	2013-12-04 17:42:48 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java	2013-12-18 12:58:19 +0000
@@ -28,9 +28,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.Map;
-import java.util.UUID;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.system.startup.AbstractStartupRoutine;
@@ -39,6 +36,9 @@
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.jdbc.support.rowset.SqlRowSet;
 
+import java.util.Map;
+import java.util.UUID;
+
 /**
  * @author bobj
  */
@@ -133,7 +133,7 @@
 
                 if ( count > 0 )
                 {
-                    log.info( count + " timestamps set on " + table );
+                    log.info( count + " created timestamps set on " + table );
                 }
             }
             catch ( Exception ex ) // Log and continue
@@ -151,6 +151,30 @@
         createOrgUnitUuids();
 
         log.debug( "Organisation unit uuids updated" );
+
+        updatePasswordLastUpdated();
+
+        log.debug( "UserCredential passwordLastUpdated updated" );
+    }
+
+    private void updatePasswordLastUpdated()
+    {
+        try
+        {
+            String timestamp = DateUtils.getLongDateString();
+
+            SqlRowSet resultSet = jdbcTemplate.queryForRowSet( "SELECT * from users WHERE passwordlastupdated IS NULL" );
+
+            while ( resultSet.next() )
+            {
+                String sql = "UPDATE users SET passwordlastupdated = '" + timestamp + "' WHERE passwordlastupdated IS NULL";
+                jdbcTemplate.update( sql );
+            }
+        }
+        catch ( Exception ex ) // Log and continue
+        {
+            log.error( "Problem updating passwordLastUpdated on table user: " + ex.getMessage() );
+        }
     }
 
     private String getIdColumn( String table )

=== modified 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	2013-09-04 13:10:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserCredentialsStore.java	2013-12-18 12:58:19 +0000
@@ -28,11 +28,6 @@
  * 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;
@@ -47,6 +42,11 @@
 import org.hisp.dhis.user.UserService;
 import org.hisp.dhis.user.UserSetting;
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+
 /**
  * @author Lars Helge Overland
  */
@@ -88,6 +88,13 @@
     {
         Session session = sessionFactory.getCurrentSession();
 
+        User persistedUser = userService.getUser( userCredentials.getUser().getUid() );
+
+        if ( !persistedUser.getUserCredentials().getPassword().equals( userCredentials.getPassword() ) )
+        {
+            userCredentials.setPasswordLastUpdated( new Date() );
+        }
+
         session.update( userCredentials );
     }
 
@@ -97,7 +104,7 @@
         {
             return null;
         }
-        
+
         Session session = sessionFactory.getCurrentSession();
 
         return (UserCredentials) session.get( UserCredentials.class, user.getId() );
@@ -115,7 +122,7 @@
         return (UserCredentials) query.uniqueResult();
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public Collection<UserCredentials> getAllUserCredentials()
     {
         Session session = sessionFactory.getCurrentSession();
@@ -141,7 +148,7 @@
         return rs != null ? rs.intValue() : 0;
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public Collection<UserCredentials> searchUsersByName( String key )
     {
         Session session = sessionFactory.getCurrentSession();
@@ -169,7 +176,7 @@
         return rs != null ? rs.intValue() : 0;
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public Collection<UserCredentials> getUsersBetween( int first, int max )
     {
         Session session = sessionFactory.getCurrentSession();
@@ -178,7 +185,7 @@
             .setMaxResults( max ).list();
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public Collection<UserCredentials> getUsersBetweenByName( String name, int first, int max )
     {
         Session session = sessionFactory.getCurrentSession();
@@ -235,7 +242,7 @@
         return findByName( toUserCredentials( userService.getUsersWithoutOrganisationUnit() ), name ).size();
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public Collection<UserCredentials> getSelfRegisteredUserCredentials( int first, int max )
     {
         Criteria criteria = sessionFactory.getCurrentSession().createCriteria( UserCredentials.class );
@@ -258,7 +265,7 @@
         return rs != null ? rs.intValue() : 0;
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public Collection<UserCredentials> getInactiveUsers( Date date )
     {
         Criteria criteria = sessionFactory.getCurrentSession().createCriteria( UserCredentials.class );
@@ -267,7 +274,7 @@
         return criteria.list();
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public Collection<UserCredentials> getInactiveUsers( Date date, int first, int max )
     {
         Criteria criteria = sessionFactory.getCurrentSession().createCriteria( UserCredentials.class );
@@ -331,7 +338,7 @@
         return (UserSetting) query.uniqueResult();
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public Collection<UserSetting> getAllUserSettings( User user )
     {
         Session session = sessionFactory.getCurrentSession();
@@ -341,7 +348,7 @@
         return query.list();
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public Collection<UserSetting> getUserSettings( String name )
     {
         Session session = sessionFactory.getCurrentSession();
@@ -358,7 +365,7 @@
         session.delete( userSetting );
     }
 
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public Collection<String> getUsernames( String key, Integer max )
     {
         Session session = sessionFactory.getCurrentSession();
@@ -371,7 +378,7 @@
         }
 
         Query query = session.createQuery( hql );
-        
+
         if ( max != null )
         {
             query.setMaxResults( max );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/UserCredentials.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/UserCredentials.hbm.xml	2013-09-18 13:26:26 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/UserCredentials.hbm.xml	2013-12-18 12:58:19 +0000
@@ -24,6 +24,8 @@
       <column name="password" not-null="false" />
     </property>
 
+    <property name="passwordLastUpdated" />
+
     <set name="userAuthorityGroups" table="userrolemembers" cascade="save-update">
       <cache usage="read-write" />
       <key column="userid" foreign-key="fk_userrolemembers_userid" />

_______________________________________________
Mailing list: https://launchpad.net/~dhis2-devs
Post to     : dhis2-devs@lists.launchpad.net
Unsubscribe : https://launchpad.net/~dhis2-devs
More help   : https://help.launchpad.net/ListHelp

Reply via email to