use of org.pac4j.saml.client.SAML2Client in project cas by apereo.
the class SamlIdentityProviderDiscoveryFeedController method redirect.
/**
* Redirect.
*
* @param entityID the entity id
* @param httpServletRequest the http servlet request
* @param httpServletResponse the http servlet response
* @return the view
*/
@GetMapping(path = "redirect")
public View redirect(@RequestParam("entityID") final String entityID, final HttpServletRequest httpServletRequest, final HttpServletResponse httpServletResponse) {
val idp = getDiscoveryFeed().stream().filter(entity -> entity.getEntityID().equals(entityID)).findFirst().orElseThrow();
val samlClient = clients.findAllClients().stream().filter(c -> c instanceof SAML2Client).map(SAML2Client.class::cast).peek(InitializableObject::init).filter(c -> c.getIdentityProviderResolvedEntityId().equalsIgnoreCase(idp.getEntityID())).findFirst().orElseThrow();
val webContext = new JEEContext(httpServletRequest, httpServletResponse);
val service = this.argumentExtractor.extractService(httpServletRequest);
if (delegatedAuthenticationAccessStrategyHelper.isDelegatedClientAuthorizedForService(samlClient, service, httpServletRequest)) {
val provider = DelegatedClientIdentityProviderConfigurationFactory.builder().service(service).client(samlClient).webContext(webContext).casProperties(casProperties).build().resolve();
if (provider.isPresent()) {
return new RedirectView('/' + provider.get().getRedirectUrl(), true, true, true);
}
}
throw new UnauthorizedServiceException(UnauthorizedServiceException.CODE_UNAUTHZ_SERVICE, StringUtils.EMPTY);
}
use of org.pac4j.saml.client.SAML2Client in project cas by apereo.
the class SamlIdentityProviderDiscoveryFeedController method home.
/**
* Home.
*
* @return the model and view
*/
@GetMapping
public ModelAndView home() {
val model = new HashMap<String, Object>();
val entityIds = clients.findAllClients().stream().filter(c -> c instanceof SAML2Client).map(SAML2Client.class::cast).peek(InitializableObject::init).map(SAML2Client::getServiceProviderResolvedEntityId).collect(Collectors.toList());
LOGGER.debug("Using service provider entity id [{}]", entityIds);
model.put("entityIds", entityIds);
model.put("casServerPrefix", casProperties.getServer().getPrefix());
return new ModelAndView("saml2-discovery/casSamlIdPDiscoveryView", model);
}
use of org.pac4j.saml.client.SAML2Client in project cas by apereo.
the class DefaultDelegatedClientAuthenticationWebflowManager method store.
@Override
public TransientSessionTicket store(final JEEContext webContext, final Client client) throws Exception {
val ticket = storeDelegatedClientAuthenticationRequest(webContext);
rememberSelectedClientIfNecessary(webContext, client);
if (client instanceof SAML2Client) {
trackSessionIdForSAML2Client(webContext, ticket, (SAML2Client) client);
}
if (client instanceof OAuth20Client) {
trackSessionIdForOAuth20Client(webContext, (OAuth20Client) client, ticket);
}
if (client instanceof OidcClient) {
trackSessionIdForOidcClient(webContext, (OidcClient) client, ticket);
}
if (client instanceof CasClient) {
trackSessionIdForCasClient(webContext, ticket, (CasClient) client);
}
if (client instanceof OAuth10Client) {
trackSessionIdForOAuth10Client(webContext, ticket);
}
return ticket;
}
use of org.pac4j.saml.client.SAML2Client in project cas by apereo.
the class DelegatedAuthenticationClientFinishLogoutAction method doExecute.
@Override
protected Event doExecute(final RequestContext requestContext) {
val request = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
val response = WebUtils.getHttpServletResponseFromExternalWebflowContext(requestContext);
val context = new JEEContext(request, response);
var clientName = WebUtils.getDelegatedAuthenticationClientName(requestContext);
if (clientName == null) {
clientName = requestContext.getRequestParameters().get(SamlProtocolConstants.PARAMETER_SAML_RELAY_STATE);
if (StringUtils.isNotBlank(clientName)) {
clients.findClient(clientName).filter(client -> client instanceof SAML2Client).map(SAML2Client.class::cast).ifPresent(client -> {
try {
LOGGER.debug("Located client from relay-state: [{}]", client);
val samlContext = client.getContextProvider().buildContext(client, context, this.sessionStore);
client.getLogoutProfileHandler().receive(samlContext);
} catch (final HttpAction action) {
LOGGER.debug("Adapting logout response via [{}]", action.toString());
JEEHttpActionAdapter.INSTANCE.adapt(action, context);
} catch (final Exception e) {
LoggingUtils.error(LOGGER, e);
}
});
}
} else {
clients.findClient(clientName).filter(client -> client instanceof SAML2Client).map(SAML2Client.class::cast).ifPresent(client -> {
LOGGER.debug("Located client from webflow state: [{}]", client);
val logoutRedirect = WebUtils.getLogoutRedirectUrl(requestContext, String.class);
if (logoutRedirect != null) {
val validator = client.getLogoutValidator();
validator.setPostLogoutURL(logoutRedirect);
LOGGER.debug("Captured post logout url: [{}]", logoutRedirect);
WebUtils.putLogoutRedirectUrl(requestContext, null);
}
});
}
return null;
}
use of org.pac4j.saml.client.SAML2Client in project cas by apereo.
the class DefaultDelegatedClientAuthenticationWebflowManagerTests method verifySamlStoreOperation.
@Test
public void verifySamlStoreOperation() throws Exception {
val config = new SAML2Configuration();
val client = new SAML2Client(config);
val ticket = delegatedClientAuthenticationWebflowManager.store(context, client);
assertNotNull(ticketRegistry.getTicket(ticket.getId()));
assertEquals(ticket.getId(), delegatedClientDistributedSessionStore.get(context, SAML2StateGenerator.SAML_RELAY_STATE_ATTRIBUTE).get());
httpServletRequest.addParameter("RelayState", ticket.getId());
val service = delegatedClientAuthenticationWebflowManager.retrieve(requestContext, context, client);
assertNotNull(service);
assertNull(ticketRegistry.getTicket(ticket.getId()));
}
Aggregations