Skip to content

Commit

Permalink
feat : 관리자 페이지 로그인 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
KJBig committed Oct 24, 2024
1 parent 5f9f03c commit efbe6c5
Show file tree
Hide file tree
Showing 14 changed files with 332 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.sluv.admin.common.service;

import com.sluv.domain.admin.entity.Admin;
import com.sluv.domain.admin.service.AdminDomainService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
public class UserDetailsServiceImpl implements UserDetailsService {

private final AdminDomainService adminDomainService;

@Override
@Transactional(readOnly = true)
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
Admin admin = adminDomainService.findByEmail(email);
return toUserDetails(admin);
}

private UserDetails toUserDetails(Admin admin) {
return User.builder()
.username(admin.getEmail())
.password(admin.getPwd())
.authorities(new SimpleGrantedAuthority("USER"))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;

/*
Expand All @@ -23,17 +24,33 @@ public class SpringSecurityConfig {
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests((request) -> request // 허용 범위 설정
.anyRequest().permitAll()
.requestMatchers("/admin/login").permitAll()
.anyRequest().authenticated()
)
.csrf().disable()
.cors()
.and()
.formLogin().disable()
.httpBasic().disable()
.sessionManagement((session) -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS));
.formLogin(formLogin -> {
formLogin.loginPage("/admin/login")
.defaultSuccessUrl("/admin/home", true)
.failureUrl("/login?error=true")
.usernameParameter("email")
.passwordParameter("password")
.loginProcessingUrl("/admin/login-process");
})
.logout(logout -> {
logout.logoutUrl("/admin/logout-process");
})
.httpBasic().disable();
// .sessionManagement((session) -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS));

return http.build();
}

@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder(); // 비밀번호 암호화 방식
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.sluv.admin.router.home;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/admin")
@RequiredArgsConstructor
public class LoginRouter {

@GetMapping("/login")
public String getLoginPage(Model model) {
return "home/login";
}

}
10 changes: 8 additions & 2 deletions sluv-admin/src/main/resources/templates/brand/brandRegister.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
font-weight: bold;
}

.header-right {
margin-left: auto;
}

/* 본문과 사이드바를 헤더 아래로 밀기 위한 상단 패딩 추가 */
.content {
display: flex;
Expand Down Expand Up @@ -178,9 +182,11 @@
<a th:href="@{/admin/home}">Sluv Back-Office</a>
<div class="header-center">
<a th:href="@{/admin/celebs}">Celeb</a>
<a th:href="@{/admin/brands}" class="active">Brand</a>
<a th:href="@{/admin/brands}">Brand</a>
</div>
<div class="header-right">
<a th:href="@{/admin/logout-process}" class="logout-btn">로그아웃</a>
</div>
<div></div>
</header>

<!-- 메뉴바와 본문을 감싸는 컨테이너 -->
Expand Down
10 changes: 8 additions & 2 deletions sluv-admin/src/main/resources/templates/brand/brands.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
font-weight: bold;
}

.header-right {
margin-left: auto;
}

/* 본문과 사이드바를 헤더 아래로 밀기 위한 상단 패딩 추가 */
.content {
display: flex;
Expand Down Expand Up @@ -259,9 +263,11 @@
<a th:href="@{/admin/home}">Sluv Back-Office</a>
<div class="header-center">
<a th:href="@{/admin/celebs}">Celeb</a>
<a th:href="@{/admin/brands}" class="active">Brand</a>
<a th:href="@{/admin/brands}">Brand</a>
</div>
<div class="header-right">
<a th:href="@{/admin/logout-process}" class="logout-btn">로그아웃</a>
</div>
<div></div>
</header>

<div class="content">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
font-weight: bold;
}

.header-right {
margin-left: auto;
}

/* 본문과 사이드바를 헤더 아래로 밀기 위한 상단 패딩 추가 */
.content {
display: flex;
Expand Down Expand Up @@ -178,9 +182,11 @@
<a th:href="@{/admin/home}">Sluv Back-Office</a>
<div class="header-center">
<a th:href="@{/admin/celebs}">Celeb</a>
<a th:href="@{/admin/brands}" class="active">Brand</a>
<a th:href="@{/admin/brands}">Brand</a>
</div>
<div class="header-right">
<a th:href="@{/admin/logout-process}" class="logout-btn">로그아웃</a>
</div>
<div></div>
</header>

<div class="content">
Expand Down
10 changes: 8 additions & 2 deletions sluv-admin/src/main/resources/templates/brand/newBrands.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
font-weight: bold;
}

.header-right {
margin-left: auto;
}

/* 본문과 사이드바를 헤더 아래로 밀기 위한 상단 패딩 추가 */
.content {
display: flex;
Expand Down Expand Up @@ -147,9 +151,11 @@
<a th:href="@{/admin/home}">Sluv Back-Office</a>
<div class="header-center">
<a th:href="@{/admin/celebs}">Celeb</a>
<a th:href="@{/admin/brands}" class="active">Brand</a>
<a th:href="@{/admin/brands}">Brand</a>
</div>
<div class="header-right">
<a th:href="@{/admin/logout-process}" class="logout-btn">로그아웃</a>
</div>
<div></div>
</header>

<div class="content">
Expand Down
10 changes: 8 additions & 2 deletions sluv-admin/src/main/resources/templates/celeb/celebRegister.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
font-weight: bold;
}

.header-right {
margin-left: auto;
}

/* 본문과 사이드바를 헤더 아래로 밀기 위한 상단 패딩 추가 */
.content {
display: flex;
Expand Down Expand Up @@ -196,10 +200,12 @@
<header>
<a th:href="@{/admin/home}">Sluv Back-Office</a>
<div class="header-center">
<a th:href="@{/admin/celebs}" class="active">Celeb</a>
<a th:href="@{/admin/celebs}">Celeb</a>
<a th:href="@{/admin/brands}">Brand</a>
</div>
<div></div>
<div class="header-right">
<a th:href="@{/admin/logout-process}" class="logout-btn">로그아웃</a>
</div>
</header>

<!-- 메뉴바와 본문을 감싸는 컨테이너 -->
Expand Down
10 changes: 8 additions & 2 deletions sluv-admin/src/main/resources/templates/celeb/celebs.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
font-weight: bold;
}

.header-right {
margin-left: auto;
}

/* 본문과 사이드바를 헤더 아래로 밀기 위한 상단 패딩 추가 */
.content {
display: flex;
Expand Down Expand Up @@ -266,10 +270,12 @@
<header>
<a th:href="@{/admin/home}">Sluv Back-Office</a>
<div class="header-center">
<a th:href="@{/admin/celebs}" class="active">Celeb</a>
<a th:href="@{/admin/celebs}">Celeb</a>
<a th:href="@{/admin/brands}">Brand</a>
</div>
<div></div>
<div class="header-right">
<a th:href="@{/admin/logout-process}" class="logout-btn">로그아웃</a>
</div>
</header>

<div class="content">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
font-weight: bold;
}

.header-right {
margin-left: auto;
}

/* 본문과 사이드바를 헤더 아래로 밀기 위한 상단 패딩 추가 */
.content {
display: flex;
Expand Down Expand Up @@ -209,10 +213,12 @@
<header>
<a th:href="@{/admin/home}">Sluv Back-Office</a>
<div class="header-center">
<a th:href="@{/admin/celebs}" class="active">Celeb</a>
<a th:href="@{/admin/celebs}">Celeb</a>
<a th:href="@{/admin/brands}">Brand</a>
</div>
<div></div>
<div class="header-right">
<a th:href="@{/admin/logout-process}" class="logout-btn">로그아웃</a>
</div>
</header>

<div class="content">
Expand Down
10 changes: 8 additions & 2 deletions sluv-admin/src/main/resources/templates/celeb/newCelebs.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
font-weight: bold;
}

.header-right {
margin-left: auto;
}

/* 본문과 사이드바를 헤더 아래로 밀기 위한 상단 패딩 추가 */
.content {
display: flex;
Expand Down Expand Up @@ -146,10 +150,12 @@
<header>
<a th:href="@{/admin/home}">Sluv Back-Office</a>
<div class="header-center">
<a th:href="@{/admin/celebs}" class="active">Celeb</a>
<a th:href="@{/admin/celebs}">Celeb</a>
<a th:href="@{/admin/brands}">Brand</a>
</div>
<div></div>
<div class="header-right">
<a th:href="@{/admin/logout-process}" class="logout-btn">로그아웃</a>
</div>
</header>

<div class="content">
Expand Down
25 changes: 24 additions & 1 deletion sluv-admin/src/main/resources/templates/home/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,27 @@
font-weight: bold;
}

.header-right {
margin-left: auto;
}

.logout-btn {
text-decoration: none;
color: #ddd;
font-size: 18px;
font-weight: bold;
margin-left: 20px;
padding: 8px 16px;
background-color: transparent;
border-radius: 3px;
transition: background-color 0.3s ease, color 0.3s ease;
}

.logout-btn:hover {
background-color: #555;
color: #fff;
}

.content {
display: flex;
flex: 1;
Expand Down Expand Up @@ -111,7 +132,9 @@
<a th:href="@{/admin/celebs}">Celeb</a>
<a th:href="@{/admin/brands}">Brand</a>
</div>
<div></div>
<div class="header-right">
<a th:href="@{/admin/logout-process}" class="logout-btn">로그아웃</a>
</div>
</header>

<div class="content">
Expand Down
Loading

0 comments on commit efbe6c5

Please sign in to comment.