From b80f8f0997b2cef88b0eb669c23d91a9bb66f4af Mon Sep 17 00:00:00 2001 From: pranabjyotiopsmx Date: Fri, 20 Nov 2020 11:35:48 +0530 Subject: [PATCH 1/3] Code to customize login form --- gate-core/gate-core.gradle | 2 +- .../spinnaker/gate/config/AuthConfig.groovy | 10 ++- .../gate/config/GateWebConfig.groovy | 8 ++ .../src/main/resources/templates/hello.html | 27 ++++++ .../src/main/resources/templates/login.html | 87 +++++++++++++++++++ 5 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 gate-web/src/main/resources/templates/hello.html create mode 100644 gate-web/src/main/resources/templates/login.html diff --git a/gate-core/gate-core.gradle b/gate-core/gate-core.gradle index 1e41062571..8888e66981 100644 --- a/gate-core/gate-core.gradle +++ b/gate-core/gate-core.gradle @@ -18,7 +18,7 @@ dependencies { api "org.springframework.boot:spring-boot-starter-web" api "org.springframework.boot:spring-boot-starter-actuator" api "org.springframework.boot:spring-boot-starter-security" - + api "org.springframework.boot:spring-boot-starter-thymeleaf" api "com.squareup.retrofit:retrofit" implementation "com.jakewharton.retrofit:retrofit1-okhttp3-client:1.1.0" diff --git a/gate-core/src/main/groovy/com/netflix/spinnaker/gate/config/AuthConfig.groovy b/gate-core/src/main/groovy/com/netflix/spinnaker/gate/config/AuthConfig.groovy index 4e423081a6..3ffd97b5b7 100644 --- a/gate-core/src/main/groovy/com/netflix/spinnaker/gate/config/AuthConfig.groovy +++ b/gate-core/src/main/groovy/com/netflix/spinnaker/gate/config/AuthConfig.groovy @@ -33,13 +33,13 @@ import org.springframework.context.annotation.Configuration import org.springframework.http.HttpMethod import org.springframework.security.config.annotation.web.builders.HttpSecurity import org.springframework.security.config.annotation.web.builders.WebSecurity +import org.springframework.security.config.http.SessionCreationPolicy import org.springframework.security.core.Authentication import org.springframework.security.web.authentication.AnonymousAuthenticationFilter +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter import org.springframework.security.web.authentication.logout.LogoutSuccessHandler import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler import org.springframework.stereotype.Component -import org.springframework.security.config.http.SessionCreationPolicy; -import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; import javax.servlet.Filter import javax.servlet.ServletException @@ -98,7 +98,9 @@ class AuthConfig { .antMatchers(HttpMethod.POST, '/webhooks/**').permitAll() .antMatchers(HttpMethod.POST, '/notifications/callbacks/**').permitAll() .antMatchers('/health').permitAll() + .antMatchers('/hello*').permitAll() .antMatchers('/**').authenticated() + if (fiatSessionFilterEnabled) { Filter fiatSessionFilter = new FiatSessionFilter( fiatSessionFilterEnabled, @@ -108,6 +110,10 @@ class AuthConfig { http.addFilterBefore(fiatSessionFilter, AnonymousAuthenticationFilter.class) } + http.formLogin() + .loginPage("/login") + .permitAll() + http.logout() .logoutUrl("/auth/logout") .logoutSuccessHandler(permissionRevokingLogoutSuccessHandler) diff --git a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/config/GateWebConfig.groovy b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/config/GateWebConfig.groovy index 93da998e47..2330e0061c 100644 --- a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/config/GateWebConfig.groovy +++ b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/config/GateWebConfig.groovy @@ -40,6 +40,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler import org.springframework.web.bind.annotation.ResponseBody import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer import org.springframework.web.servlet.config.annotation.InterceptorRegistry +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry import org.springframework.web.servlet.config.annotation.WebMvcConfigurer import org.springframework.web.servlet.handler.HandlerMappingIntrospector import retrofit.RetrofitError @@ -68,6 +69,8 @@ public class GateWebConfig implements WebMvcConfigurer { @Value('${rate-limit.learning:true}') Boolean rateLimitLearningMode + + @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor( @@ -138,4 +141,9 @@ public class GateWebConfig implements WebMvcConfigurer { void configureContentNegotiation(ContentNegotiationConfigurer configurer) { configurer.favorPathExtension(false) } + + public void addViewControllers(ViewControllerRegistry registry) { + registry.addViewController("/login").setViewName("login") + registry.addViewController("/hello").setViewName("hello") + } } diff --git a/gate-web/src/main/resources/templates/hello.html b/gate-web/src/main/resources/templates/hello.html new file mode 100644 index 0000000000..e0ea9bdf6c --- /dev/null +++ b/gate-web/src/main/resources/templates/hello.html @@ -0,0 +1,27 @@ + + + + + + + Title +

Hello World

+ + + + + diff --git a/gate-web/src/main/resources/templates/login.html b/gate-web/src/main/resources/templates/login.html new file mode 100644 index 0000000000..5246e52b01 --- /dev/null +++ b/gate-web/src/main/resources/templates/login.html @@ -0,0 +1,87 @@ + + + + + + + + OES Login - Please sign in + + + + + +
+
+
+ +
+ +
+
+ + + + + From 60748795c192b3f61590cc5926071df316422718 Mon Sep 17 00:00:00 2001 From: pranabjyotiopsmx Date: Fri, 20 Nov 2020 13:17:31 +0530 Subject: [PATCH 2/3] Removed dummy templates --- .../spinnaker/gate/config/AuthConfig.groovy | 1 - .../src/main/resources/templates/hello.html | 27 ------------------- 2 files changed, 28 deletions(-) delete mode 100644 gate-web/src/main/resources/templates/hello.html diff --git a/gate-core/src/main/groovy/com/netflix/spinnaker/gate/config/AuthConfig.groovy b/gate-core/src/main/groovy/com/netflix/spinnaker/gate/config/AuthConfig.groovy index 3ffd97b5b7..6a5a03088e 100644 --- a/gate-core/src/main/groovy/com/netflix/spinnaker/gate/config/AuthConfig.groovy +++ b/gate-core/src/main/groovy/com/netflix/spinnaker/gate/config/AuthConfig.groovy @@ -98,7 +98,6 @@ class AuthConfig { .antMatchers(HttpMethod.POST, '/webhooks/**').permitAll() .antMatchers(HttpMethod.POST, '/notifications/callbacks/**').permitAll() .antMatchers('/health').permitAll() - .antMatchers('/hello*').permitAll() .antMatchers('/**').authenticated() if (fiatSessionFilterEnabled) { diff --git a/gate-web/src/main/resources/templates/hello.html b/gate-web/src/main/resources/templates/hello.html deleted file mode 100644 index e0ea9bdf6c..0000000000 --- a/gate-web/src/main/resources/templates/hello.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - Title -

Hello World

- - - - - From 5de0de730d46ec184a718130924b01ca259ff781 Mon Sep 17 00:00:00 2001 From: pranabjyotiopsmx Date: Fri, 20 Nov 2020 13:20:30 +0530 Subject: [PATCH 3/3] Removed dummy templates --- .../com/netflix/spinnaker/gate/config/GateWebConfig.groovy | 1 - 1 file changed, 1 deletion(-) diff --git a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/config/GateWebConfig.groovy b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/config/GateWebConfig.groovy index 2330e0061c..4978924b8d 100644 --- a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/config/GateWebConfig.groovy +++ b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/config/GateWebConfig.groovy @@ -144,6 +144,5 @@ public class GateWebConfig implements WebMvcConfigurer { public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/login").setViewName("login") - registry.addViewController("/hello").setViewName("hello") } }