use of org.apereo.cas.services.RegisteredService in project cas by apereo.
the class GenericSuccessViewAction method doExecute.
@Override
protected Event doExecute(final RequestContext requestContext) {
if (StringUtils.isNotBlank(this.redirectUrl)) {
final Service service = this.serviceFactory.createService(this.redirectUrl);
final RegisteredService registeredService = this.servicesManager.findServiceBy(service);
RegisteredServiceAccessStrategyUtils.ensureServiceAccessIsAllowed(service, registeredService);
requestContext.getExternalContext().requestExternalRedirect(service.getId());
} else {
final String tgt = WebUtils.getTicketGrantingTicketId(requestContext);
WebUtils.putPrincipal(requestContext, getAuthenticationPrincipal(tgt));
}
return success();
}
use of org.apereo.cas.services.RegisteredService in project cas by apereo.
the class LogoutAction method doInternalExecute.
@Override
protected Event doInternalExecute(final HttpServletRequest request, final HttpServletResponse response, final RequestContext context) {
boolean needFrontSlo = false;
final List<LogoutRequest> logoutRequests = WebUtils.getLogoutRequests(context);
if (logoutRequests != null) {
needFrontSlo = logoutRequests.stream().anyMatch(logoutRequest -> logoutRequest.getStatus() == LogoutRequestStatus.NOT_ATTEMPTED);
}
final String paramName = StringUtils.defaultIfEmpty(logoutProperties.getRedirectParameter(), CasProtocolConstants.PARAMETER_SERVICE);
LOGGER.debug("Using parameter name [{}] to detect destination service, if any", paramName);
final String service = request.getParameter(paramName);
LOGGER.debug("Located target service [{}] for redirection after logout", paramName);
if (logoutProperties.isFollowServiceRedirects() && StringUtils.isNotBlank(service)) {
final Service webAppService = webApplicationServiceFactory.createService(service);
final RegisteredService rService = this.servicesManager.findServiceBy(webAppService);
if (rService != null && rService.getAccessStrategy().isServiceAccessAllowed()) {
LOGGER.debug("Redirecting to service [{}]", service);
WebUtils.putLogoutRedirectUrl(context, service);
} else {
LOGGER.warn("Cannot redirect to [{}] given the service is unauthorized to use CAS. " + "Ensure the service is registered with CAS and is enabled to allowed access", service);
}
} else {
LOGGER.debug("No target service is located for redirection after logout, or CAS is not allowed to follow redirects after logout");
}
// there are some front services to logout, perform front SLO
if (needFrontSlo) {
LOGGER.debug("Proceeding forward with front-channel single logout");
return new Event(this, CasWebflowConstants.TRANSITION_ID_FRONT);
}
LOGGER.debug("Moving forward to finish the logout process");
return new Event(this, CasWebflowConstants.TRANSITION_ID_FINISH);
}
use of org.apereo.cas.services.RegisteredService in project cas by apereo.
the class ServiceAuthorizationCheckTests method setUpMocks.
@Before
public void setUpMocks() {
final RegexRegisteredService authorizedRegisteredService = new RegexRegisteredService();
final RegexRegisteredService unauthorizedRegisteredService = new RegexRegisteredService();
unauthorizedRegisteredService.setAccessStrategy(new DefaultRegisteredServiceAccessStrategy(false, false));
final List<RegisteredService> list = new ArrayList<>();
list.add(authorizedRegisteredService);
list.add(unauthorizedRegisteredService);
when(this.servicesManager.findServiceBy(this.authorizedService)).thenReturn(authorizedRegisteredService);
when(this.servicesManager.findServiceBy(this.unauthorizedService)).thenReturn(unauthorizedRegisteredService);
when(this.servicesManager.findServiceBy(this.undefinedService)).thenReturn(null);
when(this.servicesManager.getAllServices()).thenReturn(list);
this.serviceAuthorizationCheck = new ServiceAuthorizationCheck(this.servicesManager, new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy()));
}
use of org.apereo.cas.services.RegisteredService in project cas by apereo.
the class CheckConsentRequiredAction method determineConsentEvent.
/**
* Determine consent event string.
*
* @param requestContext the request context
* @return the string
*/
protected String determineConsentEvent(final RequestContext requestContext) {
final Service service = this.authenticationRequestServiceSelectionStrategies.resolveService(WebUtils.getService(requestContext));
if (service == null) {
return null;
}
final RegisteredService registeredService = getRegisteredServiceForConsent(requestContext, service);
final Authentication authentication = WebUtils.getAuthentication(requestContext);
if (authentication == null) {
return null;
}
return isConsentRequired(service, registeredService, authentication, requestContext);
}
use of org.apereo.cas.services.RegisteredService in project cas by apereo.
the class ConfirmConsentAction method doExecute.
@Override
protected Event doExecute(final RequestContext requestContext) {
final HttpServletRequest request = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
final Service service = this.authenticationRequestServiceSelectionStrategies.resolveService(WebUtils.getService(requestContext));
final RegisteredService registeredService = getRegisteredServiceForConsent(requestContext, service);
final Authentication authentication = WebUtils.getAuthentication(requestContext);
final int optionValue = Integer.parseInt(request.getParameter("option"));
final ConsentOptions option = ConsentOptions.valueOf(optionValue);
final long reminder = Long.parseLong(request.getParameter("reminder"));
final String reminderTimeUnit = request.getParameter("reminderTimeUnit");
final ChronoUnit unit = ChronoUnit.valueOf(reminderTimeUnit.toUpperCase());
consentEngine.storeConsentDecision(service, registeredService, authentication, reminder, unit, option);
return new EventFactorySupport().success(this);
}
Aggregations