FR [2893090] - Implement remember me

https://sourceforge.net/tracker/?func=detail&atid=955896&aid=2893090&group_id=176962
Implemented sysconfig keys to control the feature - it can be configured now to allow saving User/Password/None for zk or swing
This commit is contained in:
Carlos Ruiz 2009-12-15 03:04:01 +00:00
parent b32c97c23d
commit b93ee106b0
8 changed files with 153 additions and 45 deletions

View File

@ -55,7 +55,7 @@ public class MSystem extends X_AD_System
/**
*
*/
private static final long serialVersionUID = 5528932721084369075L;
private static final long serialVersionUID = 8639311032004561198L;
/**
* Load System Record
@ -461,7 +461,38 @@ public class MSystem extends X_AD_System
*/
} // info
/*
* Allow remember me feature
* ZK_LOGIN_ALLOW_REMEMBER_ME and SWING_ALLOW_REMEMBER_ME parameter allow the next values
* U - Allow remember the username (default for zk)
* P - Allow remember the username and password (default for swing)
* N - None
*
* @return boolean representing if remember me feature is allowed
*/
private static final String SYSTEM_ALLOW_REMEMBER_USER = "U";
private static final String SYSTEM_ALLOW_REMEMBER_PASSWORD = "P";
public static boolean isZKRememberUserAllowed() {
String ca = MSysConfig.getValue("ZK_LOGIN_ALLOW_REMEMBER_ME", SYSTEM_ALLOW_REMEMBER_USER);
return (ca.equalsIgnoreCase(SYSTEM_ALLOW_REMEMBER_USER) || ca.equalsIgnoreCase(SYSTEM_ALLOW_REMEMBER_PASSWORD));
}
public static boolean isZKRememberPasswordAllowed() {
String ca = MSysConfig.getValue("ZK_LOGIN_ALLOW_REMEMBER_ME", SYSTEM_ALLOW_REMEMBER_USER);
return (ca.equalsIgnoreCase(SYSTEM_ALLOW_REMEMBER_PASSWORD));
}
public static boolean isSwingRememberUserAllowed() {
String ca = MSysConfig.getValue("SWING_LOGIN_ALLOW_REMEMBER_ME", SYSTEM_ALLOW_REMEMBER_PASSWORD);
return (ca.equalsIgnoreCase(SYSTEM_ALLOW_REMEMBER_USER) || ca.equalsIgnoreCase(SYSTEM_ALLOW_REMEMBER_PASSWORD));
}
public static boolean isSwingRememberPasswordAllowed() {
String ca = MSysConfig.getValue("SWING_LOGIN_ALLOW_REMEMBER_ME", SYSTEM_ALLOW_REMEMBER_PASSWORD);
return (ca.equalsIgnoreCase(SYSTEM_ALLOW_REMEMBER_PASSWORD));
}
/**
* Test
* @param args

View File

@ -317,9 +317,12 @@ public class Login
Env.setContext(m_ctx, "#SalesRep_ID", rs.getInt(1));
//
if (Ini.isClient())
{
Ini.setProperty(Ini.P_UID, app_user);
if (Ini.isPropertyBool(Ini.P_STORE_PWD))
{
if (MSystem.isSwingRememberUserAllowed())
Ini.setProperty(Ini.P_UID, app_user);
else
Ini.setProperty(Ini.P_UID, "");
if (Ini.isPropertyBool(Ini.P_STORE_PWD) && MSystem.isSwingRememberPasswordAllowed())
Ini.setProperty(Ini.P_PWD, app_pwd);
m_connectionProfile = rs.getString(4); // User Based

View File

@ -53,6 +53,7 @@ import org.compiere.db.CConnection;
import org.compiere.grid.ed.VDate;
import org.compiere.minigrid.MiniTable;
import org.compiere.model.MRole;
import org.compiere.model.MSystem;
import org.compiere.model.MUser;
import org.compiere.print.CPrinter;
import org.compiere.swing.CButton;
@ -257,15 +258,18 @@ public final class Preference extends CDialog
customizePane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
Border insetBorder = BorderFactory.createEmptyBorder(2, 2, 2, 0);
CPanel loginPanel = new CPanel();
loginPanel.setBorder(BorderFactory.createTitledBorder(Msg.getMsg(Env.getCtx(), "Login")));
loginPanel.setLayout(new GridLayout(1, 2));
autoLogin.setBorder(insetBorder);
storePassword.setBorder(insetBorder);
loginPanel.add(autoLogin);
loginPanel.add(storePassword);
customizePane.add(loginPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 0, 2, 0), 0, 0));
if (MSystem.isSwingRememberPasswordAllowed()) {
CPanel loginPanel = new CPanel();
loginPanel.setBorder(BorderFactory.createTitledBorder(Msg.getMsg(Env.getCtx(), "Login")));
loginPanel.setLayout(new GridLayout(1, 2));
autoLogin.setBorder(insetBorder);
storePassword.setBorder(insetBorder);
loginPanel.add(autoLogin);
loginPanel.add(storePassword);
customizePane.add(loginPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 0, 2, 0), 0, 0));
}
CPanel windowPanel = new CPanel();
windowPanel.setBorder(BorderFactory.createTitledBorder(Msg.getMsg(Env.getCtx(), "Window")));
@ -480,10 +484,15 @@ public final class Preference extends CDialog
logMigrationScript.setEnabled(false);
}
}
// AutoLogin
autoLogin.setSelected(Ini.isPropertyBool(Ini.P_A_LOGIN));
// Save Password
storePassword.setSelected(Ini.isPropertyBool(Ini.P_STORE_PWD));
if (MSystem.isSwingRememberPasswordAllowed()) {
// AutoLogin
autoLogin.setSelected(Ini.isPropertyBool(Ini.P_A_LOGIN));
// Save Password
storePassword.setSelected(Ini.isPropertyBool(Ini.P_STORE_PWD));
} else {
autoLogin.setSelected(false);
storePassword.setSelected(false);
}
// Show Acct Tab
if (MRole.getDefault().isShowAcct())
showAcct.setSelected(Ini.isPropertyBool(Ini.P_SHOW_ACCT));
@ -566,10 +575,15 @@ public final class Preference extends CDialog
Ini.setProperty(Ini.P_ADEMPIERESYS, adempiereSys.isSelected());
// LogMigrationScript
Ini.setProperty(Ini.P_LOGMIGRATIONSCRIPT, logMigrationScript.isSelected());
// AutoLogin
Ini.setProperty(Ini.P_A_LOGIN, (autoLogin.isSelected()));
// Save Password
Ini.setProperty(Ini.P_STORE_PWD, (storePassword.isSelected()));
if (MSystem.isSwingRememberPasswordAllowed()) {
// AutoLogin
Ini.setProperty(Ini.P_A_LOGIN, (autoLogin.isSelected()));
// Save Password
Ini.setProperty(Ini.P_STORE_PWD, (storePassword.isSelected()));
} else {
Ini.setProperty(Ini.P_A_LOGIN, false);
Ini.setProperty(Ini.P_STORE_PWD, false);
}
// Show Acct Tab
Ini.setProperty(Ini.P_SHOW_ACCT, (showAcct.isSelected()));
Env.setContext(Env.getCtx(), "#ShowAcct", (showAcct.isSelected()));

View File

@ -0,0 +1,21 @@
-- Dec 14, 2009 6:16:10 PM COT
-- FR2893090_Implement remember me
INSERT INTO AD_SysConfig (AD_Client_ID,AD_Org_ID,AD_SysConfig_ID,ConfigurationLevel,Created,CreatedBy,Description,EntityType,IsActive,Name,Updated,UpdatedBy,Value) VALUES (0,0,50037,'S',TO_DATE('2009-12-14 18:16:10','YYYY-MM-DD HH24:MI:SS'),100,'Allow remember me on zkwebui - allowed values [U]ser / [P]assword / [N]one','D','Y','ZK_LOGIN_ALLOW_REMEMBER_ME',TO_DATE('2009-12-14 18:16:10','YYYY-MM-DD HH24:MI:SS'),100,'U')
;
-- Dec 14, 2009 6:16:24 PM COT
INSERT INTO AD_SysConfig (AD_Client_ID,AD_Org_ID,AD_SysConfig_ID,ConfigurationLevel,Created,CreatedBy,Description,EntityType,IsActive,Name,Updated,UpdatedBy,Value) VALUES (0,0,50038,'S',TO_DATE('2009-12-14 18:16:23','YYYY-MM-DD HH24:MI:SS'),100,'Allow remember me on swing - allowed values [U]ser / [P]assword / [N]one','D','Y','SWING_LOGIN_ALLOW_REMEMBER_ME',TO_DATE('2009-12-14 18:16:23','YYYY-MM-DD HH24:MI:SS'),100,'P')
;
-- Dec 14, 2009 8:32:30 PM COT
INSERT INTO AD_Message (AD_Client_ID,AD_Message_ID,AD_Org_ID,Created,CreatedBy,EntityType,IsActive,MsgText,MsgType,Updated,UpdatedBy,Value) VALUES (0,53091,0,TO_DATE('2009-12-14 20:32:29','YYYY-MM-DD HH24:MI:SS'),100,'D','Y','Remember Me','I',TO_DATE('2009-12-14 20:32:29','YYYY-MM-DD HH24:MI:SS'),100,'RememberMe')
;
-- Dec 14, 2009 8:32:30 PM COT
INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=53091 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID)
;
-- Dec 14, 2009 8:32:51 PM COT
UPDATE AD_Message_Trl SET IsTranslated='Y',MsgText='Recordar mis datos',Updated=TO_DATE('2009-12-14 20:32:51','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Message_ID=53091 AND AD_Language LIKE 'es_%'
;

View File

@ -0,0 +1,21 @@
-- Dec 14, 2009 6:16:10 PM COT
-- FR2893090_Implement remember me
INSERT INTO AD_SysConfig (AD_Client_ID,AD_Org_ID,AD_SysConfig_ID,ConfigurationLevel,Created,CreatedBy,Description,EntityType,IsActive,Name,Updated,UpdatedBy,Value) VALUES (0,0,50037,'S',TO_TIMESTAMP('2009-12-14 18:16:10','YYYY-MM-DD HH24:MI:SS'),100,'Allow remember me on zkwebui - allowed values [U]ser / [P]assword / [N]one','D','Y','ZK_LOGIN_ALLOW_REMEMBER_ME',TO_TIMESTAMP('2009-12-14 18:16:10','YYYY-MM-DD HH24:MI:SS'),100,'U')
;
-- Dec 14, 2009 6:16:24 PM COT
INSERT INTO AD_SysConfig (AD_Client_ID,AD_Org_ID,AD_SysConfig_ID,ConfigurationLevel,Created,CreatedBy,Description,EntityType,IsActive,Name,Updated,UpdatedBy,Value) VALUES (0,0,50038,'S',TO_TIMESTAMP('2009-12-14 18:16:23','YYYY-MM-DD HH24:MI:SS'),100,'Allow remember me on swing - allowed values [U]ser / [P]assword / [N]one','D','Y','SWING_LOGIN_ALLOW_REMEMBER_ME',TO_TIMESTAMP('2009-12-14 18:16:23','YYYY-MM-DD HH24:MI:SS'),100,'P')
;
-- Dec 14, 2009 8:32:30 PM COT
INSERT INTO AD_Message (AD_Client_ID,AD_Message_ID,AD_Org_ID,Created,CreatedBy,EntityType,IsActive,MsgText,MsgType,Updated,UpdatedBy,Value) VALUES (0,53091,0,TO_TIMESTAMP('2009-12-14 20:32:29','YYYY-MM-DD HH24:MI:SS'),100,'D','Y','Remember Me','I',TO_TIMESTAMP('2009-12-14 20:32:29','YYYY-MM-DD HH24:MI:SS'),100,'RememberMe')
;
-- Dec 14, 2009 8:32:30 PM COT
INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=53091 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID)
;
-- Dec 14, 2009 8:32:51 PM COT
UPDATE AD_Message_Trl SET IsTranslated='Y',MsgText='Recordar mis datos',Updated=TO_TIMESTAMP('2009-12-14 20:32:51','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Message_ID=53091 AND AD_Language LIKE 'es_%'
;

View File

@ -37,6 +37,7 @@ import org.adempiere.webui.util.UserPreference;
import org.compiere.model.MRole;
import org.compiere.model.MSession;
import org.compiere.model.MSysConfig;
import org.compiere.model.MSystem;
import org.compiere.model.MUser;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
@ -244,7 +245,7 @@ public class AdempiereWebUI extends Window implements EventListener, IWebClient
currSess.setAttribute("execution.carryover", eco);
}
if ("Y".equalsIgnoreCase(Env.getContext(ctx, BrowserToken.REMEMBER_ME)))
if ("Y".equalsIgnoreCase(Env.getContext(ctx, BrowserToken.REMEMBER_ME)) && MSystem.isZKRememberUserAllowed())
{
MUser user = MUser.get(ctx);
BrowserToken.save(mSession, user);

View File

@ -24,6 +24,7 @@
package org.adempiere.webui.panel;
import java.text.MessageFormat;
import java.util.Locale;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.logging.Level;
@ -45,6 +46,7 @@ import org.adempiere.webui.util.UserPreference;
import org.adempiere.webui.window.LoginWindow;
import org.compiere.Adempiere;
import org.compiere.model.MSession;
import org.compiere.model.MSystem;
import org.compiere.model.MUser;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
@ -178,17 +180,19 @@ public class LoginPanel extends Window implements EventListener
tr.appendChild(td);
td.appendChild(lstLanguage);
tr = new Tr();
tr.setId("rowRememberMe");
table.appendChild(tr);
td = new Td();
tr.appendChild(td);
td.setSclass(ITheme.LOGIN_LABEL_CLASS);
td.appendChild(new Label(""));
td = new Td();
td.setSclass(ITheme.LOGIN_FIELD_CLASS);
tr.appendChild(td);
td.appendChild(chkRememberMe);
if (MSystem.isZKRememberUserAllowed()) {
tr = new Tr();
tr.setId("rowRememberMe");
table.appendChild(tr);
td = new Td();
tr.appendChild(td);
td.setSclass(ITheme.LOGIN_LABEL_CLASS);
td.appendChild(new Label(""));
td = new Td();
td.setSclass(ITheme.LOGIN_FIELD_CLASS);
tr.appendChild(td);
td.appendChild(chkRememberMe);
}
div = new Div();
div.setSclass(ITheme.LOGIN_BOX_FOOTER_CLASS);
@ -218,12 +222,16 @@ public class LoginPanel extends Window implements EventListener
String token = data[1];
if (BrowserToken.validateToken(session, user, token))
{
txtUserId.setValue(user.getName());
onUserIdChange();
txtPassword.setValue(token);
txtPassword.setAttribute("user.token.hash", token);
txtPassword.setAttribute("user.token.sid", AD_Session_ID);
chkRememberMe.setChecked(true);
if (MSystem.isZKRememberUserAllowed()) {
txtUserId.setValue(user.getName());
onUserIdChange();
chkRememberMe.setChecked(true);
}
if (MSystem.isZKRememberPasswordAllowed()) {
txtPassword.setValue(token);
txtPassword.setAttribute("user.token.hash", token);
txtPassword.setAttribute("user.token.sid", AD_Session_ID);
}
}
}
}
@ -278,6 +286,8 @@ public class LoginPanel extends Window implements EventListener
lstLanguage.appendItem(langName, language.getAD_Language());
}
chkRememberMe = new Checkbox(Msg.getMsg(Language.getBaseAD_Language(), "RememberMe"));
//set base language
String baseLanguage = Language.getBaseLanguage().getName();
for(int i = 0; i < lstLanguage.getItemCount(); i++)
@ -290,9 +300,6 @@ public class LoginPanel extends Window implements EventListener
break;
}
}
//TODO: localization
chkRememberMe = new Checkbox("Remember Me");
}
public void onEvent(Event event)
@ -349,10 +356,15 @@ public class LoginPanel extends Window implements EventListener
{
Language language = findLanguage(langName);
res = ResourceBundle.getBundle(RESOURCE, language.getLocale());
// Locales
Locale loc = language.getLocale();
Locale.setDefault(loc);
res = ResourceBundle.getBundle(RESOURCE, loc);
lblUserId.setValue(res.getString("User"));
lblPassword.setValue(res.getString("Password"));
lblLanguage.setValue(res.getString("Language"));
chkRememberMe.setLabel(Msg.getMsg(language, "RememberMe"));
}
private Language findLanguage(String langName) {

View File

@ -21,6 +21,7 @@ import java.util.logging.Level;
import org.compiere.Adempiere;
import org.compiere.model.MSession;
import org.compiere.model.MSystem;
import org.compiere.model.MUser;
import org.compiere.util.CLogger;
import org.zkoss.zk.au.out.AuScript;
@ -126,7 +127,11 @@ public final class BrowserToken {
BASE64Encoder encoder = new BASE64Encoder();
digest.reset();
digest.update(session.getWebSession().getBytes("UTF-8"));
String password = user.getPassword();
String password = null;
if (MSystem.isZKRememberPasswordAllowed())
password = user.getPassword();
else
password = new String("");
byte[] input = digest.digest(password.getBytes("UTF-8"));
String hash = encoder.encode(input);
hash = URLEncoder.encode(hash, "UTF-8");