Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would like to supplement Ralph's response about creating custom SpEL expression. His explanations helped very much on my attempt to find the right way to do this, but i think that they need to be extended. </p> <p>Here is a way on how to create custom SpEL expression:</p> <p>1) Create custom subclass of <strong><em>WebSecurityExpressionRoot</em></strong> class. In this subclass create a new method which you will use in expression. For example:</p> <pre><code>public class CustomWebSecurityExpressionRoot extends WebSecurityExpressionRoot { public CustomWebSecurityExpressionRoot(Authentication a, FilterInvocation fi) { super(a, fi); } public boolean yourCustomMethod() { boolean calculatedValue = ...; return calculatedValue; } }</code></pre> <p>2) Create custom subclass of <strong><em>DefaultWebSecurityExpressionHandler</em></strong> class and override method <strong><em>createSecurityExpressionRoot(Authentication authentication, FilterInvocation fi)</em></strong> (not createEvaluationContext(...)) in it to return your <strong><em>CustomWebSecurityExpressionRoot</em></strong> instance. For example:</p> <pre><code>@Component(value="customExpressionHandler") public class CustomWebSecurityExpressionHandler extends DefaultWebSecurityExpressionHandler { @Override protected SecurityExpressionRoot createSecurityExpressionRoot( Authentication authentication, FilterInvocation fi) { WebSecurityExpressionRoot expressionRoot = new CustomWebSecurityExpressionRoot(authentication, fi); return expressionRoot; }}</code></pre> <p>3) Define in your spring-security.xml the reference to your expression handler bean</p> <pre><code>&lt;security:http access-denied-page="/error403.jsp" use-expressions="true" auto-config="false"&gt; ... &lt;security:expression-handler ref="customExpressionHandler"/&gt; &lt;/security:http&gt; </code></pre> <p>After this, you can use your own custom expression instead of the standard one:</p> <pre><code>&lt;security:authorize access="yourCustomMethod()"&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload