From 66080be14336a7d0b06bc244249fcf0d528ea449 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Fri, 3 Jul 2015 18:47:55 +0200 Subject: [client] bwIDM Authentication implemented, yet to be finalized. --- dozentenmodul/pom.xml | 2 +- .../src/main/java/auth/Authenticator.java | 9 -- .../src/main/java/auth/BWIDMAuthenticator.java | 62 ++++++++ .../src/main/java/auth/BaseAuthenticator.java | 31 ++++ dozentenmodul/src/main/java/gui/GuiManager.java | 31 +++- .../src/main/java/gui/core/LoginComposite.java | 148 ++++++------------ dozentenmodul/src/main/java/gui/core/LoginGUI.java | 173 +++++++++++++++++++++ .../src/main/java/util/ResourceLoader.java | 111 +++++-------- .../src/main/java/util/ShibbolethECP.java | 5 +- 9 files changed, 388 insertions(+), 184 deletions(-) delete mode 100644 dozentenmodul/src/main/java/auth/Authenticator.java create mode 100644 dozentenmodul/src/main/java/auth/BWIDMAuthenticator.java create mode 100644 dozentenmodul/src/main/java/auth/BaseAuthenticator.java create mode 100644 dozentenmodul/src/main/java/gui/core/LoginGUI.java diff --git a/dozentenmodul/pom.xml b/dozentenmodul/pom.xml index b4c51dce..3e4d2195 100644 --- a/dozentenmodul/pom.xml +++ b/dozentenmodul/pom.xml @@ -231,7 +231,7 @@ log4j log4j - [1.2.10,1.2.20] + [1.2.15,1.2.17] compile diff --git a/dozentenmodul/src/main/java/auth/Authenticator.java b/dozentenmodul/src/main/java/auth/Authenticator.java deleted file mode 100644 index fb3a7050..00000000 --- a/dozentenmodul/src/main/java/auth/Authenticator.java +++ /dev/null @@ -1,9 +0,0 @@ -package auth; - -public class Authenticator { - - public boolean auth(String username, String pass) { - return false; - - } -} diff --git a/dozentenmodul/src/main/java/auth/BWIDMAuthenticator.java b/dozentenmodul/src/main/java/auth/BWIDMAuthenticator.java new file mode 100644 index 00000000..a5a99da7 --- /dev/null +++ b/dozentenmodul/src/main/java/auth/BWIDMAuthenticator.java @@ -0,0 +1,62 @@ +package auth; + +import org.apache.log4j.Logger; +import org.apache.thrift.TException; +import org.openslx.bwlp.thrift.iface.TInvalidTokenException; +import org.openslx.bwlp.thrift.iface.UserInfo; +import org.openslx.thrifthelper.ThriftManager; + +import util.ShibbolethECP; +import util.ShibbolethECP.ReturnCode; +import edu.kit.scc.dei.ecplean.ECPAuthenticationException; + +/** + * @author Jonathan Bauer + * + */ +public class BWIDMAuthenticator implements BaseAuthenticator { + + /** + * Logger instance for this class + */ + private final static Logger LOGGER = Logger.getLogger(BWIDMAuthenticator.class); + + private final String ecpUrl; + + public BWIDMAuthenticator(String ecpUrl) { + // first lets check the given ecpUrl + if (!ecpUrl.isEmpty()) + this.ecpUrl = ecpUrl; + else + this.ecpUrl = null; + // NOTE: the actual check for a correct URI will be done by + // the ECP client. + } + + @Override + public void login(String username, String password, + AuthenticatorCallback callback) throws ECPAuthenticationException { + // sanity check on the ecpUrl, should have been set + + ReturnCode ret; + try { + ret = ShibbolethECP.doLogin(this.ecpUrl, username, password); + } catch (ECPAuthenticationException e) { + LOGGER.error("Bad credentials, see trace: ", e); + throw e; + } + if (ret == ReturnCode.NO_ERROR) { + UserInfo userInfo; + try { + userInfo = ThriftManager.getMasterClient().getUserFromToken(ShibbolethECP.getResponse().token); + } catch (TInvalidTokenException e) { + LOGGER.error("Masterserver does not accepts the token received from the Service Provider. See trace: ", e); + return; + } catch (TException e) { + LOGGER.error("Thrift transport error, see trace: ", e); + return; + } + callback.postLogin(userInfo); + } + } +} diff --git a/dozentenmodul/src/main/java/auth/BaseAuthenticator.java b/dozentenmodul/src/main/java/auth/BaseAuthenticator.java new file mode 100644 index 00000000..bebbff02 --- /dev/null +++ b/dozentenmodul/src/main/java/auth/BaseAuthenticator.java @@ -0,0 +1,31 @@ +package auth; + +import org.openslx.bwlp.thrift.iface.UserInfo; + +import edu.kit.scc.dei.ecplean.ECPAuthenticationException; + +/** + * @author Jonathan Bauer + * + */ +public interface BaseAuthenticator { + + /** + * Callback interface to the login to be called after a login + * Note that this will be called after every login, independent + * of the success of the operation. This way the GUI can show a + * corresponding message to the user. + */ + interface AuthenticatorCallback { + void postLogin(UserInfo user); + } + /** + * Definition of the generic login method. + * + * @param username The username as String. + * @param password The password as String. + * @param callback The callback function to be called after the login + * @throws ECPAuthenticationException + */ + void login(String username, String password, AuthenticatorCallback callback) throws ECPAuthenticationException; +} \ No newline at end of file diff --git a/dozentenmodul/src/main/java/gui/GuiManager.java b/dozentenmodul/src/main/java/gui/GuiManager.java index ae97d90b..8e28409c 100644 --- a/dozentenmodul/src/main/java/gui/GuiManager.java +++ b/dozentenmodul/src/main/java/gui/GuiManager.java @@ -1,5 +1,6 @@ package gui; +import org.apache.log4j.Logger; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; @@ -10,10 +11,14 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Monitor; import org.eclipse.swt.widgets.Shell; public abstract class GuiManager { + + private final static Logger LOGGER = Logger.getLogger(GuiManager.class); + static Shell mainShell; static Composite contentComposite; static Display display; @@ -48,6 +53,29 @@ public abstract class GuiManager { } } + // TODO use showMessageBox + public static void showMessage(final String message) { + MessageBox msgBox = new MessageBox(mainShell, SWT.ICON_INFORMATION); + msgBox.setText("Information"); + msgBox.setMessage(message); + int ret = msgBox.open(); + } +// /** +// * Generic helper to show a message box to the user, and optionally log the message to the log file. +// * +// * @param message Message to display. Can be multi line. +// * @param messageType Type of message (warning, information) +// * @param logger Logger instance to log to. Can be null. +// * @param exception Exception related to this message. Can be null. +// */ +// public static void showMessageBox(String message, MessageType messageType, Logger logger, +// Throwable exception) { +// if (logger != null) +// logger.log(messageType.logPriority, message, exception); +// if (exception != null) +// message += "\n\n" + exception.getClass().getSimpleName(); +// JOptionPane.showMessageDialog(mainWindow, message, messageType.title, messageType.optionPaneId); +// } public static Display getDisplay(){ return display; @@ -80,7 +108,7 @@ public abstract class GuiManager { // Set layout for the mainshell, items added to the shell should get a gridData mainShell.setLayout(new GridLayout(1, true)); - addContent(new gui.core.LoginComposite(mainShell)); + addContent(new gui.core.LoginGUI(mainShell)); // center the window on the primary monitor @@ -96,6 +124,7 @@ public abstract class GuiManager { mainShell.pack(); mainShell.open(); + LOGGER.info("GUI initialised."); while (!mainShell.isDisposed()) { if (!display.readAndDispatch()) diff --git a/dozentenmodul/src/main/java/gui/core/LoginComposite.java b/dozentenmodul/src/main/java/gui/core/LoginComposite.java index 5a387e8f..060b1c61 100644 --- a/dozentenmodul/src/main/java/gui/core/LoginComposite.java +++ b/dozentenmodul/src/main/java/gui/core/LoginComposite.java @@ -2,9 +2,8 @@ package gui.core; import gui.GuiManager; +import org.apache.log4j.Logger; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.layout.GridData; @@ -19,21 +18,37 @@ import org.eclipse.swt.widgets.Text; public class LoginComposite extends Composite { + private final static Logger LOGGER = Logger.getLogger(LoginComposite.class); + + protected enum LOGIN_TYPE { + BWIDM, BWLP, SAT + } + + protected LOGIN_TYPE loginType = LOGIN_TYPE.BWIDM; + private Image titleImage; - // textfield of the username - private Text usernameText; + // textfields for the username/password + protected Text usernameText; + protected Text passwordText; - // textfield of the password - private Text passwordText; + // ComboBox/label for the IDP + protected final Combo idpCombo; + protected final Label idpText; - String title = "Dozmod - Login"; - String authenticationGroupLabel = "Authentifizierungsart"; + // buttons + protected final Button loginButton; + protected final Button saveUsernameCheck; + protected final Button[] authButtons; + private static final String title = "Dozmod - Login"; + private static final String authenticationGroupLabel = "Authentifizierungsart"; /** * Create a new login composite - * @param mainShell The shell it should be added to + * + * @param mainShell + * The shell it should be added to */ public LoginComposite(final Shell mainShell) { super(mainShell, SWT.NONE); @@ -67,8 +82,7 @@ public class LoginComposite extends Composite { authGroup.setLayoutData(gridData); // add the authentication method selection buttons - Button[] authButtons = new Button[3]; - + authButtons = new Button[3]; authButtons[0] = new Button(authGroup, SWT.RADIO); authButtons[0].setSelection(true); authButtons[0].setText("Authentifizierung über bwIDM"); @@ -81,11 +95,10 @@ public class LoginComposite extends Composite { authButtons[1].setLayoutData(gridData); authButtons[2] = new Button(authGroup, SWT.RADIO); - authButtons[2].setText("Direkte Verbindung zum Satteliten"); + authButtons[2].setText("Direkte Verbindung zum Satelliten"); gridData = new GridData(GridData.FILL, GridData.FILL, true, true); authButtons[2].setLayoutData(gridData); - // group for the login mask final Group loginGroup = new Group(this, SWT.NONE); loginGroup.setText("Zugangsdaten"); @@ -96,111 +109,40 @@ public class LoginComposite extends Composite { gridData.heightHint = 150; loginGroup.setLayoutData(gridData); - - final Label idpText = new Label(loginGroup, SWT.NONE); + idpText = new Label(loginGroup, SWT.NONE); idpText.setText("IdP:"); - - final Combo idpCombo = new Combo(loginGroup, SWT.DROP_DOWN | SWT.READ_ONLY); - idpCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); - - fillIdPCombo(idpCombo); - + idpCombo = new Combo(loginGroup, SWT.DROP_DOWN | SWT.READ_ONLY); + idpCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, + false)); new Label(loginGroup, SWT.NONE).setText("Benutzername:"); usernameText = new Text(loginGroup, SWT.SINGLE | SWT.BORDER); - usernameText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); + usernameText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, + true, false)); new Label(loginGroup, SWT.NONE).setText("Passwort:"); passwordText = new Text(loginGroup, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD); - passwordText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); - Button loginButton = new Button(loginGroup, SWT.PUSH); + passwordText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, + true, false)); + // login button + loginButton = new Button(loginGroup, SWT.PUSH); loginButton.setText("Login"); - Button saveUsernameCheck = new Button(loginGroup, SWT.CHECK); + saveUsernameCheck = new Button(loginGroup, SWT.CHECK); saveUsernameCheck.setText("Benutzername speichern"); - - // actions of the login button - loginButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - clickedLoginButton(); - } - }); - - // for save username checkbox. - saveUsernameCheck.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - clickedSaveUsernameCheck(); - } - }); - - // selecting the "Authentifizierung über bwIDM" radio button - authButtons[0].addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - idpText.setVisible(true); - idpCombo.setVisible(true); - } - }); - - // selecting the "Test-Zugang über bwIDM" radio button - authButtons[1].addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - idpText.setVisible(false); - idpCombo.setVisible(false); - } - }); - - authButtons[2].setEnabled(false); - // selecting the "Direkte Verbindung zum Satteliten" radio button - authButtons[2].addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - idpText.setVisible(false); - idpCombo.setVisible(false); - } - }); } - - - // - // logical functions for GUI - // - - /** - * function to execute when checking the saveUsername checkbox - */ - protected void clickedSaveUsernameCheck() { - System.out.println("Checkboxtoggle"); - } - - - /** - * function to execute when clicking the login button - */ - protected void clickedLoginButton() { - GuiManager.addContent(new DisclaimerComposite(getShell())); - } - - - /** - * fill the idpCombo with idpCombo.add(String) - * @param idpCombo - */ - protected void fillIdPCombo(Combo idpCombo) { - idpCombo.add("No Entries!"); - } - - - private void loadImage(){ + private void loadImage() { try { - titleImage = new Image(GuiManager.getDisplay(), getClass().getResourceAsStream("/img/Logo_bwLehrpool.png")); + // TODO use the ResourceLoader class to load the logo + // this way, we can be sure to get an image + // (since the ResourceLoader always returns an image, + // even if it cannot load the specified one). + titleImage = new Image(GuiManager.getDisplay(), getClass() + .getResourceAsStream("/img/Logo_bwLehrpool.png")); ImageData imgData = titleImage.getImageData(); - imgData = imgData.scaledTo(imgData.width/5, imgData.height/5); + imgData = imgData.scaledTo(imgData.width / 5, imgData.height / 5); titleImage = new Image(GuiManager.getDisplay(), imgData); } catch (Exception e) { System.out.println("Cannot load image"); diff --git a/dozentenmodul/src/main/java/gui/core/LoginGUI.java b/dozentenmodul/src/main/java/gui/core/LoginGUI.java new file mode 100644 index 00000000..5c329d5d --- /dev/null +++ b/dozentenmodul/src/main/java/gui/core/LoginGUI.java @@ -0,0 +1,173 @@ +package gui.core; + +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import org.apache.log4j.Logger; +import org.apache.thrift.TException; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.widgets.Shell; +import org.openslx.bwlp.thrift.iface.Organization; +import org.openslx.bwlp.thrift.iface.UserInfo; +import org.openslx.thrifthelper.ThriftManager; + +import auth.BWIDMAuthenticator; +import auth.BaseAuthenticator.AuthenticatorCallback; +import edu.kit.scc.dei.ecplean.ECPAuthenticationException; +import gui.GuiManager; + +public class LoginGUI extends LoginComposite { + + private final static Logger LOGGER = Logger.getLogger(LoginGUI.class); + + private final String NO_USERNAME = "Kein Benutzername angegeben!"; + private final String NO_PASSWORD = "Kein Passwort angegeben!"; + + private String username = null; + private String password = null; + + /** + * @param mainShell + */ + public LoginGUI(final Shell mainShell) { + // call the constructor of the superclass + super(mainShell); + + // entries in the combo + List orgs = null; + try { + orgs = ThriftManager.getMasterClient().getOrganizations(); + } catch (TException e) { + LOGGER.error( + "Could not fetch the IdP list from the masterserver! See trace:", e); + // in this case, we can just call the default fillIdPCombo method of the + // superclass + idpCombo.add("No entries"); + } + // all fine, lets sort it + Collections.sort(orgs, new Comparator() { + public int compare(Organization o1, Organization o2) { + return o1.getDisplayName().compareTo(o2.getDisplayName()); + } + }); + for (Organization o : orgs) { + idpCombo.add(o.displayName); + idpCombo.setData(o.displayName, o); + } + idpCombo.select(0); + + // actions of the login button + loginButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + try { + doLogin(loginType); + } catch (ECPAuthenticationException ae) { + LOGGER.error("Authentication error, see trace: ", ae); + GuiManager.showMessage(ae.getMessage()); + } + } + }); + + // for save username checkbox. + saveUsernameCheck.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + // clickedSaveUsernameCheck(); + } + }); + + // selecting the "Authentifizierung über bwIDM" radio button + authButtons[0].addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + idpText.setVisible(true); + idpCombo.setVisible(true); + loginType = LOGIN_TYPE.BWIDM; + } + }); + + // selecting the "Test-Zugang mit festem Benutzer" radio button + authButtons[1].addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + idpText.setVisible(false); + idpCombo.setVisible(false); + loginType = LOGIN_TYPE.BWLP; + } + }); + + authButtons[2].setEnabled(false); + // selecting the "Direkte Verbindung zum Satteliten" radio button + authButtons[2].addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + idpText.setVisible(false); + idpCombo.setVisible(false); + loginType = LOGIN_TYPE.SAT; + } + }); + } + + /** + * Actually do the login using the username/password in the field using the + * authentication mechanism corresponding to the selected authButton + * @throws ECPAuthenticationException + */ + private void doLogin(LOGIN_TYPE loginType) throws ECPAuthenticationException { + // here we only check for the fields + username = usernameText.getText(); + password = passwordText.getText(); + // login clicked, lets first read the fields + if (username == null) { + // tell the GUIManager to show an error to the user + // TODO either popup or in the bottom status bar + GuiManager.showMessage(NO_USERNAME); + return; + } + if (password == null) { + // tell the GUIManager to show an error to the user + // TODO either popup or in the bottom status bar + GuiManager.showMessage(NO_PASSWORD); + return; + } + // get the index of the selected item in the combobox + int selectionIndex = idpCombo.getSelectionIndex(); + if (selectionIndex == -1) { + LOGGER + .error("No IdP is selected in the combobox. There should be a default value!"); + return; + } + Organization selectedOrg = + (Organization) idpCombo.getData(idpCombo.getItem(selectionIndex)); + + // now switch over the login types. + switch (loginType) { + case BWIDM: + BWIDMAuthenticator bwidmAuth = new BWIDMAuthenticator( + selectedOrg.getEcpUrl()); + bwidmAuth.login(username, password, new AuthenticatorCallback() { + @Override + public void postLogin(UserInfo user) { + LOGGER.info(user.firstName + " " + user.lastName); + if (user != null) + GuiManager.addContent(new DisclaimerComposite(getShell())); + } + }); + break; + case BWLP: + LOGGER.info("bwlp"); + break; + case SAT: + LOGGER.info("sat"); + break; + default: + LOGGER.error("derp"); + break; + } + return; + + } +} diff --git a/dozentenmodul/src/main/java/util/ResourceLoader.java b/dozentenmodul/src/main/java/util/ResourceLoader.java index 731cedeb..8ad23601 100644 --- a/dozentenmodul/src/main/java/util/ResourceLoader.java +++ b/dozentenmodul/src/main/java/util/ResourceLoader.java @@ -1,9 +1,9 @@ package util; -import java.awt.Color; -import java.awt.Font; +import gui.GuiManager; + import java.awt.Graphics2D; -import java.awt.font.FontRenderContext; +import java.awt.SystemColor; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.net.URL; @@ -12,11 +12,20 @@ import javax.swing.ImageIcon; import org.apache.commons.io.IOUtils; import org.apache.log4j.Logger; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontMetrics; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Text; /** - * Helper class for loading resources. - * This should be error safe loaders with a fall back in case the - * requested resource can't be found, or isn't of the expected type. + * Helper class for loading resources. This should be error safe loaders with a + * fall back in case the requested resource can't be found, or isn't of the + * expected type. */ public class ResourceLoader { @@ -25,91 +34,57 @@ public class ResourceLoader { */ private final static Logger LOGGER = Logger.getLogger(ResourceLoader.class); - /** - * Load the given resource as an ImageIcon. - * This is guaranteed to never throw an Exception and always return - * an ImageIcon. If the requested resource could not be loaded, - * an icon is generated, containing an error message. If even that - * fails, an empty icon is returned. - * @param path Resource path to load - * @param description Icon description - * @return ImageIcon instance - */ - public static ImageIcon getIcon(String path, String description) { - URL url = ResourceLoader.class.getResource(path); - if (url == null) { + public static ImageData getImageData(String path) { + + ImageData _imgData = null; + URL _url = ResourceLoader.class.getResource(path); + if (_url == null) { LOGGER.error("Resource not found: " + path); + return errorIcon("nope").getImageData(); } else { try { - return new ImageIcon(url, description); + _imgData = new ImageData(_url.openStream()); } catch (Exception e) { - LOGGER.error("Resource not loadable: " + path); + LOGGER.error("Resource not loadable: " + path + ". See trace: ", e); + return errorIcon("nope").getImageData(); } - } - // If we reach here loading failed, create image containing error - // message - try { - return errorIcon("Invalid Resource: " + path); - } catch (Throwable t) { - return new ImageIcon(); + return _imgData; } } - - /** - * Load the given resource as an ImageIcon. - * This is guaranteed to never throw an Exception and always return - * an ImageIcon. If the requested resource could not be loaded, - * an icon is generated, containing an error message. If even that - * fails, an empty icon is returned. - * @param path Resource path to load - * @return ImageIcon instance - */ - public static ImageIcon getIcon(String path) { - return getIcon(path, path); - } - /** + /** * Helper that will create an icon with given text. * @param errorText Text to render to icon * @return the icon */ - private static ImageIcon errorIcon(String errorText) { - Font font = new Font("Tahoma", Font.PLAIN, 20); - + private static Image errorIcon(String errorText) { + GC gc = new GC(GuiManager.getDisplay()); + Font font = new Font(GuiManager.getDisplay(), "Tahoma", 20, SWT.NORMAL); + gc.setFont(font); // get dimensions of text - FontRenderContext frc = new FontRenderContext(null, true, true); - Rectangle2D bounds = font.getStringBounds(errorText, frc); - int w = (int) bounds.getWidth(); - int h = (int) bounds.getHeight(); - - // create a BufferedImage object - BufferedImage image = new BufferedImage(w, h, - BufferedImage.TYPE_INT_RGB); - Graphics2D g = image.createGraphics(); - - // set color and other parameters - g.setColor(Color.WHITE); - g.fillRect(0, 0, w, h); - g.setColor(Color.RED); - g.setFont(font); - - g.drawString(errorText, (float) bounds.getX(), (float) -bounds.getY()); - - g.dispose(); - return new ImageIcon(image, "ERROR"); + Image image = new Image(GuiManager.getDisplay(), gc.stringExtent(errorText).x, gc.stringExtent(errorText).y); + GC gc2 = new GC(image); + gc2.setBackground(GuiManager.getDisplay().getSystemColor(SWT.COLOR_CYAN)); + gc2.drawText(errorText, 0, 0); + gc2.dispose(); + return image; } /** * Tries to load the given resource treating it as a text file - * @param path Resource path to load + * + * @param path + * Resource path to load * @return content of the loaded resource as String */ public static String getTextFile(String path) { String fileContent = null; try { - fileContent = IOUtils.toString(ResourceLoader.class.getResourceAsStream(path)); + fileContent = IOUtils.toString(ResourceLoader.class + .getResourceAsStream(path)); } catch (Exception e) { - LOGGER.error("IO error while trying to load resource '" + path + "'. See trace: ", e); + LOGGER.error("IO error while trying to load resource '" + path + + "'. See trace: ", e); } if (fileContent != null) { diff --git a/dozentenmodul/src/main/java/util/ShibbolethECP.java b/dozentenmodul/src/main/java/util/ShibbolethECP.java index a3e13a38..f3e35400 100644 --- a/dozentenmodul/src/main/java/util/ShibbolethECP.java +++ b/dozentenmodul/src/main/java/util/ShibbolethECP.java @@ -98,8 +98,9 @@ public class ShibbolethECP { * Password as String. * @return * true if login worked, false otherwise. + * @throws ECPAuthenticationException */ - public static ReturnCode doLogin(final String idpUrl, final String user, final String pass) { + public static ReturnCode doLogin(final String idpUrl, final String user, final String pass) throws ECPAuthenticationException { // first lets do some sanity checks if (BWLP_SP == null) { @@ -131,7 +132,7 @@ public class ShibbolethECP { auth.authenticate(); } catch (ECPAuthenticationException e) { LOGGER.error("ECP Authentication Exception, see trace: ", e); - return ReturnCode.ERROR_IDP; + throw e; } // here test again for the SPURL HttpGet testSp = new HttpGet(BWLP_SP); -- cgit v1.2.3-55-g7522