use of org.apereo.cas.oidc.ticket.OidcPushedAuthorizationRequestFactory in project cas by apereo.
the class OidcConsentApprovalViewResolverTests method verifyPushedAuthz.
@Test
public void verifyPushedAuthz() throws Exception {
val registeredService = getOidcRegisteredService();
val profile = new CommonProfile();
profile.setId("casTest");
val holder = AccessTokenRequestContext.builder().clientId(registeredService.getClientId()).service(RegisteredServiceTestUtils.getService()).authentication(RegisteredServiceTestUtils.getAuthentication()).registeredService(registeredService).grantType(OAuth20GrantTypes.AUTHORIZATION_CODE).responseType(OAuth20ResponseTypes.CODE).userProfile(profile).scopes(CollectionUtils.wrapSet("email", "profile")).build();
val factory = (OidcPushedAuthorizationRequestFactory) defaultTicketFactory.get(OidcPushedAuthorizationRequest.class);
val ticket = factory.create(holder);
ticketRegistry.addTicket(ticket);
val request = new MockHttpServletRequest();
request.setRequestURI("https://cas.org/something/" + OidcConstants.AUTHORIZE_URL);
request.addParameter(OidcConstants.REQUEST_URI, ticket.getId());
val response = new MockHttpServletResponse();
val context = new JEEContext(request, response);
val service = getOidcRegisteredService(UUID.randomUUID().toString());
val mv = consentApprovalViewResolver.resolve(context, service);
assertTrue(mv.hasView());
assertEquals(3, ((Collection) mv.getModel().get("scopes")).size());
}
use of org.apereo.cas.oidc.ticket.OidcPushedAuthorizationRequestFactory in project cas by apereo.
the class OidcConsentApprovalViewResolver method prepareApprovalViewModel.
@Override
protected void prepareApprovalViewModel(final Map<String, Object> model, final WebContext webContext, final OAuthRegisteredService svc) throws Exception {
super.prepareApprovalViewModel(model, webContext, svc);
if (svc instanceof OidcRegisteredService) {
val oidcRegisteredService = (OidcRegisteredService) svc;
model.put("dynamic", oidcRegisteredService.isDynamicallyRegistered());
model.put("dynamicTime", oidcRegisteredService.getDynamicRegistrationDateTime());
val supportedScopes = new HashSet<>(casProperties.getAuthn().getOidc().getDiscovery().getScopes());
supportedScopes.retainAll(oidcRegisteredService.getScopes());
val requestedScopes = OAuth20Utils.getRequestedScopes(webContext);
val userInfoClaims = OAuth20Utils.parseUserInfoRequestClaims(webContext);
webContext.getRequestParameter(OidcConstants.REQUEST_URI).ifPresent(Unchecked.consumer(uri -> {
val authzRequest = centralAuthenticationService.getTicket(uri, OidcPushedAuthorizationRequest.class);
val uriFactory = (OidcPushedAuthorizationRequestFactory) centralAuthenticationService.getTicketFactory().get(OidcPushedAuthorizationRequest.class);
val holder = uriFactory.toAccessTokenRequest(authzRequest);
userInfoClaims.addAll(holder.getClaims().keySet());
requestedScopes.addAll(holder.getScopes());
}));
supportedScopes.retainAll(requestedScopes);
supportedScopes.add(OidcConstants.StandardScopes.OPENID.getScope());
model.put("scopes", supportedScopes);
model.put("userInfoClaims", userInfoClaims);
}
}
use of org.apereo.cas.oidc.ticket.OidcPushedAuthorizationRequestFactory in project cas by apereo.
the class OidcPushedAuthorizationRequestUriResponseBuilder method build.
@Override
public ModelAndView build(final AccessTokenRequestContext holder) throws Exception {
val factory = (OidcPushedAuthorizationRequestFactory) configurationContext.getTicketFactory().get(OidcPushedAuthorizationRequest.class);
val uri = factory.create(holder);
LOGGER.debug("Generated pushed authorization URI code: [{}]", uri);
configurationContext.getTicketRegistry().addTicket(uri);
val parameters = new HashMap<String, String>();
parameters.put(OidcConstants.EXPIRES_IN, String.valueOf(uri.getExpirationPolicy().getTimeToLive()));
parameters.put(OidcConstants.REQUEST_URI, uri.getId());
LOGGER.debug("Pushed authorization request verification successful for client [{}] with redirect uri [{}]", holder.getClientId(), holder.getRedirectUri());
return authorizationModelAndViewBuilder.build(holder.getRegisteredService(), holder.getResponseMode(), holder.getRedirectUri(), parameters);
}
use of org.apereo.cas.oidc.ticket.OidcPushedAuthorizationRequestFactory in project cas by apereo.
the class OidcPushedAuthorizationRequestUriResponseBuilder method toAuthorizationRequest.
@Override
public Optional<OAuth20AuthorizationRequest.OAuth20AuthorizationRequestBuilder> toAuthorizationRequest(final WebContext context, final Authentication authentication, final Service service, final OAuthRegisteredService registeredService) {
val requestUri = context.getRequestParameter(OidcConstants.REQUEST_URI);
if (context.getRequestURL().endsWith(OidcConstants.AUTHORIZE_URL) && requestUri.isEmpty()) {
return Optional.empty();
}
val builder = super.toAuthorizationRequest(context, authentication, service, registeredService).get();
return requestUri.map(Unchecked.function(uri -> {
val cas = configurationContext.getCentralAuthenticationService();
val factory = (OidcPushedAuthorizationRequestFactory) cas.getTicketFactory().get(OidcPushedAuthorizationRequest.class);
val request = cas.getTicket(uri, OidcPushedAuthorizationRequest.class);
val tokenRequest = factory.toAccessTokenRequest(request);
request.update();
FunctionUtils.doIf(request.isExpired(), Unchecked.consumer(r -> cas.deleteTicket(request)), Unchecked.consumer(r -> cas.updateTicket(request))).accept(request);
val tgt = configurationContext.fetchTicketGrantingTicketFrom((JEEContext) context);
tokenRequest.setTicketGrantingTicket(tgt);
return Optional.of(builder.accessTokenRequest(tokenRequest).responseType(tokenRequest.getResponseType().getType()).clientId(tokenRequest.getClientId()).grantType(tokenRequest.getGrantType().getType()));
})).orElseGet(() -> Optional.of(builder.singleSignOnSessionRequired(!context.getRequestURL().endsWith(OidcConstants.PUSHED_AUTHORIZE_URL))));
}
Aggregations