comparison flys-client/src/main/java/de/intevation/flys/client/server/auth/was/Authenticator.java @ 2956:d7f76f197d89

Refactor GGInA authentication Move authentication related classes to de.intevation.fly.client.server.auth package. Abstract the authentication classes to allow other authentications beside WAS/GGInA. flys-client/trunk@4936 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Bjoern Ricks <bjoern.ricks@intevation.de>
date Wed, 11 Jul 2012 13:31:56 +0000
parents
children 71ba3cf3ec5e
comparison
equal deleted inserted replaced
2955:f1030909eeb6 2956:d7f76f197d89
1 package de.intevation.flys.client.server.auth.was;
2
3 import java.io.IOException;
4 import java.security.GeneralSecurityException;
5
6 import org.apache.http.HttpEntity;
7 import org.apache.http.HttpResponse;
8 import org.apache.http.client.HttpClient;
9 import org.apache.http.conn.scheme.Scheme;
10 import org.apache.http.conn.ssl.SSLSocketFactory;
11 import org.apache.http.impl.client.DefaultHttpClient;
12
13 import de.intevation.flys.client.server.GGInATrustStrategy;
14 import de.intevation.flys.client.server.auth.Authentication;
15 import de.intevation.flys.client.server.auth.AuthenticationException;
16
17 public class Authenticator implements de.intevation.flys.client.server.auth.Authenticator {
18
19 public Authentication auth(String username, String password, String encoding)
20 throws AuthenticationException, IOException {
21 try {
22 SSLSocketFactory sf = new SSLSocketFactory(
23 new GGInATrustStrategy());
24 Scheme https = new Scheme("https", 443, sf);
25 HttpClient httpclient = new DefaultHttpClient();
26 httpclient.getConnectionManager().getSchemeRegistry().register(https);
27
28 Request httpget = new Request("https://geoportal.bafg.de/" +
29 "administration/WAS", username, password, encoding);
30 HttpResponse response = httpclient.execute(httpget);
31 HttpEntity entity = response.getEntity();
32 if (entity == null) {
33 //FIXME throw AuthenticationException
34 return null;
35 }
36 else {
37 return new Response(entity, username, password);
38 }
39 }
40 catch(GeneralSecurityException e) {
41 throw new AuthenticationException(e);
42 }
43 }
44 }

http://dive4elements.wald.intevation.org