package com.example;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
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.WebSecurityConfigurerAdapter;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;
import java.util.LinkedHashMap;
import java.util.Map;

@SpringBootApplication
@EnableRedisHttpSession
@EnableZuulProxy
@RestController
public class GatewayApplication extends WebSecurityConfigurerAdapter {

    @RequestMapping("/user")
    public Map<String, Object> user(Principal user) {
        Map<String, Object> map = new LinkedHashMap<>();
        map.put("name", "user");
        return map;
    }

    @Autowired
    public void globalUserDetails(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication().withUser("user").password("password").roles("USER")
                .and().withUser("admin").password("admin").roles("USER", "ADMIN", "READER", "WRITER")
                .and().withUser("audit").password("audit").roles("USER", "ADMIN", "READER");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .httpBasic()
        .and()
            .authorizeRequests()
                .antMatchers("/index.html", "/login", "/").permitAll()
                .antMatchers("/admin/**").hasRole("ADMIN")
            .anyRequest().authenticated();
    }

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

@@ -229,42 +229,228 @@
 ork.
-cloud.netflix.zuul.EnableZuulProxy
+boot.autoconfigure.security.SecurityProperties;%0Aimport org.springframework.cloud.netflix.zuul.EnableZuulProxy;%0Aimport org.springframework.context.annotation.Configuration;%0Aimport org.springframework.core.annotation.Order
 ;%0Aim
@@ -734,24 +734,148 @@
 rerAdapter;%0A
+import org.springframework.security.core.Authentication;%0Aimport org.springframework.security.core.authority.AuthorityUtils;%0A
 import org.s
@@ -1289,45 +1289,8 @@
 ion 
-extends WebSecurityConfigurerAdapter 
 %7B%0A%0A 
@@ -1456,44 +1456,320 @@
 e%22, 
-%22user%22);%0A        return map;%0A    %7D%0A%0A
+user.getName());%0A        map.put(%22roles%22, AuthorityUtils.authorityListToSet(((Authentication) user).getAuthorities()));%0A        return map;%0A    %7D%0A%0A    @Configuration%0A    @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)%0A    protected static class SecurityConfiguration extends WebSecurityConfigurerAdapter %7B%0A%0A    
     
@@ -1779,16 +1779,20 @@
 towired%0A
+    
     publ
@@ -1879,16 +1879,20 @@
         
+    
 auth.inM
@@ -1912,16 +1912,33 @@
 cation()
+%0A                
 .withUse
@@ -1990,34 +1990,47 @@
             
-    
 .and()
+%0A                
 .withUser(%22a
@@ -2109,26 +2109,39 @@
         
-    
 .and()
+%0A                
 .withUse
@@ -2203,27 +2203,35 @@
 ADER%22);%0A    
-%7D%0A%0A
+    %7D%0A%0A    
     @Overrid
@@ -2232,16 +2232,20 @@
 verride%0A
+    
     prot
@@ -2315,13 +2315,21 @@
     
+    
 http%0A
+    
     
@@ -2349,39 +2349,92 @@
 Basic()%0A        
+ 
+   
 .and()%0A
+                .logout()%0A            .and()%0A    
             .aut
@@ -2592,16 +2592,20 @@
         
+    
 .anyRequ
@@ -2623,24 +2623,34 @@
 nticated();%0A
+        %7D%0A
     %7D%0A%0A    p

modify the authentication method and configurations