Tar*_*tor 23 java spring annotations spring-mvc spring-security
我有Spring WebMVC应用程序使用@PreAuthorize和@PostAuthorice注释控制器方法.但是这些注释被忽略了,因为我没有在我的Spring安全性中启用它.
如果我有一个,spring-security.xml我可以使用以下行启用它:
<global-method-security pre-post-annotations="enabled" />
Run Code Online (Sandbox Code Playgroud)
不幸的是,我有一个完整的基于注释的配置.Spring-Security原则上适用于我的应用程序.
我的问题:如何使用基于注释的MVC配置启用前后注释?
这是我的WebSecurityConfigurerAdapter实施:
@Configuration
@EnableWebMvcSecurity()
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired DataSource dataSource;
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication()
.dataSource(dataSource)
.passwordEncoder(new ShaPasswordEncoder(256))
.usersByUsernameQuery("select username,password, enabled from user where USERNAME=?")
.authoritiesByUsernameQuery("select u.username, r.name from user u, role r, user_has_role uhr where u.id = uhr.user_id and r.id = uhr.role_id and u.username = ? ");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/resources/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.defaultSuccessUrl("/", true)
.and()
.logout()
//.logoutUrl("/logout") //this is the default
// Call the URL invalidate_session after logout...
.logoutSuccessUrl("/invalidate_session")
.permitAll()
.and()
// @see http://docs.spring.io/spring-security/site/docs/3.2.x/reference/htmlsingle/#csrf-configure
.csrf().disable();
}
}
Run Code Online (Sandbox Code Playgroud)
我MessageSecurityWebApplicationInitializer是空的:
public class MessageSecurityWebApplicationInitializer extends
AbstractSecurityWebApplicationInitializer {
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8238 次 |
| 最近记录: |