diff --git a/build.gradle b/build.gradle index 8ad37d0..19bb56d 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'site.easy-startup' -version = '0.0.1-SNAPSHOT' +version = '0.0.8' sourceCompatibility = "17" configurations { @@ -20,7 +20,8 @@ repositories { } dependencies { - implementation 'org.springdoc:springdoc-openapi-ui:1.6.9' + implementation 'mysql:mysql-connector-java:8.0.30' + implementation 'org.springdoc:springdoc-openapi-ui:1.6.11' implementation 'com.google.code.gson:gson:2.9.0' implementation 'com.auth0:java-jwt:4.0.0' implementation 'org.springframework:spring-websocket:5.3.22' @@ -53,4 +54,4 @@ tasks.named('compileJava') { inputs.files(tasks.named('processResources')) } -targetCompatibility = JavaVersion.VERSION_17 +targetCompatibility = JavaVersion.VERSION_17 \ No newline at end of file diff --git a/src/main/java/site/easystartup/web/controller/MainController.java b/src/main/java/site/easystartup/web/controller/MainController.java new file mode 100644 index 0000000..6556289 --- /dev/null +++ b/src/main/java/site/easystartup/web/controller/MainController.java @@ -0,0 +1,12 @@ +package site.easystartup.web.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class MainController { + @GetMapping("/") + public String main() { + return "/main"; + } +} diff --git a/src/main/java/site/easystartup/web/security/JWTFilter.java b/src/main/java/site/easystartup/web/security/JWTFilter.java index eda6c4b..341a429 100644 --- a/src/main/java/site/easystartup/web/security/JWTFilter.java +++ b/src/main/java/site/easystartup/web/security/JWTFilter.java @@ -5,6 +5,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; import org.springframework.web.filter.OncePerRequestFilter; @@ -36,6 +37,7 @@ public class JWTFilter extends OncePerRequestFilter { } else { try { String email = jwtUtil.validateTokenAndRetrieveClaim(jwt); + UserDetails userDetails = userDetailService.loadUserByUsername(email); UsernamePasswordAuthenticationToken authenticationToken = diff --git a/src/main/java/site/easystartup/web/security/SecurityConfig.java b/src/main/java/site/easystartup/web/security/SecurityConfig.java index 74af23f..9bbb175 100644 --- a/src/main/java/site/easystartup/web/security/SecurityConfig.java +++ b/src/main/java/site/easystartup/web/security/SecurityConfig.java @@ -41,9 +41,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { .and() .authorizeRequests() .antMatchers(SecurityConstants.SIGN_UP_URLS).permitAll() - .antMatchers("/auth/*").anonymous() - .antMatchers("/").permitAll() - .anyRequest().authenticated(); + .anyRequest().authenticated().and() + .antMatcher("/auth/*").anonymous(); http.addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class); } diff --git a/src/main/java/site/easystartup/web/service/AuthService.java b/src/main/java/site/easystartup/web/service/AuthService.java index 67af619..06b9f68 100644 --- a/src/main/java/site/easystartup/web/service/AuthService.java +++ b/src/main/java/site/easystartup/web/service/AuthService.java @@ -1,6 +1,7 @@ package site.easystartup.web.service; import lombok.RequiredArgsConstructor; +import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import site.easystartup.web.domain.exception.UserExistException; @@ -20,10 +21,15 @@ public class AuthService { private final PasswordEncoder passwordEncoder; public User createUser(SignupRequest signupRequest) { - if (userRepo.findUserByUsername(signupRequest.getUsername()).isPresent()) { - throw new UserExistException("An account with this username already exists."); - } + boolean exists = false; + try { + if (userRepo.findUserByUsername(signupRequest.getUsername()).isPresent()) { + exists = true; + } + } catch (UsernameNotFoundException e) {} + + if(exists) throw new UserExistException("An account with this username already exists."); User user = new User(); user.setEmail(signupRequest.getEmail()); user.setUsername(signupRequest.getUsername()); diff --git a/src/main/java/site/easystartup/web/storage/service/FileLocalStorageService.java b/src/main/java/site/easystartup/web/storage/service/FileLocalStorageService.java index f331aee..131d989 100644 --- a/src/main/java/site/easystartup/web/storage/service/FileLocalStorageService.java +++ b/src/main/java/site/easystartup/web/storage/service/FileLocalStorageService.java @@ -1,11 +1,14 @@ package site.easystartup.web.storage.service; import lombok.SneakyThrows; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; import org.springframework.core.io.UrlResource; import org.springframework.util.FileSystemUtils; import org.springframework.web.multipart.MultipartFile; +import javax.servlet.ServletContext; import java.io.IOException; import java.net.MalformedURLException; import java.nio.file.Files; @@ -14,7 +17,10 @@ import java.nio.file.Paths; import java.util.stream.Stream; public class FileLocalStorageService implements StorageService { - private final Path root = Paths.get("uploads"); + @Autowired + ServletContext context; + + private final Path root = Path.of(new FileSystemResource("").getFile().getAbsolutePath()); public FileLocalStorageService() { init(); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 1d36ab8..4712cb9 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -4,9 +4,15 @@ spring.jpa.hibernate.ddl-auto=update spring.sql.init.mode=always -spring.sql.init.platform=postgres -spring.datasource.url=jdbc:postgresql://localhost:5432/testdb -spring.datasource.username=postgres -spring.datasource.password=root + +#spring.sql.init.platform=postgres +#spring.datasource.url=jdbc:postgresql://localhost:5432/testdb +#spring.datasource.username=postgres +#spring.datasource.password=root + +spring.datasource.url=jdbc:mysql://mysql.joinserver.xyz:3306/s45925_test +spring.datasource.username=u45925_MqxGXdRT8T +spring.datasource.password=K=9KkskkTa3.IAW!fkJx95JE +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.security.filter.order=10 \ No newline at end of file diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html new file mode 100644 index 0000000..f73dffb --- /dev/null +++ b/src/main/resources/static/index.html @@ -0,0 +1,5 @@ + + +

API

+ + \ No newline at end of file diff --git a/src/main/resources/static/js/main.js b/src/main/resources/static/js/main.js deleted file mode 100644 index be49c38..0000000 --- a/src/main/resources/static/js/main.js +++ /dev/null @@ -1,30 +0,0 @@ -const connect = () => { - const Stomp = require("stompjs"); - var SockJS = require("sockjs-client"); - SockJS = new SockJS("http://localhost:8080/ws"); - stompClient = Stomp.over(SockJS); - stompClient.connect({}, onConnected, onError); - }; - - const onConnected = () => { - console.log("connected"); - - stompClient.subscribe( - "/user/" + currentUser.id + "/queue/messages", - onMessageReceived - ); - }; - - const sendMessage = (msg) => { - if (msg.trim() !== "") { - const message = { - senderId: currentUser.id, - recipientId: activeContact.id, - senderName: currentUser.name, - recipientName: activeContact.name, - content: msg, - }; - - stompClient.send("/app/chat", {}, JSON.stringify(message)); - } - }; diff --git a/src/main/resources/static/js/notification.js b/src/main/resources/static/js/notification.js deleted file mode 100644 index 6cfb415..0000000 --- a/src/main/resources/static/js/notification.js +++ /dev/null @@ -1,34 +0,0 @@ -function connect() { - let socket = new SockJs(`api/socket`); - - let stompClient = Stomp.over(socket); - - return stompClient; -} - - -let stompClient = this.webSocketService.connect(); - -stompClient.connect({}, frame => { - - stompClient.subscribe('/user/queue/notification', notification => { - console.log('test'+ notification) - JSON.parse(notification.body); - }) -}); - - - const sendMessage = (msg) => { - if (msg.trim() !== "") { - const message = { - senderId: currentUser.id, - recipientId: activeContact.id, - senderName: currentUser.name, - recipientName: activeContact.name, - content: msg, - }; - - stompClient.send("/app/chat", {}, JSON.stringify(message)); - } - }; - diff --git a/src/main/resources/templates/main.html b/src/main/resources/templates/main.html new file mode 100644 index 0000000..f1ea715 --- /dev/null +++ b/src/main/resources/templates/main.html @@ -0,0 +1,9 @@ + + + + API + + +

API

+ + \ No newline at end of file