From bd999de22f4ff49521c608d66879d07218753c43 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 8 Aug 2017 13:55:14 +0200 Subject: Update apache httpclient, minor cleanups --- .../edu/kit/scc/dei/ecplean/ECPAuthenticator.java | 27 ++++++++-------------- 1 file changed, 10 insertions(+), 17 deletions(-) (limited to 'src/main/java/edu/kit/scc/dei/ecplean/ECPAuthenticator.java') diff --git a/src/main/java/edu/kit/scc/dei/ecplean/ECPAuthenticator.java b/src/main/java/edu/kit/scc/dei/ecplean/ECPAuthenticator.java index 60833a1..ce41f62 100644 --- a/src/main/java/edu/kit/scc/dei/ecplean/ECPAuthenticator.java +++ b/src/main/java/edu/kit/scc/dei/ecplean/ECPAuthenticator.java @@ -13,8 +13,7 @@ import org.apache.http.ParseException; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.DefaultHttpClient; -import org.apache.http.params.HttpParams; +import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.util.EntityUtils; import org.w3c.dom.Document; import org.w3c.dom.Node; @@ -23,24 +22,19 @@ import org.xml.sax.SAXException; public class ECPAuthenticator extends ECPAuthenticatorBase { - public ECPAuthenticator(DefaultHttpClient client, String username, String password, + public ECPAuthenticator(CloseableHttpClient client, String username, String password, URI idpEcpEndpoint, URI spUrl) { super(client); authInfo = new ECPAuthenticationInfo(username, password, idpEcpEndpoint, spUrl); - authInfo.setAuthState(ECPAuthState.NOT_STARTED); } public ECPAuthenticator(String username, String password, URI idpEcpEndpoint, URI spUrl) { - this(new DefaultHttpClient(), username, password, idpEcpEndpoint, spUrl); - HttpParams params = client.getParams(); - params.setParameter("http.socket.timeout", 6000); - params.setParameter("http.connection.timeout", 3000); - params.setParameter("http.connection-manager.timeout", new Long(3000)); - params.setParameter("http.protocol.head-body-timeout", 5000); + super(); + authInfo = new ECPAuthenticationInfo(username, password, idpEcpEndpoint, spUrl); } - public void authenticate() throws ECPAuthenticationException { + public HttpResponse authenticate() throws ECPAuthenticationException { logger.info("Starting authentication"); logger.info("Contacting SP " + authInfo.getSpUrl()); @@ -59,6 +53,7 @@ public class ECPAuthenticator extends ECPAuthenticatorBase { try { httpResponse = client.execute(httpGet); responseBody = EntityUtils.toString(httpResponse.getEntity()); + httpGet.reset(); } catch (IOException | ParseException e) { logger.debug("Initial SP Request failed"); throw new ECPAuthenticationException(e); @@ -123,7 +118,8 @@ public class ECPAuthenticator extends ECPAuthenticatorBase { try { httpPost.setEntity(new StringEntity(documentToString(idpResponse))); httpResponse = client.execute(httpPost); - responseBody = EntityUtils.toString(httpResponse.getEntity()); + logger.info("Asserting resulted in " + httpResponse.getStatusLine()); + httpPost.reset(); } catch (TransformerException | IOException e) { logger.debug("Could not post assertion back to SP"); throw new ECPAuthenticationException(e); @@ -133,14 +129,11 @@ public class ECPAuthenticator extends ECPAuthenticatorBase { httpGet = new HttpGet(authInfo.getSpUrl().toString()); try { httpResponse = client.execute(httpGet); - responseBody = EntityUtils.toString(httpResponse.getEntity()); - - logger.info(responseBody); - } catch (IOException | ParseException e) { + } catch (IOException e) { logger.debug("Could not request original URL"); throw new ECPAuthenticationException(e); } - + return httpResponse; } private String getStatusCode(Document idpResponse) { -- cgit v1.2.3-55-g7522