Search in sources :

Example 1 with ExternalContext

use of org.springframework.webflow.context.ExternalContext in project uPortal by Jasig.

the class PersonQueryValidator method validatePersonLookup.

/** Ensures all passed attributes are part of the valid query attribute set. */
public void validatePersonLookup(PersonQuery personQuery, MessageContext context) {
    final RequestContext requestContext = RequestContextHolder.getRequestContext();
    final ExternalContext externalContext = requestContext.getExternalContext();
    final Set<String> queryAttributes = personLookupHelper.getQueryAttributes(externalContext);
    final Map<String, Attribute> attributes = personQuery.getAttributes();
    for (final String attribute : attributes.keySet()) {
        if (!queryAttributes.contains(attribute)) {
            final MessageBuilder messageBuilder = new MessageBuilder();
            messageBuilder.error();
            messageBuilder.source("attributes[" + attribute + "].value");
            messageBuilder.code("personLookup.invalidQueryAttribute");
            messageBuilder.arg(attribute);
            final MessageResolver errorMessage = messageBuilder.build();
            context.addMessage(errorMessage);
        }
    }
}
Also used : MessageResolver(org.springframework.binding.message.MessageResolver) MessageBuilder(org.springframework.binding.message.MessageBuilder) Attribute(org.apereo.portal.portlets.Attribute) ExternalContext(org.springframework.webflow.context.ExternalContext) RequestContext(org.springframework.webflow.execution.RequestContext)

Example 2 with ExternalContext

use of org.springframework.webflow.context.ExternalContext in project cas by apereo.

the class DelegatedClientAuthenticationAction method doExecute.

@Override
protected Event doExecute(final RequestContext context) throws Exception {
    final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
    final HttpServletResponse response = WebUtils.getHttpServletResponse(context);
    final HttpSession session = request.getSession();
    // web context
    final WebContext webContext = WebUtils.getPac4jJ2EContext(request, response);
    // get client
    final String clientName = request.getParameter(this.clients.getClientNameParameter());
    LOGGER.debug("clientName: [{}]", clientName);
    if (hasDelegationRequestFailed(request, response.getStatus()).isPresent()) {
        return stopWebflow();
    }
    // it's an authentication
    if (StringUtils.isNotBlank(clientName)) {
        // get client
        final BaseClient<Credentials, CommonProfile> client = (BaseClient<Credentials, CommonProfile>) this.clients.findClient(clientName);
        LOGGER.debug("Client: [{}]", client);
        // get credentials
        final Credentials credentials;
        try {
            credentials = client.getCredentials(webContext);
            LOGGER.debug("Retrieved credentials: [{}]", credentials);
        } catch (final Exception e) {
            LOGGER.debug("The request requires http action", e);
            return stopWebflow();
        }
        // retrieve parameters from web session
        final Service service = (Service) session.getAttribute(CasProtocolConstants.PARAMETER_SERVICE);
        context.getFlowScope().put(CasProtocolConstants.PARAMETER_SERVICE, service);
        LOGGER.debug("Retrieve service: [{}]", service);
        if (service != null) {
            request.setAttribute(CasProtocolConstants.PARAMETER_SERVICE, service.getId());
        }
        restoreRequestAttribute(request, session, this.themeParamName);
        restoreRequestAttribute(request, session, this.localParamName);
        restoreRequestAttribute(request, session, CasProtocolConstants.PARAMETER_METHOD);
        // credentials not null -> try to authenticate
        if (credentials != null) {
            final AuthenticationResult authenticationResult = this.authenticationSystemSupport.handleAndFinalizeSingleAuthenticationTransaction(service, new ClientCredential(credentials));
            final TicketGrantingTicket tgt = this.centralAuthenticationService.createTicketGrantingTicket(authenticationResult);
            WebUtils.putTicketGrantingTicketInScopes(context, tgt);
            return success();
        }
    }
    // no or aborted authentication : go to login page
    prepareForLoginPage(context);
    if (response.getStatus() == HttpStatus.UNAUTHORIZED.value()) {
        return stopWebflow();
    }
    if (this.autoRedirect) {
        final Set<ProviderLoginPageConfiguration> urls = context.getFlowScope().get(PAC4J_URLS, Set.class);
        if (urls != null && urls.size() == 1) {
            final ProviderLoginPageConfiguration cfg = urls.stream().findFirst().get();
            LOGGER.debug("Auto-redirecting to client url [{}]", cfg.getRedirectUrl());
            response.sendRedirect(cfg.getRedirectUrl());
            final ExternalContext externalContext = context.getExternalContext();
            externalContext.recordResponseComplete();
            return stopWebflow();
        }
    }
    return error();
}
Also used : WebContext(org.pac4j.core.context.WebContext) HttpSession(javax.servlet.http.HttpSession) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) HttpServletResponse(javax.servlet.http.HttpServletResponse) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) Service(org.apereo.cas.authentication.principal.Service) BaseClient(org.pac4j.core.client.BaseClient) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) HttpServletRequest(javax.servlet.http.HttpServletRequest) ClientCredential(org.apereo.cas.authentication.principal.ClientCredential) CommonProfile(org.pac4j.core.profile.CommonProfile) ExternalContext(org.springframework.webflow.context.ExternalContext) Credentials(org.pac4j.core.credentials.Credentials)

Example 3 with ExternalContext

use of org.springframework.webflow.context.ExternalContext in project uPortal by Jasig.

the class AttributeSwapRequestValidator method validateAttributesForm.

/** Ensures all passed attributes are part of the valid query attribute set. */
public void validateAttributesForm(AttributeSwapRequest attributeSwapRequest, MessageContext context) {
    final RequestContext requestContext = RequestContextHolder.getRequestContext();
    final ExternalContext externalContext = requestContext.getExternalContext();
    final Set<String> swappableAttributes = this.attributeSwapperHelper.getSwappableAttributes(externalContext);
    final Map<String, Attribute> currentAttributes = attributeSwapRequest.getCurrentAttributes();
    this.checkAttributesMap(context, "currentAttributes", swappableAttributes, currentAttributes);
    final Map<String, Attribute> attributesToCopy = attributeSwapRequest.getAttributesToCopy();
    this.checkAttributesMap(context, "attributesToCopy", swappableAttributes, attributesToCopy);
}
Also used : Attribute(org.apereo.portal.portlets.Attribute) ExternalContext(org.springframework.webflow.context.ExternalContext) RequestContext(org.springframework.webflow.execution.RequestContext)

Example 4 with ExternalContext

use of org.springframework.webflow.context.ExternalContext in project uPortal by Jasig.

the class RuntimeMvcViewFactory method createMvcView.

/* (non-Javadoc)
     * @see org.springframework.webflow.mvc.view.AbstractMvcViewFactory#createMvcView(org.springframework.web.servlet.View, org.springframework.webflow.execution.RequestContext)
     */
@Override
protected AbstractMvcView createMvcView(View view, RequestContext context) {
    final ExternalContext externalContext = context.getExternalContext();
    final Object nativeRequest = externalContext.getNativeRequest();
    if (nativeRequest instanceof PortletRequest) {
        return new PortletMvcView(view, context);
    }
    return new ServletMvcView(view, context);
}
Also used : ServletMvcView(org.springframework.webflow.mvc.servlet.ServletMvcView) PortletRequest(javax.portlet.PortletRequest) PortletMvcView(org.springframework.webflow.mvc.portlet.PortletMvcView) ExternalContext(org.springframework.webflow.context.ExternalContext)

Aggregations

ExternalContext (org.springframework.webflow.context.ExternalContext)4 Attribute (org.apereo.portal.portlets.Attribute)2 RequestContext (org.springframework.webflow.execution.RequestContext)2 PortletRequest (javax.portlet.PortletRequest)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpSession (javax.servlet.http.HttpSession)1 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)1 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)1 ClientCredential (org.apereo.cas.authentication.principal.ClientCredential)1 Service (org.apereo.cas.authentication.principal.Service)1 WebApplicationService (org.apereo.cas.authentication.principal.WebApplicationService)1 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)1 BaseClient (org.pac4j.core.client.BaseClient)1 WebContext (org.pac4j.core.context.WebContext)1 Credentials (org.pac4j.core.credentials.Credentials)1 CommonProfile (org.pac4j.core.profile.CommonProfile)1 MessageBuilder (org.springframework.binding.message.MessageBuilder)1 MessageResolver (org.springframework.binding.message.MessageResolver)1 PortletMvcView (org.springframework.webflow.mvc.portlet.PortletMvcView)1