Mercurial > dive4elements > river
diff gwt-client/src/main/java/org/dive4elements/river/client/server/auth/was/Authenticator.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-client/src/main/java/org/dive4elements/river/client/server/auth/was/Authenticator.java@821a02bbfb4e |
children | 172338b1407f |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/server/auth/was/Authenticator.java Thu Apr 25 15:23:37 2013 +0200 @@ -0,0 +1,62 @@ +package org.dive4elements.river.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.StatusLine; +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 org.dive4elements.river.client.server.GGInATrustStrategy; +import org.dive4elements.river.client.server.auth.Authentication; +import org.dive4elements.river.client.server.auth.AuthenticationException; +import org.dive4elements.river.client.server.features.Features; + +public class Authenticator +implements org.dive4elements.river.client.server.auth.Authenticator { + + @Override + public Authentication auth( + String username, + String password, + String encoding, + Features features + ) 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); + StatusLine stline = response.getStatusLine(); + if (stline.getStatusCode() != 200) { + throw new AuthenticationException("GGInA Server Error. " + + "Statuscode: " + stline.getStatusCode() + + ". Reason: " + stline.getReasonPhrase()); + } + HttpEntity entity = response.getEntity(); + if (entity == null) { + //FIXME throw AuthenticationException + return null; + } + else { + return new Response(entity, username, password, features); + } + } + catch(GeneralSecurityException e) { + throw new AuthenticationException(e); + } + } +}