Skip to content

Commit

Permalink
Merge pull request #30 from kssumin/feat/#94/slack-oauth
Browse files Browse the repository at this point in the history
[BE/FEAT] 슬랙Oauth를 이용한 인증/인가 구현
  • Loading branch information
kssumin authored Jan 3, 2024
2 parents bda93d7 + 94f282a commit 851186a
Show file tree
Hide file tree
Showing 96 changed files with 2,018 additions and 132 deletions.
41 changes: 23 additions & 18 deletions BE/eeos/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
buildscript {
buildscript {
ext {
projectName = 'eeos'
projectVersion = '1.0.1'
springBootVersion = '2.7.5'
dependencyManagementVersion = '1.0.15.RELEASE'
spotlessVersion = '6.8.0'

set('springCloudVersion', "2021.0.4")
jsonwebtokenVersion = '0.11.5'

asciidoctorVersion = '3.3.2'
epagesRestDocsApiSpecVersion = '0.16.0'
epagesRestDocsApiSpecVersion = '0.16.0'
asciidoctorVersion = '3.3.2'
swaggerUIVersion = '4.11.1'
swaggerGeneratorVersion ='2.18.2'
}
}
plugins {
Expand All @@ -19,10 +20,10 @@ plugins {
id 'io.spring.dependency-management' version "${dependencyManagementVersion}"

id "com.diffplug.spotless" version "${spotlessVersion}"

id 'com.epages.restdocs-api-spec' version "${epagesRestDocsApiSpecVersion}"
// docs plugins
id 'org.asciidoctor.jvm.convert' version "${asciidoctorVersion}"
id 'org.hidetake.swagger.generator' version "${swaggerGeneratorVersion}"
id 'com.epages.restdocs-api-spec' version "${epagesRestDocsApiSpecVersion}"
id 'org.hidetake.swagger.generator' version '2.18.2'
}

group = 'com.econovation'
Expand All @@ -42,23 +43,23 @@ repositories {
mavenCentral()
}

repositories {
mavenCentral()
}

/** apply tasks */
apply from: './integration-test.gradle'

apply from: './tasks/install-git-hooks.gradle'
apply from: './tasks/formatting-task.gradle'
apply from: './tasks/docs-task.gradle'
apply from: './tasks/install-git-hooks.gradle'

dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'

// test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.cloud:spring-cloud-starter-contract-stub-runner'

// lombok
compileOnly 'org.projectlombok:lombok'
Expand All @@ -68,8 +69,13 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'mysql:mysql-connector-java'

// apache commons
implementation 'org.apache.commons:commons-lang3:3.0'
// openfeign
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'

// jwt
implementation "io.jsonwebtoken:jjwt-api:${jsonwebtokenVersion}"
implementation "io.jsonwebtoken:jjwt-impl:${jsonwebtokenVersion}"
implementation "io.jsonwebtoken:jjwt-jackson:${jsonwebtokenVersion}"

// swagger & restdocs
implementation 'org.springdoc:springdoc-openapi-ui:1.6.9'
Expand All @@ -79,7 +85,6 @@ dependencies {
}

test {
dependsOn spotlessApply
useJUnitPlatform()

testLogging {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ create table program

create table member
(
member_id bigint not null auto_increment,
created_date datetime not null,
is_deleted boolean not null,
updated_date datetime not null,
member_name varchar(255) not null,
member_generation BIGINT not null,
member_id bigint not null auto_increment,
created_date datetime not null,
is_deleted boolean not null,
updated_date datetime not null,
member_name varchar(255) not null,
member_oath_server_type varchar(255) not null,
primary key (member_id)
) engine = InnoDB;

Expand All @@ -35,7 +35,7 @@ create table attend
) engine = InnoDB;

ALTER TABLE member
ADD INDEX idx_generation_name (member_generation, member_name);
ADD INDEX idx_name (member_name);

ALTER TABLE attend
ADD INDEX idx_program (attend_program_id);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class AttendInfoConverter {
public AttendInfoResponse from(final MemberEntity source, final AttendStatus attendStatus) {
return AttendInfoResponse.builder()
.memberId(source.getId())
.generation(source.getGeneration())
.name(source.getName())
.attendStatus(attendStatus.getStatus())
.build();
Expand All @@ -20,7 +19,6 @@ public AttendInfoResponse from(final MemberEntity source, final AttendStatus att
public AttendInfoResponse from(final MemberEntity source, final String status) {
return AttendInfoResponse.builder()
.memberId(source.getId())
.generation(source.getGeneration())
.name(source.getName())
.attendStatus(status)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@
import com.blackcompany.eeos.common.exception.BusinessException;
import org.springframework.http.HttpStatus;

/** 존재하지 않는 참석 정보일 때 발생하는 예외 */
public class NotFoundAttendException extends BusinessException {
private static final String FAIL_CODE = "2004";
private final Long programId;

public NotFoundAttendException() {
super("존재하지 않는 참석 정보입니다.", HttpStatus.NOT_FOUND);
public NotFoundAttendException(Long programId) {
super(FAIL_CODE, HttpStatus.NOT_FOUND);
this.programId = programId;
}

@Override
public String getMessage() {
return String.format("%s 프로그램에 대한 참여 정보가 없습니다.", programId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.blackcompany.eeos.attend.application.exception;

import com.blackcompany.eeos.common.exception.BusinessException;
import org.springframework.http.HttpStatus;

/** 존재하지 않는 참석 상태일 때 발생하는 예외 */
public class NotFoundAttendStatusException extends BusinessException {
private static final String FAIL_CODE = "2000";
private final String attendStatus;

public NotFoundAttendStatusException(String attendStatus) {
super(FAIL_CODE, HttpStatus.NOT_FOUND);
this.attendStatus = attendStatus;
}

@Override
public String getMessage() {
return String.format("%s 참석 상태는 존재하지 않습니다.", attendStatus);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.blackcompany.eeos.attend.application.exception;

import com.blackcompany.eeos.common.exception.BusinessException;
import org.springframework.http.HttpStatus;

/** 이전 참석상태가 일치하지 않을 때 발생하는 예외 */
public class NotSameBeforeAttendStatusException extends BusinessException {
private static final String FAIL_CODE = "2001";
private final Long memberId;

public NotSameBeforeAttendStatusException(Long memberId) {
super(FAIL_CODE, HttpStatus.NOT_FOUND);
this.memberId = memberId;
}

@Override
public String getMessage() {
return String.format("%s 회원의 이전 상태가 올바르지 않습니다.", memberId);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.blackcompany.eeos.attend.application.dto.ChangeStatusRequest;
import com.blackcompany.eeos.attend.application.dto.converter.AttendInfoConverter;
import com.blackcompany.eeos.attend.application.exception.NotFoundAttendException;
import com.blackcompany.eeos.attend.application.exception.NotSameBeforeAttendStatusException;
import com.blackcompany.eeos.attend.application.model.AttendModel;
import com.blackcompany.eeos.attend.application.model.AttendStatus;
import com.blackcompany.eeos.attend.application.model.converter.AttendEntityConverter;
Expand Down Expand Up @@ -44,7 +45,7 @@ private AttendStatus getAttendStatus(final Long memberId, final Long programId)
return attendRepository
.findByProgramIdAndMemberId(programId, memberId)
.map(AttendEntity::getStatus)
.orElseThrow(NotFoundAttendException::new);
.orElseThrow(() -> new NotFoundAttendException(programId));
}

@Override
Expand All @@ -71,7 +72,7 @@ public void changeStatus(final ChangeStatusRequest request, final Long programId
attendRepository
.findByProgramIdAndMemberId(programId, request.getMemberId())
.map(attendEntityConverter::from)
.orElseThrow(NotFoundAttendException::new);
.orElseThrow(() -> new NotSameBeforeAttendStatusException(request.getMemberId()));

model.isSame(request.getBeforeAttendStatus());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.blackcompany.eeos.auth.application.domain;

import com.blackcompany.eeos.common.support.AbstractModel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Getter
@ToString
@AllArgsConstructor
@NoArgsConstructor
@Builder(toBuilder = true)
public class OauthMemberModel implements AbstractModel {
private String oauthId;
private String name;
private OauthServerType oauthServerType;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.blackcompany.eeos.auth.application.domain;

import com.blackcompany.eeos.auth.application.exception.NotFoundOauthServerException;
import java.util.Arrays;
import lombok.Getter;

@Getter
public enum OauthServerType {
SLACK("slack");

private final String oauthServer;

OauthServerType(String oauthServer) {
this.oauthServer = oauthServer;
}

public static OauthServerType find(String type) {
return Arrays.stream(values())
.filter(oauthServerType -> oauthServerType.oauthServer.equals(type))
.findAny()
.orElseThrow(() -> new NotFoundOauthServerException(type));
}

public static OauthServerType find(OauthServerType type) {
return Arrays.stream(values())
.filter(oauthServerType -> oauthServerType.equals(type))
.findAny()
.orElseThrow(() -> new NotFoundOauthServerException(type.getOauthServer()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.blackcompany.eeos.auth.application.domain;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder(toBuilder = true)
public class TokenModel {

private String accessToken;
private Long accessExpiredTime;
private String refreshToken;
private Long refreshExpiredTime;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.blackcompany.eeos.auth.application.domain.client;

import com.blackcompany.eeos.auth.application.domain.OauthMemberModel;
import com.blackcompany.eeos.auth.application.domain.OauthServerType;

public interface OauthMemberClient {
OauthServerType support();

OauthMemberModel fetch(String code);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.blackcompany.eeos.auth.application.domain.client;

import com.blackcompany.eeos.auth.application.domain.OauthMemberModel;
import com.blackcompany.eeos.auth.application.domain.OauthServerType;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.springframework.stereotype.Component;

@Component
public class OauthMemberClientComposite {

private final Map<OauthServerType, OauthMemberClient> clients;

public OauthMemberClientComposite(Set<OauthMemberClient> providers) {
this.clients =
providers.stream()
.collect(Collectors.toMap(OauthMemberClient::support, Function.identity()));
}

public OauthMemberModel fetch(String oauthServerType, String authCode) {
return getClient(oauthServerType).fetch(authCode);
}

private OauthMemberClient getClient(String type) {
OauthServerType oauthServerType = OauthServerType.find(type);
return clients.get(oauthServerType);
}
}
Loading

0 comments on commit 851186a

Please sign in to comment.