Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2746c45
feature : profile설정 , logback설정
dadadamarine May 1, 2019
c577f67
feature : AcceptanceTest 부모클래스 생성, BasicAuthIntercepter생성
dadadamarine May 2, 2019
b53da28
feature : test profile 설정
dadadamarine May 2, 2019
06ad55d
feature : 빌드 자동화 테스트
dadadamarine May 3, 2019
f38a888
fix : text failure fix
dadadamarine May 3, 2019
0b7cce5
fix : acceptanceTest error
dadadamarine May 3, 2019
2fb6294
feature : 포트 변경 및 배포 자동화 테스트
dadadamarine May 3, 2019
335dba3
fix : 배포 script permission denied해결
dadadamarine May 3, 2019
b4e5298
fix : 배포 script directory 변경
dadadamarine May 3, 2019
68344e9
feature : mysql init을 위한 ddl-auto create 초기실행
dadadamarine May 3, 2019
e6b5b24
feature : development ddl-auto validate로 변경
dadadamarine May 3, 2019
8299ea9
chore
dadadamarine May 3, 2019
144bec1
feature : 슬랙 noti
dadadamarine May 22, 2019
84d7131
feature : 자동배포 테스트
dadadamarine May 22, 2019
cb370cc
fix : 배포 스크립트 수정 / 경로문제
dadadamarine May 22, 2019
4945bc7
fix : 배포 스크립트 수정 / background 실행
dadadamarine May 22, 2019
66425d9
fix : slack noti 주소수정
dadadamarine May 22, 2019
555f1ee
fix : 배포 스크립트 process 중복 해결
dadadamarine May 22, 2019
a5dfd73
fix : jar파일 name 수정
dadadamarine May 24, 2019
49ee8e4
fix : jar파일 name 수정
dadadamarine May 24, 2019
79a2c95
fix : jar파일 name 수정
dadadamarine May 24, 2019
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
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<modelVersion>4.0.0</modelVersion>

<groupId>kr.codesquad</groupId>
<artifactId>baeminchan</artifactId>
<artifactId>webApi</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>

<name>baeminchan</name>
<name>webApi</name>
<description>배민찬 서비스</description>

<parent>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package codesquad.configration;
package codesquad.configuration;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package codesquad.configration;
package codesquad.configuration;

import codesquad.intercepter.AdminInterceptor;

import codesquad.security.ManagerAccountHandlerMethodArgumentResolver;
import codesquad.intercepter.BasicAuthInterceptor;
import codesquad.security.AdminAccountHandlerMethodArgumentResolver;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
Expand All @@ -29,18 +31,38 @@ public PasswordEncoder passwordEncoder() {
}

@Bean
public ManagerAccountHandlerMethodArgumentResolver managerAccountHandlerMethodArgumentResolver() {
return new ManagerAccountHandlerMethodArgumentResolver();
public AdminAccountHandlerMethodArgumentResolver managerAccountHandlerMethodArgumentResolver() {
return new AdminAccountHandlerMethodArgumentResolver();
}

@Configuration
@Profile("test")
public class TestWebMvcConfig extends WebMvcConfig{

@Bean
public BasicAuthInterceptor basicAuthInterceptor(){
return new BasicAuthInterceptor();
}

@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(basicAuthInterceptor());
}
}

@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add(managerAccountHandlerMethodArgumentResolver());
}

@Bean
public AdminInterceptor adminInterceptor(){
return new AdminInterceptor();
}

@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new AdminInterceptor())
registry.addInterceptor(adminInterceptor())
.addPathPatterns("/admin");
}
}
12 changes: 6 additions & 6 deletions src/main/java/codesquad/domain/AccountType.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

public enum AccountType {
MEMBER(false),
MANAGER(true);
ADMIN(true);

boolean isManager;
boolean isAdmin;

AccountType(boolean isManager) {
this.isManager = isManager;
AccountType(boolean isAdmin) {
this.isAdmin = isAdmin;
}

public boolean isManager() {
return isManager;
public boolean isAdmin() {
return isAdmin;
}
}
2 changes: 1 addition & 1 deletion src/main/java/codesquad/intercepter/AdminInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
}

Account account = (Account) loginAccount;
if (!account.getType().isManager()) {
if (!account.getType().isAdmin()) {
throw new UnAuthorizedException("you're not manager");
}
return true;
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/codesquad/intercepter/BasicAuthInterceptor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package codesquad.intercepter;

import codesquad.domain.Account;
import codesquad.domain.AccountRepository;
import codesquad.exception.account.UnAuthenticationException;
import codesquad.util.SessionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.nio.charset.Charset;
import java.util.Base64;

public class BasicAuthInterceptor extends HandlerInterceptorAdapter {
private static final Logger log = LoggerFactory.getLogger(BasicAuthInterceptor.class);

@Autowired
private AccountRepository accountRepository;

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String base64Credentials;
try {
base64Credentials = getEncodedCredentials(request);
String[] credentialValues = getDecodedCredentials(base64Credentials);
String userId = credentialValues[0];
String password = credentialValues[1];
log.debug("userId : {}", userId);
log.debug("password : {}", password);
login(request, userId, password);
return true;
} catch (UnAuthenticationException e) {
return true;
}
}

public String getEncodedCredentials(HttpServletRequest request) {
String authorization = request.getHeader("Authorization");
if (authorization == null || !authorization.startsWith("Basic")) {
throw new UnAuthenticationException();
}
return authorization.substring("Basic".length()).trim();
}

public String[] getDecodedCredentials(String base64Credentials) {
String credentials = new String(Base64.getDecoder().decode(base64Credentials), Charset.forName("UTF-8"));
return credentials.split(":", 2);
}

public void login(HttpServletRequest request, String userId, String password) {
Account account = accountRepository.findByUserId(userId).orElseThrow(UnAuthenticationException::new);

if (account.matchPassword(password)) {
request.getSession().setAttribute(SessionUtils.USER_SESSION_KEY, account);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package codesquad.security;


import org.springframework.beans.factory.annotation.Required;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface ManagerAccount {
public @interface AdminAccount {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

public class ManagerAccountHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver {
public class AdminAccountHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver {
@Override
public boolean supportsParameter(MethodParameter methodParameter) {
return methodParameter.hasParameterAnnotation(ManagerAccount.class);
return methodParameter.hasParameterAnnotation(AdminAccount.class);
}

@Override
Expand All @@ -21,7 +21,7 @@ public Object resolveArgument(MethodParameter methodParameter,
NativeWebRequest nativeWebRequest,
WebDataBinderFactory webDataBinderFactory) throws Exception {
Account account = SessionUtils.getUserFromSession(nativeWebRequest);
if (!account.getType().isManager()) {
if (!account.getType().isAdmin()) {
throw new UnAuthorizedException("You're not manager!");
}
return account;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/codesquad/web/ApiMemberController.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class ApiMemberController {
@PostMapping("")
public ResponseEntity<Void> createMember(@Valid @RequestBody AccountRegistrationDTO accountRegistrationDTO) {
accountService.save(accountRegistrationDTO);

return makeDefaultResponseEntity("/login", HttpStatus.CREATED);
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/codesquad/web/ApiMenuCategoryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import codesquad.domain.Account;
import codesquad.domain.MenuCategory;
import codesquad.security.ManagerAccount;
import codesquad.security.AdminAccount;
import codesquad.service.MenuCategoryService;
import codesquad.web.dto.MenuCategoryDTO;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -26,13 +26,13 @@ public List<MenuCategory> getCategories() {
}

@PostMapping("")
public ResponseEntity<MenuCategory> create(@ManagerAccount Account manager, @RequestBody MenuCategoryDTO menuCategoryDTO) {
public ResponseEntity<MenuCategory> create(@AdminAccount Account manager, @RequestBody MenuCategoryDTO menuCategoryDTO) {
MenuCategory createdCategory = menuCategoryService.create(menuCategoryDTO);
return makeCreatedResponseEntity(createdCategory);
}

@DeleteMapping("/{id}")
public MenuCategory delete(@ManagerAccount Account manager, @PathVariable Long id) {
public MenuCategory delete(@AdminAccount Account manager, @PathVariable Long id) {
return menuCategoryService.deleteById(id);
}
}
6 changes: 4 additions & 2 deletions src/main/java/support/domain/AbstractEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ public AbstractEntity(Long id) {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
AbstractEntity that = (AbstractEntity) o;
return Objects.equals(id, that.id);
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/application-development.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
spring.datasource.url=jdbc:mysql://localhost:3306/springboot?useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.username=minseok
spring.datasource.password=password

server.port=80

spring.jpa.hibernate.ddl-auto=validate

logging.config=classpath:logback-${spring.profiles.active}.xml
6 changes: 6 additions & 0 deletions src/main/resources/application-local.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
spring.jpa.hibernate.ddl-auto=create

spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
logging.level.org.hibernate.type.descriptor.sql=trace

8 changes: 8 additions & 0 deletions src/main/resources/application-prod.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
server.port=80

spring.datasource.url=jdbc:mysql://localhost:3306/springboot?useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.username=minseok
spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=validate

logging.config=classpath:logback-${spring.profiles.active}.xml
16 changes: 5 additions & 11 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
spring.profiles.active=local

spring.autoconfigure.exclude= org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration

handlebars.suffix=.hbs
handlebars.cache=false
handlebars.expose-session-attributes=true

spring.datasource.url=jdbc:mysql://localhost:3306/springboot?useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.username=minseok
spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=create

spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
logging.level.org.hibernate.type.descriptor.sql=trace
log4j.logger.org.hibernate.type=debug

spring.autoconfigure.exclude= org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
logging.config=classpath:logback.xml
2 changes: 1 addition & 1 deletion src/main/resources/import.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
INSERT INTO account (id, user_id, password, name, email, phone_number, type ,create_at) values (1, 'test@google.com', '$2a$10$75iOIZVohML12YADpMEqre39yvfFQWn8PkoCf0VMct6ItcVVb77B.', '자바지기', 'javajigi@slipp.net', '010-1111-1111', 'MEMBER', CURRENT_TIMESTAMP());
INSERT INTO account (id, user_id, password, name, email, phone_number, type ,create_at) values (2, 'admin@admin.com', '$2a$10$75iOIZVohML12YADpMEqre39yvfFQWn8PkoCf0VMct6ItcVVb77B.', '관리자', 'admin@admin.com', '010-1111-1111', 'MANAGER', CURRENT_TIMESTAMP());
INSERT INTO account (id, user_id, password, name, email, phone_number, type ,create_at) values (2, 'admin@admin.com', '$2a$10$75iOIZVohML12YADpMEqre39yvfFQWn8PkoCf0VMct6ItcVVb77B.', '관리자', 'admin@admin.com', '010-1111-1111', 'ADMIN', CURRENT_TIMESTAMP());

INSERT INTO menu_category (name, parent_id, id, create_at) values ('밑반찬', NULL, 1, CURRENT_TIMESTAMP());
INSERT INTO menu_category (name, parent_id, id, create_at) values ('무침', 1, 2, CURRENT_TIMESTAMP());
Expand Down
30 changes: 30 additions & 0 deletions src/main/resources/logback-development.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="30 seconds">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
<file>mylog.txt</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>mylog-%d{yyyy-MM-dd}.%i.txt</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 100MB -->
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>[%-5level] %d{HH:mm:ss.SSS} %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="debug">
<appender-ref ref="STDOUT"/>
<appender-ref ref="ROLLING"/>
</root>
</configuration>
30 changes: 30 additions & 0 deletions src/main/resources/logback-prod.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="30 seconds">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
<file>mylog.txt</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>mylog-%d{yyyy-MM-dd}.%i.txt</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 100MB -->
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>[%-5level] %d{HH:mm:ss.SSS} %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="debug">
<appender-ref ref="STDOUT"/>
<appender-ref ref="ROLLING"/>
</root>
</configuration>
12 changes: 12 additions & 0 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="30 seconds">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="debug">
<appender-ref ref="STDOUT"/>
</root>
</configuration>

Loading