【发布时间】:2016-11-27 15:47:31
【问题描述】:
在扩展 WebSecurityConfigurerAdapter 的类中 我有这段代码可以通过 url 为不同的角色添加安全性。
http.authorizeRequests().antMatchers(HttpMethod.GET, "/rest/setup/defaultpassword/**").hasRole("USER");
http.authorizeRequests().antMatchers(HttpMethod.GET, "/rest/setup/commerces/**").hasRole("USER");
http.authorizeRequests().antMatchers(HttpMethod.GET, "/rest/setup/tax").hasRole("USER");
http.authorizeRequests().antMatchers("/rest/setup/tax").hasRole("ADMIN");
http.authorizeRequests().antMatchers("/login").permitAll(); //
http.authorizeRequests().antMatchers("/rest/**").authenticated();
http.csrf().disable();
http.exceptionHandling().authenticationEntryPoint(authenticationEntryPoint);
http.formLogin().successHandler(authenticationSuccessHandler);
http.formLogin().failureHandler(authenticationFailureHandler);
http.logout().logoutUrl("/logout");
http.logout().logoutSuccessUrl("/");
当我以用户角色登录时,我可以访问:/rest/setup/tax
当我以管理员身份登录时,我可以访问 /rest/setup/tax
http://localhost:8080/rest/setup/tax403(禁止)
我搜索只提供用户角色的获取和管理员角色的所有内容。
【问题讨论】: