Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/auth/was/Authenticator.java Wed Jul 11 13:31:56 2012 +0000 @@ -0,0 +1,44 @@ +package de.intevation.flys.client.server.auth.was; + +import java.io.IOException; +import java.security.GeneralSecurityException; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.conn.scheme.Scheme; +import org.apache.http.conn.ssl.SSLSocketFactory; +import org.apache.http.impl.client.DefaultHttpClient; + +import de.intevation.flys.client.server.GGInATrustStrategy; +import de.intevation.flys.client.server.auth.Authentication; +import de.intevation.flys.client.server.auth.AuthenticationException; + +public class Authenticator implements de.intevation.flys.client.server.auth.Authenticator { + + public Authentication auth(String username, String password, String encoding) + throws AuthenticationException, IOException { + try { + SSLSocketFactory sf = new SSLSocketFactory( + new GGInATrustStrategy()); + Scheme https = new Scheme("https", 443, sf); + HttpClient httpclient = new DefaultHttpClient(); + httpclient.getConnectionManager().getSchemeRegistry().register(https); + + Request httpget = new Request("https://geoportal.bafg.de/" + + "administration/WAS", username, password, encoding); + HttpResponse response = httpclient.execute(httpget); + HttpEntity entity = response.getEntity(); + if (entity == null) { + //FIXME throw AuthenticationException + return null; + } + else { + return new Response(entity, username, password); + } + } + catch(GeneralSecurityException e) { + throw new AuthenticationException(e); + } + } +}