IDEMPIERE-389 - Fixing AD_Session to log actual IP in case of server is behind Load balancer.
This commit is contained in:
parent
c69143900b
commit
b636776abb
|
@ -180,6 +180,15 @@ public interface I_AD_Session
|
||||||
*/
|
*/
|
||||||
public String getRemote_Host();
|
public String getRemote_Host();
|
||||||
|
|
||||||
|
/** Column name ServerName */
|
||||||
|
public static final String COLUMNNAME_ServerName = "ServerName";
|
||||||
|
|
||||||
|
/** Set Server name */
|
||||||
|
public void setServerName (String ServerName);
|
||||||
|
|
||||||
|
/** Get Server name */
|
||||||
|
public String getServerName();
|
||||||
|
|
||||||
/** Column name Updated */
|
/** Column name Updated */
|
||||||
public static final String COLUMNNAME_Updated = "Updated";
|
public static final String COLUMNNAME_Updated = "Updated";
|
||||||
|
|
||||||
|
|
|
@ -148,6 +148,7 @@ public class MSession extends X_AD_Session
|
||||||
public MSession (Properties ctx, String Remote_Addr, String Remote_Host, String WebSession, String trxName)
|
public MSession (Properties ctx, String Remote_Addr, String Remote_Host, String WebSession, String trxName)
|
||||||
{
|
{
|
||||||
this (ctx, 0, trxName);
|
this (ctx, 0, trxName);
|
||||||
|
setServerName(Ini.getProperties().getProperty("ServerName"));
|
||||||
if (Remote_Addr != null)
|
if (Remote_Addr != null)
|
||||||
setRemote_Addr(Remote_Addr);
|
setRemote_Addr(Remote_Addr);
|
||||||
if (Remote_Host != null)
|
if (Remote_Host != null)
|
||||||
|
@ -172,6 +173,7 @@ public class MSession extends X_AD_Session
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
InetAddress lh = InetAddress.getLocalHost();
|
InetAddress lh = InetAddress.getLocalHost();
|
||||||
|
setServerName(Ini.getProperties().getProperty("ServerName"));
|
||||||
setRemote_Addr(lh.getHostAddress());
|
setRemote_Addr(lh.getHostAddress());
|
||||||
setRemote_Host(lh.getHostName());
|
setRemote_Host(lh.getHostName());
|
||||||
setDescription(Adempiere.MAIN_VERSION + "_"
|
setDescription(Adempiere.MAIN_VERSION + "_"
|
||||||
|
|
|
@ -220,6 +220,20 @@ public class X_AD_Session extends PO implements I_AD_Session, I_Persistent
|
||||||
return (String)get_Value(COLUMNNAME_Remote_Host);
|
return (String)get_Value(COLUMNNAME_Remote_Host);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Set Server name.
|
||||||
|
@param ServerName Server name */
|
||||||
|
public void setServerName (String ServerName)
|
||||||
|
{
|
||||||
|
set_Value (COLUMNNAME_ServerName, ServerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get Server name.
|
||||||
|
@return Server name */
|
||||||
|
public String getServerName ()
|
||||||
|
{
|
||||||
|
return (String)get_Value(COLUMNNAME_ServerName);
|
||||||
|
}
|
||||||
|
|
||||||
/** Set Web Session.
|
/** Set Web Session.
|
||||||
@param WebSession
|
@param WebSession
|
||||||
Web Session ID
|
Web Session ID
|
||||||
|
|
|
@ -141,6 +141,9 @@ public final class Ini implements Serializable
|
||||||
/** Role */
|
/** Role */
|
||||||
public static final String P_ROLE = "Role";
|
public static final String P_ROLE = "Role";
|
||||||
private static final String DEFAULT_ROLE = "";
|
private static final String DEFAULT_ROLE = "";
|
||||||
|
/**Server Name */
|
||||||
|
public static final String P_SERVERNAME = "ServerName";
|
||||||
|
private static final String DEFAULT_SERVERNAME = "";
|
||||||
/** Client Name */
|
/** Client Name */
|
||||||
public static final String P_CLIENT = "Client";
|
public static final String P_CLIENT = "Client";
|
||||||
private static final String DEFAULT_CLIENT = "";
|
private static final String DEFAULT_CLIENT = "";
|
||||||
|
@ -196,7 +199,7 @@ public final class Ini implements Serializable
|
||||||
P_ADEMPIERESYS, P_LOGMIGRATIONSCRIPT, P_SHOW_ACCT, P_SHOW_TRL,
|
P_ADEMPIERESYS, P_LOGMIGRATIONSCRIPT, P_SHOW_ACCT, P_SHOW_TRL,
|
||||||
P_SHOW_ADVANCED, P_CACHE_WINDOW,
|
P_SHOW_ADVANCED, P_CACHE_WINDOW,
|
||||||
P_CONTEXT, P_TEMP_DIR,
|
P_CONTEXT, P_TEMP_DIR,
|
||||||
P_ROLE, P_CLIENT, P_ORG, P_PRINTER, P_WAREHOUSE, P_TODAY,
|
P_ROLE, P_SERVERNAME, P_CLIENT, P_ORG, P_PRINTER, P_WAREHOUSE, P_TODAY,
|
||||||
P_PRINTPREVIEW,
|
P_PRINTPREVIEW,
|
||||||
P_VALIDATE_CONNECTION_ON_STARTUP,
|
P_VALIDATE_CONNECTION_ON_STARTUP,
|
||||||
P_SINGLE_INSTANCE_PER_WINDOW,
|
P_SINGLE_INSTANCE_PER_WINDOW,
|
||||||
|
@ -214,7 +217,7 @@ public final class Ini implements Serializable
|
||||||
DEFAULT_ADEMPIERESYS?"Y":"N", DEFAULT_LOGMIGRATIONSCRIPT?"Y":"N", DEFAULT_SHOW_ACCT?"Y":"N", DEFAULT_SHOW_TRL?"Y":"N",
|
DEFAULT_ADEMPIERESYS?"Y":"N", DEFAULT_LOGMIGRATIONSCRIPT?"Y":"N", DEFAULT_SHOW_ACCT?"Y":"N", DEFAULT_SHOW_TRL?"Y":"N",
|
||||||
DEFAULT_SHOW_ADVANCED?"Y":"N", DEFAULT_CACHE_WINDOW?"Y":"N",
|
DEFAULT_SHOW_ADVANCED?"Y":"N", DEFAULT_CACHE_WINDOW?"Y":"N",
|
||||||
DEFAULT_CONTEXT, DEFAULT_TEMP_DIR,
|
DEFAULT_CONTEXT, DEFAULT_TEMP_DIR,
|
||||||
DEFAULT_ROLE, DEFAULT_CLIENT, DEFAULT_ORG, DEFAULT_PRINTER, DEFAULT_WAREHOUSE, DEFAULT_TODAY.toString(),
|
DEFAULT_ROLE, DEFAULT_SERVERNAME, DEFAULT_CLIENT, DEFAULT_ORG, DEFAULT_PRINTER, DEFAULT_WAREHOUSE, DEFAULT_TODAY.toString(),
|
||||||
DEFAULT_PRINTPREVIEW?"Y":"N",
|
DEFAULT_PRINTPREVIEW?"Y":"N",
|
||||||
DEFAULT_VALIDATE_CONNECTION_ON_STARTUP?"Y":"N",
|
DEFAULT_VALIDATE_CONNECTION_ON_STARTUP?"Y":"N",
|
||||||
DEFAULT_SINGLE_INSTANCE_PER_WINDOW?"Y":"N",
|
DEFAULT_SINGLE_INSTANCE_PER_WINDOW?"Y":"N",
|
||||||
|
|
|
@ -154,6 +154,9 @@ public class WebLogin
|
||||||
*/
|
*/
|
||||||
public boolean action() throws IOException, ServletException
|
public boolean action() throws IOException, ServletException
|
||||||
{
|
{
|
||||||
|
//remote Address
|
||||||
|
String remoteIP = m_request.getHeader("X-Forwarded-For");
|
||||||
|
remoteIP = remoteIP!=null ? remoteIP : m_request.getRemoteAddr();
|
||||||
// Mode
|
// Mode
|
||||||
if (getMode() == null)
|
if (getMode() == null)
|
||||||
{
|
{
|
||||||
|
@ -228,7 +231,7 @@ public class WebLogin
|
||||||
if (m_forward==null || m_forward.equals(getLogin_RelURL ()))
|
if (m_forward==null || m_forward.equals(getLogin_RelURL ()))
|
||||||
m_forward = "/index.jsp";
|
m_forward = "/index.jsp";
|
||||||
// Create Session with User ID
|
// Create Session with User ID
|
||||||
MSession cSession = MSession.get (m_ctx, m_request.getRemoteAddr(),
|
MSession cSession = MSession.get (m_ctx, remoteIP,
|
||||||
m_request.getRemoteHost(), m_session.getId());
|
m_request.getRemoteHost(), m_session.getId());
|
||||||
if (cSession != null)
|
if (cSession != null)
|
||||||
cSession.setWebStoreSession(true);
|
cSession.setWebStoreSession(true);
|
||||||
|
@ -275,7 +278,7 @@ public class WebLogin
|
||||||
// Create / set session
|
// Create / set session
|
||||||
if (m_wu.isLoggedIn())
|
if (m_wu.isLoggedIn())
|
||||||
{
|
{
|
||||||
MSession cSession = MSession.get (m_ctx, m_request.getRemoteAddr(),
|
MSession cSession = MSession.get (m_ctx, remoteIP,
|
||||||
m_request.getRemoteHost(), m_session.getId());
|
m_request.getRemoteHost(), m_session.getId());
|
||||||
if (cSession != null)
|
if (cSession != null)
|
||||||
cSession.setWebStoreSession(true);
|
cSession.setWebStoreSession(true);
|
||||||
|
@ -312,7 +315,7 @@ public class WebLogin
|
||||||
{
|
{
|
||||||
m_session.setAttribute (WebInfo.NAME, new WebInfo (m_ctx, m_wu));
|
m_session.setAttribute (WebInfo.NAME, new WebInfo (m_ctx, m_wu));
|
||||||
// Create / set session
|
// Create / set session
|
||||||
MSession cSession = MSession.get (m_ctx, m_request.getRemoteAddr(),
|
MSession cSession = MSession.get (m_ctx, remoteIP,
|
||||||
m_request.getRemoteHost(), m_session.getId());
|
m_request.getRemoteHost(), m_session.getId());
|
||||||
if (cSession != null)
|
if (cSession != null)
|
||||||
cSession.setWebStoreSession(true);
|
cSession.setWebStoreSession(true);
|
||||||
|
@ -380,7 +383,7 @@ public class WebLogin
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
MSession cSession = MSession.get (m_ctx, m_request.getRemoteAddr(), m_request.getRemoteHost(), m_session.getId());
|
MSession cSession = MSession.get (m_ctx, remoteIP, m_request.getRemoteHost(), m_session.getId());
|
||||||
if (cSession != null)
|
if (cSession != null)
|
||||||
cSession.setWebStoreSession(true);
|
cSession.setWebStoreSession(true);
|
||||||
|
|
||||||
|
|
|
@ -202,8 +202,9 @@ public class AdempiereWebUI extends Window implements EventListener<Event>, IWeb
|
||||||
// Create adempiere Session - user id in ctx
|
// Create adempiere Session - user id in ctx
|
||||||
Session currSess = Executions.getCurrent().getDesktop().getSession();
|
Session currSess = Executions.getCurrent().getDesktop().getSession();
|
||||||
HttpSession httpSess = (HttpSession) currSess.getNativeSession();
|
HttpSession httpSess = (HttpSession) currSess.getNativeSession();
|
||||||
|
String x_Forward_IP = Executions.getCurrent().getHeader("X-Forwarded-For");
|
||||||
|
|
||||||
MSession mSession = MSession.get (ctx, currSess.getRemoteAddr(),
|
MSession mSession = MSession.get (ctx, x_Forward_IP!=null ? x_Forward_IP : currSess.getRemoteAddr(),
|
||||||
currSess.getRemoteHost(), httpSess.getId() );
|
currSess.getRemoteHost(), httpSess.getId() );
|
||||||
|
|
||||||
currSess.setAttribute("Check_AD_User_ID", Env.getAD_User_ID(ctx));
|
currSess.setAttribute("Check_AD_User_ID", Env.getAD_User_ID(ctx));
|
||||||
|
|
Loading…
Reference in New Issue