summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java
diff options
context:
space:
mode:
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java66
1 files changed, 55 insertions, 11 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java
index eab1c4f9..0f2e1f35 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java
@@ -3,6 +3,7 @@ package org.openslx.dozmod.gui.window;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.InputEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
@@ -11,6 +12,7 @@ import java.awt.event.WindowEvent;
import java.io.File;
import java.util.Iterator;
import java.util.List;
+import java.util.UUID;
import javax.swing.AbstractAction;
import javax.swing.DefaultComboBoxModel;
@@ -26,8 +28,10 @@ import org.apache.thrift.TException;
import org.openslx.bwlp.thrift.iface.Organization;
import org.openslx.bwlp.thrift.iface.Satellite;
import org.openslx.dozmod.App;
+import org.openslx.dozmod.Branding;
import org.openslx.dozmod.Config;
import org.openslx.dozmod.authentication.Authenticator;
+import org.openslx.dozmod.authentication.BrowserAuthenticator;
import org.openslx.dozmod.authentication.Authenticator.AuthenticationData;
import org.openslx.dozmod.authentication.Authenticator.AuthenticatorCallback;
import org.openslx.dozmod.authentication.EcpAuthenticator;
@@ -69,7 +73,8 @@ public class LoginWindow extends LoginWindowLayout {
public static enum LoginType {
ECP(0),
TEST_ACCOUNT(1),
- DIRECT_CONNECT(2);
+ DIRECT_CONNECT(2),
+ EXTERNAL_BROWSER(3);
public final int id;
@@ -80,6 +85,9 @@ public class LoginWindow extends LoginWindowLayout {
// authentication method to use for login attempts
protected LoginType loginType = null;
+
+ // Currently running authentication
+ protected Authenticator currentAuthenticator;
private boolean forceCustomSatellite = false;
@@ -99,10 +107,25 @@ public class LoginWindow extends LoginWindowLayout {
rdoLoginType[type.id].addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
- if (e.getStateChange() == ItemEvent.SELECTED) {
- cboOrganization.setEnabled(cboOrganization.getModel().getSize() != 0 && type == LoginType.ECP);
- loginType = type;
- btnOpenRegistration.setEnabled(type == LoginType.ECP);
+ if (e.getStateChange() != ItemEvent.SELECTED)
+ return;
+ cboOrganization.setEnabled(cboOrganization.getModel().getSize() != 0 && type == LoginType.ECP);
+ loginType = type;
+ btnOpenRegistration.setEnabled(type == LoginType.ECP || type == LoginType.EXTERNAL_BROWSER);
+ boolean browser = (type == LoginType.EXTERNAL_BROWSER);
+ cboOrganization.setVisible(!browser);
+ txtUsername.setVisible(!browser);
+ txtPassword.setVisible(!browser);
+ lblOrganization.setVisible(!browser);
+ lblUsername.setVisible(!browser);
+ lblPassword.setVisible(!browser);
+ txtUrl.setVisible(browser);
+ lblError.setText("-");
+ lblError.setVisible(browser);
+ pnlLoginForm.doLayout();
+ if (currentAuthenticator != null) {
+ currentAuthenticator.cancel();
+ currentAuthenticator = null;
}
}
});
@@ -183,6 +206,9 @@ public class LoginWindow extends LoginWindowLayout {
// make enter key activate login
pnlLoginForm.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "login");
+ pnlLoginForm.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
+ KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_DOWN_MASK), "login");
+
pnlLoginForm.getActionMap().put("login", new AbstractAction() {
/**
*
@@ -317,8 +343,19 @@ public class LoginWindow extends LoginWindowLayout {
return;
}
// here we only check for the fields
- String username = txtUsername.getText();
- final String password = String.copyValueOf(txtPassword.getPassword());
+ String username;
+ final String password;
+ // SPECIAL CASE - browser based
+ // username is the full URL including token, password is just the token
+ if (loginType == LoginType.EXTERNAL_BROWSER) {
+ password = UUID.randomUUID().toString();
+ username = "https://" + Branding.getMasterServerAddress() + "/webif/shib/?do=SuiteLogin&accessToken=" + password;
+ lblError.setText(I18n.WINDOW.getString("Login.Label.error.continueBrowser"));
+ txtUrl.setText(username);
+ } else {
+ username = txtUsername.getText();
+ password = String.copyValueOf(txtPassword.getPassword());
+ }
// login clicked, lets first read the fields
if (username.isEmpty()) {
Gui.showMessageBox(this, I18n.WINDOW.getString("Login.Message.error.noUsername"), MessageType.ERROR, LOGGER, null);
@@ -340,6 +377,9 @@ public class LoginWindow extends LoginWindowLayout {
final AuthenticatorCallback authenticatorCallback = new AuthenticatorCallback() {
@Override
public void postLogin(ReturnCode returnCode, final AuthenticationData data, Throwable t) {
+ if (t != null) {
+ lblError.setText(t.getMessage());
+ }
switch (returnCode) {
case NO_ERROR:
Gui.asyncExec(new Runnable() {
@@ -384,13 +424,15 @@ public class LoginWindow extends LoginWindowLayout {
};
// now switch over the login types.
- final Authenticator authenticator;
switch (loginType) {
case ECP:
- authenticator = new EcpAuthenticator(selectedOrg.getEcpUrl());
+ currentAuthenticator = new EcpAuthenticator(selectedOrg.getEcpUrl());
break;
case TEST_ACCOUNT:
- authenticator = new TestAccountAuthenticator();
+ currentAuthenticator = new TestAccountAuthenticator();
+ break;
+ case EXTERNAL_BROWSER:
+ currentAuthenticator = new BrowserAuthenticator(lblError);
break;
case DIRECT_CONNECT:
Gui.showMessageBox(this, I18n.WINDOW.getString("Login.Message.error.loginTypeDirectConnect"),
@@ -410,7 +452,7 @@ public class LoginWindow extends LoginWindowLayout {
// Execute login
App.waitForInit();
try {
- authenticator.login(finalUsername, password, authenticatorCallback);
+ currentAuthenticator.login(finalUsername, password, authenticatorCallback);
return;
} catch (TException e) {
ThriftError.showMessage(LoginWindow.this, LOGGER, e,
@@ -418,6 +460,8 @@ public class LoginWindow extends LoginWindowLayout {
} catch (Exception e) {
Gui.showMessageBox(LoginWindow.this, I18n.WINDOW.getString("Login.Message.error.loginFailed"),
MessageType.ERROR, LOGGER, e);
+ } finally {
+ currentAuthenticator = null;
}
enableLogin(true);
}