dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #38833
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19730: AuthenticationSuccessHandler, re-impl update of lastlogin for user, got lost in 2.20
------------------------------------------------------------
revno: 19730
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-08-06 16:04:41 +0200
message:
AuthenticationSuccessHandler, re-impl update of lastlogin for user, got lost in 2.20
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/security/DefaultAuthenticationSuccessHandler.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
=== 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 2015-07-13 12:34:39 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java 2015-08-06 14:04:41 +0000
@@ -365,6 +365,14 @@
{
return username;
}
+
+ /**
+ * Sets the last login property to the current date.
+ */
+ public void updateLastLogin()
+ {
+ this.lastLogin = new Date();
+ }
/**
* Tests whether the credentials contain all needed parameters to
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/security/DefaultAuthenticationSuccessHandler.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/security/DefaultAuthenticationSuccessHandler.java 2015-02-22 20:30:29 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/security/DefaultAuthenticationSuccessHandler.java 2015-08-06 14:04:41 +0000
@@ -28,16 +28,20 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import org.hisp.dhis.security.intercept.LoginInterceptor;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
+import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
-import java.io.IOException;
+
+import org.hisp.dhis.security.intercept.LoginInterceptor;
+import org.hisp.dhis.user.UserCredentials;
+import org.hisp.dhis.user.UserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.User;
+import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
/**
* Since ActionContext is not available at this point, we set a mark in the
@@ -56,16 +60,29 @@
*/
public static final int DEFAULT_SESSION_TIMEOUT = 60 * 60;
+ @Autowired
+ private UserService userService;
+
@Override
public void onAuthenticationSuccess( HttpServletRequest request, HttpServletResponse response, Authentication authentication )
throws ServletException, IOException
{
HttpSession session = request.getSession();
+
+ String username = ((User)authentication.getPrincipal()).getUsername();
- session.setAttribute( "userIs", ((User)authentication.getPrincipal()).getUsername());
+ session.setAttribute( "userIs", username);
session.setAttribute( LoginInterceptor.JLI_SESSION_VARIABLE, Boolean.TRUE );
session.setMaxInactiveInterval( DefaultAuthenticationSuccessHandler.DEFAULT_SESSION_TIMEOUT );
+ UserCredentials credentials = userService.getUserCredentialsByUsername( username );
+
+ if ( credentials != null )
+ {
+ credentials.updateLastLogin();
+ userService.updateUserCredentials( credentials );
+ }
+
super.onAuthenticationSuccess( request, response, authentication );
}
}