summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/gui/intro/Login_GUI.java
diff options
context:
space:
mode:
Diffstat (limited to 'dozentenmodul/src/main/java/gui/intro/Login_GUI.java')
-rw-r--r--dozentenmodul/src/main/java/gui/intro/Login_GUI.java115
1 files changed, 99 insertions, 16 deletions
diff --git a/dozentenmodul/src/main/java/gui/intro/Login_GUI.java b/dozentenmodul/src/main/java/gui/intro/Login_GUI.java
index 75d60051..1ac62333 100644
--- a/dozentenmodul/src/main/java/gui/intro/Login_GUI.java
+++ b/dozentenmodul/src/main/java/gui/intro/Login_GUI.java
@@ -8,16 +8,20 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
+import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import javax.swing.ButtonGroup;
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.DefaultListCellRenderer;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
+import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
@@ -36,14 +40,15 @@ import models.person;
import org.apache.log4j.Logger;
import org.apache.thrift.TException;
import org.openslx.imagemaster.thrift.iface.ImageServer.Client;
+import org.openslx.imagemaster.thrift.iface.OrganizationData;
import org.openslx.imagemaster.thrift.iface.UserInfo;
-//import server.generated.Server.Client;
import thrift.MasterThriftConnection;
import thrift.ThriftConnection;
import util.GuiOrganizer;
import util.ResourceLoader;
import util.ShibbolethECP;
+
import config.Config;
@SuppressWarnings("serial")
@@ -84,8 +89,9 @@ public class Login_GUI extends JFrame {
private ActionListener loginTypeActionListener;
// bwIDM label and dropdown
- private JComboBox<String> choice;
+ private JComboBox<OrganizationData> idpChoice;
private JLabel lblIdp;
+ private List<OrganizationData> organizations;
// Satellite IP label and text field
private JLabel lblSatellitenIp;
@@ -221,12 +227,11 @@ public class Login_GUI extends JFrame {
lblSatIP.setToolTipText("Bitte geben Sie die IP-Adresse des Satelliten ein.");
//panel.add(lblSatIP);
- String organisations[] = { "https://testidp3-dev.aai.dfn.de/idp/profile/SAML2/SOAP/ECP" };
- choice = new JComboBox<String>(organisations);
- choice.setBounds(135, 35, 237, 20);
+ idpChoice = new JComboBox<OrganizationData>();
+ idpChoice.setBounds(135, 35, 237, 20);
//panel.add(choice);
- lblIdp = new JLabel("IDP:");
+ lblIdp = new JLabel("IdP:");
lblIdp.setBounds(25, 35, 82, 20);
//panel.add(lblIdp);
@@ -270,6 +275,7 @@ public class Login_GUI extends JFrame {
rdbtnDirekteVerbindung.setBounds(32, 85, 244, 23);
rdbtnDirekteVerbindung.setActionCommand(LOGIN_TYPE_SATELLITE);
rdbtnDirekteVerbindung.addActionListener(loginTypeActionListener);
+ rdbtnDirekteVerbindung.setEnabled(false);
bgLoginType.add(rdbtnDirekteVerbindung);
panel_1.add(rdbtnDirekteVerbindung);
@@ -289,7 +295,6 @@ public class Login_GUI extends JFrame {
if (loginType == LOGIN_TYPE_BWLEHRPOOL) {
-
// start the authentication process against the masterserver
org.openslx.imagemaster.thrift.iface.SessionData result = null;
// Connect to Master
@@ -386,16 +391,14 @@ public class Login_GUI extends JFrame {
@Override
protected Boolean doInBackground() throws Exception {
publish("Info: Initialisiere Shibboleth-Client ...");
- ShibbolethECP.init(choice.getSelectedItem().toString());
+ OrganizationData selectedOrg = (OrganizationData) idpChoice.getSelectedItem();
publish("Info: Überprüfe Zugangdaten über bwIDM ...");
- return ShibbolethECP.doLogin(lblusername.getText().trim(), String.valueOf(lblpass.getPassword()));
+ return ShibbolethECP.doLogin(selectedOrg.getEcpUrl(), lblusername.getText().trim(), String.valueOf(lblpass.getPassword()));
}
protected void done() {
try {
if (get()) {
setStatus(Color.green, "Info: bwIDM-Login erfolgreich.", null);
- // TODO: call showNextStep()
- //showMainMenu();
JOptionPane.showMessageDialog(c, "Der Shibboleth-Login war erfolgreich! Der Rest ist noch in Entwicklung :)",
"bwIDM-Login erfolgreich", JOptionPane.PLAIN_MESSAGE);
// all done, show main menu
@@ -539,10 +542,11 @@ public class Login_GUI extends JFrame {
panel.setVisible(false);
switch(type) {
case LOGIN_TYPE_BWIDM:
+ initIdpList();
panel.remove(lblSatIP);
panel.remove(lblSatellitenIp);
+ panel.add(idpChoice);
panel.add(lblIdp);
- panel.add(choice);
panel.add(LabelPass);
lblpass.setText("");
lblpass.setToolTipText("Bitte geben Sie Ihr bwIDM-Passwort ein.");
@@ -553,7 +557,7 @@ public class Login_GUI extends JFrame {
panel.setVisible(true);
break;
case LOGIN_TYPE_BWLEHRPOOL:
- panel.remove(choice);
+ panel.remove(idpChoice);
panel.remove(lblIdp);
panel.remove(lblSatIP);
panel.remove(lblSatellitenIp);
@@ -566,7 +570,7 @@ public class Login_GUI extends JFrame {
panel.setVisible(true);
break;
case LOGIN_TYPE_SATELLITE:
- panel.remove(choice);
+ panel.remove(idpChoice);
panel.remove(lblIdp);
panel.remove(LabelPass);
panel.remove(lblpass);
@@ -578,12 +582,91 @@ public class Login_GUI extends JFrame {
panel.revalidate();
panel.repaint();
panel.setVisible(true);
+ setStatus(Color.black, "Info: Bereit für bwIDM-Login", null);
break;
default:
- LOGGER.error("Unknown action '" + type + "'. Ignoring.");
panel.setVisible(true);
return;
}
-
+ }
+
+ /**
+ * Request the list of identity providers from the masterserver and
+ * display them in a combobox.
+ */
+ private void initIdpList() {
+ // abort if we fetched the list already.
+ if (organizations != null) {
+ return;
+ } else {
+ organizations = new ArrayList<OrganizationData>();
+ }
+ LOGGER.info("Fetching list of identity providers from masterserver...");
+ SwingWorker<Boolean, String> worker = new SwingWorker<Boolean, String>(){
+ @Override
+ protected Boolean doInBackground() throws Exception {
+ publish("Info: Hole Liste von IdPs");
+ // if not then request it from the masterserver
+ MasterThriftConnection thrift = new MasterThriftConnection();
+ Client client = thrift.getMasterThriftConnection();
+ List<OrganizationData> tempOrgs = null;
+ try {
+ tempOrgs = client.getOrganizations();
+ } catch (TException e) {
+ LOGGER.error("Could not fetch list of identity providers from the masterserver, see trace: ", e);
+ return false;
+ }
+ // safety check to see if we got any organizations at all
+ if (tempOrgs != null) {
+ // now add those with an Ecp URL to the result list.
+ for (OrganizationData org : tempOrgs) {
+ if (org.getEcpUrl() != null && !org.getEcpUrl().isEmpty()) {
+ organizations.add(org);
+ }
+ LOGGER.debug("Valid IdP: " + org.toString());
+ }
+ } else {
+ LOGGER.error("Thrift call of 'getOrganizations()' seems to have worked, but 'organizations' is still null.");
+ LOGGER.error("Is the API of the masterserver working correctly?");
+ return false;
+ }
+ publish("Info: Liste von IdPs empfangen.");
+ return true;
+ }
+ protected void done() {
+ try {
+ if (get()) {
+ // fill the combobox with the IdPs returned from the masterserver
+ OrganizationData[] orgs = organizations.toArray(new OrganizationData[]{});
+ idpChoice.setModel(new DefaultComboBoxModel<OrganizationData>(orgs));
+ // now override the renderer, to show the display names of the organizations.
+ idpChoice.setRenderer(new DefaultListCellRenderer() {
+ @Override
+ public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
+ super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
+ if (value instanceof OrganizationData){
+ OrganizationData org = (OrganizationData) value;
+ setText(org.getDisplayName());
+ }
+ return this;
+ }
+ });
+ setStatus(Color.black, "Info: Bereit für Login", null);
+ } else {
+ setStatus(Color.red, "Fehler: Vorbereitung für bwIDM-Login fehlgeschlagen!", null);
+ }
+ } catch (InterruptedException e) {
+ LOGGER.error("SwingWorker for 'getOrganizationsList' got interrupted, see trace: ", e);
+ } catch (ExecutionException e) {
+ LOGGER.error("Execution of SwingWorker for 'getOrganizationsList' failed, see trace: ", e);
+ }
+ }
+ @Override
+ protected void process(List<String> msgs) {
+ String currentMessage = msgs.get(msgs.size()-1);
+ setStatus(Color.black, currentMessage, null);
+ }
+ };
+ worker.execute();
}
}// end class