summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/auth/BWIDMAuthenticator.java
diff options
context:
space:
mode:
Diffstat (limited to 'dozentenmodul/src/main/java/auth/BWIDMAuthenticator.java')
-rw-r--r--dozentenmodul/src/main/java/auth/BWIDMAuthenticator.java62
1 files changed, 62 insertions, 0 deletions
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);
+ }
+ }
+}