ads367
04-02
2024-04-02 [최민식] 시큐리티 진행중
[최민식] 시큐리티 진행중
@eb9e08449189855a07a526ce1d045a26ac5a183f
--- .idea/jarRepositories.xml
+++ .idea/jarRepositories.xml
... | ... | @@ -7,9 +7,9 @@ |
7 | 7 |
<option name="url" value="https://repo.maven.apache.org/maven2" /> |
8 | 8 |
</remote-repository> |
9 | 9 |
<remote-repository> |
10 |
- <option name="id" value="egovframe" /> |
|
11 |
- <option name="name" value="egovframe" /> |
|
12 |
- <option name="url" value="https://maven.egovframe.go.kr/maven/" /> |
|
10 |
+ <option name="id" value="central" /> |
|
11 |
+ <option name="name" value="Maven Central repository" /> |
|
12 |
+ <option name="url" value="https://repo1.maven.org/maven2" /> |
|
13 | 13 |
</remote-repository> |
14 | 14 |
<remote-repository> |
15 | 15 |
<option name="id" value="mvn2s" /> |
... | ... | @@ -17,9 +17,9 @@ |
17 | 17 |
<option name="url" value="https://repo1.maven.org/maven2/" /> |
18 | 18 |
</remote-repository> |
19 | 19 |
<remote-repository> |
20 |
- <option name="id" value="central" /> |
|
21 |
- <option name="name" value="Maven Central repository" /> |
|
22 |
- <option name="url" value="https://repo1.maven.org/maven2" /> |
|
20 |
+ <option name="id" value="egovframe" /> |
|
21 |
+ <option name="name" value="egovframe" /> |
|
22 |
+ <option name="url" value="https://maven.egovframe.go.kr/maven/" /> |
|
23 | 23 |
</remote-repository> |
24 | 24 |
<remote-repository> |
25 | 25 |
<option name="id" value="jboss.community" /> |
--- .idea/misc.xml
+++ .idea/misc.xml
... | ... | @@ -8,7 +8,7 @@ |
8 | 8 |
</list> |
9 | 9 |
</option> |
10 | 10 |
</component> |
11 |
- <component name="ProjectRootManager" version="2" languageLevel="JDK_14" project-jdk-name="11" project-jdk-type="JavaSDK"> |
|
11 |
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="false" project-jdk-name="11" project-jdk-type="JavaSDK"> |
|
12 | 12 |
<output url="file://$PROJECT_DIR$/classes" /> |
13 | 13 |
</component> |
14 | 14 |
</project>(파일 끝에 줄바꿈 문자 없음) |
--- .idea/modules.xml
... | ... | @@ -1,8 +0,0 @@ |
1 | -<?xml version="1.0" encoding="UTF-8"?> | |
2 | -<project version="4"> | |
3 | - <component name="ProjectModuleManager"> | |
4 | - <modules> | |
5 | - <module fileurl="file://$PROJECT_DIR$/cms.iml" filepath="$PROJECT_DIR$/cms.iml" /> | |
6 | - </modules> | |
7 | - </component> | |
8 | -</project>(파일 끝에 줄바꿈 문자 없음) |
--- pom.xml
+++ pom.xml
... | ... | @@ -156,12 +156,26 @@ |
156 | 156 |
<artifactId>poi-ooxml</artifactId> |
157 | 157 |
<version>4.1.2</version> |
158 | 158 |
</dependency> |
159 |
- <!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt --> |
|
160 |
-<!-- <dependency>--> |
|
161 |
-<!-- <groupId>io.jsonwebtoken</groupId>--> |
|
162 |
-<!-- <artifactId>jjwt</artifactId>--> |
|
163 |
-<!-- <version>0.12.5</version>--> |
|
164 |
-<!-- </dependency>--> |
|
159 |
+ <!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-api --> |
|
160 |
+ <dependency> |
|
161 |
+ <groupId>io.jsonwebtoken</groupId> |
|
162 |
+ <artifactId>jjwt-api</artifactId> |
|
163 |
+ <version>0.12.5</version> |
|
164 |
+ </dependency> |
|
165 |
+ <!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-impl --> |
|
166 |
+ <dependency> |
|
167 |
+ <groupId>io.jsonwebtoken</groupId> |
|
168 |
+ <artifactId>jjwt-impl</artifactId> |
|
169 |
+ <version>0.12.5</version> |
|
170 |
+ <scope>runtime</scope> |
|
171 |
+ </dependency> |
|
172 |
+ <!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-jackson --> |
|
173 |
+ <dependency> |
|
174 |
+ <groupId>io.jsonwebtoken</groupId> |
|
175 |
+ <artifactId>jjwt-jackson</artifactId> |
|
176 |
+ <version>0.12.5</version> |
|
177 |
+ <scope>runtime</scope> |
|
178 |
+ </dependency> |
|
165 | 179 |
<!-- 추가 --> |
166 | 180 |
</dependencies> |
167 | 181 |
|
+++ src/main/java/com/takensoft/common/config/CorsMvcConfig.java
... | ... | @@ -0,0 +1,20 @@ |
1 | +package com.takensoft.common.config; | |
2 | + | |
3 | +import org.springframework.beans.factory.annotation.Value; | |
4 | +import org.springframework.web.servlet.config.annotation.CorsRegistry; | |
5 | +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | |
6 | + | |
7 | +public class CorsMvcConfig implements WebMvcConfigurer { | |
8 | + | |
9 | + private static String FRONT_URL; //1시간 | |
10 | + @Value("${front.url}") | |
11 | + public void setFrontUrl(String value) { | |
12 | + FRONT_URL = value; | |
13 | + } | |
14 | + | |
15 | + @Override | |
16 | + public void addCorsMappings(CorsRegistry corsRegistry) { | |
17 | + corsRegistry.addMapping("/**") | |
18 | + .allowedOrigins(FRONT_URL); | |
19 | + } | |
20 | +} |
--- src/main/java/com/takensoft/common/config/SecurityConfig.java
+++ src/main/java/com/takensoft/common/config/SecurityConfig.java
... | ... | @@ -1,21 +1,70 @@ |
1 | 1 |
package com.takensoft.common.config; |
2 | 2 |
|
3 |
+import org.springframework.beans.factory.annotation.Value; |
|
3 | 4 |
import org.springframework.context.annotation.Bean; |
4 | 5 |
import org.springframework.context.annotation.Configuration; |
5 | 6 |
import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
6 | 7 |
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; |
8 |
+import org.springframework.security.config.http.SessionCreationPolicy; |
|
7 | 9 |
import org.springframework.security.web.SecurityFilterChain; |
10 |
+import org.springframework.web.cors.CorsConfiguration; |
|
11 |
+import org.springframework.web.cors.CorsConfigurationSource; |
|
12 |
+ |
|
13 |
+import javax.servlet.http.HttpServletRequest; |
|
14 |
+import java.util.Collections; |
|
8 | 15 |
|
9 | 16 |
@Configuration |
10 | 17 |
@EnableWebSecurity |
11 | 18 |
public class SecurityConfig { |
19 |
+ |
|
20 |
+ private static String FRONT_URL; //1시간 |
|
21 |
+ @Value("${front.url}") |
|
22 |
+ public void setFrontUrl(String value) { |
|
23 |
+ FRONT_URL = value; |
|
24 |
+ } |
|
25 |
+ |
|
12 | 26 |
@Bean |
13 | 27 |
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { |
14 | 28 |
http |
15 |
- .csrf().disable() |
|
16 |
- .authorizeHttpRequests((authorizeRequests) -> |
|
17 |
- authorizeRequests.anyRequest().permitAll() |
|
29 |
+ .cors((cors) -> cors |
|
30 |
+ .configurationSource(new CorsConfigurationSource() { |
|
31 |
+ @Override |
|
32 |
+ public CorsConfiguration getCorsConfiguration(HttpServletRequest request) { |
|
33 |
+ CorsConfiguration configuration = new CorsConfiguration(); |
|
34 |
+ // 허용할 프론트 포트 포함 경로 입력 |
|
35 |
+ configuration.setAllowedOrigins(Collections.singletonList(FRONT_URL)); |
|
36 |
+ // 허용할 메소드(GET, POST, PUT 등) |
|
37 |
+ configuration.setAllowedMethods(Collections.singletonList("*")); |
|
38 |
+ // 프론트에서 credentials 설정하면 true |
|
39 |
+ configuration.setAllowCredentials(true); |
|
40 |
+ // 허용할 헤드 |
|
41 |
+ configuration.setAllowedHeaders(Collections.singletonList("*")); |
|
42 |
+ // 허용을 물고 있을 시간 |
|
43 |
+ configuration.setMaxAge(3600L); |
|
44 |
+ |
|
45 |
+ // 서버에서 JWT를 Authorization에 담아 보내기 위해 허용을 함 |
|
46 |
+ configuration.setExposedHeaders(Collections.singletonList("Authorization")); |
|
47 |
+ return configuration; |
|
48 |
+ } |
|
49 |
+ }) |
|
18 | 50 |
); |
51 |
+ // csrf disable |
|
52 |
+ http.csrf((auth) -> auth.disable()); |
|
53 |
+ // formLogin disable |
|
54 |
+ http.formLogin((auth) -> auth.disable()); |
|
55 |
+ // http basic 인증 방식 disable |
|
56 |
+ http.httpBasic((auth) -> auth.disable()); |
|
57 |
+ |
|
58 |
+ // 경로별 인가 설정 |
|
59 |
+ http |
|
60 |
+ .authorizeHttpRequests((auth) -> auth |
|
61 |
+ .anyRequest().permitAll() |
|
62 |
+ ); |
|
63 |
+ |
|
64 |
+ // 세션 설정 |
|
65 |
+ http |
|
66 |
+ .sessionManagement((session) -> session |
|
67 |
+ .sessionCreationPolicy(SessionCreationPolicy.STATELESS)); |
|
19 | 68 |
return http.build(); |
20 | 69 |
} |
21 | 70 |
}(파일 끝에 줄바꿈 문자 없음) |
--- src/main/resources/application.yml
+++ src/main/resources/application.yml
... | ... | @@ -22,4 +22,12 @@ |
22 | 22 |
type-aliases-package: com.takensoft.**.**.vo, com.takensoft.**.**.dto |
23 | 23 |
mapper-locations: classpath:mybatis/mapper/**/*-SQL.xml |
24 | 24 |
|
25 |
+# jwt |
|
26 |
+jwt: |
|
27 |
+ secret: akdnciepwlmdkcngpqktmektakensoftepckdbnskqmdkfsdflksdfoasjkdfbasdfasdfwerhjjhkgdfgdfseasdfef |
|
28 |
+ accessTime: 600000 # 1시간 |
|
29 |
+ refreshTime: 86400000 # 24시간 |
|
25 | 30 |
|
31 |
+# frontUrl |
|
32 |
+front: |
|
33 |
+ url: http://localhost:3000(파일 끝에 줄바꿈 문자 없음) |
--- target/classes/application.yml
+++ target/classes/application.yml
... | ... | @@ -22,4 +22,8 @@ |
22 | 22 |
type-aliases-package: com.takensoft.**.**.vo, com.takensoft.**.**.dto |
23 | 23 |
mapper-locations: classpath:mybatis/mapper/**/*-SQL.xml |
24 | 24 |
|
25 |
- |
|
25 |
+# jwt |
|
26 |
+jwt: |
|
27 |
+ secret: akdnciepwlmdkcngpqktmektakensoftepckdbnskqmdkfsdflksdfoasjkdfbasdfasdfwerhjjhkgdfgdfseasdfef |
|
28 |
+ accessTime: 600000 # 1시간 |
|
29 |
+ refreshTime: 86400000 # 24시간 |
--- target/classes/com/takensoft/CmsApplication.class
+++ target/classes/com/takensoft/CmsApplication.class
Binary file is not shown |
--- target/classes/com/takensoft/cms/sample/dao/SampleDAO.class
+++ target/classes/com/takensoft/cms/sample/dao/SampleDAO.class
Binary file is not shown |
--- target/classes/com/takensoft/cms/sample/service/Impl/SampleServiceImpl.class
+++ target/classes/com/takensoft/cms/sample/service/Impl/SampleServiceImpl.class
Binary file is not shown |
--- target/classes/com/takensoft/cms/sample/service/SampleService.class
+++ target/classes/com/takensoft/cms/sample/service/SampleService.class
Binary file is not shown |
--- target/classes/com/takensoft/cms/sample/vo/SampleVO.class
+++ target/classes/com/takensoft/cms/sample/vo/SampleVO.class
Binary file is not shown |
--- target/classes/com/takensoft/cms/sample/web/SampleController.class
+++ target/classes/com/takensoft/cms/sample/web/SampleController.class
Binary file is not shown |
--- target/classes/com/takensoft/portal/entrprsInfo/dao/EntrprsInfoDAO.class
+++ target/classes/com/takensoft/portal/entrprsInfo/dao/EntrprsInfoDAO.class
Binary file is not shown |
--- target/classes/com/takensoft/portal/entrprsInfo/dao/FnlttDAO.class
+++ target/classes/com/takensoft/portal/entrprsInfo/dao/FnlttDAO.class
Binary file is not shown |
--- target/classes/com/takensoft/portal/entrprsInfo/service/EntrprsInfoService.class
+++ target/classes/com/takensoft/portal/entrprsInfo/service/EntrprsInfoService.class
Binary file is not shown |
--- target/classes/com/takensoft/portal/entrprsInfo/service/FnlttService.class
+++ target/classes/com/takensoft/portal/entrprsInfo/service/FnlttService.class
Binary file is not shown |
--- target/classes/com/takensoft/portal/entrprsInfo/service/Impl/EntrprsInfoServiceImpl.class
+++ target/classes/com/takensoft/portal/entrprsInfo/service/Impl/EntrprsInfoServiceImpl.class
Binary file is not shown |
--- target/classes/com/takensoft/portal/entrprsInfo/service/Impl/FnlttServiceImpl.class
+++ target/classes/com/takensoft/portal/entrprsInfo/service/Impl/FnlttServiceImpl.class
Binary file is not shown |
--- target/classes/com/takensoft/portal/entrprsInfo/vo/EntrprsInfoVO.class
+++ target/classes/com/takensoft/portal/entrprsInfo/vo/EntrprsInfoVO.class
Binary file is not shown |
--- target/classes/com/takensoft/portal/entrprsInfo/vo/FnlttVO.class
+++ target/classes/com/takensoft/portal/entrprsInfo/vo/FnlttVO.class
Binary file is not shown |
--- target/classes/com/takensoft/portal/entrprsInfo/web/EntrprsInfoController.class
+++ target/classes/com/takensoft/portal/entrprsInfo/web/EntrprsInfoController.class
Binary file is not shown |
--- target/classes/com/takensoft/portal/investment/dao/InvestmentDAO.class
+++ target/classes/com/takensoft/portal/investment/dao/InvestmentDAO.class
Binary file is not shown |
--- target/classes/com/takensoft/portal/investment/service/Impl/InvestmentServiceImpl.class
+++ target/classes/com/takensoft/portal/investment/service/Impl/InvestmentServiceImpl.class
Binary file is not shown |
--- target/classes/com/takensoft/portal/investment/service/InvestmentService.class
+++ target/classes/com/takensoft/portal/investment/service/InvestmentService.class
Binary file is not shown |
--- target/classes/com/takensoft/portal/investment/vo/InvestmentVO.class
+++ target/classes/com/takensoft/portal/investment/vo/InvestmentVO.class
Binary file is not shown |
--- target/classes/com/takensoft/portal/investment/web/InvestmentController.class
+++ target/classes/com/takensoft/portal/investment/web/InvestmentController.class
Binary file is not shown |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?