diff options
| author | Jonathan Bauer | 2015-07-03 18:47:55 +0200 |
|---|---|---|
| committer | Jonathan Bauer | 2015-07-03 18:47:55 +0200 |
| commit | 66080be14336a7d0b06bc244249fcf0d528ea449 (patch) | |
| tree | 3f5a81734bfea8837efbb4793c5263b805c40fc2 /dozentenmodul/src/main/java/auth | |
| parent | Merge branch 'v1.1' of git.openslx.org:openslx-ng/tutor-module into v1.1 (diff) | |
| download | tutor-module-66080be14336a7d0b06bc244249fcf0d528ea449.tar.gz tutor-module-66080be14336a7d0b06bc244249fcf0d528ea449.tar.xz tutor-module-66080be14336a7d0b06bc244249fcf0d528ea449.zip | |
[client] bwIDM Authentication implemented, yet to be finalized.
Diffstat (limited to 'dozentenmodul/src/main/java/auth')
| -rw-r--r-- | dozentenmodul/src/main/java/auth/Authenticator.java | 9 | ||||
| -rw-r--r-- | dozentenmodul/src/main/java/auth/BWIDMAuthenticator.java | 62 | ||||
| -rw-r--r-- | dozentenmodul/src/main/java/auth/BaseAuthenticator.java | 31 |
3 files changed, 93 insertions, 9 deletions
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 |
