diff options
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/authentication/ShibbolethEcp.java')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/authentication/ShibbolethEcp.java | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/ShibbolethEcp.java b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/ShibbolethEcp.java index 6a594e6a..ce8bbe95 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/ShibbolethEcp.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/ShibbolethEcp.java @@ -9,11 +9,11 @@ import java.net.URL; import org.apache.http.HttpResponse; import org.apache.http.ParseException; import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.methods.HttpGet; import org.apache.http.util.EntityUtils; import org.apache.log4j.Logger; import org.openslx.bwlp.thrift.iface.AuthorizationError; import org.openslx.bwlp.thrift.iface.TAuthorizationException; +import org.openslx.dozmod.util.ProxyConfigurator; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -130,21 +130,26 @@ public class ShibbolethEcp { } // now init the authenticator for that idp and our static sp - final ECPAuthenticator auth = new ECPAuthenticator(user, pass, new URI(idpUrl), BWLP_SP); + final ECPAuthenticator auth = new ECPAuthenticator(ProxyConfigurator.getClient(), user, pass, new URI(idpUrl), BWLP_SP); + HttpResponse spResponse; try { - auth.authenticate(); + spResponse = auth.authenticate(); } catch (ECPAuthenticationException e) { LOGGER.error("ECP Authentication Exception, see trace: ", e); throw new TAuthorizationException(AuthorizationError.GENERIC_ERROR, e.getMessage()); } - // here test again for the SP's URL - final HttpGet testSp = new HttpGet(BWLP_SP); - final HttpResponse response = auth.getHttpClient().execute(testSp); - LOGGER.debug("SP request returned: " + response.getStatusLine()); - final String responseBody = EntityUtils.toString(response.getEntity()); + if (spResponse.getStatusLine().getStatusCode() != 200) { + LOGGER.error("SP does not return HTTP status code 200"); + throw new TAuthorizationException(AuthorizationError.GENERIC_ERROR, "SP says: " + + spResponse.getStatusLine().toString()); + } + + LOGGER.debug("Login complete, getting body"); + final String responseBody = EntityUtils.toString(spResponse.getEntity()); + try { lastResponse = GSON.fromJson(responseBody, ServiceProviderResponse.class); } catch (JsonSyntaxException e) { @@ -152,7 +157,7 @@ public class ShibbolethEcp { LOGGER.warn("Response was:\n" + responseBody); throw e; } - + // TODO: here we will need to parse the answer accordingly. // no errors, meaning everything worked fine. if (lastResponse.status.equals("unregistered")) { |