diff options
| author | Jonathan Bauer | 2015-07-08 11:36:55 +0200 |
|---|---|---|
| committer | Jonathan Bauer | 2015-07-08 11:36:55 +0200 |
| commit | 900d8920b0427961a852321b077d1b2fadeb050f (patch) | |
| tree | d7decb784026ef11e5f782b2a55c42b4f01bc025 /dozentenmodul/src/main/java | |
| parent | [client] Added imageWindowComposite and early stage of wizard for creating/ed... (diff) | |
| download | tutor-module-900d8920b0427961a852321b077d1b2fadeb050f.tar.gz tutor-module-900d8920b0427961a852321b077d1b2fadeb050f.tar.xz tutor-module-900d8920b0427961a852321b077d1b2fadeb050f.zip | |
[client] authenticator for the direct masterserver login
Diffstat (limited to 'dozentenmodul/src/main/java')
| -rw-r--r-- | dozentenmodul/src/main/java/auth/BWLPAuthenticator.java | 50 | ||||
| -rw-r--r-- | dozentenmodul/src/main/java/gui/core/LoginGUI.java | 19 |
2 files changed, 69 insertions, 0 deletions
diff --git a/dozentenmodul/src/main/java/auth/BWLPAuthenticator.java b/dozentenmodul/src/main/java/auth/BWLPAuthenticator.java new file mode 100644 index 00000000..f619b453 --- /dev/null +++ b/dozentenmodul/src/main/java/auth/BWLPAuthenticator.java @@ -0,0 +1,50 @@ +package auth; + +import org.apache.log4j.Logger; +import org.apache.thrift.TException; +import org.openslx.bwlp.thrift.iface.SessionData; +import org.openslx.bwlp.thrift.iface.TAuthenticationException; +import org.openslx.bwlp.thrift.iface.UserInfo; +import org.openslx.thrifthelper.ThriftManager; + +import util.ShibbolethECP.ReturnCode; + +/** + * @author Jonathan Bauer + * + */ +public class BWLPAuthenticator implements BaseAuthenticator { + + /** + * Logger instance for this class + */ + private final static Logger LOGGER = Logger.getLogger(BWLPAuthenticator.class); + + @Override + public void login(String username, String password, + AuthenticatorCallback callback) throws TAuthenticationException { + + SessionData authResult = null; + // try to login user + try { + authResult = ThriftManager.getMasterClient().authenticate(username, password); + } catch (TException e) { + LOGGER.error("Thrift communication error: ", e); + return; + } + + // handle answer from server + if (authResult != null && authResult.authToken != null) { + UserInfo userInfo = null; + try { + userInfo = ThriftManager.getMasterClient().getUserFromToken(authResult.authToken); + } catch (TException e) { + LOGGER.error("Thrift communication error: ", e); + } + callback.postLogin(ReturnCode.NO_ERROR, userInfo); + } else { + // it should then show a corresponding error message! + callback.postLogin(ReturnCode.ERROR_OTHER, null); + } + } +} diff --git a/dozentenmodul/src/main/java/gui/core/LoginGUI.java b/dozentenmodul/src/main/java/gui/core/LoginGUI.java index 3e52df29..7718c0dd 100644 --- a/dozentenmodul/src/main/java/gui/core/LoginGUI.java +++ b/dozentenmodul/src/main/java/gui/core/LoginGUI.java @@ -19,6 +19,7 @@ import org.openslx.thrifthelper.ThriftManager; import util.ShibbolethECP.ReturnCode; import auth.BWIDMAuthenticator; +import auth.BWLPAuthenticator; import auth.BaseAuthenticator.AuthenticatorCallback; import edu.kit.scc.dei.ecplean.ECPAuthenticationException; import gui.GuiManager; @@ -188,6 +189,24 @@ public class LoginGUI extends LoginComposite { break; case BWLP: LOGGER.info("bwlp"); + BWLPAuthenticator bwlpAuth = new BWLPAuthenticator(); + try { + bwlpAuth.login(username, password, new AuthenticatorCallback() { + @Override + public void postLogin(ReturnCode returnCode, UserInfo user) { + // handle errors first + if (returnCode != ReturnCode.NO_ERROR && user == null) { + GuiManager.showMessage("Internal error!"); + } else { + // TODO: FOR DEBUGGING/DEV PURPOSES! + ThriftManager.setSatelliteAddress( "132.230.8.113" ); + GuiManager.addContent(new DisclaimerComposite(getShell())); + } + } + }); + } catch (TAuthenticationException e) { + GuiManager.showMessage(BAD_AUTH); + } break; case SAT: LOGGER.info("sat"); |
