Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of use-expressions attribute in XML based Spring Security configuration to code based configuration

How to enable the use-expressions option of the Spring Security configuration in a code based configuration? This option is needed to enable Expression-Based Access Control usage for Thymeleaf.

In the XML configuration it looks like this:

...
<http auto-config="true" use-expressions="true" >
   ...   
</http>
...
like image 767
Flo Avatar asked May 16 '14 14:05

Flo


People also ask

Which annotation can be used with Spring Security to apply method level security?

Method-level security is implemented by placing the @PreAuthorize annotation on controller methods (actually one of a set of annotations available, but the most commonly used). This annotation contains a Spring Expression Language (SpEL) snippet that is assessed to determine if the request should be authenticated.

What is hasRole and hasAnyRole?

hasRole, hasAnyRole. These expressions are responsible for defining the access control or authorization to specific URLs and methods in our application: @Override protected void configure(final HttpSecurity http) throws Exception { ... . antMatchers("/auth/admin/*").

What is @PreAuthorize?

@PostAuthorize: The @PostAuthorize as name suggest checks for authorization after method execution. The @PostAuthorize authorizes on the basis of logged in roles, return object by method and passed argument to the method. For the returned object spring security provides built-in keyword i.e. returnObject.

What is the use of WebSecurityConfigurerAdapter in Spring boot?

In Spring Boot 2, if we want our own security configuration, we can simply add a custom WebSecurityConfigurerAdapter. This will disable the default auto-configuration and enable our custom security configuration. Spring Boot 2 also uses most of Spring Security's defaults.


1 Answers

According to this blog post, use-expressions is set to true when using the Java Configuration.

Comparison to XML Namespace
...
One difference is that Java Configuration uses authorizeUrls 
to specify use-expressions="true"

Hope this helps.

like image 124
Shinichi Kai Avatar answered Oct 09 '22 08:10

Shinichi Kai