Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove useless error log when use device login #2690

Merged
merged 4 commits into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions PluginsAndFeatures/azure-toolkit-for-intellij/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ repositories {

configurations {
compile.exclude module:'slf4j-api'
compile.exclude module:'log4j'
cucumberRuntime {
extendsFrom testRuntime
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
import com.microsoft.aad.adal4j.AuthenticationResult;
import com.microsoft.aad.adal4j.DeviceCode;
import com.microsoft.intellij.ui.components.AzureDialogWrapper;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.Nullable;

import java.awt.Desktop;
import java.awt.Toolkit;
import java.awt.Window;
Expand Down Expand Up @@ -87,20 +91,29 @@ private void pullAuthenticationResult(final AuthenticationContext ctx, final Dev
final AuthenticationCallback<AuthenticationResult> callback) {
final long interval = deviceCode.getInterval();
long remaining = deviceCode.getExpiresIn();
while (remaining > 0 && authenticationResult == null) {
try {
remaining -= interval;
Thread.sleep(interval * 1000);
authenticationResult = ctx.acquireTokenByDeviceCode(deviceCode, callback).get();
} catch (ExecutionException | InterruptedException e) {
if (e.getCause() instanceof AuthenticationException &&
((AuthenticationException) e.getCause()).getErrorCode() == AdalErrorCode.AUTHORIZATION_PENDING) {
// swallow the pending exception
} else {
e.printStackTrace();
break;
// Close adal logger for it will write useless error log
// for issue #2368 https://github.com/Microsoft/azure-tools-for-java/issues/2368
Logger authLogger = Logger.getLogger(AuthenticationContext.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Level authLoggerLevel = authLogger.getLevel();
authLogger.setLevel(Level.OFF);
try {
while (remaining > 0 && authenticationResult == null) {
try {
remaining -= interval;
Thread.sleep(interval * 1000);
authenticationResult = ctx.acquireTokenByDeviceCode(deviceCode, callback).get();
} catch (ExecutionException | InterruptedException e) {
if (e.getCause() instanceof AuthenticationException &&
((AuthenticationException) e.getCause()).getErrorCode() == AdalErrorCode.AUTHORIZATION_PENDING) {
// swallow the pending exception
} else {
e.printStackTrace();
break;
}
}
}
} finally {
authLogger.setLevel(authLoggerLevel);
}
closeDialog();
}
Expand Down