From 73c047b790d713b7f2fc0e8e9c7d503563f44daf Mon Sep 17 00:00:00 2001 From: Phung Huu Thanh <102614541+phuuthanh2003@users.noreply.github.com> Date: Thu, 13 Jun 2024 01:29:30 +0700 Subject: [PATCH 1/2] config utf-8 db --- src/main/resources/application-dev.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index 352c024..557a03c 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -7,7 +7,7 @@ frontend.base-url=http://localhost:3000 spring.banner.location=banner.txt # Config db -spring.datasource.url=jdbc:sqlserver://localhost:1433;encrypt=true;trustServerCertificate=true;databaseName=DB_AUCTION; +spring.datasource.url=jdbc:sqlserver://localhost:1433;encrypt=true;trustServerCertificate=true;collation=Latin1_General_100_CI_AS_SC_UTF8;databaseName=DB_AUCTION; spring.datasource.username=sa spring.datasource.password=Thanhth@nh1 From 0dbb1961964ab91afb02f5b5dd6b3e5abd0d4b4c Mon Sep 17 00:00:00 2001 From: Phung Huu Thanh <102614541+phuuthanh2003@users.noreply.github.com> Date: Thu, 13 Jun 2024 02:23:05 +0700 Subject: [PATCH 2/2] fix db and security config --- .../backend/auction/config/SecurityConfiguration.java | 8 ++++---- .../auction/filter/JwtAuthenticationFilter.java | 2 ++ .../webapp/backend/auction/model/RequestApproval.java | 1 + .../java/vn/webapp/backend/auction/model/User.java | 11 ----------- src/main/resources/application-dev.properties | 4 ++-- 5 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/main/java/vn/webapp/backend/auction/config/SecurityConfiguration.java b/src/main/java/vn/webapp/backend/auction/config/SecurityConfiguration.java index bbdc413..a85c863 100644 --- a/src/main/java/vn/webapp/backend/auction/config/SecurityConfiguration.java +++ b/src/main/java/vn/webapp/backend/auction/config/SecurityConfiguration.java @@ -1,5 +1,6 @@ package vn.webapp.backend.auction.config; +import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -63,15 +64,14 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti .sessionManagement((session) -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) .authenticationProvider(authenticationProvider) .httpBasic(Customizer.withDefaults()) - .formLogin(formLogin -> - formLogin.loginPage("/api/v1/auth/login").permitAll() - ) .addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class) .logout(logout -> logout.logoutUrl("/api/v1/auth/logout") .addLogoutHandler(logoutHandler) .logoutSuccessHandler((request, response, authentication) -> SecurityContextHolder.clearContext()) - ); + ).exceptionHandling(exceptionHandling -> exceptionHandling + .authenticationEntryPoint((request, response, authException) -> response.sendError(HttpServletResponse.SC_UNAUTHORIZED)) + );; return http.build(); } } \ No newline at end of file diff --git a/src/main/java/vn/webapp/backend/auction/filter/JwtAuthenticationFilter.java b/src/main/java/vn/webapp/backend/auction/filter/JwtAuthenticationFilter.java index 4905567..506b12c 100644 --- a/src/main/java/vn/webapp/backend/auction/filter/JwtAuthenticationFilter.java +++ b/src/main/java/vn/webapp/backend/auction/filter/JwtAuthenticationFilter.java @@ -78,6 +78,8 @@ protected void doFilterInternal( filterChain.doFilter(request, response); } catch (ExpiredJwtException ex) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "JWT token is expired!"); + } catch (Exception ex) { + response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized"); } } diff --git a/src/main/java/vn/webapp/backend/auction/model/RequestApproval.java b/src/main/java/vn/webapp/backend/auction/model/RequestApproval.java index 06c5a07..0d480ee 100644 --- a/src/main/java/vn/webapp/backend/auction/model/RequestApproval.java +++ b/src/main/java/vn/webapp/backend/auction/model/RequestApproval.java @@ -61,6 +61,7 @@ public class RequestApproval { @Column(name = "request_time", nullable = false) private Timestamp requestTime; + @Column(name = "response_time") private Timestamp responseTime; diff --git a/src/main/java/vn/webapp/backend/auction/model/User.java b/src/main/java/vn/webapp/backend/auction/model/User.java index cb934ce..dd265ef 100644 --- a/src/main/java/vn/webapp/backend/auction/model/User.java +++ b/src/main/java/vn/webapp/backend/auction/model/User.java @@ -92,11 +92,6 @@ public class User implements UserDetails { @Column(name ="bank_account_name", nullable = false, length = 30) private String bankAccountName; -// @ManyToOne -// @JoinColumn(name = "role_id") -// @EqualsAndHashCode.Exclude -// @ToString.Exclude -// private Role role; @Enumerated(EnumType.STRING) private Role role; @@ -113,12 +108,6 @@ public class User implements UserDetails { @JsonIgnore private List jewelries; -// @OneToMany(mappedBy = "user", cascade = CascadeType.ALL) -// @EqualsAndHashCode.Exclude -// @ToString.Exclude -// @JsonIgnore -// private List requestApprovals; - public String getFullName() { return firstName + " " + lastName; } diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index 3327313..557a03c 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -9,10 +9,10 @@ spring.banner.location=banner.txt # Config db spring.datasource.url=jdbc:sqlserver://localhost:1433;encrypt=true;trustServerCertificate=true;collation=Latin1_General_100_CI_AS_SC_UTF8;databaseName=DB_AUCTION; spring.datasource.username=sa -spring.datasource.password=12345 +spring.datasource.password=Thanhth@nh1 # Config create table automatically -spring.jpa.hibernate.ddl-auto=update +spring.jpa.hibernate.ddl-auto=none # Config email spring.mail.host=smtp.gmail.com