Bootcamp/Web

[Spring] Spring Security

K_Hyul 2023. 12. 27. 09:38
728x90

인증 - 해당 사용자가 본인이 맞는지 확인하는 것

인가 - 인증된 사용자가 요청한 자원에 접근 가능한지를 결정하는 절차

 권한을 그룹별로지정해줘서 접근 가능한 부분을 나눠서 주는데

이 그룹을 지정해주는 것을 인가라 생각해도 된다.

 

Spring Security는 Spring 기반의 애플리케이션 보안을 담당하는 스프링 하위 프레임워크이다.

 

 

 

 

아래는 실습 예시이다.

Fig. 1 설정

 

Fig. 2 화면 예시

 

아래 해당 코드는 application.yml에 넣어줄 코드

server:
  servlet:
    encoding:
      # 한글깨짐 처리
      force-response: true
# Spring Data Source 설정
spring:
  output:
    ansi:
      enabled: always
  # 데이터 베이스
  datasource:
    url: jdbc:mysql://127.0.0.1:3306/examplesdb?userSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Seoul
    username: urstory
    password: u1234
    driver-class-name: com.mysql.cj.jdbc.Driver
  #  데이터 베이스 커넥션
  jpa:
    hibernate:
      ddl-auto: update
    properties:
      hibernate:
        show_sql: true
        format_sql: true
  # mustache (1. 루트폴더 변경, 2. 타임리프 캐시 설정 변경)
  mustache:
    prefix: classpath:templates/
    check-template-location: true
    suffix: .html
    cache: false
  mvc:
    static-path-pattern: /static/**

 

 

admin.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>관리자 화면</h1>
    <p>관리자만 들어올 수 있음</p>
    <p>접속가능한 사람 유형: 관리자</p>
</body>
</html>

 

 

client.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>Client들이 보는 화면임</h1>
    <p>로그인 했을 경우</p>
    <p>접속가능한 사람 유형: 관리자, 로그인을 한 사용자</p>
</body>
</html>

 

 

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>Hello World</h1>
    <p>누구냐? 넌!</p>
    <p>접속가능한 사람 유형: 관리자, 로그인을 한 사용자, 로그인을 하지 않은 사용자</p>
</body>
</html>

 

join.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="" method="post"></form>    
        <input type="text" name="userID" placeholder="아이디를 입력해주세요." />
        <br />
        <input type="password" name="userPassword" placeholder="비밀번호를 입력해주세요." />
        <br />
        <input type="email" name="Email" placeholder="이메일 주소를 입력해주세요." />
    <input type="submit" value="회원가입" />
    </form>
    <a href="">로그인 화면 이동</a>
</body>
</html>

 

login.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>로그인 화면</h1>
    <form action="" method="post">
        <input type="text" name="userID" placeholder="아이디를 입력해주세요." />
        <br />
        <input type="password" name="userPassword" placeholder="비밀번호를 입력해주세요." />
        <br />
        <input type="submit" value="로그인" />
    </form>
    <a href="">신규 회원 가입 화면 이동</a>
</body>
</html>

 

728x90

'Bootcamp > Web' 카테고리의 다른 글

[Crawling] 주식 정보  (1) 2024.01.04
[Notalone] mini project (web)  (0) 2023.12.27
[Spring] Spring _ Validation, Valid annotation & Exception  (0) 2023.12.07
[Front] HTML, CSS  (1) 2023.11.23
[SQL] ERD, MySQL, Docker, DBeaver 설치  (0) 2023.11.17