简体   繁体   中英

How to add channel security as https in spring security using “annotations”?

I am using annotations in my application for spring and spring security. As I am not using xml configuration files for spring security, I am not able to use below code:

<intercept-url pattern="/secure/**" access="ROLE_ADMIN" requires-channel="https"/> 

I want an alternative for above code in annotation based configuration, but even after searching a lot, was not able to get any luck.

Thanks in advance

That code was part of spring security config. You need to create a class and extend WebSecurityConfigurerAdapter . Part of the code above is same as:

.antMatchers("/secure/**").access("hasRole('ADMIN')")
.requiresChannel().anyRequest().requiresSecure()

In addition, you can refer to @PreAuthorize("hasRole('ROLE_ADMIN')") as one of annotation method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM