Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SpringBootSecurityDemo

spring boot REST security URL and METHOD annotation

拦截机制

先通过http request 级别的过滤
即所有的访问都必须满足拥有 USER权限

  @Override
	protected void configure(HttpSecurity http) throws Exception {
		// @formatter:off
		http
			.csrf().disable();
		http
			.authorizeRequests()
						.antMatchers("/**").hasRole("USER")
						.and()
						.httpBasic()
						;
		// @formatter:on				
	}

再通过方法级别的验证
也就是说想要访问/adminAT的用户所拥有的roles必须包含USER
像这样.withUser("provider").password("providerTenmax").roles("PROVIDER", "USER")
这样才能成功使用provider用户访问/adminAT接口

  @RolesAllowed({"ADMIN","PROVIDER"})
  	@RequestMapping(value = "/adminAT", method = RequestMethod.GET)
  	public @ResponseBody String adminAT() {
  		System.out.println("user adminAT login !");
  		return "user adminAT login";
  	}

About

spring boot REST security URL and METHOD annotation

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages