IDEMPIERE-5813 Change Role must close session like Logout does (#1959)

* IDEMPIERE-5813 Change Role must close session like Logout does

* IDEMPIERE-5813 Change Role must close session like Logout does
This commit is contained in:
hengsin 2023-08-02 01:14:26 +08:00 committed by GitHub
parent 159fbbd04c
commit 03c6187fde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 5 deletions

View File

@ -127,6 +127,8 @@ public final class Env
public static final String M_PRICELIST_ID = "#M_PriceList_ID";
public static final String M_PRODUCT_CATEGORY_ID = "#M_Product_Category_ID";
public static final String M_WAREHOUSE_ID = "#M_Warehouse_ID";
/** Context for multi factor authentication */
public static final String MFA_Registration_ID = "#MFA_Registration_ID";
/** Context for POS ID */
public static final String POS_ID = "#POS_ID";
public static final String R_STATUSCATEGORY_ID = "#R_StatusCategory_ID";

View File

@ -708,6 +708,7 @@ public class AdempiereWebUI extends Window implements EventListener<Event>, IWeb
Env.setContext(properties, Env.CLIENT_INFO_ORIENTATION, clientInfo.orientation);
Env.setContext(properties, Env.CLIENT_INFO_MOBILE, clientInfo.tablet);
Env.setContext(properties, Env.CLIENT_INFO_TIME_ZONE, clientInfo.timeZone.getID());
Env.setContext(properties, Env.MFA_Registration_ID, Env.getContext(Env.getCtx(), Env.MFA_Registration_ID));
Desktop desktop = Executions.getCurrent().getDesktop();
Locale locale = (Locale) desktop.getSession().getAttribute(Attributes.PREFERRED_LOCALE);
@ -720,7 +721,7 @@ public class AdempiereWebUI extends Window implements EventListener<Event>, IWeb
IDesktop appDesktop = getAppDeskop();
HttpSession session = httpRequest.getSession();
if (appDesktop != null)
appDesktop.logout(T -> {if (T) asyncChangeRole(session, locale, properties);});
appDesktop.logout(T -> {if (T) asyncChangeRole(session, locale, properties, desktop);});
}
/**
@ -728,8 +729,9 @@ public class AdempiereWebUI extends Window implements EventListener<Event>, IWeb
* @param httpSession
* @param locale
* @param properties
* @param desktop
*/
private void asyncChangeRole(HttpSession httpSession, Locale locale, Properties properties) {
private void asyncChangeRole(HttpSession httpSession, Locale locale, Properties properties, Desktop desktop) {
//stop key listener
if (keyListener != null) {
keyListener.detach();
@ -761,6 +763,8 @@ public class AdempiereWebUI extends Window implements EventListener<Event>, IWeb
//show change role window and set new context for env and session
onChangeRole(locale, properties);
Executions.schedule(desktop, e -> DesktopWatchDog.removeOtherDesktopsInSession(desktop), new Event("onRemoveOtherDesktops"));
}
@Override

View File

@ -376,7 +376,7 @@ public class ValidateMFAPanel extends Window implements EventListener<Event> {
PO.clearCrossTenantSafe();
}
}
Env.setContext(m_ctx, "#MFA_Registration_ID", registrationId);
Env.setContext(m_ctx, Env.MFA_Registration_ID, registrationId);
if (m_isClientDefined) {
wndLogin.showRolePanel(m_userName, m_showRolePanel, m_clientsKNPairs, m_isClientDefined, true);

View File

@ -43,7 +43,7 @@ public class SessionManager
String adRoleId = Env.getContext(ctx, Env.AD_ROLE_ID);
String adClientId = Env.getContext(ctx, Env.AD_CLIENT_ID);
String adOrgId = Env.getContext(ctx, Env.AD_ORG_ID);
String mfaId = Env.getContext(ctx, "#MFA_Registration_ID");
String mfaId = Env.getContext(ctx, Env.MFA_Registration_ID);
return ( !"".equals(mfaId)
&& !"".equals(adOrgId)

View File

@ -133,4 +133,29 @@ public class DesktopWatchDog {
}
}
}
/**
* Remove other desktops that share the same session with the pass in desktop parameter
* @param desktop
*/
public static void removeOtherDesktopsInSession(Desktop desktop) {
Iterator<DesktopEntry> iterator = INSTANCE.desktops.iterator();
while (iterator.hasNext()) {
DesktopEntry entry = iterator.next();
if (entry.desktop == desktop)
continue;
if (entry.desktop.getSession() != desktop.getSession())
continue;
iterator.remove();
try {
final WebApp wapp = desktop.getWebApp();
final Session session = desktop.getSession();
final DesktopCache desktopCache = ((WebAppCtrl) wapp).getDesktopCache(session);
desktopCache.removeDesktop(entry.desktop);
} catch (Throwable t) {
t.printStackTrace();
}
}
}
}