Search in sources :

Example 1 with RuntimeContainer

use of org.springframework.extensions.webscripts.RuntimeContainer in project alfresco-remote-api by Alfresco.

the class BaseSSOAuthenticationFilter method doFilter.

/*
     * (non-Javadoc)
     * @see org.alfresco.repo.web.filter.beans.DependencyInjectedFilter#doFilter(javax.servlet.ServletContext,
     * javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
     */
public void doFilter(ServletContext context, ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    // Get the publicapi.container bean.
    ApplicationContext appContext = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
    RuntimeContainer container = (RuntimeContainer) appContext.getBean("publicapi.container");
    // Get the HTTP request/response
    HttpServletRequest req = (HttpServletRequest) request;
    Match match = null;
    try {
        match = container.getRegistry().findWebScript(req.getMethod(), getScriptUrl(req));
    } catch (NotFoundException | IllegalArgumentException Ex) {
        getLogger().debug(req.getMethod() + " " + getScriptUrl(req) + "not found in Public API Container.");
    }
    // If a filter up the chain has marked the request as not requiring auth then respect it
    if (request.getAttribute(NO_AUTH_REQUIRED) != null) {
        if (getLogger().isTraceEnabled()) {
            getLogger().trace("Authentication not required (filter), chaining ...");
        }
        chain.doFilter(request, response);
    } else // check the authentication required - if none then we don't want any of the filters down the chain to require any authentication checks
    if ((match != null) && (match.getWebScript() != null) && (RequiredAuthentication.none == match.getWebScript().getDescription().getRequiredAuthentication())) {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Found webscript with no authentication - set NO_AUTH_REQUIRED flag.");
        }
        req.setAttribute(NO_AUTH_REQUIRED, Boolean.TRUE);
        chain.doFilter(request, response);
    } else if (authenticateRequest(context, (HttpServletRequest) request, (HttpServletResponse) response)) {
        chain.doFilter(request, response);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ApplicationContext(org.springframework.context.ApplicationContext) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) RuntimeContainer(org.springframework.extensions.webscripts.RuntimeContainer) Match(org.springframework.extensions.webscripts.Match)

Aggregations

HttpServletRequest (javax.servlet.http.HttpServletRequest)1 NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)1 ApplicationContext (org.springframework.context.ApplicationContext)1 Match (org.springframework.extensions.webscripts.Match)1 RuntimeContainer (org.springframework.extensions.webscripts.RuntimeContainer)1