public HttpURLConnection buildHttpURLConnection(final URLConnection url) { return this.configureHttpsConnectionIfNeeded(url); }
public HttpsURLConnectionFactory(final HostnameVerifier verifier, final Properties config) { setHostnameVerifier(verifier); setSSLConfiguration(config); }
/** * Configures the connection with specific settings for secure http connections * If the connection instance is not a {@link HttpsURLConnection}, * no additional changes will be made and the connection itself is simply returned. * * @param conn the http connection */ private HttpURLConnection configureHttpsConnectionIfNeeded(final URLConnection conn) { if (conn instanceof HttpsURLConnection) { final HttpsURLConnection httpsConnection = (HttpsURLConnection) conn; final SSLSocketFactory socketFactory = this.createSSLSocketFactory(); if (socketFactory != null) { httpsConnection.setSSLSocketFactory(socketFactory); } if (this.hostnameVerifier != null) { httpsConnection.setHostnameVerifier(this.hostnameVerifier); } } return (HttpURLConnection) conn; }
@Before public void setUp() throws Exception { this.httpsURLConnectionFactory = new HttpsURLConnectionFactory(); }
InputStreamReader in = null; try { conn = factory.buildHttpURLConnection(constructedUrl.openConnection());
/** * Test method for {@link RegexHostnameVerifier#verify(String, SSLSession)}. */ public void testVerify() { final RegexHostnameVerifier verifier = new RegexHostnameVerifier("\\w+\\.vt\\.edu"); Assert.assertTrue(verifier.verify("a.vt.edu", null)); Assert.assertTrue(verifier.verify("host.vt.edu", null)); Assert.assertFalse(verifier.verify("1-host.vt.edu", null)); Assert.assertFalse(verifier.verify("mallory.example.com", null)); }
/** * Test method for {@link WhitelistHostnameVerifier#verify(String, javax.net.ssl.SSLSession)}. */ public void testVerify() { final WhitelistHostnameVerifier verifier = new WhitelistHostnameVerifier("red.vt.edu, green.vt.edu,blue.vt.edu"); Assert.assertTrue(verifier.verify("red.vt.edu", null)); Assert.assertTrue(verifier.verify("green.vt.edu", null)); Assert.assertTrue(verifier.verify("blue.vt.edu", null)); Assert.assertFalse(verifier.verify("purple.vt.edu", null)); }
public void testGetResponseFromServer() throws Exception { final String RESPONSE = "test1\r\ntest2"; server.content = RESPONSE.getBytes(server.encoding); final String responsedContent = CommonUtils.getResponseFromServer(new URL("http://localhost:8092"), new HttpsURLConnectionFactory(), null); assertEquals(RESPONSE, responsedContent); }
protected String retrieveResponseFromServer(final URL validationUrl, final String ticket) { final String request = String.format( SAML_REQUEST_TEMPLATE, generateId(), SamlUtils.formatForUtcTime(new Date()), ticket); HttpURLConnection conn = null; try { conn = this.getURLConnectionFactory().buildHttpURLConnection(validationUrl.openConnection()); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "text/xml"); conn.setRequestProperty("SOAPAction", "http://www.oasis-open.org/committees/security"); conn.setUseCaches(false); conn.setDoInput(true); conn.setDoOutput(true); final Charset charset = CommonUtils.isNotBlank(getEncoding()) ? Charset.forName(getEncoding()) : IOUtils.UTF8; conn.getOutputStream().write(request.getBytes(charset)); return IOUtils.readString(conn.getInputStream(), charset); } catch (final IOException e) { throw new RuntimeException("IO error sending HTTP request to /samlValidate", e); } finally { if (conn != null) { conn.disconnect(); } } }
protected final TicketValidator getTicketValidator(final FilterConfig filterConfig) { final String casServerUrlPrefix = getString(ConfigurationKeys.CAS_SERVER_URL_PREFIX); final Cas10TicketValidator validator = new Cas10TicketValidator(casServerUrlPrefix); validator.setRenew(getBoolean(ConfigurationKeys.RENEW)); final HttpURLConnectionFactory factory = new HttpsURLConnectionFactory(getHostnameVerifier(), getSSLConfig()); validator.setURLConnectionFactory(factory); validator.setEncoding(getString(ConfigurationKeys.ENCODING)); return validator; } }
protected String retrieveResponseFromServer(final URL validationUrl, final String ticket) { final String request = String.format( SAML_REQUEST_TEMPLATE, generateId(), SamlUtils.formatForUtcTime(new Date()), ticket); HttpURLConnection conn = null; try { conn = this.getURLConnectionFactory().buildHttpURLConnection(validationUrl.openConnection()); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "text/xml"); conn.setRequestProperty("SOAPAction", "http://www.oasis-open.org/committees/security"); conn.setUseCaches(false); conn.setDoInput(true); conn.setDoOutput(true); final Charset charset = CommonUtils.isNotBlank(getEncoding()) ? Charset.forName(getEncoding()) : IOUtils.UTF8; conn.getOutputStream().write(request.getBytes(charset)); return IOUtils.readString(conn.getInputStream(), charset); } catch (final IOException e) { throw new RuntimeException("IO error sending HTTP request to /samlValidate", e); } finally { if (conn != null) { conn.disconnect(); } } }
protected final TicketValidator getTicketValidator(final FilterConfig filterConfig) { final Saml11TicketValidator validator = new Saml11TicketValidator(getString(ConfigurationKeys.CAS_SERVER_URL_PREFIX)); final long tolerance = getLong(ConfigurationKeys.TOLERANCE); validator.setTolerance(tolerance); validator.setRenew(getBoolean(ConfigurationKeys.RENEW)); final HttpURLConnectionFactory factory = new HttpsURLConnectionFactory(getHostnameVerifier(), getSSLConfig()); validator.setURLConnectionFactory(factory); validator.setEncoding(getString(ConfigurationKeys.ENCODING)); return validator; } }
protected final TicketValidator getTicketValidator(final FilterConfig filterConfig) { final Saml11TicketValidator validator = new Saml11TicketValidator(getString(ConfigurationKeys.CAS_SERVER_URL_PREFIX)); final long tolerance = getLong(ConfigurationKeys.TOLERANCE); validator.setTolerance(tolerance); validator.setRenew(getBoolean(ConfigurationKeys.RENEW)); final HttpURLConnectionFactory factory = new HttpsURLConnectionFactory(getHostnameVerifier(), getSSLConfig()); validator.setURLConnectionFactory(factory); validator.setEncoding(getString(ConfigurationKeys.ENCODING)); return validator; } }
validator.setProxyGrantingTicketStorage(this.proxyGrantingTicketStorage); final HttpURLConnectionFactory factory = new HttpsURLConnectionFactory(getHostnameVerifier(), getSSLConfig()); validator.setURLConnectionFactory(factory);
new URL( clearPassRequestUrl ), new HttpsURLConnectionFactory(), "UTF-8" ); password = new PasswordData( XmlUtils.getTextForElement( response, "credentials" ) );