Skip to content

Commit

Permalink
fix: 로그인 안된 상태 코드 500_3으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
AlmondBreez3 committed Jan 31, 2024
1 parent 9bf3b00 commit ac2bffd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
http.authorizeRequests()
.requestMatchers("/api/auth/**").permitAll()
.requestMatchers( "/api/swagger-ui/**", "/api/v3/api-docs/**").permitAll()
.requestMatchers("/api/**").authenticated();
.requestMatchers("/api/**").authenticated().and().anonymous().disable();

http.apply(filterConfig);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.example.api.config.security;

import com.example.error.exception.SecurityContextNotFoundException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class SecurityUtil {
public static Long getCurrentUserId() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

if (authentication == null) {
throw new IllegalArgumentException("잘못된 접근");
throw SecurityContextNotFoundException.EXCEPTION;
}
return Long.valueOf(authentication.getName());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.example.api.user.service;

public class GetUserGenresUseCase {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.error.exception;

import com.example.error.BaseErrorException;
import com.example.error.GlobalErrorCode;

public class SecurityContextNotFoundException extends BaseErrorException {

public static final BaseErrorException EXCEPTION = new SecurityContextNotFoundException();

private SecurityContextNotFoundException() {
super(GlobalErrorCode.SECURITY_CONTEXT_NOT_FOUND);
}
}

0 comments on commit ac2bffd

Please sign in to comment.