Search in sources :

Example 1 with HttpClient

use of org.apereo.cas.util.http.HttpClient in project cas by apereo.

the class FileTrustStoreSslSocketFactoryTests method verifyTrustStoreLoadingSuccessfullyWithCertAvailable2.

@Test
public void verifyTrustStoreLoadingSuccessfullyWithCertAvailable2() throws Exception {
    final SimpleHttpClientFactoryBean clientFactory = new SimpleHttpClientFactoryBean();
    clientFactory.setSslSocketFactory(sslFactory());
    final HttpClient client = clientFactory.getObject();
    assertTrue(client.isValidEndPoint("https://untrusted-root.badssl.com"));
}
Also used : SimpleHttpClientFactoryBean(org.apereo.cas.util.http.SimpleHttpClientFactoryBean) HttpClient(org.apereo.cas.util.http.HttpClient) Test(org.junit.Test)

Example 2 with HttpClient

use of org.apereo.cas.util.http.HttpClient in project cas by apereo.

the class FileTrustStoreSslSocketFactoryTests method verifyTrustStoreLoadingSuccessfullyWihInsecureEndpoint.

@Test
public void verifyTrustStoreLoadingSuccessfullyWihInsecureEndpoint() throws Exception {
    final SimpleHttpClientFactoryBean clientFactory = new SimpleHttpClientFactoryBean();
    clientFactory.setSslSocketFactory(sslFactory());
    final HttpClient client = clientFactory.getObject();
    assertTrue(client.isValidEndPoint("http://wikipedia.org"));
}
Also used : SimpleHttpClientFactoryBean(org.apereo.cas.util.http.SimpleHttpClientFactoryBean) HttpClient(org.apereo.cas.util.http.HttpClient) Test(org.junit.Test)

Example 3 with HttpClient

use of org.apereo.cas.util.http.HttpClient in project cas by apereo.

the class FileTrustStoreSslSocketFactoryTests method verifyTrustStoreLoadingSuccessfullyWithCertAvailable.

@Test
public void verifyTrustStoreLoadingSuccessfullyWithCertAvailable() throws Exception {
    final SimpleHttpClientFactoryBean clientFactory = new SimpleHttpClientFactoryBean();
    clientFactory.setSslSocketFactory(sslFactory());
    final HttpClient client = clientFactory.getObject();
    assertTrue(client.isValidEndPoint("https://self-signed.badssl.com"));
}
Also used : SimpleHttpClientFactoryBean(org.apereo.cas.util.http.SimpleHttpClientFactoryBean) HttpClient(org.apereo.cas.util.http.HttpClient) Test(org.junit.Test)

Example 4 with HttpClient

use of org.apereo.cas.util.http.HttpClient in project cas by apereo.

the class RemoteEndpointServiceAccessStrategy method doPrincipalAttributesAllowServiceAccess.

@Override
public boolean doPrincipalAttributesAllowServiceAccess(final String principal, final Map<String, Object> principalAttributes) {
    try {
        if (super.doPrincipalAttributesAllowServiceAccess(principal, principalAttributes)) {
            final HttpClient client = ApplicationContextProvider.getApplicationContext().getBean("noRedirectHttpClient", HttpClient.class);
            final URIBuilder builder = new URIBuilder(this.endpointUrl);
            builder.addParameter("username", principal);
            final URL url = builder.build().toURL();
            final HttpMessage message = client.sendMessageToEndPoint(url);
            LOGGER.debug("Message received from [{}] is [{}]", url, message);
            return message != null && StringUtils.commaDelimitedListToSet(this.acceptableResponseCodes).contains(String.valueOf(message.getResponseCode()));
        }
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return false;
}
Also used : HttpClient(org.apereo.cas.util.http.HttpClient) HttpMessage(org.apereo.cas.util.http.HttpMessage) URL(java.net.URL) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 5 with HttpClient

use of org.apereo.cas.util.http.HttpClient in project cas by apereo.

the class HttpBasedServiceCredentialsAuthenticationHandlerTests method verifyNoAcceptableStatusCodeButOneSet.

@Test
public void verifyNoAcceptableStatusCodeButOneSet() throws Exception {
    final SimpleHttpClientFactoryBean clientFactory = new SimpleHttpClientFactoryBean();
    clientFactory.setAcceptableCodes(new int[] { 900 });
    final HttpClient httpClient = clientFactory.getObject();
    this.authenticationHandler = new HttpBasedServiceCredentialsAuthenticationHandler("", null, null, null, httpClient);
    this.thrown.expect(FailedLoginException.class);
    this.thrown.expectMessage("https://www.ja-sig.org sent an unacceptable response status code");
    this.authenticationHandler.authenticate(RegisteredServiceTestUtils.getHttpBasedServiceCredentials("https://www.ja-sig.org"));
}
Also used : SimpleHttpClientFactoryBean(org.apereo.cas.util.http.SimpleHttpClientFactoryBean) HttpClient(org.apereo.cas.util.http.HttpClient) Test(org.junit.Test)

Aggregations

HttpClient (org.apereo.cas.util.http.HttpClient)7 SimpleHttpClientFactoryBean (org.apereo.cas.util.http.SimpleHttpClientFactoryBean)5 Test (org.junit.Test)5 URL (java.net.URL)1 List (java.util.List)1 StringUtils (org.apache.commons.lang3.StringUtils)1 URIBuilder (org.apache.http.client.utils.URIBuilder)1 BasicDuoAuthenticationService (org.apereo.cas.adaptors.duo.authn.BasicDuoAuthenticationService)1 DefaultDuoMultifactorAuthenticationProvider (org.apereo.cas.adaptors.duo.authn.DefaultDuoMultifactorAuthenticationProvider)1 DuoAuthenticationHandler (org.apereo.cas.adaptors.duo.authn.DuoAuthenticationHandler)1 PrepareDuoWebLoginFormAction (org.apereo.cas.adaptors.duo.web.flow.action.PrepareDuoWebLoginFormAction)1 DuoMultifactorWebflowConfigurer (org.apereo.cas.adaptors.duo.web.flow.config.DuoMultifactorWebflowConfigurer)1 AuthenticationEventExecutionPlan (org.apereo.cas.authentication.AuthenticationEventExecutionPlan)1 AuthenticationHandler (org.apereo.cas.authentication.AuthenticationHandler)1 AuthenticationMetaDataPopulator (org.apereo.cas.authentication.AuthenticationMetaDataPopulator)1 AuthenticationContextAttributeMetaDataPopulator (org.apereo.cas.authentication.metadata.AuthenticationContextAttributeMetaDataPopulator)1 DefaultPrincipalFactory (org.apereo.cas.authentication.principal.DefaultPrincipalFactory)1 PrincipalFactory (org.apereo.cas.authentication.principal.PrincipalFactory)1 AuthenticationEventExecutionPlanConfigurer (org.apereo.cas.config.support.authentication.AuthenticationEventExecutionPlanConfigurer)1 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)1