简体   繁体   English

如何在春季安全性中使用“注释”将通道安全性添加为https?

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

I am using annotations in my application for spring and spring security. 我在我的应用程序中使用注释来实现Spring和Spring安全性。 As I am not using xml configuration files for spring security, I am not able to use below code: 由于我没有将xml配置文件用于弹簧安全性,因此无法使用以下代码:

<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. 该代码是spring安全配置的一部分。 You need to create a class and extend WebSecurityConfigurerAdapter . 您需要创建一个类并扩展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. 另外,您可以将@PreAuthorize("hasRole('ROLE_ADMIN')")称为注释方法之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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