diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index 3f521fc..7c2c321 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -56,5 +56,10 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index ba0541a..447794c 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -7,7 +7,7 @@
-
+
\ No newline at end of file
diff --git a/src/main/java/edu/kit/kastel/sdq/intelligrade/extensions/settings/ArtemisSettings.java b/src/main/java/edu/kit/kastel/sdq/intelligrade/extensions/settings/ArtemisSettings.java
index dea187e..23030c7 100644
--- a/src/main/java/edu/kit/kastel/sdq/intelligrade/extensions/settings/ArtemisSettings.java
+++ b/src/main/java/edu/kit/kastel/sdq/intelligrade/extensions/settings/ArtemisSettings.java
@@ -87,7 +87,16 @@ public class ArtemisSettings implements Configurable {
this.apply();
PluginState.getInstance().connect();
});
- contentPanel.add(loginButton, "span 2, growx");
+ contentPanel.add(loginButton, "span 1, growx");
+
+ // Button to log out of artemis
+ var logoutButton = new JButton("Logout");
+ logoutButton.addActionListener(a -> {
+ // request a logout
+ PluginState.getInstance().logout();
+ this.apply();
+ });
+ contentPanel.add(logoutButton, "span 1, growx");
// Login options
contentPanel.add(new TitledSeparator("Login Options"), "span 2, growx");
diff --git a/src/main/java/edu/kit/kastel/sdq/intelligrade/login/CefUtils.java b/src/main/java/edu/kit/kastel/sdq/intelligrade/login/CefUtils.java
index a720bf0..b0fff5c 100644
--- a/src/main/java/edu/kit/kastel/sdq/intelligrade/login/CefUtils.java
+++ b/src/main/java/edu/kit/kastel/sdq/intelligrade/login/CefUtils.java
@@ -29,6 +29,24 @@ private CefUtils() {
throw new IllegalAccessError("Utility Class");
}
+ /**
+ * Reset the CEF Browsers cookies to remove the artemis login token
+ */
+ public static void resetCookies() {
+
+ // offscreen rendering is problematic on Linux
+ JBCefBrowser browser = JBCefBrowser.createBuilder()
+ .setClient(browserClient)
+ .setOffScreenRendering(false)
+ .build();
+
+ // clear cookies
+ CefApp.getInstance().onInitialization(state -> {
+ browser.getJBCefCookieManager().deleteCookies(null, null);
+ });
+ browser.dispose();
+ }
+
/**
* Create and display a Window containing a JBCef Window to request login. Call this on the EDT!
*
@@ -36,10 +54,6 @@ private CefUtils() {
*/
public static CompletableFuture jcefBrowserLogin() {
- if (browserClient == null) {
- browserClient = JBCefApp.getInstance().createClient();
- }
-
// offscreen rendering is problematic on Linux
JBCefBrowser browser = JBCefBrowser.createBuilder()
.setClient(browserClient)
@@ -47,12 +61,6 @@ public static CompletableFuture jcefBrowserLogin() {
.setUrl(ArtemisSettingsState.getInstance().getArtemisInstanceUrl())
.build();
- // TODO the following code deletes the jwt cookie, which is needed for a "fresh" login
- // TODO add this somewhere where it is useful
- // CefApp.getInstance().onInitialization(state -> {
- // browser.getJBCefCookieManager().deleteCookies(null, null);
- // });
-
// set focus handler because it gets invoked sometimes and causes NullPE otherwise
CefFocusHandler focusHandler = new CefWindowFocusHandler();
browserClient.addFocusHandler(focusHandler, browser.getCefBrowser());
diff --git a/src/main/java/edu/kit/kastel/sdq/intelligrade/state/PluginState.java b/src/main/java/edu/kit/kastel/sdq/intelligrade/state/PluginState.java
index aad1fac..4d8cc20 100644
--- a/src/main/java/edu/kit/kastel/sdq/intelligrade/state/PluginState.java
+++ b/src/main/java/edu/kit/kastel/sdq/intelligrade/state/PluginState.java
@@ -15,11 +15,14 @@
import java.util.concurrent.ExecutionException;
import java.util.function.Consumer;
+import javax.swing.*;
+
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
+import com.intellij.openapi.ui.MessageDialogBuilder;
import com.intellij.ui.jcef.JBCefApp;
import edu.kit.kastel.sdq.artemis4j.ArtemisClientException;
import edu.kit.kastel.sdq.artemis4j.ArtemisNetworkException;
@@ -61,6 +64,35 @@ public static PluginState getInstance() {
return pluginState;
}
+ /**
+ * Logs out while displaying a warning if an assessment is still running
+ */
+ public void logout() {
+ boolean answer = true;
+ // check if confirmation is necessary because assessment is running
+ if (isAssessing()) {
+ answer = MessageDialogBuilder.okCancel(
+ "Logging out while assessing!",
+ "Logging out while assessing will discard current changes. Continue?")
+ .guessWindowAndAsk();
+ }
+ // actually reset state
+ if (answer) {
+ this.resetState();
+
+ // reset state in settings
+ ArtemisCredentialsProvider.getInstance().setJwt(null);
+ ArtemisCredentialsProvider.getInstance().setArtemisPassword(null);
+ ArtemisSettingsState.getInstance().setJwtExpiry(null);
+
+ // reset JBCef cookies iff available
+ if (JBCefApp.isSupported()) {
+ CefUtils.resetCookies();
+ }
+ }
+ this.notifyConnectedListeners();
+ }
+
public void connect() {
this.resetState();