/** * <p> * Process an already-built URL just before returning it. * </p> * <p> * By default, this method will apply the {@code HttpServletResponse.encodeURL(url)} mechanism, as standard * when using the Java Servlet API. Note however that this will only be applied if {@code context} is * an implementation of {@code IWebContext} (i.e. the Servlet API will only be applied in web environments). * </p> * <p> * This method can be overridden by any subclasses that want to change this behaviour (e.g. in order to * avoid using the Servlet API). * </p> * * @param context the execution context. * @param link the already-built URL. * @return the processed URL, ready to be used. */ protected String processLink(final IExpressionContext context, final String link) { if (!(context instanceof IWebContext)) { return link; } final HttpServletResponse response = ((IWebContext)context).getResponse(); return (response != null? response.encodeURL(link) : link); }
return ((IWebContext) context).getResponse();
return new WebEngineContext( configuration, templateData, templateResolutionAttributes, webContext.getRequest(), webContext.getResponse(), webContext.getServletContext(), webContext.getLocale(), Collections.EMPTY_MAP); return new WebEngineContext( configuration, templateData, templateResolutionAttributes, webContext.getRequest(), webContext.getResponse(), webContext.getServletContext(), webContext.getLocale(), variables);
@Override public HttpServletResponse getHttpServletResponse(final IContext context) { if (context instanceof IWebContext) { return ((IWebContext)context).getResponse(); } throw new TemplateProcessingException( "Cannot obtain HttpServletResponse from a non-WebFlux context implementation (\"" + context.getClass().getName() + "\")"); }
@Override public HttpServletResponse getHttpServletResponse(final IContext context) { if (context instanceof IWebContext) { return ((IWebContext)context).getResponse(); } throw new TemplateProcessingException( "Cannot obtain HttpServletResponse from a non-WebFlux context implementation (\"" + context.getClass().getName() + "\")"); }
@Override protected boolean isVisible( final ITemplateContext context, final IProcessableElementTag tag, final AttributeName attributeName, final String attributeValue) { final String attrValue = (attributeValue == null? null : attributeValue.trim()); if (attrValue == null || attrValue.length() == 0) { return false; } if (!(context instanceof IWebContext)) { throw new ConfigurationException( "Thymeleaf execution context is not a web context (implementation of " + IWebContext.class.getName() + "). Spring Security integration can only be used in " + "web environments."); } final IWebContext webContext = (IWebContext) context; final HttpServletRequest request = webContext.getRequest(); final HttpServletResponse response = webContext.getResponse(); final ServletContext servletContext = webContext.getServletContext(); final Authentication authentication = AuthUtils.getAuthenticationObject(); if (authentication == null) { return false; } return AuthUtils.authorizeUsingAccessExpression( context, attrValue, authentication, request, response, servletContext); }
@Override protected boolean isVisible( final ITemplateContext context, final IProcessableElementTag tag, final AttributeName attributeName, final String attributeValue) { final String attrValue = (attributeValue == null? null : attributeValue.trim()); if (attrValue == null || attrValue.length() == 0) { return false; } if (!(context instanceof IWebContext)) { throw new ConfigurationException( "Thymeleaf execution context is not a web context (implementation of " + IWebContext.class.getName() + "). Spring Security integration can only be used in " + "web environments."); } final IWebContext webContext = (IWebContext) context; final HttpServletRequest request = webContext.getRequest(); final HttpServletResponse response = webContext.getResponse(); final ServletContext servletContext = webContext.getServletContext(); final Authentication authentication = AuthUtils.getAuthenticationObject(); if (authentication == null) { return false; } return AuthUtils.authorizeUsingAccessExpression( context, attrValue, authentication, request, response, servletContext); }
@Override protected boolean isVisible( final ITemplateContext context, final IProcessableElementTag tag, final AttributeName attributeName, final String attributeValue) { final String attrValue = (attributeValue == null? null : attributeValue.trim()); if (attrValue == null || attrValue.length() == 0) { return false; } if (!(context instanceof IWebContext)) { throw new ConfigurationException( "Thymeleaf execution context is not a web context (implementation of " + IWebContext.class.getName() + "). Spring Security integration can only be used in " + "web environments."); } final IWebContext webContext = (IWebContext) context; final HttpServletRequest request = webContext.getRequest(); final HttpServletResponse response = webContext.getResponse(); final ServletContext servletContext = webContext.getServletContext(); final Authentication authentication = AuthUtils.getAuthenticationObject(); if (authentication == null) { return false; } return AuthUtils.authorizeUsingAccessExpression( context, attrValue, authentication, request, response, servletContext); }
@Override protected boolean isVisible( final ITemplateContext context, final IProcessableElementTag tag, final AttributeName attributeName, final String attributeValue) { final String attrValue = (attributeValue == null? null : attributeValue.trim()); if (attrValue == null || attrValue.length() == 0) { return false; } if (!(context instanceof IWebContext)) { throw new ConfigurationException( "Thymeleaf execution context is not a web context (implementation of " + IWebContext.class.getName() + "). Spring Security integration can only be used in " + "web environments."); } final IWebContext webContext = (IWebContext) context; final HttpServletRequest request = webContext.getRequest(); final HttpServletResponse response = webContext.getResponse(); final ServletContext servletContext = webContext.getServletContext(); final Authentication authentication = AuthUtils.getAuthenticationObject(); if (authentication == null) { return false; } return AuthUtils.authorizeUsingAccessExpression( context, attrValue, authentication, request, response, servletContext); }
public Object buildObject(final IExpressionContext context, final String expressionObjectName) { if (AUTHENTICATION_EXPRESSION_OBJECT_NAME.equals(expressionObjectName)) { if (context instanceof IWebContext) { return AuthUtils.getAuthenticationObject(); } } if (AUTHORIZATION_EXPRESSION_OBJECT_NAME.equals(expressionObjectName)) { if (context instanceof IWebContext) { // We retrieve it like this in order to give it the opportunity to come from cache final Authentication authentication = (Authentication) context.getExpressionObjects().getObject(AUTHENTICATION_EXPRESSION_OBJECT_NAME); final IWebContext webContext = (IWebContext)context; final HttpServletRequest request = webContext.getRequest(); final HttpServletResponse response = webContext.getResponse(); final ServletContext servletContext = webContext.getServletContext(); return new Authorization(context, authentication, request, response, servletContext); } return null; } return null; }
public Object buildObject(final IExpressionContext context, final String expressionObjectName) { if (AUTHENTICATION_EXPRESSION_OBJECT_NAME.equals(expressionObjectName)) { if (context instanceof IWebContext) { return AuthUtils.getAuthenticationObject(); } } if (AUTHORIZATION_EXPRESSION_OBJECT_NAME.equals(expressionObjectName)) { if (context instanceof IWebContext) { // We retrieve it like this in order to give it the opportunity to come from cache final Authentication authentication = (Authentication) context.getExpressionObjects().getObject(AUTHENTICATION_EXPRESSION_OBJECT_NAME); final IWebContext webContext = (IWebContext)context; final HttpServletRequest request = webContext.getRequest(); final HttpServletResponse response = webContext.getResponse(); final ServletContext servletContext = webContext.getServletContext(); return new Authorization(context, authentication, request, response, servletContext); } return null; } return null; }
public Object buildObject(final IExpressionContext context, final String expressionObjectName) { if (AUTHENTICATION_EXPRESSION_OBJECT_NAME.equals(expressionObjectName)) { if (context instanceof IWebContext) { return AuthUtils.getAuthenticationObject(); } } if (AUTHORIZATION_EXPRESSION_OBJECT_NAME.equals(expressionObjectName)) { if (context instanceof IWebContext) { // We retrieve it like this in order to give it the opportunity to come from cache final Authentication authentication = (Authentication) context.getExpressionObjects().getObject(AUTHENTICATION_EXPRESSION_OBJECT_NAME); final IWebContext webContext = (IWebContext)context; final HttpServletRequest request = webContext.getRequest(); final HttpServletResponse response = webContext.getResponse(); final ServletContext servletContext = webContext.getServletContext(); return new Authorization(context, authentication, request, response, servletContext); } return null; } return null; }
public Object buildObject(final IExpressionContext context, final String expressionObjectName) { if (AUTHENTICATION_EXPRESSION_OBJECT_NAME.equals(expressionObjectName)) { if (context instanceof IWebContext) { return AuthUtils.getAuthenticationObject(); } } if (AUTHORIZATION_EXPRESSION_OBJECT_NAME.equals(expressionObjectName)) { if (context instanceof IWebContext) { // We retrieve it like this in order to give it the opportunity to come from cache final Authentication authentication = (Authentication) context.getExpressionObjects().getObject(AUTHENTICATION_EXPRESSION_OBJECT_NAME); final IWebContext webContext = (IWebContext)context; final HttpServletRequest request = webContext.getRequest(); final HttpServletResponse response = webContext.getResponse(); final ServletContext servletContext = webContext.getServletContext(); return new Authorization(context, authentication, request, response, servletContext); } return null; } return null; }