Example usage for org.apache.http.conn.ssl SSLSocketFactory getSystemSocketFactory

List of usage examples for org.apache.http.conn.ssl SSLSocketFactory getSystemSocketFactory

Introduction

In this page you can find the example usage for org.apache.http.conn.ssl SSLSocketFactory getSystemSocketFactory.

Prototype

public static SSLSocketFactory getSystemSocketFactory() throws SSLInitializationException 

Source Link

Document

Obtains default SSL socket factory with an SSL context based on system properties as described in <a href="http://docs.oracle.com/javase/1.5.0/docs/guide/security/jsse/JSSERefGuide.html"> "JavaTM Secure Socket Extension (JSSE) Reference Guide for the JavaTM 2 Platform Standard Edition 5</a>

Usage

From source file:ddf.test.itests.platform.TestSecurity.java

@Test
public void testBadX509TokenSTS() throws Exception {
    String onBehalfOf = "<wst:OnBehalfOf>\n"
            + "                    <wsse:BinarySecurityToken xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\" ValueType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3\" >\n"
            + BAD_X509_TOKEN + "                   </wsse:BinarySecurityToken>\n"
            + "                </wst:OnBehalfOf>\n";
    String body = getSoapEnvelope(onBehalfOf);

    given().auth()/*w w  w.  j a va 2 s. c om*/
            .certificate(KEY_STORE_PATH, PASSWORD,
                    certAuthSettings().sslSocketFactory(SSLSocketFactory.getSystemSocketFactory()))
            .log().all().body(body).header("Content-Type", "text/xml; charset=utf-8")
            .header("SOAPAction", "http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue").expect()
            .statusCode(equalTo(500)).when().post(SERVICE_ROOT.getUrl() + "/SecurityTokenService").then().log()
            .all();

}

From source file:ddf.test.itests.platform.TestSecurity.java

@Test
public void testX509TokenSTS() throws Exception {
    String onBehalfOf = "<wst:OnBehalfOf>\n"
            + "<wsse:BinarySecurityToken xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" "
            + "EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\" "
            + "ValueType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3\" >"
            + GOOD_X509_TOKEN + "</wsse:BinarySecurityToken>\n" + "</wst:OnBehalfOf>\n";
    String body = getSoapEnvelope(onBehalfOf);

    given().auth()//from www  .  ja  v  a  2 s .c om
            .certificate(KEY_STORE_PATH, PASSWORD,
                    certAuthSettings().sslSocketFactory(SSLSocketFactory.getSystemSocketFactory()))
            .log().all().body(body).header("Content-Type", "text/xml; charset=utf-8")
            .header("SOAPAction", "http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue").expect()
            .statusCode(equalTo(200)).when().post(SERVICE_ROOT.getUrl() + "/SecurityTokenService").then().log()
            .all().assertThat().body(HasXPath.hasXPath("//*[local-name()='Assertion']"));

}

From source file:ddf.test.itests.platform.TestSecurity.java

@Test
public void testX509PathSTS() throws Exception {
    String onBehalfOf = "<wst:OnBehalfOf>\n"
            + "<wsse:BinarySecurityToken xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" "
            + "EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\" "
            + "ValueType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509PKIPathv1\" >"
            + GOOD_X509_PATH_TOKEN + "</wsse:BinarySecurityToken>\n" + "</wst:OnBehalfOf>\n";
    String body = getSoapEnvelope(onBehalfOf);

    given().auth()//from  ww  w  . j  a va  2 s  .co m
            .certificate(KEY_STORE_PATH, PASSWORD,
                    certAuthSettings().sslSocketFactory(SSLSocketFactory.getSystemSocketFactory()))
            .log().all().body(body).header("Content-Type", "text/xml; charset=utf-8")
            .header("SOAPAction", "http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue").expect()
            .statusCode(equalTo(200)).when().post(SERVICE_ROOT.getUrl() + "/SecurityTokenService").then().log()
            .all().assertThat().body(HasXPath.hasXPath("//*[local-name()='Assertion']"));

}

From source file:ddf.test.itests.platform.TestSecurity.java

@Test
public void testSamlAssertionInHeaders() throws Exception {
    String onBehalfOf = "<wst:OnBehalfOf>"
            + "                    <wsse:UsernameToken xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">\n"
            + "                        <wsse:Username>admin</wsse:Username>\n"
            + "                        <wsse:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText\">admin</wsse:Password>\n"
            + "                   </wsse:UsernameToken>\n" + "                </wst:OnBehalfOf>\n";
    String body = getSoapEnvelope(onBehalfOf);

    String assertionHeader = given().auth()
            .certificate(KEY_STORE_PATH, PASSWORD,
                    certAuthSettings().sslSocketFactory(SSLSocketFactory.getSystemSocketFactory()))
            .log().all().body(body).header("Content-Type", "text/xml; charset=utf-8")
            .header("SOAPAction", "http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue").expect()
            .statusCode(equalTo(200)).when().post(SERVICE_ROOT.getUrl() + "/SecurityTokenService").then()
            .extract().response().asString();
    assertionHeader = assertionHeader.substring(assertionHeader.indexOf("<saml2:Assertion"),
            assertionHeader.indexOf("</saml2:Assertion>") + "</saml2:Assertion>".length());

    LOGGER.trace(assertionHeader);//from w  ww.  ja  va2s  .  co  m

    //try that admin level assertion token on a restricted resource
    given().header(SecurityConstants.SAML_HEADER_NAME,
            "SAML " + RestSecurity.deflateAndBase64Encode(assertionHeader)).when().get(ADMIN_PATH.getUrl())
            .then().log().all().assertThat().statusCode(equalTo(200));
}

From source file:ddf.test.itests.platform.TestSecurity.java

@Test
public void testGoodHokSamlAssertionInHeaders() throws Exception {
    String body = getSoapEnvelope(GOOD_HOK_EXAMPLE, null);

    String assertionHeader = given().auth()
            .certificate(KEY_STORE_PATH, PASSWORD,
                    certAuthSettings().sslSocketFactory(SSLSocketFactory.getSystemSocketFactory()))
            .log().all().body(body).header("Content-Type", "text/xml; charset=utf-8")
            .header("SOAPAction", "http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue").expect()
            .statusCode(equalTo(200)).when().post(SERVICE_ROOT.getUrl() + "/SecurityTokenService").then()
            .extract().response().asString();
    assertionHeader = assertionHeader.substring(assertionHeader.indexOf("<saml2:Assertion"),
            assertionHeader.indexOf("</saml2:Assertion>") + "</saml2:Assertion>".length());

    LOGGER.trace(assertionHeader);// ww w. j a va  2  s.com

    //try that admin level assertion token on a restricted resource
    given().auth()
            .certificate(KEY_STORE_PATH, PASSWORD,
                    certAuthSettings().sslSocketFactory(SSLSocketFactory.getSystemSocketFactory()))
            .header(SecurityConstants.SAML_HEADER_NAME,
                    "SAML " + RestSecurity.deflateAndBase64Encode(assertionHeader))
            .when().get(ADMIN_PATH.getUrl()).then().log().all().assertThat().statusCode(equalTo(200));
}

From source file:ddf.test.itests.platform.TestSecurity.java

@Test
public void testBadHokSamlAssertionInHeaders() throws Exception {
    String body = getSoapEnvelope(BAD_HOK_EXAMPLE, null);

    String assertionHeader = given().auth()
            .certificate(KEY_STORE_PATH, PASSWORD,
                    certAuthSettings().sslSocketFactory(SSLSocketFactory.getSystemSocketFactory()))
            .log().all().body(body).header("Content-Type", "text/xml; charset=utf-8")
            .header("SOAPAction", "http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue").expect()
            .statusCode(equalTo(200)).when().post(SERVICE_ROOT.getUrl() + "/SecurityTokenService").then()
            .extract().response().asString();
    assertionHeader = assertionHeader.substring(assertionHeader.indexOf("<saml2:Assertion"),
            assertionHeader.indexOf("</saml2:Assertion>") + "</saml2:Assertion>".length());

    LOGGER.trace(assertionHeader);/*from w  ww. java 2s. co  m*/

    //try that admin level assertion token on a restricted resource
    given().auth()
            .certificate(KEY_STORE_PATH, PASSWORD,
                    certAuthSettings().sslSocketFactory(SSLSocketFactory.getSystemSocketFactory()))
            .header(SecurityConstants.SAML_HEADER_NAME,
                    "SAML " + RestSecurity.deflateAndBase64Encode(assertionHeader))
            .when().get(ADMIN_PATH.getUrl()).then().log().all().assertThat().statusCode(equalTo(401));
}