Skip to content

Instantly share code, notes, and snippets.

@monkey-codes
Created December 1, 2016 03:27
Show Gist options
  • Select an option

  • Save monkey-codes/d191fe4cbae29466c3f1a213ab3edfae to your computer and use it in GitHub Desktop.

Select an option

Save monkey-codes/d191fe4cbae29466c3f1a213ab3edfae to your computer and use it in GitHub Desktop.
Spring boot - Microservice spring config
@SpringBootApplication
@RestController
class MicroserviceApplication {
@RequestMapping(value = '/{id}', method = RequestMethod.GET)
public Map readFoo(@PathVariable Integer id, Principal principal) {
[
id: id,
resource: "${UUID.randomUUID()}" as String,
user: principal.getName()
]
}
@Configuration
@EnableResourceServer
public static class ResourceServiceConfiguration extends ResourceServerConfigurerAdapter {
@Override
void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.antMatchers("/**").hasAuthority('ROLE_READER')
}
}
public static void main(String[] args) {
SpringApplication.run(MicroserviceApplication.class, args)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment