Example usage for org.springframework.web.servlet ModelAndView hasView

List of usage examples for org.springframework.web.servlet ModelAndView hasView

Introduction

In this page you can find the example usage for org.springframework.web.servlet ModelAndView hasView.

Prototype

public boolean hasView() 

Source Link

Document

Indicate whether or not this ModelAndView has a view, either as a view name or as a direct View instance.

Usage

From source file:org.squashtest.tm.web.internal.interceptor.SecurityExpressionResolverExposerInterceptor.java

/**
 * @see org.springframework.web.servlet.handler.HandlerInterceptorAdapter#postHandle(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse, java.lang.Object, org.springframework.web.servlet.ModelAndView)
 *//*from   www .  j a v a  2s  .co m*/
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) {
    if (modelAndView != null && modelAndView.hasView()
            && !StringUtils.startsWith(modelAndView.getViewName(), "redirect:")) {
        FilterInvocation filterInvocation = new FilterInvocation(request, response, DUMMY_CHAIN);

        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

        if (authentication == null) {
            LOGGER.debug(
                    "No authentication available for '{}{}'. Thymeleaf won't have access to '#sec' in view '{}'",
                    request.getServletPath(), request.getPathInfo(), modelAndView.getViewName());
            return;
        }

        WebSecurityExpressionRoot expressionRoot = new WebSecurityExpressionRoot(authentication,
                filterInvocation);

        expressionRoot.setTrustResolver(trustResolver);
        expressionRoot.setPermissionEvaluator(permissionEvaluator);
        modelAndView.addObject("sec", expressionRoot);
    }
}