use of org.apereo.cas.web.view.DynamicHtmlView in project cas by apereo.
the class BaseDelegatedAuthenticationController method getResultingView.
/**
* Gets resulting view.
*
* @param client the client
* @param webContext the web context
* @param ticket the ticket
* @return the resulting view
* @throws Exception the exception
*/
protected View getResultingView(final IndirectClient client, final WebContext webContext, final TransientSessionTicket ticket) throws Exception {
client.init();
val actionResult = getRedirectionAction(client, webContext, ticket);
if (actionResult.isPresent()) {
val action = actionResult.get();
LOGGER.debug("Determined final redirect action for client [{}] as [{}]", client, action);
if (action instanceof WithLocationAction) {
val foundAction = WithLocationAction.class.cast(action);
val builder = new URIBuilder(foundAction.getLocation());
val url = builder.toString();
LOGGER.debug("Redirecting client [{}] to [{}] based on identifier [{}]", client.getName(), url, ticket.getId());
return new RedirectView(url);
}
if (action instanceof WithContentAction) {
val seeOtherAction = WithContentAction.class.cast(action);
return new DynamicHtmlView(seeOtherAction.getContent());
}
}
LOGGER.warn("Unable to determine redirect action for client [{}]", client);
return null;
}
use of org.apereo.cas.web.view.DynamicHtmlView in project cas by apereo.
the class DefaultDelegatedAuthenticationNavigationControllerTests method verifyRedirectByAttrPassiveAuth.
@Test
public void verifyRedirectByAttrPassiveAuth() {
val request = new MockHttpServletRequest();
request.setAttribute(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, "SAML2Client");
request.setParameter(RedirectionActionBuilder.ATTRIBUTE_PASSIVE, "true");
val response = new MockHttpServletResponse();
assertTrue(controller.redirectToProvider(request, response) instanceof DynamicHtmlView);
}
use of org.apereo.cas.web.view.DynamicHtmlView in project cas by apereo.
the class DefaultDelegatedAuthenticationNavigationControllerTests method verifyRedirectWithService.
@Test
public void verifyRedirectWithService() {
val request = new MockHttpServletRequest();
request.setAttribute(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, "SAML2Client");
val service = RegisteredServiceTestUtils.getService("https://github.com/apereo/cas");
servicesManager.save(RegisteredServiceTestUtils.getRegisteredService("https://github.com/apereo/cas"));
request.setParameter(CasProtocolConstants.PARAMETER_SERVICE, service.getId());
val response = new MockHttpServletResponse();
assertTrue(controller.redirectToProvider(request, response) instanceof DynamicHtmlView);
}
use of org.apereo.cas.web.view.DynamicHtmlView in project cas by apereo.
the class DelegatedClientNavigationController method redirectToProvider.
/**
* Redirect to provider. Receive the client name from the request and then try to determine and build the endpoint url
* for the redirection. The redirection data/url must contain a delegated client ticket id so that the request be can
* restored on the trip back. SAML clients use the relay-state session attribute while others use request parameters.
*
* @param request the request
* @param response the response
* @return the view
*/
@GetMapping(ENDPOINT_REDIRECT)
public View redirectToProvider(final HttpServletRequest request, final HttpServletResponse response) {
final String clientName = request.getParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER);
try {
final IndirectClient client = (IndirectClient<Credentials, CommonProfile>) this.clients.findClient(clientName);
final J2EContext webContext = Pac4jUtils.getPac4jJ2EContext(request, response);
final Ticket ticket = delegatedClientWebflowManager.store(webContext, client);
final View result;
final RedirectAction action = client.getRedirectAction(webContext);
if (RedirectAction.RedirectType.SUCCESS.equals(action.getType())) {
result = new DynamicHtmlView(action.getContent());
} else {
final URIBuilder builder = new URIBuilder(action.getLocation());
final String url = builder.toString();
LOGGER.debug("Redirecting client [{}] to [{}] based on identifier [{}]", client.getName(), url, ticket.getId());
result = new RedirectView(url);
}
this.delegatedSessionCookieManager.store(webContext);
return result;
} catch (final HttpAction e) {
if (e.getCode() == HttpStatus.UNAUTHORIZED.value()) {
LOGGER.debug("Authentication request was denied from the provider [{}]", clientName, e);
} else {
LOGGER.warn(e.getMessage(), e);
}
throw new UnauthorizedServiceException(e.getMessage(), e);
}
}
use of org.apereo.cas.web.view.DynamicHtmlView in project cas by apereo.
the class DefaultDelegatedAuthenticationNavigationControllerTests method verifyRedirectWithServiceSaml2Properties.
@Test
public void verifyRedirectWithServiceSaml2Properties() {
val request = new MockHttpServletRequest();
request.setAttribute(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, "SAML2Client");
val service = RegisteredServiceTestUtils.getService("https://github.com/apereo/cas");
servicesManager.save(RegisteredServiceTestUtils.getRegisteredService("https://github.com/apereo/cas"));
val registeredService = servicesManager.findServiceBy(service);
val property1 = new DefaultRegisteredServiceProperty("class1", "class2");
registeredService.getProperties().put(RegisteredServiceProperties.DELEGATED_AUTHN_SAML2_AUTHN_CONTEXT_CLASS_REFS.getPropertyName(), property1);
val property2 = new DefaultRegisteredServiceProperty("true");
registeredService.getProperties().put(RegisteredServiceProperties.DELEGATED_AUTHN_SAML2_WANTS_RESPONSES_SIGNED.getPropertyName(), property2);
servicesManager.save(registeredService);
request.setParameter(CasProtocolConstants.PARAMETER_SERVICE, service.getId());
val response = new MockHttpServletResponse();
assertTrue(controller.redirectToProvider(request, response) instanceof DynamicHtmlView);
}
Aggregations