Git Product home page Git Product logo

session-loginskeleton's Introduction

Session Login Skeleton

License: MIT Build Status Coverage Status

자주 사용되는 로그인, 회원가입 기능에 대한 베이스 코드를 작성한 뒤 향후 프로젝트에 적용하기 위해 만든 저장소입니다.

Key Summary

  1. Spring MVC + Thymeleaf 를 이용한 MVC pattern 웹 애플리케이션
  2. Spring Security 를 이용한 세션기반 로그인, 회원가입
  3. Spring Security OAth2 를 이용한 소셜 로그인 (Google), 회원가입
  4. Adapter pattern 을 이용한 세션기반 회원가입 유저, OAuth2기반 회원가입 유저 통합관리
  5. Junit 5 를 이용한 테스트 코드
  6. Travis CI 를 이용한 CI(Continuous Integration)
  7. Coveralls + jacoco 를 이용한 coverage 수치화

Folder structure

com
    └── kiseok
        └── sessionskeleton
            ├── SessionSkeletonApplication.java
            ├── AppRunner.java
            ├── account
            │   ├── Account.java
            │   ├── AccountAdapter.java
            │   ├── AccountController.java
            │   ├── AccountRepository.java
            │   ├── AuthAccount.java
            │   ├── AccountService.java
            │   ├── AccountRole.java
            │   ├── SocialType.java
            │   └── dto
            │       └── AccountDto.java
            └── config
                ├── BeanConfig.java
                ├── SecurityConfig.java
                └── auth
                    └── OAuthAttributes.java

API 스펙

HTTP 메서드 요청 URL 인증 여부 응답 HTTP 상태
GET /sign-in - 로그인 페이지를 반환합니다. 200
GET /sign-up - 회원가입 페이지를 반환합니다. 200
GET /sign-up-form - 회원가입 페이지를 반환합니다. 200
GET /test O 테스트 페이지를 반환합니다. 200
GET / O 메인 페이지를 반환합니다 200
POST /sign-in - 메인 페이지로 리다이렉션됩니다. 302
POST /sign-up - 아래 참고 201
POST /sign-up-form - 로그인 페이지로 리다이렉션됩니다. 302

POST /sign-in

  • Request 예시

    HTTP Method = POST
          Request URI = /sign-in
           Parameters = {email=[[email protected]], password=[password], _csrf=[6bad1c0a-50cb-445e-ab8a-b2caa8e9b4a9]}
    
  • Request Parameters 설명

    파라미터명 자료형 설명
    email String 이메일
    password String 비밀번호
    _csrf String csrf 토큰

POST /sign-up

  • Request 예시

    HTTP Method = POST
          Request URI = /sign-up
           Parameters = {_csrf=[e0cdabf5-9dce-4a1f-b1b6-c4cfbfc6b68f]}
              Headers = [Content-Type:"application/json;charset=UTF-8", Content-Length:"49"]
                 Body = {"email":"[email protected]","password":"password"}
    
  • Request Parameters 설명

    파라미터명 자료형 설명
    _csrf String csrf 토큰
  • Response 예시

    1. CREATED

      Status = 201
      Error message = null
      Headers = [Content-Type:"text/plain;charset=UTF-8", Content-Length:"32", X-Content-Type-Options:"nosniff", X-XSS-Protection:"1; mode=block", Cache-Control:"no-cache, no-store, max-age=0, must-revalidate", Pragma:"no-cache", Expires:"0"]
      Content type = text/plain;charset=UTF-8
      Body = {}
      
    2. BAD_REQUEST

      Status = 400
      Error message = null
      Headers = [Content-Type:"text/plain;charset=UTF-8", Content-Length:"18", X-Content-Type-Options:"nosniff", X-XSS-Protection:"1; mode=block", Cache-Control:"no-cache, no-store, max-age=0, must-revalidate", Pragma:"no-cache", Expires:"0"]
      Content type = text/plain;charset=UTF-8
      Body = {}
      

POST /sign-up-form

  • Request 예시

    HTTP Method = POST
          Request URI = /sign-up-form
           Parameters = {email=[[email protected]], password=[password], _csrf=[9f529fe5-b50b-46e5-a93f-8c0b087c989e]}
    
  • Request Parameters 설명

    파라미터명 자료형 설명
    email String 이메일
    password String 비밀번호
    _csrf String csrf 토큰

DB 스키마

  • 데이터베이스는 인-메모리 데이터베이스 H2 를 사용하였습니다.

  • Account

    필드 타입 NULL KEY
    ID BIGINT NO PRIMARY
    EMAIL VARCHAR(255) YES -
    NAME VARCHAR(255) YES -
    PASSWORD VARCHAR(255) YES -
    PICTURE VARCHAR(255) YES -

실행방법

  1. 구글 클라우드 플랫폼 에서 클라이언트 ID클라이언트 보안 비밀 을 발급받는다.
  2. /src/main/resources/application-oauth.yml 을 발급받은 IDSecret 으로 수정한다.
  3. IntelliJ 를 이용한 실행
    1. File → New → Project From Version Control
    2. URL : https://github.com/yks095/Session-LoginSkeleton.git → CLONE
    3. Run → SessionSkeletonApplication.java
    4. Localhost:8080 입력
  4. Gradle을 이용한 실행
    1. $ git clone https://github.com/yks095/Session-LoginSkeleton.git
    2. $ cd Spring-LoginSkeleton && cd Session-Skeleton
    3. $ ./gradlew test
    4. $ ./gradlew build
    5. $ ./gradlew bootrun
    6. Localhost:8080 입력

향후 추가 할 기능

  • 토큰기반 REST-API 프로젝트에 추가 예정입니다.
    1. JAVA SMTP 를 이용한 회원가입 인증
      • Account필드에 이메일 인증을 위한boolean` 변수가 추가 예정
    2. Swagger 를 이용한 API 문서 생성
    3. 소셜 로그인이 동작하는 것 처럼 테스트 코드 작성 (가능할까?)
    4. 테스트 코드를 꼼꼼하게 작성하여 coverage 올리기

개발환경

도구 버전
Spring Spring Boot 2.3.4.RELEASE
OS Mac OS X
개발 툴 Intellij IDEA Ultimate 2020. 01
JDK JDK 8
데이터베이스 H2
빌드 툴 gradle-6.6.1

With

session-loginskeleton's People

Contributors

yks095 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.