Skip to content

Commit 76a7e5e

Browse files
author
github-actions
committed
chore: Java 스타일 수정
1 parent bdf7bbb commit 76a7e5e

File tree

10 files changed

+66
-45
lines changed

10 files changed

+66
-45
lines changed

backend/src/main/java/io/f1/backend/domain/admin/app/AdminDetailService.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package io.f1.backend.domain.admin.app;
22

3-
import static io.f1.backend.domain.user.constants.SessionKeys.ADMIN;
43

54
import io.f1.backend.domain.admin.dao.AdminRepository;
65
import io.f1.backend.domain.admin.dto.AdminPrincipal;
7-
import io.f1.backend.domain.admin.dto.AuthenticationAdmin;
86
import io.f1.backend.domain.admin.entity.Admin;
9-
import jakarta.servlet.http.HttpSession;
7+
108
import lombok.RequiredArgsConstructor;
9+
1110
import org.springframework.security.core.userdetails.UserDetails;
1211
import org.springframework.security.core.userdetails.UserDetailsService;
1312
import org.springframework.security.core.userdetails.UsernameNotFoundException;
@@ -21,8 +20,11 @@ public class AdminDetailService implements UserDetailsService {
2120

2221
@Override
2322
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
24-
Admin admin = adminRepository.findByUsername(username)
25-
.orElseThrow(() -> new UsernameNotFoundException("E404007: 존재하지 않는 관리자입니다."));
23+
Admin admin =
24+
adminRepository
25+
.findByUsername(username)
26+
.orElseThrow(
27+
() -> new UsernameNotFoundException("E404007: 존재하지 않는 관리자입니다."));
2628
// 프론트엔드로 내려가지 않는 예외
2729
return new AdminPrincipal(admin);
2830
}

backend/src/main/java/io/f1/backend/domain/admin/app/handler/AdminLoginFailureHandler.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,37 @@
11
package io.f1.backend.domain.admin.app.handler;
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
4+
45
import io.f1.backend.domain.admin.dto.AdminLoginFailResponseDto;
6+
57
import jakarta.servlet.http.HttpServletRequest;
68
import jakarta.servlet.http.HttpServletResponse;
7-
import java.io.IOException;
9+
810
import lombok.RequiredArgsConstructor;
11+
912
import org.springframework.security.core.AuthenticationException;
1013
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
1114
import org.springframework.stereotype.Component;
1215

16+
import java.io.IOException;
17+
1318
@Component
1419
@RequiredArgsConstructor
1520
public class AdminLoginFailureHandler implements AuthenticationFailureHandler {
1621

1722
private final ObjectMapper objectMapper;
1823

1924
@Override
20-
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
21-
AuthenticationException exception) throws IOException {
25+
public void onAuthenticationFailure(
26+
HttpServletRequest request,
27+
HttpServletResponse response,
28+
AuthenticationException exception)
29+
throws IOException {
2230
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); // 401
2331
response.setContentType("application/json;charset=UTF-8");
2432

25-
AdminLoginFailResponseDto errorResponse = new AdminLoginFailResponseDto(
26-
"E401005",
27-
"아이디 또는 비밀번호가 일치하지 않습니다."
28-
);
33+
AdminLoginFailResponseDto errorResponse =
34+
new AdminLoginFailResponseDto("E401005", "아이디 또는 비밀번호가 일치하지 않습니다.");
2935

3036
response.getWriter().write(objectMapper.writeValueAsString(errorResponse));
3137
}

backend/src/main/java/io/f1/backend/domain/admin/app/handler/AdminLoginSuccessHandler.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@
66
import io.f1.backend.domain.admin.dao.AdminRepository;
77
import io.f1.backend.domain.admin.dto.AdminPrincipal;
88
import io.f1.backend.domain.admin.entity.Admin;
9+
910
import jakarta.servlet.http.HttpServletRequest;
1011
import jakarta.servlet.http.HttpServletResponse;
1112
import jakarta.servlet.http.HttpSession;
12-
import java.time.LocalDateTime;
13+
1314
import lombok.RequiredArgsConstructor;
15+
1416
import org.springframework.security.core.Authentication;
1517
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
1618
import org.springframework.stereotype.Component;
1719

20+
import java.time.LocalDateTime;
21+
1822
@Component
1923
@RequiredArgsConstructor
2024
public class AdminLoginSuccessHandler implements AuthenticationSuccessHandler {
@@ -24,13 +28,15 @@ public class AdminLoginSuccessHandler implements AuthenticationSuccessHandler {
2428

2529
@Override
2630
public void onAuthenticationSuccess(
27-
HttpServletRequest request,
28-
HttpServletResponse response,
29-
Authentication authentication) {
31+
HttpServletRequest request,
32+
HttpServletResponse response,
33+
Authentication authentication) {
3034

3135
AdminPrincipal principal = getCurrentAdminPrincipal();
32-
Admin admin = adminRepository.findByUsername(principal.getUsername())
33-
.orElseThrow(() -> new RuntimeException("E404007: 존재하지 않는 관리자입니다."));
36+
Admin admin =
37+
adminRepository
38+
.findByUsername(principal.getUsername())
39+
.orElseThrow(() -> new RuntimeException("E404007: 존재하지 않는 관리자입니다."));
3440

3541
admin.updateLastLogin(LocalDateTime.now());
3642
adminRepository.save(admin);
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package io.f1.backend.domain.admin.dao;
22

33
import io.f1.backend.domain.admin.entity.Admin;
4-
import java.util.Optional;
4+
55
import org.springframework.data.jpa.repository.JpaRepository;
66
import org.springframework.stereotype.Repository;
77

8+
import java.util.Optional;
9+
810
@Repository
911
public interface AdminRepository extends JpaRepository<Admin, Long> {
1012

1113
Optional<Admin> findByUsername(String username);
12-
1314
}

backend/src/main/java/io/f1/backend/domain/admin/dto/AdminPrincipal.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package io.f1.backend.domain.admin.dto;
22

33
import io.f1.backend.domain.admin.entity.Admin;
4-
import java.util.Collection;
5-
import java.util.Collections;
4+
65
import lombok.Getter;
6+
77
import org.springframework.security.core.GrantedAuthority;
88
import org.springframework.security.core.userdetails.UserDetails;
99

10+
import java.util.Collection;
11+
import java.util.Collections;
12+
1013
@Getter
1114
public class AdminPrincipal implements UserDetails {
1215

backend/src/main/java/io/f1/backend/domain/admin/entity/Admin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
import jakarta.persistence.GenerationType;
99
import jakarta.persistence.Id;
1010

11-
import java.time.LocalDateTime;
1211
import lombok.Getter;
1312

13+
import java.time.LocalDateTime;
14+
1415
@Entity
1516
@Getter
1617
public class Admin extends BaseEntity {

backend/src/main/java/io/f1/backend/domain/auth/api/AuthController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import io.f1.backend.domain.admin.dto.AdminPrincipal;
66
import io.f1.backend.domain.auth.dto.CurrentUserAndAdminResponse;
77
import io.f1.backend.domain.user.dto.UserPrincipal;
8+
89
import lombok.RequiredArgsConstructor;
10+
911
import org.springframework.http.ResponseEntity;
1012
import org.springframework.security.core.Authentication;
1113
import org.springframework.web.bind.annotation.GetMapping;

backend/src/main/java/io/f1/backend/domain/auth/dto/CurrentUserAndAdminResponse.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@ public record CurrentUserAndAdminResponse(Long id, String name, String role) {
77

88
public static CurrentUserAndAdminResponse from(UserPrincipal userPrincipal) {
99
return new CurrentUserAndAdminResponse(
10-
userPrincipal.getUserId(),
11-
userPrincipal.getUserNickname(),
12-
UserPrincipal.ROLE_USER
13-
);
10+
userPrincipal.getUserId(),
11+
userPrincipal.getUserNickname(),
12+
UserPrincipal.ROLE_USER);
1413
}
1514

1615
public static CurrentUserAndAdminResponse from(AdminPrincipal adminPrincipal) {
1716
return new CurrentUserAndAdminResponse(
18-
adminPrincipal.getAuthenticationAdmin().adminId(),
19-
adminPrincipal.getUsername(),
20-
AdminPrincipal.ROLE_ADMIN
21-
);
17+
adminPrincipal.getAuthenticationAdmin().adminId(),
18+
adminPrincipal.getUsername(),
19+
AdminPrincipal.ROLE_ADMIN);
2220
}
2321
}

backend/src/main/java/io/f1/backend/global/config/SecurityConfig.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import io.f1.backend.domain.admin.app.handler.AdminLoginSuccessHandler;
55
import io.f1.backend.domain.user.app.CustomOAuthUserService;
66
import io.f1.backend.domain.user.app.handler.CustomAuthenticationEntryPoint;
7-
import io.f1.backend.domain.user.app.handler.UserAndAdminLogoutSuccessHandler;
87
import io.f1.backend.domain.user.app.handler.OAuthSuccessHandler;
8+
import io.f1.backend.domain.user.app.handler.UserAndAdminLogoutSuccessHandler;
99

1010
import lombok.RequiredArgsConstructor;
1111

@@ -55,12 +55,12 @@ public SecurityFilterChain userFilterChain(HttpSecurity http) throws Exception {
5555
.hasAnyRole("USER", "ADMIN")
5656
.anyRequest()
5757
.authenticated())
58-
.formLogin(form -> form
59-
.loginProcessingUrl("/admin/login") // 로그인 form action 경로
60-
.successHandler(adminLoginSuccessHandler)
61-
.failureHandler(adminLoginFailureHandler)
62-
.permitAll()
63-
)
58+
.formLogin(
59+
form ->
60+
form.loginProcessingUrl("/admin/login") // 로그인 form action 경로
61+
.successHandler(adminLoginSuccessHandler)
62+
.failureHandler(adminLoginFailureHandler)
63+
.permitAll())
6464
.oauth2Login(
6565
oauth2 ->
6666
oauth2.userInfoEndpoint(

backend/src/main/java/io/f1/backend/global/util/SecurityUtils.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,31 @@
33
import io.f1.backend.domain.admin.dto.AdminPrincipal;
44
import io.f1.backend.domain.user.dto.UserPrincipal;
55
import io.f1.backend.domain.user.entity.User;
6+
67
import jakarta.servlet.http.HttpSession;
7-
import java.util.Collections;
8+
89
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
910
import org.springframework.security.core.Authentication;
1011
import org.springframework.security.core.context.SecurityContextHolder;
1112

13+
import java.util.Collections;
14+
1215
public class SecurityUtils {
1316

14-
private SecurityUtils() {
15-
}
17+
private SecurityUtils() {}
1618

1719
public static void setAuthentication(User user) {
1820
UserPrincipal userPrincipal = new UserPrincipal(user, Collections.emptyMap());
1921
UsernamePasswordAuthenticationToken authentication =
20-
new UsernamePasswordAuthenticationToken(
21-
userPrincipal, null, userPrincipal.getAuthorities());
22+
new UsernamePasswordAuthenticationToken(
23+
userPrincipal, null, userPrincipal.getAuthorities());
2224
SecurityContextHolder.getContext().setAuthentication(authentication);
2325
}
2426

2527
public static UserPrincipal getCurrentUserPrincipal() {
2628
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
2729
if (authentication != null
28-
&& authentication.getPrincipal() instanceof UserPrincipal userPrincipal) {
30+
&& authentication.getPrincipal() instanceof UserPrincipal userPrincipal) {
2931
return userPrincipal;
3032
}
3133
throw new RuntimeException("E401001: 로그인이 필요합니다.");
@@ -53,7 +55,7 @@ private static void clearAuthentication() {
5355
public static AdminPrincipal getCurrentAdminPrincipal() {
5456
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
5557
if (authentication != null
56-
&& authentication.getPrincipal() instanceof AdminPrincipal adminPrincipal) {
58+
&& authentication.getPrincipal() instanceof AdminPrincipal adminPrincipal) {
5759
return adminPrincipal;
5860
}
5961
throw new RuntimeException("E401001: 로그인이 필요합니다.");

0 commit comments

Comments
 (0)