Search in sources :

Example 1 with HttpBasedServiceCredential

use of org.apereo.cas.authentication.credential.HttpBasedServiceCredential in project cas by apereo.

the class HttpBasedServiceCredentialTests method verifyEqualsWithFalse.

@Test
public void verifyEqualsWithFalse() throws Exception {
    val registeredService = CoreAuthenticationTestUtils.getRegisteredService(CoreAuthenticationTestUtils.CONST_TEST_URL);
    val c = new HttpBasedServiceCredential(new URL(CoreAuthenticationTestUtils.CONST_GOOD_URL), registeredService);
    val c2 = new HttpBasedServiceCredential(new URL("http://www.msn.com"), registeredService);
    assertNotEquals(c2, c);
    assertNotEquals(new Object(), c);
}
Also used : lombok.val(lombok.val) HttpBasedServiceCredential(org.apereo.cas.authentication.credential.HttpBasedServiceCredential) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Example 2 with HttpBasedServiceCredential

use of org.apereo.cas.authentication.credential.HttpBasedServiceCredential in project cas by apereo.

the class HttpBasedServiceCredentialTests method verifyEqualsWithNull.

@Test
public void verifyEqualsWithNull() throws Exception {
    val registeredService = CoreAuthenticationTestUtils.getRegisteredService(CoreAuthenticationTestUtils.CONST_TEST_URL);
    val c = new HttpBasedServiceCredential(new URL(CoreAuthenticationTestUtils.CONST_GOOD_URL), registeredService);
    assertNotEquals(c, null);
}
Also used : lombok.val(lombok.val) HttpBasedServiceCredential(org.apereo.cas.authentication.credential.HttpBasedServiceCredential) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Example 3 with HttpBasedServiceCredential

use of org.apereo.cas.authentication.credential.HttpBasedServiceCredential in project cas by apereo.

the class Cas20ProxyHandler method handle.

@Override
public String handle(final Credential credential, final TicketGrantingTicket proxyGrantingTicketId) {
    val serviceCredentials = (HttpBasedServiceCredential) credential;
    val proxyIou = this.uniqueTicketIdGenerator.getNewTicketId(ProxyGrantingTicket.PROXY_GRANTING_TICKET_IOU_PREFIX);
    val callbackUrl = serviceCredentials.getCallbackUrl();
    val serviceCredentialsAsString = callbackUrl.toExternalForm();
    val bufferLength = serviceCredentialsAsString.length() + proxyIou.length() + proxyGrantingTicketId.getId().length() + BUFFER_LENGTH_ADDITIONAL_CHARGE;
    val stringBuffer = new StringBuilder(bufferLength).append(serviceCredentialsAsString);
    if (callbackUrl.getQuery() != null) {
        stringBuffer.append('&');
    } else {
        stringBuffer.append('?');
    }
    stringBuffer.append(CasProtocolConstants.PARAMETER_PROXY_GRANTING_TICKET_IOU).append('=').append(proxyIou).append('&').append(CasProtocolConstants.PARAMETER_PROXY_GRANTING_TICKET_ID).append('=').append(proxyGrantingTicketId);
    if (this.httpClient.isValidEndPoint(stringBuffer.toString())) {
        LOGGER.debug("Sent ProxyIou of [{}] for service: [{}]", proxyIou, serviceCredentials);
        return proxyIou;
    }
    LOGGER.debug("Failed to send ProxyIou of [{}] for service: [{}]", proxyIou, serviceCredentials);
    return null;
}
Also used : lombok.val(lombok.val) HttpBasedServiceCredential(org.apereo.cas.authentication.credential.HttpBasedServiceCredential)

Example 4 with HttpBasedServiceCredential

use of org.apereo.cas.authentication.credential.HttpBasedServiceCredential in project cas by apereo.

the class HttpBasedServiceCredentialsAuthenticationHandler method authenticate.

@Override
public AuthenticationHandlerExecutionResult authenticate(final Credential credential) throws GeneralSecurityException {
    val httpCredential = (HttpBasedServiceCredential) credential;
    if (!httpCredential.getService().getProxyPolicy().isAllowedProxyCallbackUrl(httpCredential.getCallbackUrl())) {
        LOGGER.warn("Proxy policy for service [{}] cannot authorize the requested callback url [{}].", httpCredential.getService().getServiceId(), httpCredential.getCallbackUrl());
        throw new FailedLoginException(httpCredential.getCallbackUrl() + " cannot be authorized");
    }
    LOGGER.debug("Attempting to authenticate [{}]", httpCredential);
    val callbackUrl = httpCredential.getCallbackUrl();
    if (!this.httpClient.isValidEndPoint(callbackUrl)) {
        throw new FailedLoginException(callbackUrl.toExternalForm() + " sent an unacceptable response status code");
    }
    return new DefaultAuthenticationHandlerExecutionResult(this, httpCredential, this.principalFactory.createPrincipal(httpCredential.getId()));
}
Also used : lombok.val(lombok.val) HttpBasedServiceCredential(org.apereo.cas.authentication.credential.HttpBasedServiceCredential) FailedLoginException(javax.security.auth.login.FailedLoginException) DefaultAuthenticationHandlerExecutionResult(org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult)

Example 5 with HttpBasedServiceCredential

use of org.apereo.cas.authentication.credential.HttpBasedServiceCredential in project cas by apereo.

the class FileAuthenticationHandlerTests method verifyDoesNotSupportBadUserCredentials.

@Test
public void verifyDoesNotSupportBadUserCredentials() {
    try {
        val c = new HttpBasedServiceCredential(new URL("http://www.rutgers.edu"), CoreAuthenticationTestUtils.getRegisteredService());
        assertFalse(this.authenticationHandler.supports(c));
    } catch (final MalformedURLException e) {
        throw new AssertionError("MalformedURLException caught.");
    }
}
Also used : lombok.val(lombok.val) MalformedURLException(java.net.MalformedURLException) HttpBasedServiceCredential(org.apereo.cas.authentication.credential.HttpBasedServiceCredential) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)10 HttpBasedServiceCredential (org.apereo.cas.authentication.credential.HttpBasedServiceCredential)10 URL (java.net.URL)7 Test (org.junit.jupiter.api.Test)6 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)2 AbstractTicketException (org.apereo.cas.ticket.AbstractTicketException)2 InvalidTicketException (org.apereo.cas.ticket.InvalidTicketException)2 UnsatisfiedAuthenticationContextTicketValidationException (org.apereo.cas.ticket.UnsatisfiedAuthenticationContextTicketValidationException)2 MalformedURLException (java.net.MalformedURLException)1 FailedLoginException (javax.security.auth.login.FailedLoginException)1 DefaultAuthenticationHandlerExecutionResult (org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult)1 PrincipalException (org.apereo.cas.authentication.PrincipalException)1 UnauthorizedProxyingException (org.apereo.cas.services.UnauthorizedProxyingException)1 UnauthorizedServiceException (org.apereo.cas.services.UnauthorizedServiceException)1 AbstractTicketValidationException (org.apereo.cas.ticket.AbstractTicketValidationException)1 ProxyGrantingTicket (org.apereo.cas.ticket.proxy.ProxyGrantingTicket)1 DefaultUniqueTicketIdGenerator (org.apereo.cas.util.DefaultUniqueTicketIdGenerator)1 SimpleHttpClientFactoryBean (org.apereo.cas.util.http.SimpleHttpClientFactoryBean)1 UnauthorizedServiceTicketValidationException (org.apereo.cas.validation.UnauthorizedServiceTicketValidationException)1