注释安全弹簧文件属性

时间:2015-06-01 08:16:14

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

我希望在春天的应用程序中使用注释@PreAuthorized和@PostAuthorized,但我使用它并没有什么都不做。 我需要在application.properties中激活“something”,但我不知道。 我读到这是servlet.xl

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

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

1 个答案:

答案 0 :(得分:0)

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

@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

相关问题