Skip to content

Commit 82c205b

Browse files
authored
Bugfix: mise client is single instance, can't assignLogMessageCallback again (#709)
<!-- 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) - [ ] 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. - [x] [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.* - [x] 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: - [ ] 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 3be04b4 commit 82c205b

1 file changed

Lines changed: 25 additions & 21 deletions

File tree

  • center/src/main/java/com/microsoft/hydralab/center/util

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

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@ public class AuthUtil {
6161
String ignoreUri;
6262
@Value("${spring.security.oauth2.client.registration.azure-client.scope:}")
6363
String scope;
64-
@Value("${spring.security.oauth2.client.provider.azure-ad.miseEnabled:false}")
64+
@Value("${spring.security.oauth2.client.provider.azure-ad.mise-enabled:false}")
6565
boolean miseEnabled;
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;
6970

7071
public boolean isValidToken(String token) {
7172
LOGGER.info("Starting token validation...");
@@ -118,35 +119,38 @@ private boolean validateTokenWithPublicKey(String token) {
118119
}
119120
}
120121

121-
public boolean validateTokenWithMISE(String token) {
122+
private boolean validateTokenWithMISE(String token) {
122123
LOGGER.info("Starting MISE token validation...");
123124

124125
try {
125126
// Mise mise = Mise.createClient();
126127
Class<?> miseClass = Class.forName("com.microsoft.identity.service.essentials.Mise");
127128
Object mise = miseClass.getMethod("createClient").invoke(null);
128129

129-
// mise.assignLogMessageCallback(new Mise.ILogCallback() {...}, null);
130-
Class<?> logLevelClass = Class.forName("com.microsoft.identity.service.essentials.MiseLogLevel");
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);
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;
143147
}
144-
return null;
145-
}
146-
);
148+
);
147149

148-
miseClass.getMethod("assignLogMessageCallback", iLogCallbackClass, Object.class)
149-
.invoke(mise, logCallback, null);
150+
miseClass.getMethod("assignLogMessageCallback", iLogCallbackClass, Object.class)
151+
.invoke(mise, logCallback, null);
152+
isMiseLogInitialized = true;
153+
}
150154

151155
// Configure MISE
152156
JSONObject config = new JSONObject();

0 commit comments

Comments
 (0)