Skip to content

Commit

Permalink
feat:카카오 로그인 구현 (#9)
Browse files Browse the repository at this point in the history
* feat:엔티티 설정

* fix:comment 반영해서 엔티티 수정

* fix:엔티티 최종 수정

* feat:카카오 로그인 구현

* fix:ci cd 구현

* fix:카카오 로그인 수정 + Swagger

* feat:cors 허용

* fix:comment 받고 수정

* fix:순환참조 문제 해결
  • Loading branch information
JjungminLee authored Aug 13, 2023
1 parent a6466f1 commit e1cb499
Show file tree
Hide file tree
Showing 45 changed files with 1,574 additions and 118 deletions.
12 changes: 10 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,16 @@ dependencies {
implementation group: 'org.postgresql', name: 'postgresql', version: '42.6.0'
runtimeOnly 'org.postgresql:postgresql'

//ouath
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client:2.6.2'
// oauth2-client 라이브러리
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'

//jwt
implementation 'com.auth0:java-jwt:4.2.1'

// swagger
implementation 'io.springfox:springfox-boot-starter:3.0.0'
implementation "io.springfox:springfox-swagger-ui:3.0.0"


implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.onna.onnaback.domain.member.adapter.in.web;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.oauth2.core.user.OAuth2User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MemberController {
@GetMapping("/test")
public String index() {
return "Hello World";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.onna.onnaback.domain.member.adapter.in.web.response;

public class LoginResponse {
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.onna.onnaback.domain.member.adapter.out.persistence;

public class MemberPersistenceAdapter {
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
package com.onna.onnaback.domain.member.adapter.out.persistence;

import com.onna.onnaback.domain.member.domain.Member;
import com.onna.onnaback.domain.member.domain.SocialType;
import com.onna.onnaback.global.oauth.OAuthAttributes;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
@EnableJpaRepositories
public interface MemberRepository extends JpaRepository<Member,Long> {

public Optional<Member> findByName(String username);

public Optional<Member> findByEmail(String email);

public Optional<Member> findBySocialTypeAndSocialId(SocialType socialType, String socialId);

public Optional<Member> findByRefreshToken(String refreshToken);
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.onna.onnaback.domain.member.application.port.in;

public class MemberUseCase {
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.onna.onnaback.domain.member.application.service;

public class MemberService {
}
Empty file.
87 changes: 78 additions & 9 deletions src/main/java/com/onna/onnaback/domain/member/domain/Member.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
package com.onna.onnaback.domain.member.domain;

import com.onna.onnaback.domain.memberSparkMapping.MemberSparkMapping;
import com.onna.onnaback.domain.spark.Spark;
import com.onna.onnaback.domain.memberSparkMapping.domain.MemberSparkMapping;
import com.onna.onnaback.domain.spark.domain.Spark;

import com.onna.onnaback.global.utils.BaseEntity;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;


import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Entity
@NoArgsConstructor
@Getter
@Table(name = "Member")

public class Member extends BaseEntity {
public class Member extends BaseEntity implements UserDetails {


@Id
Expand All @@ -35,15 +39,28 @@ public class Member extends BaseEntity {
@Enumerated(value = EnumType.STRING)
@Column(name="gender")
private Gender gender;

//생일(월-일) MMDD
@Column(name="birthDate")
private LocalDateTime birthDate;
private String birthDay;
@Enumerated(value = EnumType.STRING)
@Column(name="ageRange")
private Age ageRange;
@Column(name="phoneNum")
private String phoneNum;
@Enumerated(EnumType.STRING)
@Column(name = "role")
private Role role;

@Column(name ="refreshToken")
private String refreshToken;

//oauth2
@Enumerated(EnumType.STRING)
@Column(name = "socialType")
private SocialType socialType;
@Column(name = "socialId")
private String socialId; // 로그인한 소셜 타입의 식별자 값 (일반 로그인인 경우 null)

@OneToMany(mappedBy = "host")
List<Spark> sparkList=new ArrayList<>();
Expand All @@ -53,7 +70,59 @@ public class Member extends BaseEntity {
@OneToMany(mappedBy = "applicant")
List<MemberSparkMapping> memberSparkMappingList=new ArrayList<>();




public void updateRefreshToken(String updateRefreshToken) {
this.refreshToken = updateRefreshToken;
}

@Builder
public Member(String name,Age ageRange,String email,Role role,SocialType socialType,String socialId,String phoneNum,String profileImg,String birthDay,Gender gender){
this.name=name;
this.email=email;
this.role=role;
this.socialType=socialType;
this.socialId=socialId;
this.ageRange=ageRange;
this.phoneNum=phoneNum;
this.profileImg=profileImg;
this.birthDay=birthDay;
this.gender=gender;
}


@Override
public ArrayList<GrantedAuthority> getAuthorities() {
ArrayList<GrantedAuthority> auth = new ArrayList<GrantedAuthority>();
auth.add(new SimpleGrantedAuthority(Role.USER.toString()));
return auth;
}

@Override
public String getPassword() {
return null;
}

@Override
public String getUsername() {
return getName();
}

@Override
public boolean isAccountNonExpired() {
return true;
}

@Override
public boolean isAccountNonLocked() {
return false;
}

@Override
public boolean isCredentialsNonExpired() {
return true;
}

@Override
public boolean isEnabled() {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.onna.onnaback.domain.member.domain;

public enum Role {
ADMIN,MANAGER,USER,GUEST
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.onna.onnaback.domain.member.domain;

public enum SocialType {
KAKAO,GOOGLE,NAVER
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.onna.onnaback.domain.memberSparkMapping.domain;

public enum AcceptStatus {
PENDING,ACCEPT,REFUSE
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package com.onna.onnaback.domain.memberSparkMapping;
package com.onna.onnaback.domain.memberSparkMapping.domain;


import com.onna.onnaback.domain.member.domain.Member;
import com.onna.onnaback.domain.spark.Spark;
import com.onna.onnaback.domain.memberSparkMapping.domain.AcceptStatus;
import com.onna.onnaback.domain.spark.domain.Spark;

import com.onna.onnaback.global.utils.BaseEntity;

import com.sun.xml.bind.v2.model.core.ID;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.util.UUID;

@Entity
@NoArgsConstructor
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/onna/onnaback/domain/place/Place.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.onna.onnaback.domain.place;

import com.onna.onnaback.domain.spark.Spark;
import com.onna.onnaback.domain.spark.domain.Spark;

import com.onna.onnaback.global.utils.BaseEntity;

Expand Down
5 changes: 0 additions & 5 deletions src/main/java/com/onna/onnaback/domain/spark/SparkType.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.onna.onnaback.domain.spark;
package com.onna.onnaback.domain.spark.domain;

public enum DurationHour {
THIRTY_MIN,ONE_HOUR,TWO_HOUR
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package com.onna.onnaback.domain.spark;
package com.onna.onnaback.domain.spark.domain;

import com.onna.onnaback.domain.member.domain.Member;
import com.onna.onnaback.domain.memberSparkMapping.MemberSparkMapping;
import com.onna.onnaback.domain.memberSparkMapping.domain.MemberSparkMapping;
import com.onna.onnaback.domain.place.Place;

import com.onna.onnaback.global.utils.BaseEntity;

import com.sun.xml.bind.v2.model.core.ID;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.beans.JavaBean;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.onna.onnaback.domain.spark.domain;

public enum SparkType {
CLASS,MEETING
}
59 changes: 59 additions & 0 deletions src/main/java/com/onna/onnaback/global/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.onna.onnaback.global.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.AuthorizationScope;
import springfox.documentation.service.SecurityReference;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.Arrays;
import java.util.List;

@Configuration
public class SwaggerConfig {

@Bean
public Docket api() {
return new Docket(DocumentationType.OAS_30)
.securityContexts(Arrays.asList(securityContext()))
.securitySchemes(Arrays.asList(apiKey()))
.useDefaultResponseMessages(false)
.select()
.apis(RequestHandlerSelectors.basePackage("com.onna.onnaback.domain"))
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo());
}

private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("ON;na API")
.description("ON;na API입니다")
.version("1.0")
.build();
}
private SecurityContext securityContext() {
return SecurityContext.builder()
.securityReferences(defaultAuth())
.build();
}

private List<SecurityReference> defaultAuth() {
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
authorizationScopes[0] = authorizationScope;
return Arrays.asList(new SecurityReference("Authorization", authorizationScopes));
}

private ApiKey apiKey() {
return new ApiKey("Authorization", "Authorization", "header");
}
}
Loading

0 comments on commit e1cb499

Please sign in to comment.