【问题标题】:annotation security spring file properties注释安全弹簧文件属性
【发布时间】:2015-06-01 19:30:55
【问题描述】:

我想在春季的应用程序中使用注释 @PreAuthorized 和 @PostAuthorized,但我使用它并没有做任何事情。 我需要在 application.properties 中激活“某些东西”,但我不知道。 我读到这是 servlet.xl

 <global-method-security pre-post-annotations="enabled" />

但是在文件属性中? 我使用 java 注释,但我没有激活它。

【问题讨论】:

    标签: java spring security spring-mvc spring-security


    【解决方案1】:

    我建议只使用这样的配置:

    @Configuration
    @EnableGlobalMethodSecurity(prePostEnabled = true)
    @EnableWebSecurity
    public class AuthenticationConfiguration extends WebSecurityConfigurerAdapter {
        // Your authorisation service, you need to provide one
        @Autowired
        private UserAuthenticationService userDetailsService;
    
        @Override
        protected void configure(AuthenticationManagerBuilder auth) throws Exception {
            auth.userDetailsService(userDetailsService);
        }
    
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests().anyRequest().fullyAuthenticated();
            http.httpBasic();
            http.csrf().disable();
        }
    }
    

    这里有一个非常好的教程,你应该阅读它并尝试一步一步地复制它,关于主题的更多信息可以放在这里: Building a secure REST API with Spring Data REST and Java 8

    【讨论】:

    • 谢谢,我已经实现了这个想法,但我想知道如果我不添加 EnableGlobalMethodSecurity(prePostEnabled = true) 并在文件属性中激活此属性是否可行。
    • 我不认为这可以在 application.properties 中配置,但您可以在 spring 属性文档页面检查所有可能的安全配置:docs.spring.io/spring-boot/docs/current/reference/html/…
    • 是的,我检查了这个,我没有发现任何配置的内容
    猜你喜欢
    • 2012-08-04
    • 2013-08-08
    • 2015-11-14
    • 1970-01-01
    • 1970-01-01
    • 2011-10-23
    • 2022-06-20
    • 1970-01-01
    相关资源
    最近更新 更多