summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/auth/BWIDMAuthenticator.java
blob: a5a99da741ed83e8bbd3a35b86375c63634fa5fe (plain) (blame)
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
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);
		}
	}
}