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);
}
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);
}
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;
}
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()));
}
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.");
}
}
Aggregations