use of org.apereo.cas.ticket.code.OAuth20CodeFactory in project cas by apereo.
the class OAuth20AuthorizationCodeAuthorizationResponseBuilder method build.
@Audit(action = AuditableActions.OAUTH2_CODE_RESPONSE, actionResolverName = AuditActionResolvers.OAUTH2_CODE_RESPONSE_ACTION_RESOLVER, resourceResolverName = AuditResourceResolvers.OAUTH2_CODE_RESPONSE_RESOURCE_RESOLVER)
@Override
public ModelAndView build(final AccessTokenRequestContext holder) throws Exception {
val authentication = holder.getAuthentication();
val factory = (OAuth20CodeFactory) configurationContext.getTicketFactory().get(OAuth20Code.class);
val code = factory.create(holder.getService(), authentication, holder.getTicketGrantingTicket(), holder.getScopes(), holder.getCodeChallenge(), holder.getCodeChallengeMethod(), holder.getClientId(), holder.getClaims(), holder.getResponseType(), holder.getGrantType());
LOGGER.debug("Generated OAuth code: [{}]", code);
configurationContext.getCentralAuthenticationService().addTicket(code);
val ticketGrantingTicket = holder.getTicketGrantingTicket();
Optional.ofNullable(ticketGrantingTicket).ifPresent(tgt -> {
FunctionUtils.doAndHandle(ticket -> {
configurationContext.getCentralAuthenticationService().updateTicket(ticket);
}, (CheckedFunction<Throwable, TicketGrantingTicket>) throwable -> {
LOGGER.error("Unable to update ticket-granting-ticket [{}]", ticketGrantingTicket, throwable);
return null;
}).accept(tgt);
});
return buildCallbackViewViaRedirectUri(holder, code);
}
Aggregations