Skip to content

Commit 99f847f

Browse files
authored
Bugfix: un assign LogMessageCallback after call mise (#710)
<!-- Please provide brief information about the PR, what it contains & its purpose, new behaviors after the change. And let us know here if you need any help: https://github.com/microsoft/HydraLab/issues/new --> ## Description <!-- A few words to explain your changes --> ### Linked GitHub issue ID: # ## Pull Request Checklist <!-- Put an x in the boxes that apply. This is simply a reminder of what we are going to look for before merging your code. --> - [ ] Tests for the changes have been added (for bug fixes / features) - [x] Code compiles correctly with all tests are passed. - [x] I've read the [contributing guide](https://github.com/microsoft/HydraLab/blob/main/CONTRIBUTING.md#making-changes-to-the-code) and followed the recommended practices. - [ ] [Wikis](https://github.com/microsoft/HydraLab/wiki) or [README](https://github.com/microsoft/HydraLab/blob/main/README.md) have been reviewed and added / updated if needed (for bug fixes / features) ### Does this introduce a breaking change? *If this introduces a breaking change for Hydra Lab users, please describe the impact and migration path.* - [ ] Yes - [x] No ## How you tested it *Please make sure the change is tested, you can test it by adding UTs, do local test and share the screenshots, etc.* Please check the type of change your PR introduces: - [x] Bugfix - [ ] Feature - [ ] Technical design - [ ] Build related changes - [ ] Refactoring (no functional changes, no api changes) - [ ] Code style update (formatting, renaming) or Documentation content changes - [ ] Other (please describe): ### Feature UI screenshots or Technical design diagrams *If this is a relatively large or complex change, kick it off by drawing the tech design with PlantUML and explaining why you chose the solution you did and what alternatives you considered, etc...*
1 parent ff9a860 commit 99f847f

File tree

1 file changed

+23
-25
lines changed
  • center/src/main/java/com/microsoft/hydralab/center/util

1 file changed

+23
-25
lines changed

center/src/main/java/com/microsoft/hydralab/center/util/AuthUtil.java

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public class AuthUtil {
6666

6767
Map<String, Boolean> urlMapping = null;
6868
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(AuthUtil.class);
69-
private static Boolean isMiseLogInitialized = false;
7069

7170
public boolean isValidToken(String token) {
7271
LOGGER.info("Starting token validation...");
@@ -127,31 +126,27 @@ private boolean validateTokenWithMISE(String token) {
127126
Class<?> miseClass = Class.forName("com.microsoft.identity.service.essentials.Mise");
128127
Object mise = miseClass.getMethod("createClient").invoke(null);
129128

130-
if (!isMiseLogInitialized) {
131-
LOGGER.info("Initializing MISE...");
132-
// mise.assignLogMessageCallback(new Mise.ILogCallback() {...}, null);
133-
Class<?> iLogCallbackClass = Class.forName("com.microsoft.identity.service.essentials.Mise$ILogCallback");
134-
135-
Object logCallback = java.lang.reflect.Proxy.newProxyInstance(
136-
iLogCallbackClass.getClassLoader(),
137-
new Class<?>[]{iLogCallbackClass},
138-
(proxy, method, args) -> {
139-
String methodName = method.getName();
140-
if ("callback".equals(methodName)) {
141-
Object level = args[0];
142-
String message = (String) args[1];
143-
// Print all log levels for simplicity
144-
LOGGER.info(message);
145-
}
146-
return null;
129+
LOGGER.info("Initializing MISE...");
130+
// mise.assignLogMessageCallback(new Mise.ILogCallback() {...}, null);
131+
Class<?> iLogCallbackClass = Class.forName("com.microsoft.identity.service.essentials.Mise$ILogCallback");
132+
133+
Object logCallback = java.lang.reflect.Proxy.newProxyInstance(
134+
iLogCallbackClass.getClassLoader(),
135+
new Class<?>[]{iLogCallbackClass},
136+
(proxy, method, args) -> {
137+
String methodName = method.getName();
138+
if ("callback".equals(methodName)) {
139+
Object level = args[0];
140+
String message = (String) args[1];
141+
// Print all log levels for simplicity
142+
LOGGER.info(message);
147143
}
148-
);
149-
150-
miseClass.getMethod("assignLogMessageCallback", iLogCallbackClass, Object.class)
151-
.invoke(mise, logCallback, null);
152-
isMiseLogInitialized = true;
153-
}
144+
return null;
145+
}
146+
);
154147

148+
miseClass.getMethod("assignLogMessageCallback", iLogCallbackClass, Object.class)
149+
.invoke(mise, logCallback, null);
155150
// Configure MISE
156151
JSONObject config = new JSONObject();
157152
JSONObject azureAd = new JSONObject();
@@ -180,6 +175,10 @@ private boolean validateTokenWithMISE(String token) {
180175
Object validationResult = miseClass.getMethod("validate", miseValidationInputClass)
181176
.invoke(mise, miseValidationInput);
182177

178+
// mise.unassignLogMessageCallback();
179+
miseClass.getMethod("unassignLogMessageCallback")
180+
.invoke(mise);
181+
183182
Class<?> miseValidationResultClass = Class.forName("com.microsoft.identity.service.essentials.MiseValidationResult");
184183
int statusCode = (int) miseValidationResultClass.getMethod("getHttpResponseStatusCode").invoke(validationResult);
185184
LOGGER.info("Status code " + statusCode);
@@ -188,7 +187,6 @@ private boolean validateTokenWithMISE(String token) {
188187
if (errorDescription != null) {
189188
LOGGER.error("Error message " + errorDescription);
190189
}
191-
192190
// Close validationResult if AutoCloseable
193191
if (validationResult instanceof AutoCloseable) {
194192
((AutoCloseable) validationResult).close();

0 commit comments

Comments
 (0)