Skip to content

Commit 1d88204

Browse files
authored
Merge pull request #3 from enjoy-hack/CD
Feat : 로그인 구현 중
2 parents d65550c + 0ef1dea commit 1d88204

25 files changed

Lines changed: 473 additions & 193 deletions

build.gradle

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,17 @@ dependencies {
4141
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.3'
4242
implementation 'org.springframework.boot:spring-boot-starter-webflux'
4343

44-
//MQTT
4544
implementation 'org.springframework.boot:spring-boot-starter-integration'
46-
implementation 'org.springframework.integration:spring-integration-mqtt'
4745

4846
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
4947

50-
implementation 'com.google.firebase:firebase-admin:9.2.0'
51-
52-
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
5348
implementation 'org.springframework.cloud:spring-cloud-starter-aws-messaging:2.2.6.RELEASE'
49+
50+
implementation 'com.squareup.okhttp3:okhttp:4.11.0'
51+
implementation 'com.squareup.okhttp3:okhttp-urlconnection:4.11.0' // 추가
52+
// Jsoup (HTML 파싱)
53+
implementation 'org.jsoup:jsoup:1.18.1'
54+
5455
}
5556

5657
tasks.named('test') {

src/main/java/com/example/smartair/EnjoyBackApplication.java renamed to src/main/java/com/example/enjoy/EnjoyBackApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.example.smartair;
1+
package com.example.enjoy;
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;

src/main/java/com/example/smartair/config/RestTemplateConfig.java renamed to src/main/java/com/example/enjoy/config/RestTemplateConfig.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
package com.example.smartair.config;
1+
package com.example.enjoy.config;
22

33
import org.springframework.context.annotation.Bean;
44
import org.springframework.context.annotation.Configuration;
55
import org.springframework.web.client.RestTemplate;
6+
67
@Configuration
78
public class RestTemplateConfig {
9+
810
@Bean
911
public RestTemplate restTemplate() {
1012
return new RestTemplate();
1113
}
1214
}
13-
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.example.enjoy.config;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
6+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
7+
import org.springframework.security.config.http.SessionCreationPolicy;
8+
import org.springframework.security.web.SecurityFilterChain;
9+
import org.springframework.web.cors.CorsConfiguration;
10+
import org.springframework.web.cors.CorsConfigurationSource;
11+
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
12+
13+
import java.util.Arrays;
14+
15+
@Configuration
16+
@EnableWebSecurity
17+
public class SecurityConfig {
18+
19+
@Bean
20+
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
21+
http
22+
.csrf(csrf -> csrf.disable())
23+
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
24+
.sessionManagement(session ->
25+
session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
26+
.authorizeHttpRequests(auth -> auth
27+
.anyRequest().permitAll()); // 모든 요청 허용
28+
29+
return http.build();
30+
}
31+
32+
@Bean
33+
public CorsConfigurationSource corsConfigurationSource() {
34+
CorsConfiguration configuration = new CorsConfiguration();
35+
configuration.setAllowedOrigins(Arrays.asList("http://localhost:3000"));
36+
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS"));
37+
configuration.setAllowedHeaders(Arrays.asList("*"));
38+
configuration.setAllowCredentials(true);
39+
40+
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
41+
source.registerCorsConfiguration("/**", configuration);
42+
return source;
43+
}
44+
}

src/main/java/com/example/smartair/config/SwaggerConfig.java renamed to src/main/java/com/example/enjoy/config/SwaggerConfig.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.example.smartair.config;
1+
package com.example.enjoy.config;
22

33
import io.swagger.v3.oas.models.OpenAPI;
44
import io.swagger.v3.oas.models.info.Info;
@@ -14,33 +14,31 @@
1414
public class SwaggerConfig {
1515
@Bean
1616
public OpenAPI customOpenAPI() {
17-
// Security Scheme 정의
18-
SecurityScheme securityScheme = new SecurityScheme()
19-
.type(SecurityScheme.Type.HTTP)
20-
.scheme("bearer")
21-
.bearerFormat("JWT")
17+
// API Key Scheme 정의
18+
SecurityScheme apiKeyScheme = new SecurityScheme()
19+
.type(SecurityScheme.Type.APIKEY)
2220
.in(SecurityScheme.In.HEADER)
23-
.name("Authorization");
21+
.name("Authorization")
22+
.description("인증을 위한 토큰");
2423

2524
// Security Requirement 정의
26-
SecurityRequirement securityRequirement = new SecurityRequirement().addList("BearerAuth");
25+
SecurityRequirement securityRequirement = new SecurityRequirement().addList("ApiKeyAuth");
2726

28-
// 서버 목록 정의
27+
// 서버 정의
2928
Server localServer = new Server();
3029
localServer.setUrl("http://localhost:8080");
31-
localServer.setDescription("Local server (HTTP)");
30+
localServer.setDescription("Local Server");
3231

33-
Server prodServer = new Server();
34-
prodServer.setUrl("https://smartair.site");
35-
prodServer.setDescription("Production server (HTTPS)");
32+
Server apiServer = new Server();
33+
apiServer.setUrl("http://3.36.34.67:8080");
34+
apiServer.setDescription("API Server");
3635

3736
return new OpenAPI()
3837
.info(new Info().title("Enjoy Hack API")
3938
.description("EnjoyHack Application API Documentation")
4039
.version("v1.0"))
41-
.addSecurityItem(securityRequirement) // Security Requirement 추가
42-
.schemaRequirement("BearerAuth", securityScheme) // Security Scheme 추가
43-
.servers(List.of(localServer, prodServer)); // 서버 목록 추가
40+
.addSecurityItem(securityRequirement)
41+
.schemaRequirement("ApiKeyAuth", apiKeyScheme)
42+
.servers(List.of(localServer, apiServer)); // 로컬서버와 운영서버 모두 등록
4443
}
45-
46-
}
44+
}

src/main/java/com/example/smartair/config/WebClientConfig.java renamed to src/main/java/com/example/enjoy/config/WebClientConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.example.smartair.config;
1+
package com.example.enjoy.config;
22

33
import org.springframework.context.annotation.Bean;
44
import org.springframework.context.annotation.Configuration;

src/main/java/com/example/smartair/config/corsMvcConfig.java renamed to src/main/java/com/example/enjoy/config/corsMvcConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.example.smartair.config;
1+
package com.example.enjoy.config;
22

33
import org.springframework.context.annotation.Configuration;
44
import org.springframework.web.servlet.config.annotation.CorsRegistry;

src/main/java/com/example/smartair/controller/HealthCheckController.java renamed to src/main/java/com/example/enjoy/controller/HealthCheckController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.example.smartair.controller;
1+
package com.example.enjoy.controller;
22

33
import org.springframework.http.ResponseEntity;
44
import org.springframework.web.bind.annotation.GetMapping;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.example.enjoy.controller.userController;
2+
3+
import com.example.enjoy.dto.loginDto.MemberCommand;
4+
import com.example.enjoy.dto.loginDto.MemberDto;
5+
import com.example.enjoy.service.loginService.SejongLoginService;
6+
import io.swagger.v3.oas.annotations.tags.Tag;
7+
import jakarta.validation.Valid;
8+
import lombok.AllArgsConstructor;
9+
import lombok.extern.slf4j.Slf4j;
10+
import org.springframework.http.ResponseEntity;
11+
import org.springframework.web.bind.annotation.PostMapping;
12+
import org.springframework.web.bind.annotation.RequestBody;
13+
import org.springframework.web.bind.annotation.RequestMapping;
14+
import org.springframework.web.bind.annotation.RestController;
15+
16+
@Tag(name = "로그인", description = "로그인 관련 API")
17+
@RestController
18+
@Slf4j
19+
@AllArgsConstructor
20+
@RequestMapping("/api/auth/sejong")
21+
public class LoginController {
22+
private final SejongLoginService sejongLoginService;
23+
24+
/**
25+
* 세종대학교 포털 로그인 및 사용자 정보 조회
26+
* 포털 로그인 -> 고전독서 사이트 SSO 인증 -> 사용자 정보 파싱 및 반환
27+
*/
28+
@PostMapping("/login")
29+
public ResponseEntity<MemberDto> loginAndGetUserInfo(@RequestBody @Valid MemberCommand command) {
30+
try {
31+
log.info("세종대 포털 로그인 요청: {}", command.getSejongPortalId());
32+
MemberDto memberInfo = sejongLoginService.getMemberAuthInfos(command);
33+
log.info("사용자 정보 조회 성공: {}", memberInfo.getStudentName());
34+
return ResponseEntity.ok(memberInfo);
35+
} catch (Exception e) {
36+
log.error("세종대 포털 로그인 및 정보 조회 실패: {}", e.getMessage(), e);
37+
throw new RuntimeException("세종대 포털 인증 실패", e);
38+
}
39+
}
40+
41+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.example.enjoy.dto.loginDto;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
import lombok.NoArgsConstructor;
6+
import lombok.Setter;
7+
8+
@Getter
9+
@Setter
10+
@NoArgsConstructor
11+
@AllArgsConstructor
12+
public class AuthRequest {
13+
private String id;
14+
private String pw;
15+
private String method;
16+
}
17+

0 commit comments

Comments
 (0)