2021-08-02

This commit is contained in:
2021-08-02 17:02:06 +09:00
parent 7d3ad1cce0
commit d45139dd58
79 changed files with 1685 additions and 152 deletions

View File

@@ -0,0 +1,20 @@
/*
* Spring-boot Examples
*
* Copyright (c) 2021. Elex. All Rights Reserved.
* https://www.elex-project.com/
*/
package kr.pe.elex.examples;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

View File

@@ -0,0 +1,37 @@
/*
* Spring-boot Examples
*
* Copyright (c) 2021. Elex. All Rights Reserved.
* https://www.elex-project.com/
*/
package kr.pe.elex.examples;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Slf4j
@Controller
public class MyController {
@GetMapping({"/"})
public String index() {
return "home";
}
@GetMapping({"/login"})
public String login() {
return "login";
}
@GetMapping({"/info"})
public String info() {
return "normal_info";
}
@GetMapping({"/secure"})
public String secure() {
return "secure_info";
}
}

View File

@@ -0,0 +1,55 @@
/*
* Spring-boot Examples
*
* Copyright (c) 2021. Elex. All Rights Reserved.
* https://www.elex-project.com/
*/
package kr.pe.elex.examples;
import org.jetbrains.annotations.NotNull;
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.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(@NotNull HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/", "/info").permitAll() // 아무나 접근 가능
//.antMatchers("/admin").hasAnyRole("ADMIN")
.anyRequest().authenticated() // 그 외에는 인증해야 접근 가능
.and()
.formLogin()// 커스텀 로그인 폼
.loginPage("/login")
.usernameParameter("user_id") // 로그인 폼 매개변수명 지정
.passwordParameter("user_pw")
.permitAll()
.and()
.logout()// 로그아웃
.logoutSuccessUrl("/")
.permitAll()
//.and().httpBasic();
//.and().csrf().disable()
;
}
@Override
protected void configure(@NotNull AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("user1")
.password("{noop}pw1")
.authorities("ROLE_USER")
.and()
.withUser("user2")
.password("{noop}pw2")
.authorities("ROLE_USER")
;
}
}

View File

@@ -0,0 +1,23 @@
/*
* Spring-boot Examples
*
* Copyright (c) 2021. Elex. All Rights Reserved.
* https://www.elex-project.com/
*/
package kr.pe.elex.examples;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Slf4j
@Configuration
public class WebConfig implements WebMvcConfigurer {
/*
@Override
public void addViewControllers(@NotNull ViewControllerRegistry registry) {
registry.addViewController("/login");
}
*/
}

View File

@@ -0,0 +1,8 @@
/*
* Spring-boot Examples
*
* Copyright (c) 2021. Elex. All Rights Reserved.
* https://www.elex-project.com/
*/
package kr.pe.elex.examples;

View File

@@ -0,0 +1,7 @@
spring:
application:
name: My spring-boot project
mustache:
expose-request-attributes: true # 뷰에서 CSRF를 뿌려주기 위해서 필요합니다.
server:
port: 8080

View File

@@ -0,0 +1,10 @@
('-. ('-. ) (`-.
_( OO) _( OO) ( OO ).
(,------.,--. (,------.(_/. \_)-.
| .---'| |.-') | .---' \ `.' /
| | | | OO ) | | \ /\
(| '--. | |`-' |(| '--. \ \ |
| .--'(| '---.' | .--' .' \_)
| `---.| | | `---. / .'. \
`------'`------' `------''--' '--'
powered by ELEX

View File

@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Spring-boot Examples
~
~ Copyright (c) 2021. Elex. All Rights Reserved.
~ https://www.elex-project.com/
-->
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
<springProperty name="LOG_DIR" source="logging.path"
defaultValue="${user.home}/logs"/>
<property name="LOG_PATH" value="${LOG_DIR}/stephanie.log"/>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
</encoder>
</appender>
<appender name="ROLLING-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<charset>UTF-8</charset>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
<file>${LOG_PATH}</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_DIR}/sebastian_%d{yyyy-MM-dd}_%i.log.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>60</maxHistory>
</rollingPolicy>
</appender>
<root level="verbose">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="ROLLING-FILE"/>
</root>
</configuration>

View File

@@ -0,0 +1,4 @@
<h1>홈</h1>
<p>테스트 페이지입니다.</p>
{{> links}}

View File

@@ -0,0 +1,6 @@
<div>
<a href="/">홈</a> |
<a href="/info">일반</a> |
<a href="/secure">중요</a> |
<a href="/login">로그인</a>
</div>

View File

@@ -0,0 +1,11 @@
<h1>로그인</h1>
<form action="/login" method="POST">
<label for="user_id">ID:</label>
<input type="text" name="user_id" id="user_id"/>
<label for="user_pw">PW:</label>
<input type="password" name="user_pw" id="user_pw"/>
<input type="hidden" name="_csrf" value="{{_csrf.token}}">
<input type="submit" value="로그인"/>
</form>
{{> links}}

View File

@@ -0,0 +1,3 @@
<h1>아무나 볼 수 있는 페이지</h1>
<p>This page doesn't contain any Important messages.</p>
{{> links}}

View File

@@ -0,0 +1,8 @@
<h1>로그인해야 볼 수 있는 페이지</h1>
<p>This page contains a Important message.</p>
<form action="/logout" method="POST">
{{! CSRF 토큰이 없으면 에러 남. }}
<input type="hidden" name="_csrf" value="{{_csrf.token}}">
<button type="submit">로그아웃</button>
</form>
{{> links}}