use of org.apereo.cas.authentication.AuthenticationResult in project cas by apereo.
the class AbstractServiceValidateControllerTests method verifyValidServiceTicketAndPgtUrlMismatch.
@Test
public void verifyValidServiceTicketAndPgtUrlMismatch() throws Exception {
final Service svc = RegisteredServiceTestUtils.getService("proxyService");
final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), svc);
final TicketGrantingTicket tId = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
final ServiceTicket sId = getCentralAuthenticationService().grantServiceTicket(tId.getId(), svc, ctx);
final MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, svc.getId());
request.addParameter(CasProtocolConstants.PARAMETER_TICKET, sId.getId());
request.addParameter(CasProtocolConstants.PARAMETER_PROXY_GRANTING_TICKET_URL, "http://www.github.com");
final ModelAndView modelAndView = this.serviceValidateController.handleRequestInternal(request, new MockHttpServletResponse());
assertFalse(modelAndView.getView().toString().contains(SUCCESS));
assertNull(modelAndView.getModel().get(CasProtocolConstants.PARAMETER_PROXY_GRANTING_TICKET_IOU));
}
use of org.apereo.cas.authentication.AuthenticationResult in project cas by apereo.
the class WsFederationAction method buildCredentialsFromAssertion.
private Event buildCredentialsFromAssertion(final RequestContext context, final Pair<Assertion, WsFederationConfiguration> assertion, final Service service) {
try {
LOGGER.debug("Creating credential based on the provided assertion");
final WsFederationCredential credential = this.wsFederationHelper.createCredentialFromToken(assertion.getKey());
final WsFederationConfiguration configuration = assertion.getValue();
final String rpId = wsFederationHelper.getRelyingPartyIdentifier(service, configuration);
if (credential == null) {
LOGGER.error("SAML no credential could be extracted from [{}] based on RP identifier [{}] and IdP identifier [{}]", assertion.getKey(), rpId, configuration.getIdentityProviderIdentifier());
return error();
}
if (credential != null && credential.isValid(rpId, configuration.getIdentityProviderIdentifier(), configuration.getTolerance())) {
LOGGER.debug("Validated assertion for the created credential successfully");
if (configuration.getAttributeMutator() != null) {
LOGGER.debug("Modifying credential attributes based on [{}]", configuration.getAttributeMutator().getClass().getSimpleName());
configuration.getAttributeMutator().modifyAttributes(credential.getAttributes());
}
} else {
LOGGER.error("SAML assertions are blank or no longer valid based on RP identifier [{}] and IdP identifier [{}]", rpId, configuration.getIdentityProviderIdentifier());
return error();
}
context.getFlowScope().put(CasProtocolConstants.PARAMETER_SERVICE, service);
LOGGER.debug("Creating final authentication result based on the given credential");
final AuthenticationResult authenticationResult = this.authenticationSystemSupport.handleAndFinalizeSingleAuthenticationTransaction(service, credential);
LOGGER.debug("Attempting to create a ticket-granting ticket for the authentication result");
WebUtils.putTicketGrantingTicketInScopes(context, this.centralAuthenticationService.createTicketGrantingTicket(authenticationResult));
LOGGER.info("Token validated and new [{}] created: [{}]", credential.getClass().getName(), credential);
return success();
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
return error();
}
}
Aggregations