1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
|
package gui.intro;
import java.awt.Color;
import java.awt.Component;
import java.awt.Image;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
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.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.SwingWorker;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import models.SessionData;
import models.person;
import org.apache.log4j.Logger;
import org.apache.thrift.TException;
import org.openslx.imagemaster.thrift.iface.ImageServer;
import org.openslx.imagemaster.thrift.iface.OrganizationData;
import org.openslx.imagemaster.thrift.iface.UserInfo;
import org.openslx.sat.thrift.version.Version;
import org.openslx.thrifthelper.ThriftManager;
import util.GuiManager;
import util.ResourceLoader;
import util.ShibbolethECP;
import config.Config;
@SuppressWarnings("serial")
public class Login_GUI extends JInternalFrame {
/**
* Logger instance for this class.
*/
private final static Logger LOGGER = Logger.getLogger(Login_GUI.class);
// String constants representing the different login methods
private final static String LOGIN_TYPE_BWIDM = "bwidm";
private final static String LOGIN_TYPE_BWLEHRPOOL = "bwlp";
private final static String LOGIN_TYPE_SATELLITE = "sat";
private JPanel contentPane;
private JTextField lblusername;
private JPasswordField lblpass;
private JLabel lblConnectionInfo = new JLabel("");
private JCheckBox chckbxBenutzernameSpeichern;
private JPanel panel;
private JPanel panel_1;
private JLabel LabelUser;
private JLabel LabelPass;
// radio button and group for login types.
private ButtonGroup bgLoginType;
private JRadioButton rdbtnBwIDM;
private JRadioButton rdbtnDirekteVerbindung;
private JRadioButton rdbtnMasterserver;
// its action listener
private ActionListener loginTypeActionListener;
// bwIDM label and dropdown
private JComboBox<OrganizationData> idpChoice;
private JLabel lblIdp;
private List<OrganizationData> organizations;
// Satellite IP label and text field
private JLabel lblSatellitenIp;
private JTextField lblSatIP;
/**
* Create the frame.
*/
public Login_GUI() {
// Titel des Fensters setzen
setTitle("bwLehrpool Suite");
// Größe setzen und mittig ausrichten
setBounds(0, 0, 785, 430);
// Erzeugen eines Panels
contentPane = new JPanel();
// Hintergrund Farbe des Panels setzen
contentPane.setBackground(SystemColor.menu);
// Rahmen des Fensters setzen
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
// Layout setzen
contentPane.setLayout(null);
// Label fuer das Logo erzeugen
JLabel imgLabel = new JLabel();
// Groesse und Position des Logos festelegen
imgLabel.setBounds(231, 11, 350, 142);
// Pfadangabe des Logos
ImageIcon icon = ResourceLoader.getIcon("/img/Logo_bwLehrpool.png", "Logo");
// Skalierung des Logos
Image scaled = icon.getImage().getScaledInstance(270, 64, 0);
imgLabel.setIcon(new ImageIcon(scaled));
// Hinzufuegen des Logos in das Fenster
contentPane.add(imgLabel);
lblConnectionInfo.setHorizontalAlignment(SwingConstants.LEFT);
lblConnectionInfo.setBounds(10, 359, 449, 20);
lblConnectionInfo.setEnabled(true);
lblConnectionInfo.setText("Info: Bereit für Login");
contentPane.add(lblConnectionInfo);
// Erzeugen, Hinzufuegen und definierung der Aktion des Buttons
JButton BtnLogin = new JButton("Login");
BtnLogin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
performLogin(bgLoginType.getSelection().getActionCommand());
}// end actionPerformed
});
BtnLogin.setBounds(488, 358, 239, 23);
contentPane.add(BtnLogin);
// Start of the actual content of the right panel
panel = new JPanel();
panel.setLayout(null);
panel.setBorder(new TitledBorder(null, "Zugangsdaten", TitledBorder.LEADING, TitledBorder.TOP, null,
null));
panel.setBackground(SystemColor.menu);
panel.setBounds(354, 143, 400, 181);
contentPane.add(panel);
chckbxBenutzernameSpeichern = new JCheckBox("Benutzername speichern");
chckbxBenutzernameSpeichern.setBounds(135, 137, 237, 23);
chckbxBenutzernameSpeichern.setSelected(Config.getSaveUsername());
panel.add(chckbxBenutzernameSpeichern);
// Erzeugen und Hinzufuegen des Labels
LabelUser = new JLabel("Benutzername:");
LabelUser.setBounds(25, 60, 82, 20);
panel.add(LabelUser);
// Erzeugen und Hinzufuegen des Textfeldes
lblusername = new JTextField();
lblusername.setBounds(135, 60, 237, 20);
lblusername.setToolTipText("Bitte geben Sie Ihren bwIDM-Benutzernamen ein.");
lblusername.setColumns(10);
// Lese Benutzername aus der Konfigurationsdatei
lblusername.setText(Config.getUsername());
lblusername.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
performLogin(bgLoginType.getSelection().getActionCommand());
}
});
panel.add(lblusername);
// Erzeugen und Hinzufuegen des Labels
LabelPass = new JLabel("Passwort:");
LabelPass.setBounds(25, 85, 82, 20);
panel.add(LabelPass);
// Erzeugen und Hinzufuegen des Passwortfeldes
lblpass = new JPasswordField();
lblpass.setBounds(135, 85, 237, 20);
lblpass.setToolTipText("Bitte geben Sie Ihr bwIDM-Passwort ein.");
lblpass.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
performLogin(bgLoginType.getSelection().getActionCommand());
}
});
panel.add(lblpass);
lblSatellitenIp = new JLabel("Satelliten IP:");
lblSatellitenIp.setBounds(25, 105, 82, 20);
// panel.add(lblSatellitenIp);
lblSatIP = new JTextField();
lblSatIP.setBounds(135, 110, 237, 20);
lblSatIP.setToolTipText("Bitte geben Sie die IP-Adresse des Satelliten ein.");
// panel.add(lblSatIP);
idpChoice = new JComboBox<OrganizationData>();
idpChoice.setBounds(135, 35, 237, 20);
// panel.add(choice);
lblIdp = new JLabel("IdP:");
lblIdp.setBounds(25, 35, 82, 20);
// panel.add(lblIdp);
// action listener for the radio buttons to
// toggle the gui elements depending on the login type
loginTypeActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
toggleLoginType(e.getActionCommand());
}
};
panel_1 = new JPanel();
panel_1.setLayout(null);
panel_1.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"),
"Authentifizierungsart", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
panel_1.setBackground(SystemColor.menu);
panel_1.setBounds(10, 143, 334, 181);
contentPane.add(panel_1);
// group radio button for the login type together
bgLoginType = new ButtonGroup();
rdbtnBwIDM = new JRadioButton("Authentifizierung über bwIDM");
rdbtnBwIDM.setBounds(32, 35, 244, 23);
rdbtnBwIDM.setActionCommand(LOGIN_TYPE_BWIDM);
rdbtnBwIDM.addActionListener(loginTypeActionListener);
bgLoginType.add(rdbtnBwIDM);
panel_1.add(rdbtnBwIDM);
rdbtnMasterserver = new JRadioButton("Test-Zugang mit festem Benutzer");
rdbtnMasterserver.setSelected(true);
rdbtnMasterserver.setActionCommand(LOGIN_TYPE_BWLEHRPOOL);
rdbtnMasterserver.addActionListener(loginTypeActionListener);
rdbtnMasterserver.setBounds(32, 60, 244, 23);
bgLoginType.add(rdbtnMasterserver);
panel_1.add(rdbtnMasterserver);
rdbtnDirekteVerbindung = new JRadioButton("Direkte Verbindung zum Satelliten");
rdbtnDirekteVerbindung.setBounds(32, 85, 244, 23);
rdbtnDirekteVerbindung.setActionCommand(LOGIN_TYPE_SATELLITE);
rdbtnDirekteVerbindung.addActionListener(loginTypeActionListener);
rdbtnDirekteVerbindung.setEnabled(false);
bgLoginType.add(rdbtnDirekteVerbindung);
panel_1.add(rdbtnDirekteVerbindung);
panel.setVisible(true);
panel_1.setVisible(true);
contentPane.setVisible(true);
}// end LoginGUI()
// Versuche den Benutzer einzuloggen
public void performLogin(final String loginType) {
LOGGER.info("Trying login of type: " + loginType);
if (loginType == LOGIN_TYPE_BWLEHRPOOL) {
// start the authentication process against the masterserver
org.openslx.imagemaster.thrift.iface.SessionData result = null;
// Connect to Master
ImageServer.Iface client = ThriftManager.getMasterClient();
String passText = new String(lblpass.getPassword());
UserInfo user = null;
// Log user in
try {
setStatus(Color.black, "Authentifiziere - warte auf Antwort von Server...", null);
result = client.authenticate(lblusername.getText(), passText);
// Sanity checks
if (result.authToken == null || result.sessionId == null) {
setStatus(Color.red, "Antwort des Masterservers korrupt.", null);
LOGGER.info("Antwort des Masterservers korrupt");
return;
}
// User-Info
LOGGER.info("Authentifizierung von '" + lblusername.getText() + "' erfolgreich.");
user = client.getUserFromToken(result.authToken);
} catch (org.openslx.imagemaster.thrift.iface.AuthenticationException e) {
setStatus(Color.red, "Fehler: Zugangsdaten nicht akzeptiert.",
"Benutzeranmeldung fehlgeschlagen: Bitte Benutzername und Passwort überprüfen.\n"
+ e.message);
e.printStackTrace();
return;
} catch (TException e) {
e.printStackTrace();
setStatus(Color.red, "Kommunikation mit Masterserver fehlgeschlagen.", null);
LOGGER.error("Thrift-communication to the masterserver failed, see trace: ", e);
return;
}
// set Information
SessionData.authToken = result.authToken;
SessionData.sessionID = result.sessionId;
SessionData.serverAdress = result.serverAddress;
if (!ThriftManager.setSatellite(result.serverAddress)) {
LOGGER.error("Setting satellite IP to '"
+ result.serverAddress
+ "' failed. Appears to be empty. Is the satellite IP returned from masterserver correct?");
setStatus(Color.green, "IP vom Satelliten ungültig.", null);
System.exit(1);
}
// User-Info
setStatus(Color.green, "Daten erhalten.", null);
String hochschule = user.eMail.substring(user.eMail.indexOf("@") + 1);
person.verantwortlicher.setUsername(lblusername.getText().trim());
person.verantwortlicher.setUserID(lblusername.getText().trim());
person.verantwortlicher.setName(user.lastName);
person.verantwortlicher.setVorname(user.firstName);
person.verantwortlicher.setEMail(user.eMail);
person.verantwortlicher.setHochschule(hochschule);
// Spaeter ueber result.getRole zum Beispiel die Rolle holen
if (lblusername.getText().trim().startsWith("admin@")) {
person.verantwortlicher.setRole("Admin");
} else {
person.verantwortlicher.setRole("Dozent");
// person.verantwortlicher.setRole("Student");
}
postLogin();
// }
} // end bwLehrpool-Login
if (loginType == LOGIN_TYPE_BWIDM) {
// try the shibbo login in its own SwingWorker to avoid GUI lockups
SwingWorker<ShibbolethECP.ReturnCode, String> worker = new SwingWorker<ShibbolethECP.ReturnCode, String>() {
@Override
protected ShibbolethECP.ReturnCode doInBackground() throws Exception {
publish("Info: Initialisiere Shibboleth-Client ...");
OrganizationData selectedOrg = (OrganizationData) idpChoice.getSelectedItem();
publish("Info: Überprüfe Zugangdaten über bwIDM ...");
return ShibbolethECP.doLogin(selectedOrg.getEcpUrl(), lblusername.getText().trim(),
String.valueOf(lblpass.getPassword()));
}
protected void done() {
try {
ShibbolethECP.ReturnCode ecpReturn = get();
switch (ecpReturn) {
case NO_ERROR:
setStatus(Color.green, "Info: bwIDM-Anmeldung erfolgreich.", null);
/*
* Login successful
*/
person.verantwortlicher.setUsername(lblusername.getText().trim());
person.verantwortlicher.setUserID(lblusername.getText().trim());
person.verantwortlicher.setName(ShibbolethECP.getResponse().lastName);
person.verantwortlicher.setVorname(ShibbolethECP.getResponse().firstName);
person.verantwortlicher.setEMail(ShibbolethECP.getResponse().mail);
person.verantwortlicher.setHochschule(((OrganizationData) idpChoice
.getSelectedItem()).getOrganizationId());
person.verantwortlicher.setRole("Dozent");
ThriftManager.setSatellite(ShibbolethECP.getResponse().satellites.get("default"));
SessionData.serverAdress = ShibbolethECP.getResponse().satellites.get("default");
SessionData.authToken = ShibbolethECP.getResponse().token;
SessionData.sessionID = ShibbolethECP.getResponse().sessionId;
/*
* Now postprocess successful login
*/
postLogin();
break;
case ERROR_IDP:
setStatus(Color.red, "Fehler: bwIDM-Anmeldung fehlgeschlagen!", null);
JOptionPane
.showMessageDialog(
null,
"Anmeldung fehlgeschlagen. Überprüfen Sie den Benutzername und Passwort.",
"Fehler", JOptionPane.ERROR_MESSAGE);
break;
case ERROR_UNREG:
setStatus(Color.red, "Fehler: Nicht bei bwLehrpool registriert!", null);
JOptionPane.showMessageDialog(null,
"Sie sind nicht bei bwLehrpool registriert.\nGehen Sie dazu auf folgende Seite:\n"
+ ShibbolethECP.getRegistrationUrl(), "Fehler",
JOptionPane.ERROR_MESSAGE);
break;
case ERROR_SP:
setStatus(Color.red, "Fehler: bwIDM-Anmeldung fehlgeschlagen!", null);
JOptionPane
.showMessageDialog(
null,
"Anmeldung erfolgreich aber die Antwort des Service Providers ist ungültig.",
"Fehler", JOptionPane.ERROR_MESSAGE);
break;
case ERROR_OTHER:
setStatus(Color.red, "Fehler: bwIDM-Anmeldung fehlgeschlagen!", null);
JOptionPane.showMessageDialog(null,
"Fataler Fehler. Schicken Sie die Log-Datei einem Administrator zu!",
"Fehler", JOptionPane.ERROR_MESSAGE);
break;
default:
setStatus(Color.red, "Fehler: bwIDM-Login fehlgeschlagen!", null);
}
} catch (InterruptedException e) {
LOGGER.error("SwingWorker for ShibbolethECP got interrupted, see trace: ", e);
} catch (ExecutionException e) {
LOGGER.error("Execution of SwingWorker for ShibbolethECP 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();
}
// always save to user's config file.
if (chckbxBenutzernameSpeichern.isSelected())
{
Config.setUsername(lblusername.getText());
Config.setSaveUsername(true);
Config.setIdP(String.valueOf(idpChoice.getSelectedIndex()));
} else
{
Config.setUsername("");
Config.setSaveUsername(false);
Config.setIdP(String.valueOf(0));
}
// save it to local disk
Config.store();
}// end performLogin
/**
* Common function for either authentication method
*/
private void postLogin() {
// Version check
long remoteVersion;
try {
remoteVersion = ThriftManager.getSatClient().getVersion();
LOGGER.info("Satellite RPC version: " + remoteVersion);
} catch (Exception e) {
LOGGER.error(
"Could not query sat server version after successful connect! Assuming untagged version 1",
e);
remoteVersion = 1;
}
String text = null;
if (remoteVersion > Version.VERSION) {
text = "Das von Ihnen verwendete Dozentenmodul ist zu alt, um mit dem Satelliten-Server zu verbinden.\n"
+ "Sie verwenden Version "
+ Version.VERSION
+ ", der Satellit "
+ remoteVersion
+ "\n"
+ "Aktuelle Version unter http://bwlehrpool.hs-offenburg.de/";
} else if (remoteVersion < Version.VERSION) {
text = "Das von Ihnen verwendete Dozentenmodul ist zu neu, um mit dem Satelliten-Server zu verbinden.\n"
+ "Sie verwenden Version " + Version.VERSION + ", der Satellit " + remoteVersion;
}
if (text != null) {
JOptionPane.showMessageDialog(null, text, "Fehler", JOptionPane.ERROR_MESSAGE);
}
LOGGER.debug("Post-processing login ...");
// TODO here do all the session data stuff
// TODO and the telling the sat Server who we are
LOGGER.debug("Checking token: " + SessionData.authToken);
try {
boolean authenticated = ThriftManager.getSatClient().authenticated(SessionData.authToken);
if (!authenticated) {
JOptionPane.showMessageDialog(null, "Sessionübergabe an den Satelliten fehlgeschlagen.",
"Fehler", JOptionPane.ERROR_MESSAGE);
return;
}
String pk_institution = ThriftManager.getSatClient().setInstitution(
person.verantwortlicher.getHochschule(), SessionData.authToken);
ThriftManager.getSatClient().setPerson(person.verantwortlicher.getUserID(),
SessionData.authToken, pk_institution);
} catch (TException e) {
JOptionPane.showMessageDialog(null, "Unerwarteter Fehler.\n\n" + e.toString(), "Fehler",
JOptionPane.ERROR_MESSAGE);
LOGGER.error("Unexpected exception", e);
return;
}
// at the end
showMainMenu();
}
/**
* Shows the next GUI's til the main menu. It checks if the user has already
* seen the bill of rights and/or the vmware license windows and shows them
* before continuing to the main menu.
*
* This function should be called on a successful login.
*/
private void showMainMenu() {
/**
*
* DISPLAY LICENSES / MAIN MENU
*
*/
if (!Config.getBillOfRights()) {
// display bill of rights?
GuiManager.show(new BillOfRights_GUI(), true);
} else {
// display vmware license?
if (!Config.getVmwareLicense()) {
GuiManager.show(new VmWareLink_GUI(), true);
} else {
// main menu
GuiManager.show(new MainMenue_GUI(), true);
}
}
}
/**
* Set connection status message, optionally show message box.
*
* @param color
* Color to display status message in.
* @param shortMessage
* The message to display.
* @param longMessage
* Optional message to show in a message box. null means don't
* show.
*/
private void setStatus(Color color, String shortMessage, String longMessage) {
LOGGER.info(shortMessage);
lblConnectionInfo.setForeground(color);
lblConnectionInfo.setText(shortMessage);
if (longMessage != null)
JOptionPane.showMessageDialog(null, longMessage, "Anmeldung fehlgeschlagen",
JOptionPane.ERROR_MESSAGE);
}
/**
* Toggle the elements needed for the different login types.
*
* @param type
* Type of the login to toggle. Valid are: - LOGIN_TYPE_BWIDM -
* LOGIN_TYPE_BWLEHRPOOL - LOGIN_TYPE_SATELLITE
*/
private void toggleLoginType(String type) {
LOGGER.info("Toggling to login method to: " + type);
panel.setVisible(false);
switch (type) {
case LOGIN_TYPE_BWIDM:
initIdpList();
panel.remove(lblSatIP);
panel.remove(lblSatellitenIp);
panel.add(idpChoice);
panel.add(lblIdp);
panel.add(LabelPass);
lblpass.setText("");
lblpass.setToolTipText("Bitte geben Sie Ihr bwIDM-Passwort ein.");
panel.add(lblpass);
lblusername.setToolTipText("Bitte geben Sie Ihren bwIDM-Benutzernamen ein.");
panel.revalidate();
panel.repaint();
panel.setVisible(true);
break;
case LOGIN_TYPE_BWLEHRPOOL:
panel.remove(idpChoice);
panel.remove(lblIdp);
panel.remove(lblSatIP);
panel.remove(lblSatellitenIp);
panel.add(LabelPass);
lblpass.setToolTipText("Bitte geben Sie Ihr bwLehrpool-Passwort ein.");
panel.add(lblpass);
lblusername.setToolTipText("Bitte geben Sie Ihr bwLehrpool-Benutzername ein.");
panel.revalidate();
panel.repaint();
panel.setVisible(true);
break;
case LOGIN_TYPE_SATELLITE:
panel.remove(idpChoice);
panel.remove(lblIdp);
panel.remove(LabelPass);
panel.remove(lblpass);
lblSatIP.setBounds(135, 85, 237, 20);
lblSatIP.setText("");
panel.add(lblSatIP);
lblSatellitenIp.setBounds(25, 85, 82, 20);
panel.add(lblSatellitenIp);
panel.revalidate();
panel.repaint();
panel.setVisible(true);
setStatus(Color.black, "Info: Bereit für bwIDM-Login", null);
break;
default:
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
List<OrganizationData> tempOrgs = null;
try {
tempOrgs = ThriftManager.getMasterClient().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.debug("Skipped bad organization (no ECPUrl): " + org.toString());
}
}
// now we build the list, lets sort it
Collections.sort(organizations, new Comparator<OrganizationData>() {
@Override
public int compare(OrganizationData o1, OrganizationData o2) {
return o1.displayName.compareTo(o2.displayName);
}
});
} 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);
}
if(Config.getIdP() != -1)
{
idpChoice.setSelectedIndex(Config.getIdP()); //set IdP preselction to saved value, if stored. 0 is default
}
}
@Override
protected void process(List<String> msgs) {
String currentMessage = msgs.get(msgs.size() - 1);
setStatus(Color.black, currentMessage, null);
}
};
worker.execute();
}
}// end class
|