package demo;

import java.util.Collections;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.StaticResourceRequest;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@EnableCaching
@RestController
public class HazelcastUseCasesApplication implements CommandLineRunner {

	@Autowired
	private SampleEntityRepository repository;

	public static void main(String[] args) {
		SpringApplication.run(HazelcastUseCasesApplication.class, args);
	}

	@Override
	@Transactional
	public void run(String... args) throws Exception {
		this.repository.save(new SampleEntity("sample1"));
		this.repository.save(new SampleEntity("sample2"));
		this.repository.save(new SampleEntity("sample3"));
	}

	@GetMapping(path = "/")
	public Iterable<SampleEntity> home() {
		return this.repository.findAll();
	}

	@Configuration
	static class SecurityConfiguration extends WebSecurityConfigurerAdapter {

		@Bean
		public UserDetailsService userDetailsService() {
			return new InMemoryUserDetailsManager(Collections.singletonList(
					User.withUsername("user").password("password").roles("USER").build()));
		}

		// @formatter:off
		@Override
		protected void configure(HttpSecurity http) throws Exception {
			http
				.authorizeRequests()
					.requestMatchers(StaticResourceRequest.toCommonLocations()).permitAll()
					.anyRequest().authenticated()
					.and()
				.formLogin()
					.permitAll();
		}
		// @formatter:on

	}

}

@@ -12,39 +12,8 @@
 o;%0A%0A
-import java.util.Collections;%0A%0A
 impo
@@ -1913,50 +1913,43 @@
 ger(
-Collections.singletonList(%0A%09%09%09%09%09User.withU
+User.withDefaultPasswordEncoder().u
 sern
@@ -1959,16 +1959,22 @@
 (%22user%22)
+%0A%09%09%09%09%09
 .passwor
@@ -2013,36 +2013,15 @@
 d())
-)
 ;%0A%09%09%7D%0A%0A
-%09%09// @formatter:off%0A
 %09%09@O
@@ -2093,16 +2093,37 @@
 ption %7B%0A
+%09%09%09// @formatter:off%0A
 %09%09%09http%0A
@@ -2308,19 +2308,16 @@
 All();%0A%09
-%09%7D%0A
 %09%09// @fo
@@ -2326,16 +2326,20 @@
 atter:on
+%0A%09%09%7D
 %0A%0A%09%7D%0A%0A%7D%0A

Fix hazelcast-use-cases sample user manager