diff --git a/MEMO.md b/MEMO.md new file mode 100644 index 0000000..70bb8fb --- /dev/null +++ b/MEMO.md @@ -0,0 +1,7 @@ +## 공부 주제 + +## 공부 내용 + +## 참고 사항 + +- 베너 만드는 사이트 : http://patorjk.com/software/taag/#p=display&f=Graffiti&t=Type%20Something%20 \ No newline at end of file diff --git a/pom.xml b/pom.xml index cfb7c9c..15735e9 100644 --- a/pom.xml +++ b/pom.xml @@ -8,18 +8,116 @@ 2.5.6 + com.kdt.yun spring-security-master-class 0.0.1-SNAPSHOT ssmc ssmc + + UTF-8 + UTF-8 + 2.2.9.Final + 30.1.1-jre + 3.12.0 + 2.11.0 + 2.12.4 17 + org.springframework.boot spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + + org.springframework.boot + spring-boot-starter-undertow + + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + + org.springframework.boot + spring-boot-configuration-processor + + + + + org.springframework.boot + spring-boot-starter-security + + + + io.undertow + undertow-core + ${undertow.version} + + + + io.undertow + undertow-servlet + ${undertow.version} + + + + + org.thymeleaf.extras + thymeleaf-extras-springsecurity5 + + + + com.google.guava + guava + ${guava.version} + + + + org.apache.commons + commons-lang3 + ${commons.lang.version} + + + + commons-io + commons-io + ${commons.io.version} + + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.datatype.version} + + + + com.fasterxml.jackson.module + jackson-module-afterburner + ${jackson.datatype.version} + + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${jackson.datatype.version} + + + + + org.springframework.security + spring-security-test + test @@ -31,11 +129,25 @@ + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + org.springframework.boot spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + - - + \ No newline at end of file diff --git a/src/main/java/com/kdt/yun/configures/WebMvcConfigure.java b/src/main/java/com/kdt/yun/configures/WebMvcConfigure.java new file mode 100644 index 0000000..e2bfc00 --- /dev/null +++ b/src/main/java/com/kdt/yun/configures/WebMvcConfigure.java @@ -0,0 +1,19 @@ +package com.kdt.yun.configures; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +/** + * Created by yunyun on 2021/11/11. + */ + +@Configuration +public class WebMvcConfigure implements WebMvcConfigurer { + + @Override + public void addViewControllers(ViewControllerRegistry registry){ + registry.addViewController("/").setViewName("index"); + registry.addViewController("/me").setViewName("me"); + } +} diff --git a/src/main/java/com/kdt/yun/configures/WebSecurityConfigure.java b/src/main/java/com/kdt/yun/configures/WebSecurityConfigure.java new file mode 100644 index 0000000..3bff956 --- /dev/null +++ b/src/main/java/com/kdt/yun/configures/WebSecurityConfigure.java @@ -0,0 +1,72 @@ +package com.kdt.yun.configures; + +import org.apache.commons.io.file.NoopPathVisitor; +import org.springframework.context.annotation.Bean; +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.builders.WebSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.crypto.password.NoOpPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; + +/** + * Created by yunyun on 2021/11/11. + */ + +@Configuration +@EnableWebSecurity +public class WebSecurityConfigure extends WebSecurityConfigurerAdapter { + + @Override + public void configure(AuthenticationManagerBuilder auth) throws Exception { + //super.configure(auth); + auth.inMemoryAuthentication() + .withUser("user") + .password("{noop}user123") + .roles("USER"); + auth.inMemoryAuthentication() + .withUser("admin") + .password("{noop}admin123") + .roles("ADMIN"); + } + + @Override + public void configure(WebSecurity web){ + web.ignoring().antMatchers("/assets/**"); + } + + @Override + protected void configure(HttpSecurity http) throws Exception{ + http + .authorizeRequests() + .antMatchers("/me").hasAnyRole("USER","ADMIN") + .anyRequest().permitAll() + .and() + .formLogin() + .defaultSuccessUrl("/") + .permitAll() + .and() + .rememberMe() + .rememberMeParameter("remember-me") + .tokenValiditySeconds(5 * 60) + //.alwaysRemember(true) + .and() + .logout() + //.logoutUrl("/logout") + //.deleteCookies("JSESSIONID", "remember-me") + .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) + .logoutSuccessUrl("/") + .invalidateHttpSession(true) // 기본 값이 true 이다. + .clearAuthentication(true); // 기본 값이 true 이다. + } + +// @Bean +// public PasswordEncoder passwordEncoder(){ +// return NoOpPasswordEncoder.getInstance(); +// } + + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 8b13789..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..44f784e --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,16 @@ +spring: + application: + name: spring security 01 + thymeleaf: + cache: true + security: + user: + name: user + password: user123 + roles: USER + messages: + basename: i18n/messages + encoding: UTF-8 + cache-duration: PT1H +server: + port: 8080 \ No newline at end of file diff --git a/src/main/resources/banner.txt b/src/main/resources/banner.txt new file mode 100644 index 0000000..08b4d8a --- /dev/null +++ b/src/main/resources/banner.txt @@ -0,0 +1,7 @@ + ###### ######## ###### ## ## ######## #### ######## ## ## ## ## ### ###### ######## ######## ######## +## ## ## ## ## ## ## ## ## ## ## ## ## ### ### ## ## ## ## ## ## ## ## +## ## ## ## ## ## ## ## ## #### #### #### ## ## ## ## ## ## ## + ###### ###### ## ## ## ######## ## ## ## ## ### ## ## ## ###### ## ###### ######## + ## ## ## ## ## ## ## ## ## ## ## ## ######### ## ## ## ## ## +## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## + ###### ######## ###### ####### ## ## #### ## ## ####### ## ## ## ## ###### ## ######## ## ## \ No newline at end of file diff --git a/src/main/resources/lobback.xml b/src/main/resources/lobback.xml new file mode 100644 index 0000000..c55cd77 --- /dev/null +++ b/src/main/resources/lobback.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + ${CONSOLE_LOG_PATTERN} + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/static/assets/icons/favi.png b/src/main/resources/static/assets/icons/favi.png new file mode 100644 index 0000000..3b48c65 Binary files /dev/null and b/src/main/resources/static/assets/icons/favi.png differ diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html new file mode 100644 index 0000000..384805e --- /dev/null +++ b/src/main/resources/templates/index.html @@ -0,0 +1,13 @@ + + + + + + + + + +index page + + + \ No newline at end of file diff --git a/src/main/resources/templates/me.html b/src/main/resources/templates/me.html new file mode 100644 index 0000000..95a0b99 --- /dev/null +++ b/src/main/resources/templates/me.html @@ -0,0 +1,26 @@ + + + + + + + + + +

내 정보

+
+ 님 반갑습니다. +
+ User has role ROLE_ADMIN. +
+
+ User has role ROLE_USER. +
+ + + + \ No newline at end of file