From d2e5da2166825f66bc005411e54a19c68e86c252 Mon Sep 17 00:00:00 2001 From: Tom Hombergs Date: Sat, 7 Jan 2017 22:32:29 +0100 Subject: [PATCH] added login page and secured all other pages (#5, #6, #26) --- .../GitanizerSecurityConfiguration.java | 15 ++++-- .../thymeleaf/ResourcesConfiguration.java | 16 +++--- .../gitanizer/login/LoginController.java | 14 +++++ .../resources/templates/layouts/layout.html | 16 +++--- src/main/resources/templates/login.html | 54 +++++++++++++++++++ 5 files changed, 95 insertions(+), 20 deletions(-) create mode 100644 src/main/java/org/wickedsource/gitanizer/login/LoginController.java create mode 100644 src/main/resources/templates/login.html diff --git a/src/main/java/org/wickedsource/gitanizer/core/security/GitanizerSecurityConfiguration.java b/src/main/java/org/wickedsource/gitanizer/core/security/GitanizerSecurityConfiguration.java index 344eb2a..9484a2f 100644 --- a/src/main/java/org/wickedsource/gitanizer/core/security/GitanizerSecurityConfiguration.java +++ b/src/main/java/org/wickedsource/gitanizer/core/security/GitanizerSecurityConfiguration.java @@ -14,10 +14,15 @@ public class GitanizerSecurityConfiguration extends WebSecurityConfigurerAdapter @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() - .antMatchers("/actuator").hasAnyRole("ADMIN") - .anyRequest().permitAll() + .antMatchers("/login").permitAll() + .antMatchers("/static/**/*").permitAll() + .anyRequest().hasAnyRole("USER") .and() - .httpBasic(); + .formLogin() + /**/.loginPage("/login") + /**/.loginProcessingUrl("/do-login") + /**/.passwordParameter("password") + /**/.usernameParameter("username"); http.csrf().disable(); } @@ -25,7 +30,9 @@ protected void configure(HttpSecurity http) throws Exception { @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication() - .withUser("admin").password("admin").roles("ADMIN"); + .withUser("user").password("user").roles("USER") + .and() + .withUser("admin").password("admin").roles("USER", "ADMIN"); } } diff --git a/src/main/java/org/wickedsource/gitanizer/core/thymeleaf/ResourcesConfiguration.java b/src/main/java/org/wickedsource/gitanizer/core/thymeleaf/ResourcesConfiguration.java index 918cc73..57f9148 100644 --- a/src/main/java/org/wickedsource/gitanizer/core/thymeleaf/ResourcesConfiguration.java +++ b/src/main/java/org/wickedsource/gitanizer/core/thymeleaf/ResourcesConfiguration.java @@ -25,14 +25,14 @@ public ResourcesConfiguration(GitRepositoryResolver gitRepositoryResolver, Workd @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("/bootstrap/**").addResourceLocations("classpath:/bootstrap/"); - registry.addResourceHandler("/AdminLTE/**").addResourceLocations("classpath:/AdminLTE/"); - registry.addResourceHandler("/jQuery/**").addResourceLocations("classpath:/jQuery/"); - registry.addResourceHandler("/templates/**").addResourceLocations("classpath:/templates/"); - registry.addResourceHandler("/codemirror/**").addResourceLocations("classpath:/codemirror/"); - registry.addResourceHandler("/gitanizer/**").addResourceLocations("classpath:/gitanizer/"); - registry.addResourceHandler("/clipboardjs/**").addResourceLocations("classpath:/clipboardjs/"); - registry.addResourceHandler("/img/**").addResourceLocations("classpath:/img/"); + registry.addResourceHandler("/static/bootstrap/**").addResourceLocations("classpath:/bootstrap/"); + registry.addResourceHandler("/static/AdminLTE/**").addResourceLocations("classpath:/AdminLTE/"); + registry.addResourceHandler("/static/jQuery/**").addResourceLocations("classpath:/jQuery/"); + registry.addResourceHandler("/static/templates/**").addResourceLocations("classpath:/templates/"); + registry.addResourceHandler("/static/codemirror/**").addResourceLocations("classpath:/codemirror/"); + registry.addResourceHandler("/static/gitanizer/**").addResourceLocations("classpath:/gitanizer/"); + registry.addResourceHandler("/static/clipboardjs/**").addResourceLocations("classpath:/clipboardjs/"); + registry.addResourceHandler("/static/img/**").addResourceLocations("classpath:/img/"); registry.addResourceHandler("/git/**/*") .resourceChain(true) .addResolver(gitRepositoryResolver); diff --git a/src/main/java/org/wickedsource/gitanizer/login/LoginController.java b/src/main/java/org/wickedsource/gitanizer/login/LoginController.java new file mode 100644 index 0000000..2b6f34d --- /dev/null +++ b/src/main/java/org/wickedsource/gitanizer/login/LoginController.java @@ -0,0 +1,14 @@ +package org.wickedsource.gitanizer.login; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class LoginController { + + @GetMapping(value = "/login") + public String displayLoginPage() { + return "login"; + } + +} diff --git a/src/main/resources/templates/layouts/layout.html b/src/main/resources/templates/layouts/layout.html index 03ca66e..4da9a87 100644 --- a/src/main/resources/templates/layouts/layout.html +++ b/src/main/resources/templates/layouts/layout.html @@ -5,13 +5,13 @@ Gitanizer - + - - - + + + @@ -54,10 +54,10 @@ - - - - + + + diff --git a/src/main/resources/templates/login.html b/src/main/resources/templates/login.html new file mode 100644 index 0000000..cef665f --- /dev/null +++ b/src/main/resources/templates/login.html @@ -0,0 +1,54 @@ + + + + + + gitanizer login + + + + + + + + + + + +
+ + + + +
+ + + + + +