Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,17 @@ dependencies {
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.3'
implementation 'org.springframework.boot:spring-boot-starter-webflux'

//MQTT
implementation 'org.springframework.boot:spring-boot-starter-integration'
implementation 'org.springframework.integration:spring-integration-mqtt'

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

implementation 'com.google.firebase:firebase-admin:9.2.0'

implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
implementation 'org.springframework.cloud:spring-cloud-starter-aws-messaging:2.2.6.RELEASE'

implementation 'com.squareup.okhttp3:okhttp:4.11.0'
implementation 'com.squareup.okhttp3:okhttp-urlconnection:4.11.0' // 추가
// Jsoup (HTML 파싱)
implementation 'org.jsoup:jsoup:1.18.1'

}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.smartair;
package com.example.enjoy;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.example.smartair.config;
package com.example.enjoy.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestTemplateConfig {

@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}

44 changes: 44 additions & 0 deletions src/main/java/com/example/enjoy/config/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.example.enjoy.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;
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;

@Configuration
@EnableWebSecurity
public class SecurityConfig {

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.csrf(csrf -> csrf.disable())
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
.sessionManagement(session ->
session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(auth -> auth
.anyRequest().permitAll()); // 모든 요청 허용

return http.build();
}

@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(Arrays.asList("http://localhost:3000"));
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS"));
configuration.setAllowedHeaders(Arrays.asList("*"));
configuration.setAllowCredentials(true);

UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.smartair.config;
package com.example.enjoy.config;

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

// Security Requirement 정의
SecurityRequirement securityRequirement = new SecurityRequirement().addList("BearerAuth");
SecurityRequirement securityRequirement = new SecurityRequirement().addList("ApiKeyAuth");

// 서버 목록 정의
// 서버 정의
Server localServer = new Server();
localServer.setUrl("http://localhost:8080");
localServer.setDescription("Local server (HTTP)");
localServer.setDescription("Local Server");

Server prodServer = new Server();
prodServer.setUrl("https://smartair.site");
prodServer.setDescription("Production server (HTTPS)");
Server apiServer = new Server();
apiServer.setUrl("http://3.36.34.67:8080");
apiServer.setDescription("API Server");

return new OpenAPI()
.info(new Info().title("Enjoy Hack API")
.description("EnjoyHack Application API Documentation")
.version("v1.0"))
.addSecurityItem(securityRequirement) // Security Requirement 추가
.schemaRequirement("BearerAuth", securityScheme) // Security Scheme 추가
.servers(List.of(localServer, prodServer)); // 서버 목록 추가
.addSecurityItem(securityRequirement)
.schemaRequirement("ApiKeyAuth", apiKeyScheme)
.servers(List.of(localServer, apiServer)); // 로컬서버와 운영서버 모두 등록
}

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.smartair.config;
package com.example.enjoy.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.smartair.config;
package com.example.enjoy.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.smartair.controller;
package com.example.enjoy.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.example.enjoy.controller.userController;

import com.example.enjoy.dto.loginDto.MemberCommand;
import com.example.enjoy.dto.loginDto.MemberDto;
import com.example.enjoy.service.loginService.SejongLoginService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "로그인", description = "로그인 관련 API")
@RestController
@Slf4j
@AllArgsConstructor
@RequestMapping("/api/auth/sejong")
public class LoginController {
private final SejongLoginService sejongLoginService;

/**
* 세종대학교 포털 로그인 및 사용자 정보 조회
* 포털 로그인 -> 고전독서 사이트 SSO 인증 -> 사용자 정보 파싱 및 반환
*/
@PostMapping("/login")
public ResponseEntity<MemberDto> loginAndGetUserInfo(@RequestBody @Valid MemberCommand command) {
try {
log.info("세종대 포털 로그인 요청: {}", command.getSejongPortalId());
MemberDto memberInfo = sejongLoginService.getMemberAuthInfos(command);
log.info("사용자 정보 조회 성공: {}", memberInfo.getStudentName());
return ResponseEntity.ok(memberInfo);
} catch (Exception e) {
log.error("세종대 포털 로그인 및 정보 조회 실패: {}", e.getMessage(), e);
throw new RuntimeException("세종대 포털 인증 실패", e);
}
}

}
17 changes: 17 additions & 0 deletions src/main/java/com/example/enjoy/dto/loginDto/AuthRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.enjoy.dto.loginDto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class AuthRequest {
private String id;
private String pw;
private String method;
}

24 changes: 24 additions & 0 deletions src/main/java/com/example/enjoy/dto/loginDto/AuthResponseDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.enjoy.dto.loginDto;

public class AuthResponseDto {
private String msg;
private Result result;
private String code;
private Boolean is_auth;
private Integer status_code;
private Boolean success;
private String version;

public static class Result {
private String authenticator;
private Body body;
// getters/setters
}

public static class Body {
private String major;
private String name;
// getters/setters
}
// getters/setters
}
12 changes: 12 additions & 0 deletions src/main/java/com/example/enjoy/dto/loginDto/MemberCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.enjoy.dto.loginDto;

import lombok.Getter;
import org.springframework.stereotype.Service;

@Getter
@Service
public class MemberCommand {
String sejongPortalId;
String sejongPortalPassword;

}
15 changes: 15 additions & 0 deletions src/main/java/com/example/enjoy/dto/loginDto/MemberDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.enjoy.dto.loginDto;

import lombok.Builder;
import lombok.Getter;

@Builder
@Getter
public class MemberDto {
private String major;
private String studentIdString;
private String studentName;
private String academicYear;
private String enrollmentStatus;

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.example.smartair.entity;
package com.example.enjoy.entity;

import jakarta.persistence.Entity;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.example.smartair.entity.user;
package com.example.enjoy.entity.user;

import com.example.smartair.entity.BaseTimeEntity;
import com.example.enjoy.entity.BaseTimeEntity;

import jakarta.persistence.*;
import lombok.*;

import java.util.Set;

@Builder
@Entity
@Getter
Expand All @@ -30,8 +28,6 @@ public class User extends BaseTimeEntity {

private String providerId; //소셜 로그인 시 제공자 ID

private Role role;



}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.smartair.exception;
package com.example.enjoy.exception;

import lombok.Getter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.smartair.exception;
package com.example.enjoy.exception;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -12,7 +12,10 @@ public enum ErrorCode {
USER_JOIN_INFO_BAD_REQUEST(HttpStatus.BAD_REQUEST, "회원가입 정보가 잘못되었습니다"),
USER_ALREADY_EXISTS(HttpStatus.BAD_REQUEST, "이미 존재하는 사용자입니다"),
USER_NOT_FOUND(HttpStatus.NOT_FOUND, "사용자를 찾을 수 없습니다"),
USER_PASSWORD_NOT_MATCH(HttpStatus.BAD_REQUEST, "비밀번호가 일치하지 않습니다");
USER_PASSWORD_NOT_MATCH(HttpStatus.BAD_REQUEST, "비밀번호가 일치하지 않습니다"),
SEJONG_AUTH_CONNECTION_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "세종대학교 인증 서버와의 연결에 실패했습니다"),
SEJONG_AUTH_CREDENTIALS_INVALID(HttpStatus.UNAUTHORIZED, "세종대학교 인증 정보가 유효하지 않습니다"),
SEJONG_AUTH_DATA_FETCH_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "세종대학교 인증 데이터 가져오기 실패");

private final String message;
private final int status;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.smartair.exception;
package com.example.enjoy.exception;

import lombok.extern.slf4j.Slf4j;

Expand All @@ -7,7 +7,6 @@
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.server.ResponseStatusException;

import java.util.Collections;
import java.util.HashMap;

@RestControllerAdvice
Expand Down
Loading
Loading