use of org.apache.commons.lang3.StringUtils.isNotBlank 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.apache.commons.lang3.StringUtils.isNotBlank in project cas by apereo.
the class RegisteredServicesEventListener method handleRegisteredServiceExpiredEvent.
/**
* Handle registered service expired event.
*
* @param event the event
*/
@EventListener
public void handleRegisteredServiceExpiredEvent(final CasRegisteredServiceExpiredEvent event) {
final RegisteredService registeredService = event.getRegisteredService();
final List<RegisteredServiceContact> contacts = registeredService.getContacts();
final EmailProperties mail = casProperties.getServiceRegistry().getMail();
final SmsProperties sms = casProperties.getServiceRegistry().getSms();
final String serviceName = StringUtils.defaultIfBlank(registeredService.getName(), registeredService.getServiceId());
if (communicationsManager.isMailSenderDefined()) {
final String message = String.format(mail.getText(), serviceName);
contacts.stream().filter(c -> StringUtils.isNotBlank(c.getEmail())).forEach(c -> communicationsManager.email(message, mail.getFrom(), mail.getSubject(), c.getEmail(), mail.getCc(), mail.getBcc()));
}
if (communicationsManager.isSmsSenderDefined()) {
final String message = String.format(sms.getText(), serviceName);
contacts.stream().filter(c -> StringUtils.isNotBlank(c.getPhone())).forEach(c -> communicationsManager.sms(sms.getFrom(), c.getPhone(), message));
}
servicesManager.load();
}
use of org.apache.commons.lang3.StringUtils.isNotBlank in project cas by apereo.
the class Pac4jAuthenticationEventExecutionPlanConfiguration method configureCasClient.
private void configureCasClient(final Collection<BaseClient> properties) {
final AtomicInteger index = new AtomicInteger();
casProperties.getAuthn().getPac4j().getCas().stream().filter(cas -> StringUtils.isNotBlank(cas.getLoginUrl())).forEach(cas -> {
final CasConfiguration cfg = new CasConfiguration(cas.getLoginUrl(), cas.getProtocol());
final CasClient client = new CasClient(cfg);
client.setName(client.getClass().getSimpleName() + index.incrementAndGet());
properties.add(client);
});
}
use of org.apache.commons.lang3.StringUtils.isNotBlank in project cas by apereo.
the class Pac4jAuthenticationEventExecutionPlanConfiguration method configureOidcClient.
private void configureOidcClient(final Collection<BaseClient> properties) {
final AtomicInteger index = new AtomicInteger();
casProperties.getAuthn().getPac4j().getOidc().stream().filter(oidc -> StringUtils.isNotBlank(oidc.getId()) && StringUtils.isNotBlank(oidc.getSecret())).forEach(oidc -> {
final OidcConfiguration cfg = new OidcConfiguration();
if (StringUtils.isNotBlank(oidc.getScope())) {
cfg.setScope(oidc.getScope());
}
cfg.setUseNonce(oidc.isUseNonce());
cfg.setSecret(oidc.getSecret());
cfg.setClientId(oidc.getId());
if (StringUtils.isNotBlank(oidc.getPreferredJwsAlgorithm())) {
cfg.setPreferredJwsAlgorithm(JWSAlgorithm.parse(oidc.getPreferredJwsAlgorithm().toUpperCase()));
}
cfg.setMaxClockSkew(oidc.getMaxClockSkew());
cfg.setDiscoveryURI(oidc.getDiscoveryUri());
cfg.setCustomParams(oidc.getCustomParams());
final OidcClient client;
switch(oidc.getType().toUpperCase()) {
case "GOOGLE":
client = new GoogleOidcClient(cfg);
break;
case "AZURE":
client = new AzureAdClient(cfg);
break;
case "GENERIC":
default:
client = new OidcClient(cfg);
break;
}
client.setName(client.getClass().getSimpleName() + index.incrementAndGet());
properties.add(client);
});
}
use of org.apache.commons.lang3.StringUtils.isNotBlank in project cas by apereo.
the class Pac4jAuthenticationEventExecutionPlanConfiguration method configureOAuth20Client.
private void configureOAuth20Client(final Collection<BaseClient> properties) {
final AtomicInteger index = new AtomicInteger();
casProperties.getAuthn().getPac4j().getOauth2().stream().filter(oauth -> StringUtils.isNotBlank(oauth.getId()) && StringUtils.isNotBlank(oauth.getSecret())).forEach(oauth -> {
final GenericOAuth20Client client = new GenericOAuth20Client();
client.setKey(oauth.getId());
client.setSecret(oauth.getSecret());
client.setProfileAttrs(oauth.getProfileAttrs());
client.setProfileNodePath(oauth.getProfilePath());
client.setProfileUrl(oauth.getProfileUrl());
client.setProfileVerb(Verb.valueOf(oauth.getProfileVerb().toUpperCase()));
client.setTokenUrl(oauth.getTokenUrl());
client.setAuthUrl(oauth.getAuthUrl());
client.setCustomParams(oauth.getCustomParams());
client.setName(client.getClass().getSimpleName() + index.incrementAndGet());
properties.add(client);
});
}
Aggregations