package lombelo.controller;

import lombelo.model.Account;
import lombelo.model.AccountRepository;
import org.springframework.beans.factory.annotation.Autowired;
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 java.util.Optional;
import java.util.stream.StreamSupport;

/**
 * @author Niklas Wünsche
 */
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired AccountRepository accounts;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .antMatchers("/").permitAll()
                .anyRequest().authenticated()
                .and()
                .formLogin()
                .loginPage("/login")
                .permitAll()
                .and()
                .logout()
                .permitAll();
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        Optional<Account> foundAccount = StreamSupport.stream(accounts.findAll().spliterator(), false).findAny();
        Account account;
        if(!foundAccount.isPresent()) {
            account = new Account("user", "password");
            accounts.save(account);
        }
        else {
            account = foundAccount.get();
        }

        auth
                .inMemoryAuthentication()
                .withUser(account.getUserName()).password(account.getPassword()).roles("USER");
    }

}
@@ -1503,232 +1503,195 @@
     
-Account account;%0A        if(!foundAccount.isPresent()) %7B%0A            account = new Account(%22user%22, %22password%22);%0A            accounts.save(account);%0A        %7D%0A        else %7B%0A            account = foundAccount.get();%0A        %7D
+String userName = foundAccount.isPresent() ? foundAccount.get().getUserName() : %22user%22;%0A        String password = foundAccount.isPresent() ? foundAccount.get().getPassword() : %22password%22;
 %0A%0A  
@@ -1773,29 +1773,16 @@
 ser(
-account.getU
+u
 serName
-()
 ).pa
@@ -1792,29 +1792,16 @@
 ord(
-account.getP
+p
 assword
-()
 ).ro

Change login method