2

Using Spring Security we use hasAuthority to conditionally execute code or conditionally display parts of page in jsp.

eg:

@PreAuthorize("hasAuthority('ROLE_TELLER')")
public Account post(Account account, double amount);
}

or (in jsp)

<sec:authorize access="hasAuthority('TAG_SAVE')">
 .... content to display / evaluate
</sec:authorize>

I wanted to know how to handle a case when you want to show / execute something when not having Authority.

may something like

doesNotHaveAuthority('TAG_SAVE')

I am pretty sure, this is not an out of the blue use-case. Has anyone handle this in any way?

R K Punjal
  • 1,445
  • 1
  • 15
  • 20

1 Answers1

4

Actually found that this can use EL. So Using a ! sign works.

So I got it work like this:

<sec:authorize access="!hasAuthority('TAG_SAVE')">
 .... content to display / evaluate when the Authority is not present
</sec:authorize>
R K Punjal
  • 1,445
  • 1
  • 15
  • 20