Workplace Widget 5.10.23
This commit is contained in:
82
hmi-docs/cheerpj/CHEERPJ_JAVA11_NATIVE_LOADER_SUPPORT.md
Normal file
82
hmi-docs/cheerpj/CHEERPJ_JAVA11_NATIVE_LOADER_SUPPORT.md
Normal file
@@ -0,0 +1,82 @@
|
||||
# CheerpJ 5.0 / Java 11: missing JVM_LoadLibrary import for System.loadLibrary()
|
||||
|
||||
**Status:** Reproducible with a minimal application independent of customer or vendor code.
|
||||
**CheerpJ:** Core 5.0, OpenJDK 11.0.33-internal (according to Java console output).
|
||||
**Server JDK:** Java 11 on Payara/GlassFish (independent of browser JVM).
|
||||
**Java classfile:** 55 (`javac --release 11`).
|
||||
**Browser:** Edge/Chromium (as reported by customer). Additional Firefox verification not available.
|
||||
|
||||
## Minimal reproduction steps
|
||||
|
||||
The included `NativeLoaderSmoke.java` and `wwprobe.js` are vendor-independent.
|
||||
Compile the Java class for Java 11, serve the JAR with HTTP Range support, serve
|
||||
`wwprobe.js` as an ES module. Configure:
|
||||
|
||||
```js
|
||||
await cheerpjInit({
|
||||
version: 11,
|
||||
javaProperties: ["java.library.path=/app/backend/hmi/cheerpj/natives"],
|
||||
});
|
||||
await cheerpjRunMain(
|
||||
"com.widgetworkbench.cheerpj.NativeLoaderSmoke",
|
||||
"/app/backend/hmi/cheerpj/jaas-native-loader-smoke.jar",
|
||||
"wwprobe"
|
||||
);
|
||||
```
|
||||
|
||||
Native module (`wwprobe.js`):
|
||||
|
||||
```js
|
||||
export default {
|
||||
async Java_com_widgetworkbench_cheerpj_NativeLoaderSmoke_ping() {
|
||||
return 42;
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
The Java program executes `System.loadLibrary("wwprobe")` and then calls
|
||||
its `private static native int ping()` method.
|
||||
|
||||
**Actual output:**
|
||||
|
||||
```
|
||||
[NATIVE-LOADER] java.version=11.0.33-internal
|
||||
[NATIVE-LOADER] java.library.path=/app/backend/hmi/cheerpj/natives
|
||||
[NATIVE-LOADER] about to System.loadLibrary("wwprobe")
|
||||
JVM_FindLibraryEntry: JNI_OnLoad_wwprobe
|
||||
JVM_FindLibraryEntry: JNI_OnLoad_wwprobe
|
||||
Missing import: JVM_LoadLibrary
|
||||
java.lang.UnsatisfiedLinkError: no wwprobe in java.library.path
|
||||
```
|
||||
|
||||
**Expected:** `System.loadLibrary("wwprobe")` loads the JS module and the
|
||||
subsequent native call returns 42.
|
||||
|
||||
**Control test:** Using `cheerpjInit({ natives: wwprobeNativeHandlers })`
|
||||
with the same native function and **without** `System.loadLibrary()` works:
|
||||
|
||||
```
|
||||
[NATIVE-LOADER] NATIVE_CALL_RESULT=42
|
||||
[NATIVE-LOADER] PASS DIRECT_NATIVES
|
||||
Java-Exit-Code: 0
|
||||
```
|
||||
|
||||
The same `JVM_LoadLibrary` error occurs for `System.loadLibrary("jaas")`,
|
||||
which the Java 11 JDK class `com.sun.security.auth.module.UnixSystem`
|
||||
performs in its constructor.
|
||||
|
||||
## Questions for Leaning Technologies
|
||||
|
||||
1. Is `System.loadLibrary` of JavaScript ES modules supported in **CheerpJ 5.0 with OpenJDK 11**? If so, are any additional `cheerpjInit` flags/imports required?
|
||||
2. Is `Missing import: JVM_LoadLibrary` a known issue in the runtime's OpenJDK 11 native library loader? Is there a patch, fixed build, or documented workaround?
|
||||
3. Does the Java 11 `jdk.security.auth` module's `UnixSystem` work under CheerpJ without using a synthetic OS identity? What is the recommended virtual OS identity approach?
|
||||
4. Are there specific HTTP-Range or caching requirements for the CDN resource `/5.0/11/lib/modules`? An Edge session produced `ERR_CACHE_OPERATION_NOT_SUPPORTED`, but it is not proven to be causal.
|
||||
5. Can you provide a supported browser-side extension mechanism to satisfy the UnixSystem constructor without editing vendor application JARs?
|
||||
|
||||
## Scope and exclusions
|
||||
|
||||
The original MES application JARs and its authentication process are untouched.
|
||||
The test needs no customer database, internal server, iTAC classes, user credentials,
|
||||
or workstation-specific identity. The generated Java `bridge` mode is a **separate
|
||||
non-production diagnostic** of a synthetic identity helper; it is not a fix for
|
||||
`System.loadLibrary`.
|
||||
73
hmi-docs/cheerpj/JaasIdentityBridge.java
Normal file
73
hmi-docs/cheerpj/JaasIdentityBridge.java
Normal file
@@ -0,0 +1,73 @@
|
||||
package com.widgetworkbench.cheerpj;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* CheerpJ-only shim for Java 11 UnixSystem.getUnixInfo().
|
||||
*
|
||||
* The browser does not have an OS account. This class intentionally supplies
|
||||
* an unprivileged synthetic Unix identity ONLY for the JDK OS-name lookup.
|
||||
* It does not authenticate a MES user and must never be used for access control.
|
||||
* It can be called from the CheerpJ jaas.js native implementation without
|
||||
* modifying or repackaging vendor JARs.
|
||||
*/
|
||||
public final class JaasIdentityBridge {
|
||||
public static final String VIRTUAL_USER = "cheerpj-client";
|
||||
private static final long VIRTUAL_UID = 65534L;
|
||||
|
||||
private JaasIdentityBridge() { }
|
||||
|
||||
/** Set the four instance fields the native OpenJDK Unix.c normally sets. */
|
||||
public static String populate(Object unixSystem) {
|
||||
if (unixSystem == null
|
||||
|| !"com.sun.security.auth.module.UnixSystem".equals(unixSystem.getClass().getName())) {
|
||||
throw new IllegalArgumentException("Expected an OpenJDK UnixSystem instance");
|
||||
}
|
||||
try {
|
||||
setField(unixSystem, "username", VIRTUAL_USER);
|
||||
setField(unixSystem, "uid", VIRTUAL_UID);
|
||||
setField(unixSystem, "gid", VIRTUAL_UID);
|
||||
setField(unixSystem, "groups", new long[0]);
|
||||
Method nameGetter = unixSystem.getClass().getMethod("getUsername");
|
||||
Object result = nameGetter.invoke(unixSystem);
|
||||
if (!VIRTUAL_USER.equals(result)) {
|
||||
throw new IllegalStateException("UnixSystem username was not populated");
|
||||
}
|
||||
return VIRTUAL_USER;
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
throw new IllegalStateException("Cannot populate virtual UnixSystem identity", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setField(Object target, String name, Object value)
|
||||
throws ReflectiveOperationException {
|
||||
Field field = target.getClass().getDeclaredField(name);
|
||||
// On a Java 11+ module with an open package, normal reflection is enough.
|
||||
// On standard JDKs jdk.security.auth exports but does not open the package;
|
||||
// use the JDK-provided Unsafe implementation to set exactly these fields.
|
||||
try {
|
||||
if (field.trySetAccessible()) {
|
||||
field.set(target, value);
|
||||
return;
|
||||
}
|
||||
} catch (SecurityException ex) {
|
||||
// Try the explicitly scoped fallback below.
|
||||
}
|
||||
Class<?> unsafeType = Class.forName("sun.misc.Unsafe");
|
||||
Field theUnsafe = unsafeType.getDeclaredField("theUnsafe");
|
||||
if (!theUnsafe.trySetAccessible()) {
|
||||
throw new IllegalStateException("Unsafe unavailable in this Java runtime");
|
||||
}
|
||||
Object unsafe = theUnsafe.get(null);
|
||||
long offset = ((Number) unsafeType.getMethod("objectFieldOffset", Field.class)
|
||||
.invoke(unsafe, field)).longValue();
|
||||
if (field.getType() == long.class) {
|
||||
unsafeType.getMethod("putLong", Object.class, long.class, long.class)
|
||||
.invoke(unsafe, target, offset, ((Number) value).longValue());
|
||||
} else {
|
||||
unsafeType.getMethod("putObject", Object.class, long.class, Object.class)
|
||||
.invoke(unsafe, target, offset, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
135
hmi-docs/cheerpj/NativeLoaderSmoke.java
Normal file
135
hmi-docs/cheerpj/NativeLoaderSmoke.java
Normal file
@@ -0,0 +1,135 @@
|
||||
package com.widgetworkbench.cheerpj;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Java 11/55 classfile, browser-only troubleshooting program. No proprietary
|
||||
* libraries, MES calls, credentials, or changes to JVM/UnixSystem classes.
|
||||
* Every invocation tests exactly ONE mode in a fresh browser page.
|
||||
*
|
||||
* direct - native method via cheerpjInit({natives}); no loadLibrary call
|
||||
* wwprobe - System.loadLibrary("wwprobe")
|
||||
* jaas - System.loadLibrary("jaas")
|
||||
* unix - construct the real JDK UnixSystem, hitting its native load
|
||||
* bridge - validate the Java helper independently of native loading;
|
||||
* an instance allocated WITHOUT UnixSystem's constructor is
|
||||
* used ONLY for this standalone diagnostic. Not a login path.
|
||||
* environment - benign JDK/module settings (no usernames printed)
|
||||
* sysprop - check whether user.name is present (never print its value)
|
||||
*/
|
||||
public final class NativeLoaderSmoke {
|
||||
private NativeLoaderSmoke() {}
|
||||
private static native int ping();
|
||||
|
||||
public static void main(String[] args) {
|
||||
final String mode = args.length > 0 ? args[0] : "environment";
|
||||
System.out.println("[NATIVE-LOADER] JAVA_VERSION=" + System.getProperty("java.version"));
|
||||
System.out.println("[NATIVE-LOADER] JAVA_LIBRARY_PATH=" + System.getProperty("java.library.path"));
|
||||
System.out.println("[NATIVE-LOADER] MODE=" + mode);
|
||||
try {
|
||||
switch (mode) {
|
||||
case "direct":
|
||||
System.out.println("[NATIVE-LOADER] DIRECT_NATIVES: ping WITHOUT System.loadLibrary");
|
||||
verifyPing();
|
||||
pass("DIRECT_NATIVES");
|
||||
break;
|
||||
case "wwprobe":
|
||||
case "jaas":
|
||||
System.out.println("[NATIVE-LOADER] LOAD_ATTEMPT=" + mode);
|
||||
System.loadLibrary(mode);
|
||||
System.out.println("[NATIVE-LOADER] LOAD_SUCCESS=" + mode);
|
||||
if ("wwprobe".equals(mode)) verifyPing();
|
||||
pass("MODULE_LOADER_" + mode);
|
||||
break;
|
||||
case "unix":
|
||||
testUnixConstructor();
|
||||
break;
|
||||
case "bridge":
|
||||
testBridgeWithoutUnixConstructor();
|
||||
break;
|
||||
case "sysprop":
|
||||
final String user = System.getProperty("user.name");
|
||||
System.out.println("[NATIVE-LOADER] USER_NAME_PRESENT=" + (user != null && !user.isEmpty()));
|
||||
System.out.println("[NATIVE-LOADER] OS_NAME_PRESENT=" + (System.getProperty("os.name") != null));
|
||||
pass("SYSTEM_PROPERTIES");
|
||||
break;
|
||||
case "environment":
|
||||
System.out.println("[NATIVE-LOADER] JAVA_VENDOR=" + System.getProperty("java.vendor"));
|
||||
System.out.println("[NATIVE-LOADER] JAVA_HOME=" + System.getProperty("java.home"));
|
||||
System.out.println("[NATIVE-LOADER] JAVA_CLASS_VERSION=" + System.getProperty("java.class.version"));
|
||||
Class<?> cls = Class.forName("com.sun.security.auth.module.UnixSystem", false,
|
||||
ClassLoader.getSystemClassLoader());
|
||||
System.out.println("[NATIVE-LOADER] UNIX_CLASS_PRESENT=" + (cls != null));
|
||||
System.out.println("[NATIVE-LOADER] UNIX_MODULE=" + cls.getModule().getName());
|
||||
System.out.println("[NATIVE-LOADER] UNIX_MODULE_EXPORTED=" + cls.getModule()
|
||||
.isExported("com.sun.security.auth.module"));
|
||||
pass("ENVIRONMENT");
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unbekannter Testmodus");
|
||||
}
|
||||
} catch (Throwable error) {
|
||||
System.err.println("[NATIVE-LOADER] FAIL " + mode + ": " + error.getClass().getName());
|
||||
// Reflective wrappers are printed, including their full cause chain.
|
||||
error.printStackTrace(System.err);
|
||||
if (error instanceof InvocationTargetException) {
|
||||
Throwable root = ((InvocationTargetException) error).getTargetException();
|
||||
if (root != null) {
|
||||
System.err.println("[NATIVE-LOADER] ROOT_CAUSE=" + root.getClass().getName());
|
||||
root.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
System.exit(31);
|
||||
}
|
||||
}
|
||||
|
||||
private static void pass(String label) {
|
||||
System.out.println("[NATIVE-LOADER] PASS " + label);
|
||||
}
|
||||
|
||||
private static void verifyPing() {
|
||||
int value = ping();
|
||||
System.out.println("[NATIVE-LOADER] NATIVE_CALL_RESULT=" + value);
|
||||
if (value != 42) throw new IllegalStateException("Expected 42, got " + value);
|
||||
}
|
||||
|
||||
private static void testUnixConstructor() throws Exception {
|
||||
Class<?> type = Class.forName("com.sun.security.auth.module.UnixSystem");
|
||||
System.out.println("[NATIVE-LOADER] UNIX_CONSTRUCTOR_ATTEMPT");
|
||||
Constructor<?> constructor = type.getConstructor();
|
||||
Object instance = constructor.newInstance();
|
||||
Method getter = type.getMethod("getUsername");
|
||||
Object name = getter.invoke(instance);
|
||||
// Do not print the operating-system identity to the diagnostic log.
|
||||
System.out.println("[NATIVE-LOADER] UNIX_USERNAME_PRESENT=" + (name != null));
|
||||
pass("UNIX_CONSTRUCTOR");
|
||||
}
|
||||
|
||||
private static void testBridgeWithoutUnixConstructor() throws Exception {
|
||||
System.out.println("[NATIVE-LOADER] BRIDGE: Unsafe.allocateInstance only for test");
|
||||
Class<?> unsafeType = Class.forName("sun.misc.Unsafe");
|
||||
Field singleton = unsafeType.getDeclaredField("theUnsafe");
|
||||
if (!singleton.trySetAccessible()) throw new IllegalStateException("Unsafe unavailable");
|
||||
Object unsafe = singleton.get(null);
|
||||
Class<?> unixType = Class.forName("com.sun.security.auth.module.UnixSystem", false,
|
||||
ClassLoader.getSystemClassLoader());
|
||||
// This test deliberately never calls UnixSystem.<init> or System.loadLibrary.
|
||||
Object object = unsafeType.getMethod("allocateInstance", Class.class)
|
||||
.invoke(unsafe, unixType);
|
||||
String value = JaasIdentityBridge.populate(object);
|
||||
if (!JaasIdentityBridge.VIRTUAL_USER.equals(value)) {
|
||||
throw new IllegalStateException("Synthetic identity did not match");
|
||||
}
|
||||
long uid = ((Number) unixType.getMethod("getUid").invoke(object)).longValue();
|
||||
long gid = ((Number) unixType.getMethod("getGid").invoke(object)).longValue();
|
||||
long[] groups = (long[]) unixType.getMethod("getGroups").invoke(object);
|
||||
if (uid != 65534L || gid != 65534L || groups.length != 0) {
|
||||
throw new IllegalStateException("Synthetic UnixSystem fields incomplete");
|
||||
}
|
||||
System.out.println("[NATIVE-LOADER] BRIDGE_IDENTITY_FIELDS_OK=true");
|
||||
pass("BRIDGE_WITHOUT_CONSTRUCTOR");
|
||||
}
|
||||
}
|
||||
87
hmi-docs/cheerpj/WindowGeometrySmoke.java
Normal file
87
hmi-docs/cheerpj/WindowGeometrySmoke.java
Normal file
@@ -0,0 +1,87 @@
|
||||
package com.widgetworkbench.cheerpj;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
/** Isolated Java 11 regression test. Does not start the vendor Workplace. */
|
||||
public final class WindowGeometrySmoke {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Rectangle viewport = new Rectangle(0, 0, 960, 640);
|
||||
verify(!WorkplaceResizeBridge.isOutside(new Rectangle(100, 100, 450, 330), viewport), "fully visible");
|
||||
verify(WorkplaceResizeBridge.isOutside(new Rectangle(2100, 900, 450, 330), viewport), "second monitor offscreen");
|
||||
verify(WorkplaceResizeBridge.isOutside(new Rectangle(-900, -800, 450, 330), viewport), "negative coordinates");
|
||||
verify(!WorkplaceResizeBridge.isOutside(new Rectangle(900, 580, 200, 100), viewport), "partially visible");
|
||||
verify(WorkplaceResizeBridge.isOutside(new Rectangle(945, 625, 200, 100), viewport), "tiny corner visible");
|
||||
verify("WINDOWS INVALID_VIEWPORT".equals(WorkplaceResizeBridge.diagnoseWindows(0, 0)), "invalid input");
|
||||
String diagnostic = WorkplaceResizeBridge.diagnoseWindows(960, 640);
|
||||
verify(diagnostic.contains("viewport=0,0 960x640") && diagnostic.contains("windows="), "AWT snapshot");
|
||||
if (GraphicsEnvironment.isHeadless()) {
|
||||
verify(WorkplaceResizeBridge.rescueOffscreenDialogs(960, 640).contains("RESCUE moved=0"), "no dialogs in headless test");
|
||||
} else {
|
||||
final JDialog[] holder = new JDialog[1];
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
JDialog dialog = new JDialog();
|
||||
dialog.setSize(240, 160);
|
||||
dialog.setVisible(true);
|
||||
holder[0] = dialog;
|
||||
});
|
||||
try {
|
||||
// Wait for any initial native peer/window-manager placement event,
|
||||
// then simulate restoring a saved window position.
|
||||
Thread.sleep(250);
|
||||
SwingUtilities.invokeAndWait(() -> holder[0].setLocation(100, 700));
|
||||
String before = WorkplaceResizeBridge.diagnoseWindows(960, 640);
|
||||
verify(before.contains("offscreenDialogs=1"), "offscreen dialog reported");
|
||||
String fixed = WorkplaceResizeBridge.rescueOffscreenDialogs(960, 640);
|
||||
verify(fixed.contains("RESCUE moved=1"), "dialog rescued");
|
||||
String after = WorkplaceResizeBridge.diagnoseWindows(960, 640);
|
||||
verify(after.contains("offscreenDialogs=0"), "dialog now onscreen");
|
||||
verify(WorkplaceResizeBridge.rescueOffscreenDialogs(960, 640).contains("RESCUE moved=0"), "no recurring motion");
|
||||
} finally {
|
||||
SwingUtilities.invokeAndWait(() -> holder[0].dispose());
|
||||
}
|
||||
// End-to-end Java daemon test: the offscreen dialog must be rescued
|
||||
// autonomously without any JavaScript polling or direct rescue call.
|
||||
final JDialog[] automatic = new JDialog[1];
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
JDialog dialog = new JDialog();
|
||||
dialog.setSize(240, 160);
|
||||
dialog.setVisible(true);
|
||||
automatic[0] = dialog;
|
||||
});
|
||||
try {
|
||||
// Some window managers asynchronously reset the initial position
|
||||
// after setVisible(true). Allow native realization to settle first.
|
||||
Thread.sleep(300);
|
||||
SwingUtilities.invokeAndWait(() -> automatic[0].setLocation(1300, 950));
|
||||
verify(WorkplaceResizeBridge.isOutside(automatic[0].getBounds(), viewport), "automatic test starts offscreen");
|
||||
verify(WorkplaceResizeBridge.startRuntimeMonitor(960, 640, "rescue") == 1, "autonomous rescue monitor starts");
|
||||
boolean rescued = false;
|
||||
for (int i = 0; i < 25; i++) {
|
||||
if (!WorkplaceResizeBridge.isOutside(automatic[0].getBounds(), viewport)) { rescued = true; break; }
|
||||
Thread.sleep(100);
|
||||
}
|
||||
verify(rescued, "background thread autonomously rescues dialog");
|
||||
} finally {
|
||||
WorkplaceResizeBridge.stopRuntimeMonitor();
|
||||
SwingUtilities.invokeAndWait(() -> automatic[0].dispose());
|
||||
}
|
||||
Thread.sleep(100);
|
||||
}
|
||||
// One JVM thread owns the repeated checks; no further JS bridge calls.
|
||||
verify(WorkplaceResizeBridge.startRuntimeMonitor(960, 640, "diagnose") == 1, "runtime monitor starts");
|
||||
verify(WorkplaceResizeBridge.startRuntimeMonitor(960, 640, "rescue") == 2, "runtime monitor reuses thread");
|
||||
Thread.sleep(100);
|
||||
WorkplaceResizeBridge.stopRuntimeMonitor();
|
||||
boolean rejected = false;
|
||||
try { WorkplaceResizeBridge.startRuntimeMonitor(960, 640, "invalid"); }
|
||||
catch (IllegalArgumentException expected) { rejected = true; }
|
||||
verify(rejected, "invalid monitor mode rejected");
|
||||
System.out.println("WINDOW_GEOMETRY_JAVA11_PASS");
|
||||
}
|
||||
private static void verify(boolean ok, String label) {
|
||||
if (!ok) throw new AssertionError(label);
|
||||
}
|
||||
}
|
||||
126
hmi-docs/cheerpj/WorkplaceCredentialBridge.java
Normal file
126
hmi-docs/cheerpj/WorkplaceCredentialBridge.java
Normal file
@@ -0,0 +1,126 @@
|
||||
package com.widgetworkbench.cheerpj;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Optional one-shot bridge from an authenticated HTTPS HMI browser session to
|
||||
* the *independent* iTAC Workplace PersonService login. Java 11.
|
||||
*
|
||||
* No vendor classes are patched, and IMSAPI session tokens are NOT reused.
|
||||
* The browser offers credentials before main() starts; one Java-owned daemon
|
||||
* waits for PersonService to become available and invokes the public
|
||||
* MesContext.doLogin(String, Password, String) method exactly once.
|
||||
*
|
||||
* 0 = NONE; 1 = SUCCESS; 2 = REJECTED; 3 = ALREADY_SIGNED_IN;
|
||||
* 4 = EXPIRED; 5 = BRIDGE_ERROR. No passwords, usernames, or stack traces
|
||||
* are printed. Logging must never contain credential-bearing exceptions.
|
||||
*/
|
||||
public final class WorkplaceCredentialBridge {
|
||||
private static final long TTL_MILLIS = 120_000L;
|
||||
private static final int RETRY_DELAY = 400;
|
||||
private static char[] pending;
|
||||
private static String username;
|
||||
private static String client;
|
||||
private static long expires;
|
||||
private static boolean armed;
|
||||
private static volatile int result;
|
||||
|
||||
private WorkplaceCredentialBridge() { }
|
||||
|
||||
// Direct CheerpJ native handler, registered with cheerpjInit({natives}).
|
||||
// No System.loadLibrary() is called by this helper.
|
||||
private static native void nativeReport(int code);
|
||||
|
||||
private static void report(int code) {
|
||||
result = code;
|
||||
System.out.println("[WidgetWorkbench/WorkplaceAuth] RESULT_CODE=" + code);
|
||||
try { nativeReport(code); } catch (Throwable ignored) { /* stdout still reports */ }
|
||||
}
|
||||
|
||||
/** Called ONCE via CheerpJ Library Mode, before cheerpjRunMain(). */
|
||||
public static synchronized int offer(String user, String password, String targetClient) {
|
||||
if (armed || pending != null || !valid(user, 120) || !valid(password, 1024)
|
||||
|| !valid(targetClient, 120)) return 0;
|
||||
username = user;
|
||||
pending = password.toCharArray();
|
||||
client = targetClient;
|
||||
expires = System.currentTimeMillis() + TTL_MILLIS;
|
||||
armed = true;
|
||||
Thread worker = new Thread(WorkplaceCredentialBridge::runOnce, "hmi-workplace-auth-handoff");
|
||||
worker.setDaemon(true);
|
||||
worker.start();
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static synchronized int getResultCode() { return result; }
|
||||
|
||||
private static boolean valid(String input, int max) {
|
||||
return input != null && !input.isEmpty() && input.length() <= max
|
||||
&& input.indexOf('\0') < 0;
|
||||
}
|
||||
|
||||
private static void clearPending() {
|
||||
if (pending != null) Arrays.fill(pending, '\0');
|
||||
pending = null; username = null; client = null; expires = 0L;
|
||||
}
|
||||
|
||||
private static void runOnce() {
|
||||
// Wait until the Workplace has begun its own Java initialization. The
|
||||
// service locator may be unavailable during the first few seconds.
|
||||
try { Thread.sleep(1200); } catch (InterruptedException ignored) {
|
||||
Thread.currentThread().interrupt();
|
||||
synchronized (WorkplaceCredentialBridge.class) { clearPending(); }
|
||||
report(5);return;
|
||||
}
|
||||
try {
|
||||
final ClassLoader cl = WorkplaceCredentialBridge.class.getClassLoader();
|
||||
final Class<?> locator = Class.forName("com.itac.artes.ihas.ServiceLocator", true, cl);
|
||||
final Class<?> personService = Class.forName("com.itac.mes.admin.domain.PersonService", false, cl);
|
||||
final Method getService = locator.getMethod("getService", Class.class);
|
||||
// Do not construct/use MesContext before the MES services are ready.
|
||||
Object service = null;
|
||||
while (System.currentTimeMillis() < expires) {
|
||||
try { service = getService.invoke(null, personService); } catch (Exception ignored) { }
|
||||
if (service != null) break;
|
||||
Thread.sleep(RETRY_DELAY);
|
||||
}
|
||||
if (service == null) { report(4);return; }
|
||||
final Class<?> contextType = Class.forName("com.itac.mes.gui.MesContext", true, cl);
|
||||
final Object context = contextType.getMethod("instance").invoke(null);
|
||||
// Avoid replacing an active login (including a different MES user).
|
||||
if (contextType.getMethod("getUser").invoke(context) != null) {
|
||||
report(3);return;
|
||||
}
|
||||
final Class<?> passwordType = Class.forName("com.itac.util.text.Password", true, cl);
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
final Class<? extends Enum> encryptionType =
|
||||
(Class<? extends Enum>) Class.forName("com.itac.util.text.Password$Encryption", true, cl);
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
final Object none = Enum.valueOf((Class) encryptionType, "NONE");
|
||||
final Constructor<?> passwordConstructor = passwordType.getConstructor(encryptionType, String.class);
|
||||
String user; String target; char[] chars;
|
||||
synchronized (WorkplaceCredentialBridge.class) {
|
||||
if (pending == null || System.currentTimeMillis() >= expires) { report(4);return; }
|
||||
user = username; target = client; chars = pending;
|
||||
pending = null; username = null; client = null;
|
||||
}
|
||||
try {
|
||||
// Same Password constructor used by iTAC GuiPasswordField.getValue().
|
||||
final Object pwd = passwordConstructor.newInstance(none, new String(chars));
|
||||
// Exactly one real MES authentication attempt; boolean false is
|
||||
// a rejected login. No exception contents leave the JVM.
|
||||
final Object success = contextType.getMethod("doLogin", String.class, passwordType, String.class)
|
||||
.invoke(context, user, pwd, target);
|
||||
report(Boolean.TRUE.equals(success) ? 1 : 2);
|
||||
} finally { Arrays.fill(chars, '\0'); }
|
||||
} catch (Throwable error) {
|
||||
// Do not log Throwable.toString(): vendor exceptions may contain
|
||||
// credentials or personally identifying information.
|
||||
report(5);
|
||||
} finally {
|
||||
synchronized (WorkplaceCredentialBridge.class) { clearPending(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
84
hmi-docs/cheerpj/WorkplaceLoginHotfixSmoke.java
Normal file
84
hmi-docs/cheerpj/WorkplaceLoginHotfixSmoke.java
Normal file
@@ -0,0 +1,84 @@
|
||||
package com.widgetworkbench.cheerpj;
|
||||
|
||||
import com.itac.mes.gui.dialog.MesLoginDialog;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Rectangle;
|
||||
import javax.swing.JDesktopPane;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JInternalFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
/**
|
||||
* Test-only window fixture verifying iTAC class-name detection and owner
|
||||
* geometry. Requires the unsiged fixture in hmi-scripts/tests/fixtures.
|
||||
* Do NOT bundle the fixture MesLoginDialog into the production bridge JAR.
|
||||
*/
|
||||
public final class WorkplaceLoginHotfixSmoke {
|
||||
private static final class MyDoggyTestPanel extends JPanel { }
|
||||
private static void check(boolean ok, String label) {
|
||||
if (!ok) throw new AssertionError(label);
|
||||
}
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (GraphicsEnvironment.isHeadless()) {
|
||||
System.out.println("WORKPLACE_LOGIN_HOTFIX_HEADLESS_PASS");
|
||||
return;
|
||||
}
|
||||
JFrame owner = new JFrame();
|
||||
owner.setSize(520, 420);
|
||||
owner.setLocation(1900, 1250);
|
||||
final MesLoginDialog[] holder = new MesLoginDialog[1];
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
MesLoginDialog login = new MesLoginDialog(owner);
|
||||
login.setSize(450, 350);
|
||||
login.setLocation(2400, 1300);
|
||||
holder[0] = login;
|
||||
// Do not show modal JDialog via setVisible(true) on the EDT;
|
||||
// that call enters a nested event loop. make it visible on test
|
||||
// without ever invoking the proprietary iTAC login method.
|
||||
login.setModal(false);
|
||||
login.setVisible(true);
|
||||
});
|
||||
try {
|
||||
String snapshot = WorkplaceResizeBridge.diagnoseWindows(960, 640);
|
||||
check(snapshot.contains("MES_LOGIN state=VISIBLE_OFFSCREEN observed=1"), "login class detected");
|
||||
check(snapshot.contains("MES_LOGIN_OWNER class=javax.swing.JFrame"), "owner identified");
|
||||
check(snapshot.contains("visible=false") && snapshot.contains("offscreen=true"), "invisible/offscreen owner reported");
|
||||
check(snapshot.contains("COMPONENT_TREE scanned="), "nested inventory available");
|
||||
String rescue = WorkplaceResizeBridge.rescueOffscreenDialogs(960, 640);
|
||||
check(rescue.contains("loginMoved=1"), "targeted login rescue");
|
||||
check(!WorkplaceResizeBridge.isOutside(holder[0].getBounds(),new Rectangle(0, 0, 960, 640)), "login visible after rescue");
|
||||
check(WorkplaceResizeBridge.rescueOffscreenDialogs(960, 640).contains("loginMoved=0"), "idempotent rescue");
|
||||
SwingUtilities.invokeAndWait(() -> holder[0].setVisible(false));
|
||||
check(WorkplaceResizeBridge.diagnoseWindows(960,640).contains("MES_LOGIN state=CREATED_HIDDEN"), "hidden dialog distinguishable");
|
||||
} finally {
|
||||
SwingUtilities.invokeAndWait(() -> { holder[0].dispose(); owner.dispose(); });
|
||||
}
|
||||
JFrame nested = new JFrame();
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
JDesktopPane desk = new JDesktopPane();
|
||||
JInternalFrame child = new JInternalFrame();
|
||||
child.setBounds(20, 20, 100, 100);
|
||||
desk.add(child);
|
||||
nested.add(desk);
|
||||
nested.add(new JOptionPane(), java.awt.BorderLayout.SOUTH);
|
||||
nested.add(new MyDoggyTestPanel(), java.awt.BorderLayout.NORTH);
|
||||
nested.add(new JTextField("DO_NOT_LOG_PASSWORD"), java.awt.BorderLayout.WEST);
|
||||
nested.setSize(400, 300);
|
||||
nested.setVisible(true);
|
||||
});
|
||||
try {
|
||||
String snapshot = WorkplaceResizeBridge.diagnoseWindows(960, 640);
|
||||
check(snapshot.contains("internalFrames=1"), "internal frame inventoried");
|
||||
check(snapshot.contains("desktops=1"), "desktop inventoried");
|
||||
check(snapshot.contains("optionPanes=1"), "option pane inventoried");
|
||||
check(snapshot.contains("myDoggy=1"), "MyDoggy classname diagnostic");
|
||||
check(!snapshot.contains("DO_NOT_LOG_PASSWORD"), "component text and secrets excluded");
|
||||
} finally {
|
||||
SwingUtilities.invokeAndWait(nested::dispose);
|
||||
}
|
||||
System.out.println("WORKPLACE_LOGIN_HOTFIX_JAVA11_PASS");
|
||||
}
|
||||
}
|
||||
@@ -2,53 +2,151 @@ package com.widgetworkbench.cheerpj;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Frame;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.Window;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.FutureTask;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JInternalFrame;
|
||||
import javax.swing.JDesktopPane;
|
||||
import javax.swing.JLayeredPane;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.RootPaneContainer;
|
||||
import javax.swing.JSplitPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
/**
|
||||
* Optional adapter for resizing the iTAC MES.Suite Workplace inside a CheerpJ display.
|
||||
* No iTAC class dependencies, no modifications to vendor-signed JARs.
|
||||
* The adapter must be loaded into the SAME JVM as the Workplace.
|
||||
* This affects the Swing frame, NOT browser-side display scaling.
|
||||
* Optional, unsigned compatibility bridge for the iTAC Workplace running in
|
||||
* CheerpJ's virtual Swing desktop. No vendor classes are modified.
|
||||
*
|
||||
* Window reports deliberately do not contain window titles or component text:
|
||||
* those may contain sensitive MES data. Only classes and geometry are reported.
|
||||
*/
|
||||
public final class WorkplaceResizeBridge {
|
||||
private static final String FRAME_NAME =
|
||||
"com.itac.mes.suite.presentation.MesSuiteFrame";
|
||||
private static final String PANEL_NAME =
|
||||
"com.itac.mes.gui.suite.MesSuitePanel";
|
||||
private static final String FRAME_NAME = "com.itac.mes.suite.presentation.MesSuiteFrame";
|
||||
private static final String PANEL_NAME = "com.itac.mes.gui.suite.MesSuitePanel";
|
||||
// Verified using the user-provided signed iTAC GUI JARs. These names are
|
||||
// informational only; the bridge never loads or instantiates vendor classes.
|
||||
private static final String MES_LOGIN_NAME = "com.itac.mes.gui.dialog.MesLoginDialog";
|
||||
private static final String GUI_DIALOG_NAME = "com.itac.gui.dialog.GuiDialog";
|
||||
private static final int MAX_WINDOW_REPORTS = 80;
|
||||
private static final int MAX_TREE_NODES = 2500;
|
||||
private static final int MAX_COMPONENT_REPORTS = 35;
|
||||
|
||||
private WorkplaceResizeBridge() { }
|
||||
private static volatile boolean monitorActive;
|
||||
private static volatile Thread monitorThread;
|
||||
private static volatile int monitorWidth;
|
||||
private static volatile int monitorHeight;
|
||||
private static volatile String monitorMode = "off";
|
||||
|
||||
/**
|
||||
* Requests a resize of the matching iTAC Workplace window.
|
||||
* Returns number of matching frames found; update may be scheduled on EDT.
|
||||
* Starts exactly one Java-owned AWT/window monitor. IMPORTANT: all subsequent
|
||||
* monitor calls happen on a native Java Thread, NOT through CheerpJ Library
|
||||
* Mode. That prevents simultaneous JavaScript-to-Java invocations while
|
||||
* cheerpjRunMain() is executing.
|
||||
*
|
||||
* @return 1 = started, 2 = already running
|
||||
*/
|
||||
public static synchronized int startRuntimeMonitor(int width, int height, String mode) {
|
||||
if (!validSize(width, height)) throw new IllegalArgumentException("invalid viewport");
|
||||
if (!("off".equals(mode) || "diagnose".equals(mode) || "rescue".equals(mode)))
|
||||
throw new IllegalArgumentException("invalid window mode");
|
||||
monitorWidth = width;
|
||||
monitorHeight = height;
|
||||
monitorMode = mode;
|
||||
if (monitorThread != null && monitorThread.isAlive()) return 2;
|
||||
monitorActive = true;
|
||||
final Thread worker = new Thread(new Runnable() {
|
||||
@Override public void run() {
|
||||
String lastSnapshot = null;
|
||||
boolean mainFrameSized = false;
|
||||
int reportedErrorCount = 0;
|
||||
while (monitorActive) {
|
||||
try {
|
||||
final int width = monitorWidth;
|
||||
final int height = monitorHeight;
|
||||
final String mode = monitorMode;
|
||||
// The main frame does not exist at startup. Retry until
|
||||
// first detected; do not continuously move user windows.
|
||||
if (!mainFrameSized) {
|
||||
if (resize(width, height) > 0) {
|
||||
mainFrameSized = true;
|
||||
System.out.println("[WidgetWorkbench/WindowGeometry] MAIN_FRAME_RESIZE "
|
||||
+ width + "x" + height);
|
||||
}
|
||||
}
|
||||
if (!"off".equals(mode)) {
|
||||
if ("rescue".equals(mode)) {
|
||||
final String rescue = rescueOffscreenDialogs(width, height);
|
||||
if (rescue.startsWith("RESCUE moved=") && !rescue.startsWith("RESCUE moved=0"))
|
||||
System.out.println("[WidgetWorkbench/WindowGeometry] " + rescue);
|
||||
}
|
||||
final String snapshot = diagnoseWindows(width, height);
|
||||
if (!snapshot.equals(lastSnapshot)) {
|
||||
lastSnapshot = snapshot;
|
||||
System.out.println("[WidgetWorkbench/WindowGeometry]\n" + snapshot);
|
||||
}
|
||||
}
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
break;
|
||||
} catch (Throwable ex) {
|
||||
// Diagnostics MUST NOT abort the vendor application or
|
||||
// repeatedly flood logs when the AWT implementation fails.
|
||||
if (reportedErrorCount++ < 3) System.out.println(
|
||||
"[WidgetWorkbench/WindowGeometry] MONITOR_ERROR " + ex.getClass().getName());
|
||||
try { Thread.sleep(3000); }
|
||||
catch (InterruptedException interrupted) {
|
||||
Thread.currentThread().interrupt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
monitorActive = false;
|
||||
}
|
||||
}, "WidgetWorkbench-WindowMonitor");
|
||||
worker.setDaemon(true);
|
||||
monitorThread = worker;
|
||||
worker.start();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** For isolated Java regression tests; not called by the active JS runner. */
|
||||
public static synchronized void stopRuntimeMonitor() {
|
||||
monitorActive = false;
|
||||
Thread worker = monitorThread;
|
||||
if (worker != null) worker.interrupt();
|
||||
monitorThread = null;
|
||||
}
|
||||
|
||||
|
||||
/** Resize only the main Workplace frame (not its owned dialogs). */
|
||||
public static int resize(final int width, final int height) {
|
||||
if (width < 200 || height < 150 || width > 16000 || height > 16000) {
|
||||
return 0;
|
||||
}
|
||||
if (!validSize(width, height)) return 0;
|
||||
int matches = 0;
|
||||
for (final Frame frame : Frame.getFrames()) {
|
||||
if (!(frame instanceof JFrame)
|
||||
|| !FRAME_NAME.equals(frame.getClass().getName())) {
|
||||
continue;
|
||||
}
|
||||
if (!(frame instanceof JFrame) || !FRAME_NAME.equals(frame.getClass().getName())) continue;
|
||||
final JFrame window = (JFrame) frame;
|
||||
final Container content = window.getContentPane();
|
||||
if (content == null || !PANEL_NAME.equals(content.getClass().getName())) {
|
||||
continue;
|
||||
}
|
||||
if (content == null || !PANEL_NAME.equals(content.getClass().getName())) continue;
|
||||
matches++;
|
||||
final Runnable action = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@Override public void run() {
|
||||
if (!window.isDisplayable()) return;
|
||||
// MesSuitePanel contains BorderLayout: north toolbar, center split navigation.
|
||||
// Respect iTAC navigation preference (divider initially at 150 px).
|
||||
window.setSize(width, height);
|
||||
window.setLocation(0, 0);
|
||||
content.invalidate();
|
||||
@@ -62,12 +160,10 @@ public final class WorkplaceResizeBridge {
|
||||
return matches;
|
||||
}
|
||||
|
||||
/** Inspect live dimensions without changing iTAC settings or window sizes. */
|
||||
/** Existing main-window resize diagnostics (kept for compatibility). */
|
||||
public static String diagnose() {
|
||||
final AtomicReference<String> result = new AtomicReference<String>("diagnostic unavailable");
|
||||
Runnable task = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
return onEdt(new Snapshot() {
|
||||
@Override public String get() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int count = 0;
|
||||
for (Frame frame : Frame.getFrames()) {
|
||||
@@ -86,25 +182,245 @@ public final class WorkplaceResizeBridge {
|
||||
}
|
||||
}
|
||||
if (count == 0) sb.append("Workplace window not found");
|
||||
result.set(sb.toString());
|
||||
return sb.toString();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Read-only snapshot of the virtual desktop and ALL AWT top-level windows,
|
||||
* including invisible/not-yet-displayed JDialogs. Safe for periodic polling.
|
||||
* The viewport represents the actual CheerpJ HTML display in CSS pixels.
|
||||
*/
|
||||
public static String diagnoseWindows(final int width, final int height) {
|
||||
if (!validSize(width, height)) return "WINDOWS INVALID_VIEWPORT";
|
||||
return onEdt(new Snapshot() {
|
||||
@Override public String get() {
|
||||
final Rectangle viewport = new Rectangle(0, 0, width, height);
|
||||
final StringBuilder out = new StringBuilder(4096);
|
||||
out.append("viewport=").append(rect(viewport));
|
||||
out.append(" headless=").append(GraphicsEnvironment.isHeadless()).append('\n');
|
||||
try {
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice[] devices = ge.getScreenDevices();
|
||||
Dimension toolkit = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
out.append("toolkitScreen=").append(toolkit.width).append('x').append(toolkit.height).append('\n');
|
||||
out.append("virtualScreens=").append(devices.length).append('\n');
|
||||
for (int i = 0; i < devices.length && i < 8; i++) {
|
||||
GraphicsConfiguration gc = devices[i].getDefaultConfiguration();
|
||||
out.append(" screen[").append(i).append("]=")
|
||||
.append(gc == null ? "no configuration" : rect(gc.getBounds()))
|
||||
.append('\n');
|
||||
}
|
||||
} catch (RuntimeException | LinkageError ex) {
|
||||
out.append("virtualScreens=unavailable(").append(ex.getClass().getSimpleName()).append(")\n");
|
||||
}
|
||||
final Window[] windows = Window.getWindows();
|
||||
int dialogs = 0, visibleDialogs = 0, outsideDialogs = 0;
|
||||
int loginCount = 0, loginVisible = 0, loginOffscreen = 0, loginHidden = 0;
|
||||
for (Window w : windows) {
|
||||
if (w instanceof JDialog) {
|
||||
dialogs++;
|
||||
if (w.isVisible()) visibleDialogs++;
|
||||
if (w.isVisible() && isOutside(w.getBounds(), viewport)) outsideDialogs++;
|
||||
}
|
||||
if (isMesLoginDialog(w)) {
|
||||
loginCount++;
|
||||
if (w.isVisible()) {
|
||||
loginVisible++;
|
||||
if (isOutside(w.getBounds(), viewport)) loginOffscreen++;
|
||||
} else loginHidden++;
|
||||
}
|
||||
}
|
||||
out.append("windows=").append(windows.length)
|
||||
.append(" dialogs=").append(dialogs)
|
||||
.append(" visibleDialogs=").append(visibleDialogs)
|
||||
.append(" offscreenDialogs=").append(outsideDialogs).append('\n');
|
||||
// NOT_SEEN is observational, not proof that no constructor ran:
|
||||
// a dialog may have been disposed or the monitor may have missed it.
|
||||
String loginState = loginCount == 0 ? "NOT_SEEN"
|
||||
: loginVisible == 0 ? "CREATED_HIDDEN"
|
||||
: loginOffscreen > 0 ? "VISIBLE_OFFSCREEN" : "VISIBLE_ONSCREEN";
|
||||
out.append("MES_LOGIN state=").append(loginState)
|
||||
.append(" observed=").append(loginCount)
|
||||
.append(" visible=").append(loginVisible)
|
||||
.append(" hidden=").append(loginHidden)
|
||||
.append(" offscreen=").append(loginOffscreen)
|
||||
.append(" (NOT_SEEN does not prove never constructed)\n");
|
||||
for (int i = 0; i < windows.length && i < MAX_WINDOW_REPORTS; i++) {
|
||||
Window w = windows[i];
|
||||
Rectangle b = w.getBounds();
|
||||
out.append('[').append(i).append("] ")
|
||||
.append(w.getClass().getName())
|
||||
.append(" bounds=").append(rect(b))
|
||||
.append(" visible=").append(w.isVisible())
|
||||
.append(" showing=").append(w.isShowing())
|
||||
.append(" displayable=").append(w.isDisplayable())
|
||||
.append(" active=").append(w.isActive())
|
||||
.append(" focused=").append(w.isFocused())
|
||||
.append(" outsideViewport=").append(b.width > 0 && b.height > 0 && isOutside(b, viewport));
|
||||
Window owner = w.getOwner();
|
||||
if (owner != null) out.append(" owner=").append(owner.getClass().getName());
|
||||
if (w instanceof Dialog) out.append(" modal=").append(((Dialog) w).isModal());
|
||||
out.append('\n');
|
||||
if (isMesLoginDialog(w)) {
|
||||
out.append(" MES_LOGIN_OWNER ");
|
||||
if (owner == null) out.append("none");
|
||||
else out.append("class=").append(owner.getClass().getName())
|
||||
.append(" bounds=").append(rect(owner.getBounds()))
|
||||
.append(" visible=").append(owner.isVisible())
|
||||
.append(" showing=").append(owner.isShowing())
|
||||
.append(" displayable=").append(owner.isDisplayable())
|
||||
.append(" offscreen=").append(isOutside(owner.getBounds(),viewport));
|
||||
out.append('\n');
|
||||
}
|
||||
}
|
||||
if (windows.length > MAX_WINDOW_REPORTS) out.append("... additional windows omitted\n");
|
||||
appendComponentInventory(out, windows);
|
||||
return out.toString();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static boolean isMesLoginDialog(Window w) {
|
||||
return MES_LOGIN_NAME.equals(w.getClass().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Bounded, read-only inspection of nested Swing components. JInternalFrame,
|
||||
* MyDoggy docking containers, JOptionPane and glass panes do not necessarily
|
||||
* appear in Window.getWindows(). Only class names and geometry are logged;
|
||||
* never component text, dialog titles, usernames or passwords.
|
||||
*/
|
||||
private static void appendComponentInventory(StringBuilder out, Window[] windows) {
|
||||
ArrayDeque<Component> queue = new ArrayDeque<Component>();
|
||||
for (int i = 0; i < windows.length && i < MAX_WINDOW_REPORTS; i++) queue.add(windows[i]);
|
||||
int nodes = 0, internal = 0, desktop = 0, layered = 0, option = 0, docking = 0, glass = 0, reported = 0;
|
||||
while (!queue.isEmpty() && nodes < MAX_TREE_NODES) {
|
||||
Component c = queue.removeFirst();
|
||||
nodes++;
|
||||
String name = c.getClass().getName();
|
||||
boolean isInternal = c instanceof JInternalFrame;
|
||||
boolean isDesktop = c instanceof JDesktopPane;
|
||||
boolean isLayered = c instanceof JLayeredPane;
|
||||
boolean isOption = c instanceof JOptionPane;
|
||||
boolean isDocking = name.toLowerCase(Locale.ROOT).contains("mydoggy");
|
||||
if (isInternal) internal++;
|
||||
if (isDesktop) desktop++;
|
||||
if (isLayered) layered++;
|
||||
if (isOption) option++;
|
||||
if (isDocking) docking++;
|
||||
if (c instanceof RootPaneContainer) {
|
||||
Component g = ((RootPaneContainer)c).getGlassPane();
|
||||
// Identity is checked while traversing child components below.
|
||||
if (g != null && g.isVisible()) glass++;
|
||||
}
|
||||
if ((isInternal || isDesktop || isOption || isDocking) && reported++ < MAX_COMPONENT_REPORTS) {
|
||||
out.append(" COMPONENT ").append(name)
|
||||
.append(" boundsLocal=").append(rect(c.getBounds()))
|
||||
.append(" visible=").append(c.isVisible())
|
||||
.append(" showing=").append(c.isShowing()).append('\n');
|
||||
}
|
||||
if (c instanceof Container) {
|
||||
for (Component child : ((Container)c).getComponents()) {
|
||||
if (child != null && nodes + queue.size() < MAX_TREE_NODES) queue.addLast(child);
|
||||
}
|
||||
}
|
||||
};
|
||||
if (SwingUtilities.isEventDispatchThread()) task.run();
|
||||
else {
|
||||
try { SwingUtilities.invokeAndWait(task); }
|
||||
catch (Exception ex) { return "diagnostic error: " + ex.getClass().getSimpleName(); }
|
||||
}
|
||||
return result.get();
|
||||
out.append("COMPONENT_TREE scanned=").append(nodes)
|
||||
.append(" pending=").append(queue.size())
|
||||
.append(" internalFrames=").append(internal)
|
||||
.append(" desktops=").append(desktop)
|
||||
.append(" layered=").append(layered)
|
||||
.append(" optionPanes=").append(option)
|
||||
.append(" myDoggy=").append(docking)
|
||||
.append(" visibleGlassPanes=").append(glass)
|
||||
.append(" capped=").append(!queue.isEmpty()).append('\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Opt-in recovery, NOT an authentication workaround. Reposition only visible
|
||||
* Swing dialogs which are almost entirely outside the virtual display.
|
||||
* Never resize dialogs, move the main frame, or move invisible dialogs.
|
||||
*/
|
||||
public static String rescueOffscreenDialogs(final int width, final int height) {
|
||||
if (!validSize(width, height)) return "WINDOWS INVALID_VIEWPORT";
|
||||
return onEdt(new Snapshot() {
|
||||
@Override public String get() {
|
||||
Rectangle viewport = new Rectangle(0, 0, width, height);
|
||||
int visible = 0, moved = 0, loginMoved = 0;
|
||||
for (Window window : Window.getWindows()) {
|
||||
if (!(window instanceof JDialog) || !window.isVisible() || !window.isDisplayable()) continue;
|
||||
visible++;
|
||||
Rectangle before = window.getBounds();
|
||||
if (!isOutside(before, viewport)) continue;
|
||||
// An oversized dialog is positioned at zero rather than
|
||||
// resized, avoiding changes to vendor-controlled content.
|
||||
int newX = Math.max(0, (width - before.width) / 2);
|
||||
int newY = Math.max(0, (height - before.height) / 2);
|
||||
window.setLocation(newX, newY);
|
||||
moved++;
|
||||
if (isMesLoginDialog(window)) loginMoved++;
|
||||
}
|
||||
return "RESCUE moved=" + moved + " loginMoved=" + loginMoved
|
||||
+ " visibleDialogs=" + visible;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static boolean validSize(int width, int height) {
|
||||
return width >= 200 && height >= 150 && width <= 16000 && height <= 16000;
|
||||
}
|
||||
|
||||
static boolean isOutside(Rectangle bounds, Rectangle viewport) {
|
||||
if (bounds.width <= 0 || bounds.height <= 0) return true;
|
||||
Rectangle intersection = bounds.intersection(viewport);
|
||||
int minWidth = Math.min(48, Math.max(1, bounds.width / 5));
|
||||
int minHeight = Math.min(40, Math.max(1, bounds.height / 5));
|
||||
return intersection.width < minWidth || intersection.height < minHeight;
|
||||
}
|
||||
|
||||
private static String rect(Rectangle r) {
|
||||
return r.x + "," + r.y + " " + r.width + "x" + r.height;
|
||||
}
|
||||
|
||||
private interface Snapshot { String get(); }
|
||||
|
||||
private static String onEdt(final Snapshot action) {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
try { return action.get(); }
|
||||
catch (RuntimeException | LinkageError ex) { return "WINDOWS ERROR " + ex.getClass().getSimpleName(); }
|
||||
}
|
||||
// An iTAC modal UI may be busy or its event dispatch may have thrown.
|
||||
// Do NOT wait indefinitely for the EDT from CheerpJ's library thread.
|
||||
FutureTask<String> task = new FutureTask<String>(new Callable<String>() {
|
||||
@Override public String call() {
|
||||
try { return action.get(); }
|
||||
catch (RuntimeException | LinkageError ex) { return "WINDOWS ERROR " + ex.getClass().getSimpleName(); }
|
||||
}
|
||||
});
|
||||
SwingUtilities.invokeLater(task);
|
||||
try {
|
||||
return task.get(1500, TimeUnit.MILLISECONDS);
|
||||
} catch (TimeoutException ex) {
|
||||
task.cancel(false);
|
||||
return "WINDOWS EDT_BUSY (snapshot timed out after 1500ms)";
|
||||
} catch (InterruptedException ex) {
|
||||
task.cancel(false);
|
||||
Thread.currentThread().interrupt();
|
||||
return "WINDOWS interrupted";
|
||||
} catch (Exception ex) {
|
||||
return "WINDOWS invocation error: " + ex.getClass().getSimpleName();
|
||||
}
|
||||
}
|
||||
|
||||
private static void appendSize(StringBuilder sb, String title, Component c) {
|
||||
Dimension preferred = c.getPreferredSize();
|
||||
Dimension minimum = c.getMinimumSize();
|
||||
Dimension actual = c.getSize();
|
||||
sb.append(title).append("=").append(actual.width).append('x').append(actual.height)
|
||||
sb.append(title).append('=').append(actual.width).append('x').append(actual.height)
|
||||
.append(" pref=").append(preferred.width).append('x').append(preferred.height)
|
||||
.append(" min=").append(minimum.width).append('x').append(minimum.height)
|
||||
.append("; ");
|
||||
.append(" min=").append(minimum.width).append('x').append(minimum.height).append("; ");
|
||||
}
|
||||
|
||||
private static JSplitPane findSplit(Container parent) {
|
||||
|
||||
13
hmi-docs/cheerpj/tests/WorkplaceCredentialBridgeSmoke.java
Normal file
13
hmi-docs/cheerpj/tests/WorkplaceCredentialBridgeSmoke.java
Normal file
@@ -0,0 +1,13 @@
|
||||
import com.widgetworkbench.cheerpj.WorkplaceCredentialBridge;
|
||||
/** Mimics verified public method signatures, not proprietary MES behavior. */
|
||||
public final class WorkplaceCredentialBridgeSmoke {
|
||||
public static void main(String[] args) throws Exception {
|
||||
final String secret="secret123";
|
||||
if(WorkplaceCredentialBridge.offer("tester",secret,"any")!=1)throw new AssertionError("first offer rejected");
|
||||
if(WorkplaceCredentialBridge.offer("tester",secret,"any")!=0)throw new AssertionError("duplicate offer accepted");
|
||||
long deadline=System.currentTimeMillis()+6000;
|
||||
while(WorkplaceCredentialBridge.getResultCode()==0 && System.currentTimeMillis()<deadline)Thread.sleep(50);
|
||||
if(WorkplaceCredentialBridge.getResultCode()!=1)throw new AssertionError("MES handoff failed: "+WorkplaceCredentialBridge.getResultCode());
|
||||
System.out.println("PASS Java11 independent PersonService reflection and one-shot credential delivery");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.itac.artes.ihas;
|
||||
public final class ServiceLocator {
|
||||
private ServiceLocator(){}
|
||||
public static Object getService(Class<?> ignored){return new Object();}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
package com.itac.mes.admin.domain;
|
||||
public interface PersonService {}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.itac.mes.gui;
|
||||
import com.itac.util.text.Password;
|
||||
public final class MesContext {
|
||||
private static final MesContext INSTANCE=new MesContext();
|
||||
private Object user;
|
||||
public static MesContext instance(){return INSTANCE;}
|
||||
public Object getUser(){return user;}
|
||||
public boolean doLogin(String username, Password password, String client){
|
||||
if("tester".equals(username) && password.matches("secret123") && "any".equals(client)){
|
||||
user=new Object();return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.itac.util.text;
|
||||
public final class Password {
|
||||
public enum Encryption { NONE }
|
||||
private final String value;
|
||||
public Password(Encryption encryption, String plaintext){
|
||||
if(encryption!=Encryption.NONE)throw new IllegalArgumentException();
|
||||
value=plaintext;
|
||||
}
|
||||
public boolean matches(String check){return value.equals(check);}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
SRC="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
TEMP="$(mktemp -d)"
|
||||
trap 'rm -rf "$TEMP"' EXIT
|
||||
javac --release 11 -d "$TEMP" "$SRC/WorkplaceCredentialBridge.java" \
|
||||
"$(dirname "$0")/WorkplaceCredentialBridgeSmoke.java" \
|
||||
$(find "$(dirname "$0")/stubs" -type f -name '*.java' | sort)
|
||||
java -cp "$TEMP" WorkplaceCredentialBridgeSmoke
|
||||
Reference in New Issue
Block a user