From 9735670208f6d8066b8347f4551fe7f782f2c161 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Thu, 6 Sep 2012 15:20:49 -0500 Subject: [PATCH] IDEMPIERE-221 Implement password policies / make password policy system wide configurable instead of tenant --- .../360lts-release/oracle/904_IDEMPIERE-221.sql | 8 ++++++++ .../360lts-release/postgresql/904_IDEMPIERE-221.sql | 8 ++++++++ .../src/org/compiere/model/MPasswordRule.java | 12 +++++++++++- org.adempiere.base/src/org/compiere/model/MUser.java | 6 ++---- 4 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 migration/360lts-release/oracle/904_IDEMPIERE-221.sql create mode 100644 migration/360lts-release/postgresql/904_IDEMPIERE-221.sql diff --git a/migration/360lts-release/oracle/904_IDEMPIERE-221.sql b/migration/360lts-release/oracle/904_IDEMPIERE-221.sql new file mode 100644 index 0000000000..fd6ad11cb5 --- /dev/null +++ b/migration/360lts-release/oracle/904_IDEMPIERE-221.sql @@ -0,0 +1,8 @@ +-- Sep 5, 2012 5:06:57 PM COT +-- IDEMPIERE-221 Implement password policies +UPDATE AD_Field SET DisplayLogic='@AD_Client_ID@=0',Updated=TO_DATE('2012-09-05 17:06:57','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=200096 +; + +SELECT register_migration_script('904_IDEMPIERE-221.sql') FROM dual +; + diff --git a/migration/360lts-release/postgresql/904_IDEMPIERE-221.sql b/migration/360lts-release/postgresql/904_IDEMPIERE-221.sql new file mode 100644 index 0000000000..2dff535b88 --- /dev/null +++ b/migration/360lts-release/postgresql/904_IDEMPIERE-221.sql @@ -0,0 +1,8 @@ +-- Sep 5, 2012 5:06:57 PM COT +-- IDEMPIERE-221 Implement password policies +UPDATE AD_Field SET DisplayLogic='@AD_Client_ID@=0',Updated=TO_TIMESTAMP('2012-09-05 17:06:57','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=200096 +; + +SELECT register_migration_script('904_IDEMPIERE-221.sql') FROM dual +; + diff --git a/org.adempiere.base/src/org/compiere/model/MPasswordRule.java b/org.adempiere.base/src/org/compiere/model/MPasswordRule.java index 2764a35c54..d97db19560 100644 --- a/org.adempiere.base/src/org/compiere/model/MPasswordRule.java +++ b/org.adempiere.base/src/org/compiere/model/MPasswordRule.java @@ -63,7 +63,7 @@ public class MPasswordRule extends X_AD_PasswordRule { /** * */ - private static final long serialVersionUID = -3557291675139843726L; + private static final long serialVersionUID = -4262842010340413022L; /** * @param ctx @@ -82,6 +82,16 @@ public class MPasswordRule extends X_AD_PasswordRule { public MPasswordRule(Properties ctx, ResultSet rs, String trxName) { super(ctx, rs, trxName); } + + public static MPasswordRule getRules(Properties ctx, String trxName) { + MClient system = MClient.get(ctx, 0); + int pwdruleID = system.getAD_PasswordRule_ID(); + MPasswordRule pass = null; + if (pwdruleID > 0) + pass = new MPasswordRule(ctx, pwdruleID, trxName); + + return pass; + } public void validate(String username, String newPassword) throws AdempiereException { diff --git a/org.adempiere.base/src/org/compiere/model/MUser.java b/org.adempiere.base/src/org/compiere/model/MUser.java index b0e8e6aeb6..0a6c7b75a8 100644 --- a/org.adempiere.base/src/org/compiere/model/MUser.java +++ b/org.adempiere.base/src/org/compiere/model/MUser.java @@ -927,11 +927,9 @@ public class MUser extends X_AD_User if (get_ValueOld("Salt") == null && get_Value("Salt") != null) { // being hashed ; } else { - int pwdruleid = MClient.get(getCtx(), getAD_Client_ID()).getAD_PasswordRule_ID(); - if (pwdruleid > 0) { - MPasswordRule pwdrule = new MPasswordRule(getCtx(), MClient.get(getCtx()).getAD_PasswordRule_ID(), get_TrxName()); + MPasswordRule pwdrule = MPasswordRule.getRules(getCtx(), get_TrxName()); + if (pwdrule != null) pwdrule.validate((getLDAPUser() != null ? getLDAPUser() : getName()), getPassword()); - } } // Hash password - IDEMPIERE-347