use of org.jasig.cas.client.validation.Cas30ServiceTicketValidator in project cas by apereo.
the class SSOPostProfileCallbackHandlerController method validateRequestAndBuildCasAssertion.
private Assertion validateRequestAndBuildCasAssertion(final HttpServletResponse response, final HttpServletRequest request, final Pair<AuthnRequest, MessageContext> pair) throws Exception {
final AuthnRequest authnRequest = pair.getKey();
final String ticket = CommonUtils.safeGetParameter(request, CasProtocolConstants.PARAMETER_TICKET);
final Cas30ServiceTicketValidator validator = new Cas30ServiceTicketValidator(this.serverPrefix);
validator.setRenew(authnRequest.isForceAuthn());
final String serviceUrl = constructServiceUrl(request, response, pair);
LOGGER.debug("Created service url for validation: [{}]", serviceUrl);
final Assertion assertion = validator.validate(ticket, serviceUrl);
logCasValidationAssertion(assertion);
return assertion;
}
use of org.jasig.cas.client.validation.Cas30ServiceTicketValidator in project cas by apereo.
the class WSFederationValidateRequestCallbackController method validateRequestAndBuildCasAssertion.
private Assertion validateRequestAndBuildCasAssertion(final HttpServletResponse response, final HttpServletRequest request, final WSFederationRequest fedRequest) throws Exception {
final String ticket = CommonUtils.safeGetParameter(request, CasProtocolConstants.PARAMETER_TICKET);
final Cas30ServiceTicketValidator validator = new Cas30ServiceTicketValidator(casProperties.getServer().getPrefix());
final String serviceUrl = constructServiceUrl(request, response, fedRequest);
LOGGER.debug("Created service url for validation: [{}]", serviceUrl);
final Assertion assertion = validator.validate(ticket, serviceUrl);
LOGGER.debug("Located CAS assertion [{}]", assertion);
return assertion;
}
use of org.jasig.cas.client.validation.Cas30ServiceTicketValidator in project cas by apereo.
the class TokenWebApplicationServiceResponseBuilder method generateToken.
/**
* Generate token string.
*
* @param service the service
* @param parameters the parameters
* @return the jwt
*/
protected String generateToken(final Service service, final Map<String, String> parameters) {
try {
final String ticketId = parameters.get(CasProtocolConstants.PARAMETER_TICKET);
final Cas30ServiceTicketValidator validator = new Cas30ServiceTicketValidator(casProperties.getServer().getPrefix());
final Assertion assertion = validator.validate(ticketId, service.getId());
final JWTClaimsSet.Builder claims = new JWTClaimsSet.Builder().audience(service.getId()).issuer(casProperties.getServer().getPrefix()).jwtID(ticketId).issueTime(assertion.getAuthenticationDate()).subject(assertion.getPrincipal().getName());
assertion.getAttributes().forEach(claims::claim);
assertion.getPrincipal().getAttributes().forEach(claims::claim);
if (assertion.getValidUntilDate() != null) {
claims.expirationTime(assertion.getValidUntilDate());
} else {
final ZonedDateTime dt = ZonedDateTime.now().plusSeconds(ticketGrantingTicketExpirationPolicy.getTimeToLive());
claims.expirationTime(DateTimeUtils.dateOf(dt));
}
final JWTClaimsSet claimsSet = claims.build();
final JSONObject object = claimsSet.toJSONObject();
return tokenCipherExecutor.encode(object.toJSONString());
} catch (final Exception e) {
throw Throwables.propagate(e);
}
}
Aggregations