@SpringBootApplication @EnableAuthorizationServer @EnableResourceServer public class Application extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } ///////////////////////////////// @RestController public class HelloWorldRestController { @RequestMapping(value = "/", method = RequestMethod.GET) public String lol1() { return "lol1"; } @RequestMapping(value = "/user/me", method = RequestMethod.GET) public List listAllUsers() { List users = new ArrayList<>(); User user = new User(); user.setId(1); user.setLol("Lol"); users.add(user); return users; } } ////////////////////////////////// @Configuration public class AuthServerConfig extends AuthorizationServerConfigurerAdapter { @Autowired private AuthenticationManager authenticationManager; @Override public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception { oauthServer.tokenKeyAccess("permitAll()") .checkTokenAccess("isAuthenticated()"); } @Override public void configure(ClientDetailsServiceConfigurer clients) throws Exception { clients.inMemory() .withClient("SampleClientId") .secret("secret") .authorizedGrantTypes("password", "refresh_token") .scopes("user_info") .autoApprove(true) ; } @Override public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { endpoints.authenticationManager(authenticationManager); } } /////////////////////////////// @Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired public void globalUserDetails(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication() .withUser("bill").password("abc123").roles("ADMIN").and() .withUser("bob").password("abc123").roles("USER"); } @Override protected void configure(HttpSecurity http) throws Exception { http .requestMatchers() .antMatchers("/login") .and() .authorizeRequests() .anyRequest().authenticated() .and() .formLogin().permitAll(); } @Override @Bean public AuthenticationManager authenticationManagerBean() throws Exception { return super.authenticationManagerBean(); } }