-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: 관리자 인증 및 인가 기능 구현 #213
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b2c3202
feat: 관리자 로그인 및 로그아웃 api 구현
eunsoni 30d8d23
feat: 포인트 출금, 충전 api 및 페이지 접근 시 세션정보 인증 로직 추가
eunsoni 5fe4405
feat: 로그인 페이지 구현
eunsoni a8526bc
feat: 헤더 구현 (로그아웃 및 충전, 출금 페이지 상호 이동 기능)
eunsoni ec74fdd
feat: 로그인 페이지 css 구현
eunsoni 4a4d1ca
feat: 헤더(공통 컴포넌트) css 구현
eunsoni a3f1067
feat: 헤더 추가 (충전, 출금 페이지 상호 이동 및 로그아웃 기능 추가)
eunsoni e5e8f5c
feat: Reformat Code
eunsoni cd192ab
Merge remote-tracking branch 'origin/Weekly' into Feat/issue-#199
eunsoni 53827b2
feat: 주석 삭제
eunsoni 73b5fcc
refactor: 로그인 상태에서 로그인 페이지 이동시 충전 페이지로 리다이렉트
eunsoni 0262f49
refactor: session timeout 설정
eunsoni 8086e62
feat: AdminProperties 추가
eunsoni 9be6f84
refactor: 관리자 계정 정보 숨김
eunsoni 9498cf0
refactor: @EnableConfigurationProperties에 properties 추가
eunsoni 612248f
refactor: Reformat Code
eunsoni eca1dd6
Merge remote-tracking branch 'origin/Weekly' into Feat/issue-#199
eunsoni 8208462
refactor: url에서 sessionid 숨김
eunsoni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/com/example/sinitto/common/properties/AdminProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.example.sinitto.common.properties; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties(prefix = "admin") | ||
public record AdminProperties( | ||
String adminEmail, | ||
String adminPassword | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package com.example.sinitto.member.controller; | ||
|
||
import com.example.sinitto.auth.service.TokenService; | ||
import com.example.sinitto.common.properties.AdminProperties; | ||
import com.example.sinitto.common.properties.DummyProperties; | ||
import com.example.sinitto.member.entity.Member; | ||
import com.example.sinitto.member.repository.MemberRepository; | ||
import jakarta.servlet.http.HttpSession; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
|
@@ -15,32 +17,61 @@ | |
import java.util.List; | ||
|
||
@Controller | ||
@RequestMapping("/dummy") | ||
@RequestMapping | ||
public class MemberAdminController { | ||
|
||
private final MemberRepository memberRepository; | ||
private final TokenService tokenService; | ||
private final DummyProperties dummyProperties; | ||
|
||
private final AdminProperties adminProperties; | ||
private final List<String> dummyEmails = Arrays.asList( | ||
"[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]", | ||
"[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]" | ||
); | ||
|
||
public MemberAdminController(MemberRepository memberRepository, TokenService tokenService, DummyProperties dummyProperties) { | ||
public MemberAdminController(MemberRepository memberRepository, TokenService tokenService, DummyProperties dummyProperties, AdminProperties adminProperties) { | ||
this.memberRepository = memberRepository; | ||
this.tokenService = tokenService; | ||
this.dummyProperties = dummyProperties; | ||
this.adminProperties = adminProperties; | ||
} | ||
|
||
@GetMapping | ||
@GetMapping("/dummy") | ||
public String showDummyLoginPage(Model model) { | ||
List<Member> dummyMembers = memberRepository.findAllByEmailIn(dummyEmails); | ||
model.addAttribute("members", dummyMembers); | ||
return "dummy/login"; | ||
} | ||
|
||
@PostMapping | ||
@GetMapping("/admin/login") | ||
public String showAdminLoginPage(HttpSession session) { | ||
if (isAdmin(session)) { | ||
return "redirect:/admin/point/charge"; | ||
} | ||
return "point/login"; | ||
} | ||
|
||
@PostMapping("/admin/login") | ||
public String login(@RequestParam String email, | ||
@RequestParam String password, | ||
HttpSession session) { | ||
if (adminProperties.adminEmail().equals(email) && adminProperties.adminPassword().equals(password)) { | ||
session.setAttribute("email", email); | ||
session.setAttribute("role", "ADMIN"); | ||
session.setMaxInactiveInterval(1800); | ||
return "redirect:/admin/point/charge"; | ||
} else { | ||
return "redirect:/admin/login?error=true"; | ||
} | ||
} | ||
|
||
@PostMapping("/admin/logout") | ||
public String logout(HttpSession session) { | ||
session.invalidate(); | ||
return "redirect:/admin/login"; | ||
} | ||
|
||
@PostMapping("/dummy") | ||
public String login( | ||
@RequestParam("email") String email, | ||
@RequestParam("password") String password, | ||
|
@@ -67,4 +98,9 @@ public String login( | |
String frontendRedirectUrl = env.equals("dev") ? dummyProperties.devRedirectUri() : dummyProperties.redirectUri(); | ||
return "redirect:" + frontendRedirectUrl + "?accessToken=" + accessToken + "&refreshToken=" + refreshToken + "&isSinitto=" + isSinitto; | ||
} | ||
|
||
private boolean isAdmin(HttpSession session) { | ||
String role = (String) session.getAttribute("role"); | ||
return "ADMIN".equals(role); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기 timeout도 추가해주면 좋을 것 같습니다!
session.setMaxInactiveInterval(1800);
요렇게 추가하면 될거에요. 위의 코드안의 숫자는 초단위라 저렇게 작성하면 만료시간이 30분임을 의미합니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
추가로 로그인할 때 sessionId가 url에 남던데,
server.servlet.session.tracking-modes = cookie
을 properties에 추가하면 url에 남지 않습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오오 좋은 정보 감사해요ㅎㅎ 적용해두었어요