package hello;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.oauth2.config.annotation.authentication.configurers.InMemoryClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configurers.OAuth2ServerConfigurer;
import org.springframework.security.oauth2.provider.token.InMemoryTokenStore;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

	private final String applicationName = "restservice";

	// @formatter:off
	@Override
	protected void configure(HttpSecurity http) throws Exception {
		http
			.requestMatchers()
				.and()
			.authorizeRequests()
				.antMatchers("/").permitAll()
				.anyRequest().authenticated()
				.and()
			.apply(new OAuth2ServerConfigurer())
			.tokenStore(new InMemoryTokenStore())
			.resourceId(applicationName);
	}
	// @formatter:on

	// @formatter:off
	@Override
	protected void configure(AuthenticationManagerBuilder auth) throws Exception {
		auth
			.userDetailsService(new InMemoryUserDetailsManager(getUserDetails()))
				.and()
			.apply(new InMemoryClientDetailsServiceConfigurer())
				.withClient("clientapp")
				.resourceIds(applicationName)
				.scopes("read", "write")
				.authorities("USER")
				.authorizedGrantTypes("password")
				.secret("123456");
	}
	// @formatter:on

	private static final Collection<UserDetails> getUserDetails() {
		List<UserDetails> userDetails = new ArrayList<UserDetails>();
		userDetails.add(new User("user", "password", AuthorityUtils.createAuthorityList(
				"USER", "read", "write")));
		return userDetails;
	}

}

@@ -435,110 +435,8 @@
 ty;%0A
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;%0A
 impo
@@ -494,24 +494,24 @@
 orityUtils;%0A
+
 import org.s
@@ -743,32 +743,142 @@
 viceConfigurer;%0A
+import org.springframework.security.oauth2.config.annotation.web.configuration.OAuth2ServerConfigurerAdapter;%0A
 import org.sprin
@@ -1191,27 +1191,28 @@
 extends 
-WebSecurity
+OAuth2Server
 Configur

Extend from OAuth2ServerConfigurerAdapter instead of WebSecurityConfigurerAdapter