【发布时间】:2018-05-21 12:16:04
【问题描述】:
我使用 Spring Security,我的配置是
@Override
protected void configure(HttpSecurity http) throws Exception {
http.
authorizeRequests()
.antMatchers("/**").permitAll()
.antMatchers("/admin/**").hasAuthority("ADMIN").anyRequest().authenticated()
.and().csrf().disable().formLogin().loginPage("/adminlogin").failureUrl("/adminlogin?error=true")
.defaultSuccessUrl("/admin/dashboard")
.usernameParameter("email")
.passwordParameter("password")
.and().logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/adminlogin?logout=true").and().exceptionHandling()
.accessDeniedPage("/accessdenied");
}
现在我想要实现的是,所有链接都可以在没有任何安全性的情况下访问,但链接以 /admin/** 开头只允许具有角色“admin”的用户。
但现在它允许 /admin/** 对每个人。
任何建议。
我尝试了许多来自 stackoverflow 的解决方案,即How to fix role in Spring Security?,但没有运气。行为保持不变,甚至允许 /admin/ url 公开使用。
【问题讨论】:
标签: java spring spring-mvc spring-boot spring-security