-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from codestates-seb/feat_be_profile
refactor: security configure & pakage
- Loading branch information
Showing
25 changed files
with
147 additions
and
309 deletions.
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
9 changes: 0 additions & 9 deletions
9
server/src/main/java/com/main36/pikcha/domain/hashtag/controller/HashTagController.java
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
server/src/main/java/com/main36/pikcha/domain/hashtag/dto/HashTagDto.java
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...traction_file/entity/AttractionImage.java → .../domain/image/entity/AttractionImage.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
2 changes: 1 addition & 1 deletion
2
...a/domain/post_image/entity/PostImage.java → ...pikcha/domain/image/entity/PostImage.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
4 changes: 2 additions & 2 deletions
4
...repository/AttractionImageRepository.java → ...repository/AttractionImageRepository.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
7 changes: 2 additions & 5 deletions
7
...image/repository/PostImageRepository.java → ...image/repository/PostImageRepository.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
6 changes: 3 additions & 3 deletions
6
..._file/service/AttractionImageService.java → ...image/service/AttractionImageService.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
6 changes: 3 additions & 3 deletions
6
.../post_image/service/PostImageService.java → ...omain/image/service/PostImageService.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
2 changes: 1 addition & 1 deletion
2
...raction_likes/entity/AttractionLikes.java → ...a/domain/like/entity/AttractionLikes.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
2 changes: 1 addition & 1 deletion
2
...a/domain/post_likes/entity/PostLikes.java → .../pikcha/domain/like/entity/PostLikes.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
4 changes: 2 additions & 2 deletions
4
...repository/AttractionLikesRepository.java → ...repository/AttractionLikesRepository.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
4 changes: 2 additions & 2 deletions
4
...likes/repository/PostLikesRepository.java → .../like/repository/PostLikesRepository.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
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
2 changes: 0 additions & 2 deletions
2
server/src/main/java/com/main36/pikcha/domain/post/repository/PostRepository.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
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
31 changes: 0 additions & 31 deletions
31
server/src/main/java/com/main36/pikcha/domain/post_hashtag/entity/PostHashTag.java
This file was deleted.
Oops, something went wrong.
118 changes: 118 additions & 0 deletions
118
server/src/main/java/com/main36/pikcha/global/security/SecurityConfiguration.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,118 @@ | ||
package com.main36.pikcha.global.security; | ||
|
||
|
||
import com.main36.pikcha.domain.member.repository.MemberRepository; | ||
import com.main36.pikcha.domain.member.service.MemberService; | ||
import com.main36.pikcha.global.security.filter.JwtAuthenticationFilter; | ||
import com.main36.pikcha.global.security.filter.JwtVerificationFilter; | ||
import com.main36.pikcha.global.security.jwt.JwtGenerator; | ||
import com.main36.pikcha.global.security.handler.*; | ||
import com.main36.pikcha.global.security.jwt.JwtParser; | ||
import com.main36.pikcha.global.security.oauth.OAuth2MemberSuccessHandler; | ||
import com.main36.pikcha.global.security.oauth.OauthService; | ||
import com.main36.pikcha.global.utils.CustomAuthorityUtils; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.authentication.AuthenticationManager; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; | ||
import org.springframework.security.config.http.SessionCreationPolicy; | ||
import org.springframework.security.oauth2.client.web.OAuth2LoginAuthenticationFilter; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
import org.springframework.web.cors.CorsConfiguration; | ||
import org.springframework.web.cors.CorsConfigurationSource; | ||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.springframework.boot.autoconfigure.security.servlet.PathRequest.toH2Console; | ||
|
||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class SecurityConfiguration { | ||
private final JwtParser jwtParser; | ||
private final JwtGenerator jwtGenerator; | ||
private final CustomAuthorityUtils customAuthorityUtils; | ||
private final MemberService memberService; | ||
private final OauthService oauthService; | ||
|
||
@Bean | ||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { | ||
http | ||
|
||
.httpBasic().disable() | ||
.formLogin().disable() | ||
.csrf().disable() | ||
.headers().frameOptions().sameOrigin() | ||
|
||
.and() | ||
.cors().configurationSource(corsConfigurationSource()) | ||
|
||
.and() | ||
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) | ||
|
||
.and() | ||
.exceptionHandling() | ||
.authenticationEntryPoint(new MemberAuthenticationEntryPoint()) | ||
.accessDeniedHandler(new MemberAccessDeniedHandler()) | ||
|
||
.and() | ||
.apply(new CustomFilterConfigure()) | ||
|
||
.and() | ||
.authorizeHttpRequests(authorize -> authorize | ||
.requestMatchers(toH2Console()).permitAll() | ||
.antMatchers("attractions/upload", "attractions/edit/**", "attractions/delete", "admin").hasRole("ADMIN") | ||
.anyRequest().permitAll()) | ||
|
||
.oauth2Login(oauth2 -> oauth2 | ||
.successHandler(new OAuth2MemberSuccessHandler(customAuthorityUtils, memberService, jwtGenerator)) | ||
.userInfoEndpoint() | ||
.userService(oauthService)); | ||
|
||
return http.build(); | ||
} | ||
|
||
@Bean | ||
CorsConfigurationSource corsConfigurationSource() { | ||
CorsConfiguration configuration = new CorsConfiguration(); | ||
configuration.setAllowedOrigins( | ||
List.of( | ||
"http://localhost:3000", | ||
"http://pikcha36.o-r.kr/", | ||
"https://pikcha36.o-r.kr/") | ||
); | ||
configuration.setAllowCredentials(true); | ||
configuration.addExposedHeader("Authorization"); | ||
configuration.addAllowedHeader("*"); | ||
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PATCH", "DELETE")); | ||
|
||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); | ||
source.registerCorsConfiguration("/**", configuration); | ||
|
||
return source; | ||
} | ||
|
||
public class CustomFilterConfigure extends AbstractHttpConfigurer<CustomFilterConfigure, HttpSecurity> { | ||
@Override | ||
public void configure(HttpSecurity builder) throws Exception { | ||
AuthenticationManager authenticationManager = builder.getSharedObject(AuthenticationManager.class); | ||
|
||
JwtAuthenticationFilter jwtAuthenticationFilter = new JwtAuthenticationFilter(jwtGenerator, authenticationManager); | ||
jwtAuthenticationFilter.setFilterProcessesUrl("/login"); | ||
jwtAuthenticationFilter.setAuthenticationSuccessHandler(new MemberAuthenticationSuccessHandler()); | ||
jwtAuthenticationFilter.setAuthenticationFailureHandler(new MemberAuthenticationFailureHandler()); | ||
|
||
JwtVerificationFilter jwtVerificationFilter = new JwtVerificationFilter(jwtGenerator, jwtParser); | ||
|
||
builder | ||
.addFilter(jwtAuthenticationFilter) | ||
.addFilterAfter(jwtVerificationFilter, OAuth2LoginAuthenticationFilter.class); | ||
|
||
} | ||
} | ||
} | ||
|
Oops, something went wrong.