Browse Source

rememberme fix

MaxKey 3 năm trước cách đây
mục cha
commit
86395752ba

+ 3 - 1
maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/authn/support/rememberme/AbstractRemeberMeService.java

@@ -17,6 +17,7 @@
 
 package org.maxkey.authn.support.rememberme;
 
+import java.time.LocalDate;
 import java.util.Date;
 import java.util.regex.Pattern;
 import javax.servlet.http.Cookie;
@@ -26,6 +27,7 @@ import org.maxkey.configuration.ApplicationConfig;
 import org.maxkey.constants.ConstsTimeInterval;
 import org.maxkey.crypto.Base64Utils;
 import org.maxkey.crypto.password.PasswordReciprocal;
+import org.maxkey.util.DateUtils;
 import org.maxkey.util.JsonUtils;
 import org.maxkey.web.WebConstants;
 import org.maxkey.web.WebContext;
@@ -63,7 +65,7 @@ public abstract class AbstractRemeberMeService {
             remeberMe.setAuthKey(WebContext.genId());
             remeberMe.setId(WebContext.genId());
             remeberMe.setUsername(WebContext.getUserInfo().getUsername());
-            remeberMe.setLastLogin(new Date());
+            remeberMe.setLastLogin(DateUtils.getCurrentDate());
             save(remeberMe);
             _logger.debug("Remeber Me " + remeberMe);
             _logger.debug("Cookie Name : " + WebConstants.REMEBER_ME_COOKIE);

+ 5 - 5
maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/authn/support/rememberme/JdbcRemeberMeService.java

@@ -30,17 +30,17 @@ public class JdbcRemeberMeService extends AbstractRemeberMeService {
     private static final Logger _logger = LoggerFactory.getLogger(JdbcRemeberMeService.class);
 
     private static final String DEFAULT_DEFAULT_INSERT_STATEMENT = 
-            "INSERT INTO  REMEMBER_ME(ID, USERNAME,AUTHKEY,LASTLOGIN)VALUES( ? , ? , ? , ?)";
+            "insert into  mxk_remember_me(id, username,authkey,lastlogin)values( ? , ? , ? , ?)";
 
     private static final String DEFAULT_DEFAULT_SELECT_STATEMENT = 
-            "SELECT ID, USERNAME,AUTHKEY,LASTLOGIN  FROM REMEMBER_ME " 
-                    + " WHERE ID = ?  AND USERNAME = ? AND AUTHKEY = ?";
+            "select id, username,authkey,lastlogin  from mxk_remember_me " 
+                    + " where id = ?  and username = ? and authkey = ?";
 
     private static final String DEFAULT_DEFAULT_DELETE_STATEMENT = 
-            "DELETE FROM  REMEMBER_ME WHERE  USERNAME = ?";
+            "delete from  mxk_remember_me where  username = ?";
 
     private static final String DEFAULT_DEFAULT_UPDATE_STATEMENT = 
-            "UPDATE REMEMBER_ME  SET AUTHKEY  = ? , LASTLOGIN = ?  WHERE ID = ?";
+            "update mxk_remember_me  set authkey  = ? , lastlogin = ?  where id = ?";
 
     private final JdbcTemplate jdbcTemplate;
 

+ 2 - 1
maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/autoconfigure/AuthenticationAutoConfiguration.java

@@ -24,6 +24,7 @@ import org.maxkey.authn.online.OnlineTicketServices;
 import org.maxkey.authn.online.OnlineTicketServicesFactory;
 import org.maxkey.authn.realm.AbstractAuthenticationRealm;
 import org.maxkey.authn.support.rememberme.AbstractRemeberMeService;
+import org.maxkey.authn.support.rememberme.JdbcRemeberMeService;
 import org.maxkey.authn.support.rememberme.RemeberMeServiceFactory;
 import org.maxkey.configuration.ApplicationConfig;
 import org.maxkey.constants.ConstsPersistence;
@@ -124,7 +125,7 @@ public class AuthenticationAutoConfiguration  implements InitializingBean {
             @Value("${maxkey.login.remeberme.validity}") int validity,
             JdbcTemplate jdbcTemplate,
             RedisConnectionFactory redisConnFactory) {
-        return new RemeberMeServiceFactory().getService(persistence, jdbcTemplate, redisConnFactory);
+        return new  JdbcRemeberMeService(jdbcTemplate);
     }
     
     @Bean(name = "onlineTicketServices")