Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions MEMO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## 공부 주제

## 공부 내용

## 참고 사항

- 베너 만드는 사이트 : http://patorjk.com/software/taag/#p=display&f=Graffiti&t=Type%20Something%20
116 changes: 114 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,116 @@
<version>2.5.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<groupId>com.kdt.yun</groupId>
<artifactId>spring-security-master-class</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ssmc</name>
<description>ssmc</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<undertow.version>2.2.9.Final</undertow.version>
<guava.version>30.1.1-jre</guava.version>
<commons.lang.version>3.12.0</commons.lang.version>
<commons.io.version>2.11.0</commons.io.version>
<jackson.datatype.version>2.12.4</jackson.datatype.version>
<java.version>17</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</dependency>

<!-- spring security 모듈 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>

<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-core</artifactId>
<version>${undertow.version}</version>
</dependency>

<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-servlet</artifactId>
<version>${undertow.version}</version>
</dependency>

<!-- thymeleaf spring security 화장 모듈 -->
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons.lang.version}</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons.io.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.datatype.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-afterburner</artifactId>
<version>${jackson.datatype.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson.datatype.version}</version>
</dependency>

<!-- spring security 테스트 모듈 -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
Expand All @@ -31,11 +129,25 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>

</project>
</project>
19 changes: 19 additions & 0 deletions src/main/java/com/kdt/yun/configures/WebMvcConfigure.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
72 changes: 72 additions & 0 deletions src/main/java/com/kdt/yun/configures/WebSecurityConfigure.java
Original file line number Diff line number Diff line change
@@ -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();
// }


}
1 change: 0 additions & 1 deletion src/main/resources/application.properties

This file was deleted.

16 changes: 16 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions src/main/resources/banner.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
###### ######## ###### ## ## ######## #### ######## ## ## ## ## ### ###### ######## ######## ########
## ## ## ## ## ## ## ## ## ## ## ## ## ### ### ## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ## ## #### #### #### ## ## ## ## ## ## ##
###### ###### ## ## ## ######## ## ## ## ## ### ## ## ## ###### ## ###### ########
## ## ## ## ## ## ## ## ## ## ## ## ######### ## ## ## ## ##
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
###### ######## ###### ####### ## ## #### ## ## ####### ## ## ## ## ###### ## ######## ## ##
20 changes: 20 additions & 0 deletions src/main/resources/lobback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/>
<conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>

<property name="CONSOLE_LOG_PATTERN" value="%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}:%L){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/>

<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<Pattern>${CONSOLE_LOG_PATTERN}</Pattern>
</encoder>
</appender>

<logger name="io.undertow" level="OFF"/>

<root level="DEBUG">
<appender-ref ref="console"/>
</root>
</configuration>
Binary file added src/main/resources/static/assets/icons/favi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions src/main/resources/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<meta content="no-cache"/>
<title th:text="#{html.title}"></title>
<link rel="shortcut icon" type="image/x-icon" th:href="@{/assets/icons/favi.png}">
</head>
<body>
index page

</body>
</html>
26 changes: 26 additions & 0 deletions src/main/resources/templates/me.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
<meta charset="UTF-8"/>
<meta content="no-cache"/>
<title th:text="#{html.title}"></title>
<link rel="shortcut icon" type="image/x-icon" th:href="@{/assets/icons/favi.png}">
</head>
<body>
<h1>내 정보</h1>
<hr/>
<span sec:authentication="name"></span> 님 반갑습니다.
<div sec:authorize="hasRole('ROLE_ADMIN')">
User has role ROLE_ADMIN.
</div>
<div sec:authorize="hasRole('ROLE_USER')">
User has role ROLE_USER.
</div>

<ul>
<li><a th:href="@{/logout}">로그아웃</a></li>
<li><a th:href="@{/}">홈으로 가기</a></li>
</ul>
</body>
</html>