IDEMPIERE-5174 Disable System User (#1174)
Verify hardcoded comparisons for role and system users
This commit is contained in:
parent
c90afc0948
commit
a9c4f7b642
|
@ -23,6 +23,7 @@ import java.util.logging.Level;
|
||||||
import org.compiere.Adempiere;
|
import org.compiere.Adempiere;
|
||||||
import org.compiere.model.MRole;
|
import org.compiere.model.MRole;
|
||||||
import org.compiere.model.Query;
|
import org.compiere.model.Query;
|
||||||
|
import org.compiere.model.SystemIDs;
|
||||||
import org.compiere.util.CLogMgt;
|
import org.compiere.util.CLogMgt;
|
||||||
import org.compiere.util.CLogger;
|
import org.compiere.util.CLogger;
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
|
@ -93,7 +94,7 @@ public class RoleAccessUpdate extends SvrProcess
|
||||||
whereClause.append(" AND AD_Client_ID=? ");
|
whereClause.append(" AND AD_Client_ID=? ");
|
||||||
params.add(p_AD_Client_ID);
|
params.add(p_AD_Client_ID);
|
||||||
}
|
}
|
||||||
if (p_AD_Role_ID == 0) // System Role
|
if (p_AD_Role_ID == SystemIDs.ROLE_SYSTEM) // System Role
|
||||||
{
|
{
|
||||||
whereClause.append(" AND AD_Role_ID=?");
|
whereClause.append(" AND AD_Role_ID=?");
|
||||||
params.add(p_AD_Role_ID);
|
params.add(p_AD_Role_ID);
|
||||||
|
|
|
@ -20,6 +20,7 @@ import java.util.logging.Level;
|
||||||
|
|
||||||
import org.compiere.model.MSysConfig;
|
import org.compiere.model.MSysConfig;
|
||||||
import org.compiere.model.MUser;
|
import org.compiere.model.MUser;
|
||||||
|
import org.compiere.model.SystemIDs;
|
||||||
import org.compiere.util.Util;
|
import org.compiere.util.Util;
|
||||||
/**
|
/**
|
||||||
* Reset Password
|
* Reset Password
|
||||||
|
@ -89,8 +90,8 @@ public class UserPassword extends SvrProcess
|
||||||
// Do we need a password ?
|
// Do we need a password ?
|
||||||
if (Util.isEmpty(p_OldPassword)) // Password required
|
if (Util.isEmpty(p_OldPassword)) // Password required
|
||||||
{
|
{
|
||||||
if (p_AD_User_ID == 0 // change of System
|
if (p_AD_User_ID == SystemIDs.USER_SYSTEM // change of System
|
||||||
|| p_AD_User_ID == 100 // change of SuperUser
|
|| p_AD_User_ID == SystemIDs.USER_SUPERUSER // change of SuperUser
|
||||||
|| !operator.isAdministrator())
|
|| !operator.isAdministrator())
|
||||||
throw new IllegalArgumentException("@OldPasswordMandatory@");
|
throw new IllegalArgumentException("@OldPasswordMandatory@");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.sql.ResultSet;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.compiere.model.Query;
|
import org.compiere.model.Query;
|
||||||
|
import org.compiere.model.SystemIDs;
|
||||||
import org.compiere.model.X_AD_Tab_Customization;
|
import org.compiere.model.X_AD_Tab_Customization;
|
||||||
import org.compiere.util.Util;
|
import org.compiere.util.Util;
|
||||||
|
|
||||||
|
@ -112,7 +113,7 @@ public class MTabCustomization extends X_AD_Tab_Customization {
|
||||||
@Override
|
@Override
|
||||||
public void setAD_User_ID (int AD_User_ID)
|
public void setAD_User_ID (int AD_User_ID)
|
||||||
{
|
{
|
||||||
if (AD_User_ID == 0)
|
if (AD_User_ID == SystemIDs.USER_SYSTEM_DEPRECATED)
|
||||||
set_ValueNoCheck (COLUMNNAME_AD_User_ID, AD_User_ID);
|
set_ValueNoCheck (COLUMNNAME_AD_User_ID, AD_User_ID);
|
||||||
else
|
else
|
||||||
super.setAD_User_ID(AD_User_ID);
|
super.setAD_User_ID(AD_User_ID);
|
||||||
|
|
|
@ -113,7 +113,7 @@ public class MDashboardPreference extends X_PA_DashboardPreference
|
||||||
@Override
|
@Override
|
||||||
public void setAD_User_ID (int AD_User_ID)
|
public void setAD_User_ID (int AD_User_ID)
|
||||||
{
|
{
|
||||||
if (AD_User_ID == 0)
|
if (AD_User_ID == SystemIDs.USER_SYSTEM_DEPRECATED)
|
||||||
set_ValueNoCheck (COLUMNNAME_AD_User_ID, AD_User_ID);
|
set_ValueNoCheck (COLUMNNAME_AD_User_ID, AD_User_ID);
|
||||||
else
|
else
|
||||||
super.setAD_User_ID(AD_User_ID);
|
super.setAD_User_ID(AD_User_ID);
|
||||||
|
|
|
@ -163,8 +163,8 @@ public class MDocumentStatus extends X_PA_DocumentStatus {
|
||||||
* but as they are the administrators is not a problem
|
* but as they are the administrators is not a problem
|
||||||
*/
|
*/
|
||||||
if ( (access.getAD_Role_ID() == roleId && access.getAD_User_ID() == userId)
|
if ( (access.getAD_Role_ID() == roleId && access.getAD_User_ID() == userId)
|
||||||
|| (access.getAD_Role_ID() == roleId && access.getAD_User_ID() == 0 )
|
|| (access.getAD_Role_ID() == roleId && access.getAD_User_ID() == SystemIDs.USER_SYSTEM)
|
||||||
|| (access.getAD_Role_ID() == 0 && access.getAD_User_ID() == userId) )
|
|| (access.getAD_Role_ID() == SystemIDs.ROLE_SYSTEM && access.getAD_User_ID() == userId) )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -199,7 +199,7 @@ public class MMFARegistration extends X_MFA_Registration {
|
||||||
@Override
|
@Override
|
||||||
public void setAD_User_ID (int AD_User_ID)
|
public void setAD_User_ID (int AD_User_ID)
|
||||||
{
|
{
|
||||||
if (AD_User_ID == 0)
|
if (AD_User_ID == SystemIDs.USER_SYSTEM_DEPRECATED)
|
||||||
set_ValueNoCheck (COLUMNNAME_AD_User_ID, AD_User_ID);
|
set_ValueNoCheck (COLUMNNAME_AD_User_ID, AD_User_ID);
|
||||||
else
|
else
|
||||||
super.setAD_User_ID(AD_User_ID);
|
super.setAD_User_ID(AD_User_ID);
|
||||||
|
|
|
@ -107,7 +107,7 @@ public class MPreference extends X_AD_Preference
|
||||||
@Override
|
@Override
|
||||||
public void setAD_User_ID (int AD_User_ID)
|
public void setAD_User_ID (int AD_User_ID)
|
||||||
{
|
{
|
||||||
if (AD_User_ID == 0)
|
if (AD_User_ID == SystemIDs.USER_SYSTEM_DEPRECATED)
|
||||||
set_ValueNoCheck (COLUMNNAME_AD_User_ID, AD_User_ID);
|
set_ValueNoCheck (COLUMNNAME_AD_User_ID, AD_User_ID);
|
||||||
else
|
else
|
||||||
super.setAD_User_ID(AD_User_ID);
|
super.setAD_User_ID(AD_User_ID);
|
||||||
|
|
|
@ -131,7 +131,7 @@ public final class MRole extends X_AD_Role implements ImmutablePOSupport
|
||||||
if (role == null || reload)
|
if (role == null || reload)
|
||||||
{
|
{
|
||||||
role = new MRole (ctx, AD_Role_ID, null);
|
role = new MRole (ctx, AD_Role_ID, null);
|
||||||
if (AD_Role_ID == 0)
|
if (AD_Role_ID == SystemIDs.ROLE_SYSTEM)
|
||||||
{
|
{
|
||||||
String trxName = null;
|
String trxName = null;
|
||||||
role.load(trxName); // special Handling
|
role.load(trxName); // special Handling
|
||||||
|
@ -269,7 +269,7 @@ public final class MRole extends X_AD_Role implements ImmutablePOSupport
|
||||||
{
|
{
|
||||||
super (ctx, AD_Role_ID, trxName);
|
super (ctx, AD_Role_ID, trxName);
|
||||||
// ID=0 == System Administrator
|
// ID=0 == System Administrator
|
||||||
if (AD_Role_ID == 0)
|
if (AD_Role_ID == SystemIDs.ROLE_SYSTEM)
|
||||||
{
|
{
|
||||||
setIsCanExport (true);
|
setIsCanExport (true);
|
||||||
setIsCanReport (true);
|
setIsCanReport (true);
|
||||||
|
|
|
@ -154,7 +154,7 @@ public class MUser extends X_AD_User implements ImmutablePOSupport
|
||||||
if (retValue == null)
|
if (retValue == null)
|
||||||
{
|
{
|
||||||
retValue = new MUser (ctx, AD_User_ID, (String)null);
|
retValue = new MUser (ctx, AD_User_ID, (String)null);
|
||||||
if (AD_User_ID == 0)
|
if (AD_User_ID == SystemIDs.USER_SYSTEM_DEPRECATED)
|
||||||
{
|
{
|
||||||
String trxName = null;
|
String trxName = null;
|
||||||
retValue.load(trxName); // load System Record
|
retValue.load(trxName); // load System Record
|
||||||
|
@ -835,7 +835,7 @@ public class MUser extends X_AD_User implements ImmutablePOSupport
|
||||||
MRole[] roles = getRoles(0);
|
MRole[] roles = getRoles(0);
|
||||||
for (int i = 0; i < roles.length; i++)
|
for (int i = 0; i < roles.length; i++)
|
||||||
{
|
{
|
||||||
if (roles[i].getAD_Role_ID() == 0)
|
if (roles[i].getAD_Role_ID() == SystemIDs.ROLE_SYSTEM)
|
||||||
{
|
{
|
||||||
m_isAdministrator = Boolean.TRUE;
|
m_isAdministrator = Boolean.TRUE;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class MUserPreference extends X_AD_UserPreference{
|
||||||
@Override
|
@Override
|
||||||
public void setAD_User_ID (int AD_User_ID)
|
public void setAD_User_ID (int AD_User_ID)
|
||||||
{
|
{
|
||||||
if (AD_User_ID == 0)
|
if (AD_User_ID == SystemIDs.USER_SYSTEM_DEPRECATED)
|
||||||
set_ValueNoCheck (COLUMNNAME_AD_User_ID, AD_User_ID);
|
set_ValueNoCheck (COLUMNNAME_AD_User_ID, AD_User_ID);
|
||||||
else
|
else
|
||||||
super.setAD_User_ID(AD_User_ID);
|
super.setAD_User_ID(AD_User_ID);
|
||||||
|
|
|
@ -354,7 +354,7 @@ public class MUserQuery extends X_AD_UserQuery
|
||||||
@Override
|
@Override
|
||||||
public void setAD_User_ID (int AD_User_ID)
|
public void setAD_User_ID (int AD_User_ID)
|
||||||
{
|
{
|
||||||
if (AD_User_ID == 0)
|
if (AD_User_ID == SystemIDs.USER_SYSTEM_DEPRECATED)
|
||||||
set_ValueNoCheck (COLUMNNAME_AD_User_ID, AD_User_ID);
|
set_ValueNoCheck (COLUMNNAME_AD_User_ID, AD_User_ID);
|
||||||
else
|
else
|
||||||
super.setAD_User_ID(AD_User_ID);
|
super.setAD_User_ID(AD_User_ID);
|
||||||
|
|
|
@ -122,7 +122,7 @@ public class MUserRoles extends X_AD_User_Roles
|
||||||
@Override
|
@Override
|
||||||
public void setAD_User_ID (int AD_User_ID)
|
public void setAD_User_ID (int AD_User_ID)
|
||||||
{
|
{
|
||||||
if (AD_User_ID == 0)
|
if (AD_User_ID == SystemIDs.USER_SYSTEM_DEPRECATED)
|
||||||
set_ValueNoCheck (COLUMNNAME_AD_User_ID, AD_User_ID);
|
set_ValueNoCheck (COLUMNNAME_AD_User_ID, AD_User_ID);
|
||||||
else
|
else
|
||||||
super.setAD_User_ID(AD_User_ID);
|
super.setAD_User_ID(AD_User_ID);
|
||||||
|
|
|
@ -270,7 +270,7 @@ public class ModelValidationEngine
|
||||||
if (errors != null && !errors.isEmpty())
|
if (errors != null && !errors.isEmpty())
|
||||||
return errors.get(0);
|
return errors.get(0);
|
||||||
|
|
||||||
if (AD_User_ID == 0 && AD_Role_ID == 0)
|
if ((AD_User_ID == SystemIDs.USER_SYSTEM || AD_User_ID == SystemIDs.USER_SUPERUSER) && AD_Role_ID == SystemIDs.ROLE_SYSTEM)
|
||||||
; // don't validate for user system on role system
|
; // don't validate for user system on role system
|
||||||
else
|
else
|
||||||
if (! Util.isEmpty(missingModelValidationMessage)) {
|
if (! Util.isEmpty(missingModelValidationMessage)) {
|
||||||
|
|
|
@ -181,7 +181,10 @@ public class SystemIDs
|
||||||
public final static int TREE_MENUPRIMARY = 10;
|
public final static int TREE_MENUPRIMARY = 10;
|
||||||
|
|
||||||
public final static int USER_SUPERUSER = 100;
|
public final static int USER_SUPERUSER = 100;
|
||||||
public final static int USER_SYSTEM = 0;
|
public final static int USER_SYSTEM = 10;
|
||||||
|
public final static int USER_SYSTEM_DEPRECATED = 0;
|
||||||
|
|
||||||
|
public final static int ROLE_SYSTEM = 0;
|
||||||
|
|
||||||
public final static int WINDOW_ACCOUNTCOMBINATION = 153;
|
public final static int WINDOW_ACCOUNTCOMBINATION = 153;
|
||||||
public final static int WINDOW_ATTRIBUTESETINSTANCE = 358;
|
public final static int WINDOW_ATTRIBUTESETINSTANCE = 358;
|
||||||
|
|
|
@ -38,6 +38,7 @@ import org.compiere.model.MQuery;
|
||||||
import org.compiere.model.MReportView;
|
import org.compiere.model.MReportView;
|
||||||
import org.compiere.model.MRole;
|
import org.compiere.model.MRole;
|
||||||
import org.compiere.model.MTable;
|
import org.compiere.model.MTable;
|
||||||
|
import org.compiere.model.SystemIDs;
|
||||||
import org.compiere.util.CLogMgt;
|
import org.compiere.util.CLogMgt;
|
||||||
import org.compiere.util.CLogger;
|
import org.compiere.util.CLogger;
|
||||||
import org.compiere.util.DB;
|
import org.compiere.util.DB;
|
||||||
|
@ -728,7 +729,7 @@ public class DataEngine
|
||||||
}
|
}
|
||||||
// Access Restriction
|
// Access Restriction
|
||||||
MRole role = MRole.getDefault(ctx, false);
|
MRole role = MRole.getDefault(ctx, false);
|
||||||
if (role.getAD_Role_ID() == 0 && !Ini.isClient())
|
if (role.getAD_Role_ID() == SystemIDs.ROLE_SYSTEM && !Ini.isClient())
|
||||||
; // System Access
|
; // System Access
|
||||||
else
|
else
|
||||||
finalSQL = new StringBuilder (role.addAccessSQL (finalSQL.toString (),
|
finalSQL = new StringBuilder (role.addAccessSQL (finalSQL.toString (),
|
||||||
|
|
|
@ -50,6 +50,7 @@ import org.compiere.model.MUserPreference;
|
||||||
import org.compiere.model.ModelValidationEngine;
|
import org.compiere.model.ModelValidationEngine;
|
||||||
import org.compiere.model.PO;
|
import org.compiere.model.PO;
|
||||||
import org.compiere.model.Query;
|
import org.compiere.model.Query;
|
||||||
|
import org.compiere.model.SystemIDs;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -414,7 +415,7 @@ public class Login
|
||||||
}
|
}
|
||||||
if (valid) {
|
if (valid) {
|
||||||
int AD_Role_ID = rs.getInt(2);
|
int AD_Role_ID = rs.getInt(2);
|
||||||
if (AD_Role_ID == 0)
|
if (AD_Role_ID == SystemIDs.ROLE_SYSTEM)
|
||||||
Env.setContext(m_ctx, "#SysAdmin", "Y");
|
Env.setContext(m_ctx, "#SysAdmin", "Y");
|
||||||
String Name = rs.getString(3);
|
String Name = rs.getString(3);
|
||||||
KeyNamePair p = new KeyNamePair(AD_Role_ID, Name);
|
KeyNamePair p = new KeyNamePair(AD_Role_ID, Name);
|
||||||
|
|
|
@ -42,6 +42,7 @@ import org.compiere.model.MPasswordHistory;
|
||||||
import org.compiere.model.MPasswordRule;
|
import org.compiere.model.MPasswordRule;
|
||||||
import org.compiere.model.MSysConfig;
|
import org.compiere.model.MSysConfig;
|
||||||
import org.compiere.model.MUser;
|
import org.compiere.model.MUser;
|
||||||
|
import org.compiere.model.SystemIDs;
|
||||||
import org.compiere.util.CLogger;
|
import org.compiere.util.CLogger;
|
||||||
import org.compiere.util.DisplayType;
|
import org.compiere.util.DisplayType;
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
|
@ -319,8 +320,8 @@ public class WResetPassword implements IFormController, EventListener<Event>, Va
|
||||||
MUser operator = MUser.get(Env.getCtx(), Env.getAD_User_ID(Env.getCtx()));
|
MUser operator = MUser.get(Env.getCtx(), Env.getAD_User_ID(Env.getCtx()));
|
||||||
if (log.isLoggable(Level.FINE)) log.fine("Operator=" + operator);
|
if (log.isLoggable(Level.FINE)) log.fine("Operator=" + operator);
|
||||||
|
|
||||||
if (p_AD_User_ID == 0 // change of System
|
if (p_AD_User_ID == SystemIDs.USER_SYSTEM // change of System
|
||||||
|| p_AD_User_ID == 100 // change of SuperUser
|
|| p_AD_User_ID == SystemIDs.USER_SUPERUSER // change of SuperUser
|
||||||
|| !operator.isAdministrator())
|
|| !operator.isAdministrator())
|
||||||
throw new IllegalArgumentException(Msg.getMsg(Env.getCtx(), "OldPasswordMandatory"));
|
throw new IllegalArgumentException(Msg.getMsg(Env.getCtx(), "OldPasswordMandatory"));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -43,6 +43,7 @@ import org.compiere.model.MColumn;
|
||||||
import org.compiere.model.MLookup;
|
import org.compiere.model.MLookup;
|
||||||
import org.compiere.model.MRole;
|
import org.compiere.model.MRole;
|
||||||
import org.compiere.model.MTable;
|
import org.compiere.model.MTable;
|
||||||
|
import org.compiere.model.SystemIDs;
|
||||||
import org.compiere.util.CLogger;
|
import org.compiere.util.CLogger;
|
||||||
import org.compiere.util.DisplayType;
|
import org.compiere.util.DisplayType;
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
|
@ -153,7 +154,7 @@ public class WRadioGroupEditor extends WEditor implements ContextMenuListener, L
|
||||||
lookup.setMandatory(true);
|
lookup.setMandatory(true);
|
||||||
lookup.setMandatory(isMandatory());
|
lookup.setMandatory(isMandatory());
|
||||||
|
|
||||||
if ((lookup.getDisplayType() == DisplayType.List && Env.getContextAsInt(Env.getCtx(), Env.AD_ROLE_ID) == 0)
|
if ((lookup.getDisplayType() == DisplayType.List && Env.getContextAsInt(Env.getCtx(), Env.AD_ROLE_ID) == SystemIDs.ROLE_SYSTEM)
|
||||||
|| lookup.getDisplayType() != DisplayType.List)
|
|| lookup.getDisplayType() != DisplayType.List)
|
||||||
{
|
{
|
||||||
zoom= true;
|
zoom= true;
|
||||||
|
|
|
@ -54,6 +54,7 @@ import org.compiere.model.MLookup;
|
||||||
import org.compiere.model.MRole;
|
import org.compiere.model.MRole;
|
||||||
import org.compiere.model.MSysConfig;
|
import org.compiere.model.MSysConfig;
|
||||||
import org.compiere.model.MTable;
|
import org.compiere.model.MTable;
|
||||||
|
import org.compiere.model.SystemIDs;
|
||||||
import org.compiere.util.CCache;
|
import org.compiere.util.CCache;
|
||||||
import org.compiere.util.CLogger;
|
import org.compiere.util.CLogger;
|
||||||
import org.compiere.util.CacheMgt;
|
import org.compiere.util.CacheMgt;
|
||||||
|
@ -212,7 +213,7 @@ ContextMenuListener, IZoomableEditor
|
||||||
lookup.addListDataListener(this);
|
lookup.addListDataListener(this);
|
||||||
lookup.setMandatory(isMandatory());
|
lookup.setMandatory(isMandatory());
|
||||||
|
|
||||||
if ((lookup.getDisplayType() == DisplayType.List && Env.getContextAsInt(Env.getCtx(), Env.AD_ROLE_ID) == 0)
|
if ((lookup.getDisplayType() == DisplayType.List && Env.getContextAsInt(Env.getCtx(), Env.AD_ROLE_ID) == SystemIDs.ROLE_SYSTEM)
|
||||||
|| lookup.getDisplayType() != DisplayType.List)
|
|| lookup.getDisplayType() != DisplayType.List)
|
||||||
{
|
{
|
||||||
zoom= true;
|
zoom= true;
|
||||||
|
|
Loading…
Reference in New Issue