diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index bbc0baf6..5f083e20 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -181,7 +181,7 @@ jobs: uses: actions/setup-java@v4 with: distribution: 'adopt' - java-version: '11' + java-version: '17' - name: Setup Go uses: actions/setup-go@v5 @@ -203,6 +203,16 @@ jobs: mkdir test-results go run gotest.tools/gotestsum@latest --format testname --junitfile test-results/unit-tests.xml + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + # Require: The version of golangci-lint to use. + # When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version. + # When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit. + version: v1.54 + working-directory: services/community + + - name: Run workshop tests run: | cd services/workshop diff --git a/services/community/Dockerfile b/services/community/Dockerfile index d7b6cf8e..e1428bdf 100644 --- a/services/community/Dockerfile +++ b/services/community/Dockerfile @@ -41,4 +41,6 @@ RUN ls -al /app ARG SERVER_PORT EXPOSE ${SERVER_PORT} +# Expose profiling port +EXPOSE 6060 CMD /app/main diff --git a/services/community/api/auth/token.go b/services/community/api/auth/token.go index 00e1f58c..ffa453c6 100644 --- a/services/community/api/auth/token.go +++ b/services/community/api/auth/token.go @@ -66,12 +66,12 @@ func ExtractTokenID(r *http.Request, db *gorm.DB) (uint32, error) { return 0, err } - resp, err := http.Post(tokenVerifyURL, "application/json", - bytes.NewBuffer(tokenJSON)) + resp, err := http.Post(tokenVerifyURL, "application/json", bytes.NewBuffer(tokenJSON)) if err != nil { log.Println(err) return 0, err } + defer resp.Body.Close() tokenValid := resp.StatusCode == 200 token, _, err := new(jwt.Parser).ParseUnverified(tokenString, jwt.MapClaims{}) diff --git a/services/community/api/controllers/coupon_controller.go b/services/community/api/controllers/coupon_controller.go index bcffa2f0..1714bdf1 100644 --- a/services/community/api/controllers/coupon_controller.go +++ b/services/community/api/controllers/coupon_controller.go @@ -30,6 +30,7 @@ import ( //Server have database connection func (s *Server) AddNewCoupon(w http.ResponseWriter, r *http.Request) { body, err := io.ReadAll(r.Body) + defer r.Body.Close() if err != nil { responses.ERROR(w, http.StatusBadRequest, err) return @@ -61,6 +62,7 @@ func (s *Server) ValidateCoupon(w http.ResponseWriter, r *http.Request) { var bsonMap bson.M body, err := io.ReadAll(r.Body) + defer r.Body.Close() if err != nil { responses.ERROR(w, http.StatusBadRequest, err) log.Println("No payload for ValidateCoupon", body, err) diff --git a/services/community/api/controllers/post_controller.go b/services/community/api/controllers/post_controller.go index b17ec25b..3538ac26 100644 --- a/services/community/api/controllers/post_controller.go +++ b/services/community/api/controllers/post_controller.go @@ -32,6 +32,7 @@ import ( func (s *Server) AddNewPost(w http.ResponseWriter, r *http.Request) { body, err := io.ReadAll(r.Body) + defer r.Body.Close() if err != nil { responses.ERROR(w, http.StatusBadRequest, err) return @@ -112,6 +113,7 @@ func (s *Server) Comment(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) body, err := io.ReadAll(r.Body) + defer r.Body.Close() if err != nil { responses.ERROR(w, http.StatusBadRequest, err) return diff --git a/services/community/api/router/routes.go b/services/community/api/router/routes.go index 22f924c3..cac972c7 100644 --- a/services/community/api/router/routes.go +++ b/services/community/api/router/routes.go @@ -17,6 +17,7 @@ package router import ( "log" "net/http" + _ "net/http/pprof" "os" "time" @@ -29,16 +30,19 @@ import ( type Server config.Server +var controller = controllers.Server{} // initializeRoutes initialize routes of url with Authentication or without Authentication func (server *Server) InitializeRoutes() *mux.Router { - var controller = controllers.Server{} controller.DB = server.DB controller.Client = server.Client server.Router.Use(middlewares.AccessControlMiddleware) + if os.Getenv("DEBUG") == "1" { + server.Router.PathPrefix("/debug/pprof/").Handler(http.DefaultServeMux) + } // Post Route server.Router.HandleFunc("/community/api/v2/community/posts/recent", middlewares.SetMiddlewareJSON(middlewares.SetMiddlewareAuthentication(controller.GetPost, server.DB))).Methods("GET", "OPTIONS") @@ -77,14 +81,8 @@ func (server *Server) Run(addr string) { if !is_key || key == "" { key = "certs/server.key" } - err := srv.ListenAndServeTLS(certificate, key) - if err != nil { - log.Println(err) - } + log.Println(srv.ListenAndServeTLS(certificate, key)) } else { - err := srv.ListenAndServe() - if err != nil { - log.Println(err) - } + log.Println(srv.ListenAndServe()) } } diff --git a/services/identity/.java-version b/services/identity/.java-version new file mode 100644 index 00000000..98d9bcb7 --- /dev/null +++ b/services/identity/.java-version @@ -0,0 +1 @@ +17 diff --git a/services/identity/Dockerfile b/services/identity/Dockerfile index c2ebb886..1f7e1512 100644 --- a/services/identity/Dockerfile +++ b/services/identity/Dockerfile @@ -12,9 +12,10 @@ # Java Maven Build -FROM gradle:7.3.3-jdk11 AS gradlebuild +FROM gradle:8.1-jdk17-focal AS gradlebuild WORKDIR /app COPY *.gradle.kts ./ +COPY gradle.properties ./ # Only download dependencies # Eat the expected build failure since no source code has been copied yet RUN gradle clean build --no-daemon > /dev/null 2>&1 || true @@ -23,15 +24,19 @@ RUN gradle build RUN gradle bootJar # Main Image -FROM openjdk:11.0.15-jre-slim-buster - -#Java +FROM openjdk:17.0-jdk-slim +# #Java RUN apt-get -y update && apt-get -y install curl && apt-get -y clean +# RUN apt-get -y update && apt-get -y install wget curl unzip && apt-get -y clean +# RUN wget https://www.yourkit.com/download/docker/YourKit-JavaProfiler-2023.9-docker.zip -P /tmp/ && \ +# unzip /tmp/YourKit-JavaProfiler-2023.9-docker.zip -d /usr/local && \ +# rm /tmp/YourKit-JavaProfiler-2023.9-docker.zip RUN mkdir /app COPY --from=gradlebuild /app/build/libs/identity-service-1.0-SNAPSHOT.jar /app/identity-service-1.0-SNAPSHOT.jar -ARG SERVER_PORT +ARG SERVER_PORT EXPOSE ${SERVER_PORT} +EXPOSE 10001 ENV JAVA_TOOL_OPTIONS "-Xmx128m" diff --git a/services/identity/build.gradle.kts b/services/identity/build.gradle.kts index 71b80776..f4e07d39 100644 --- a/services/identity/build.gradle.kts +++ b/services/identity/build.gradle.kts @@ -1,7 +1,7 @@ plugins { - id("java") application - id("org.springframework.boot") version "2.6.1" + id("java") + id("org.springframework.boot") version "3.2.2" id("io.spring.dependency-management") version "1.0.11.RELEASE" id("com.diffplug.spotless") version "5.9.0" } @@ -14,11 +14,13 @@ repositories { } application { - mainClassName = "com.crapi.CRAPIBootApplication" + mainClass.set("com.crapi.CRAPIBootApplication") } -java.sourceCompatibility = JavaVersion.VERSION_11 - +java { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} pluginManager.withPlugin("java") { apply(plugin = "com.diffplug.spotless") configure { @@ -32,39 +34,44 @@ pluginManager.withPlugin("java") { } } dependencies { - val lombokVersion = "1.18.12" - val mockito = "3.7.7" - val springBootVersion = "2.6.1" + val lombokVersion = "1.18.30" + val mockito = "5.2.0" + val springBootVersion = "3.2.2" + val springSecurityVersion = "6.0.3" val log4jVersion = "2.14.0" compileOnly("org.projectlombok:lombok:${lombokVersion}") testCompileOnly("org.projectlombok:lombok:${lombokVersion}") annotationProcessor("org.projectlombok:lombok:${lombokVersion}") - annotationProcessor("javax.annotation:javax.annotation-api:1.3.2") + annotationProcessor("jakarta.annotation:jakarta.annotation-api:2.1.1") annotationProcessor("org.springframework.boot:spring-boot-configuration-processor") - testImplementation("org.projectlombok:lombok:${lombokVersion}") + annotationProcessor("jakarta.xml.bind:jakarta.xml.bind-api:4.0.1") testAnnotationProcessor("org.projectlombok:lombok-mapstruct-binding:0.2.0") - implementation("org.springframework.boot:spring-boot-starter:${springBootVersion}") - implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") - implementation("org.springframework.boot:spring-boot-starter-security:${springBootVersion}") - implementation("org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}") + implementation("jakarta.xml.bind:jakarta.xml.bind-api:4.0.1") + implementation("org.springframework.boot:spring-boot-starter:${springBootVersion}") + implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") + implementation("org.springframework.boot:spring-boot-starter-security:${springBootVersion}") + implementation("org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}") implementation("org.springframework.boot:spring-boot-starter-mail:${springBootVersion}") - implementation("org.springframework.boot:spring-boot-starter-validation:${springBootVersion}") - testImplementation("org.springframework.boot:spring-boot-starter-test:${springBootVersion}") - implementation("io.jsonwebtoken:jjwt:0.9.1") - implementation("com.nimbusds:nimbus-jose-jwt:9.25.6") - implementation("javax.validation:validation-api:2.0.1.Final") + implementation("org.springframework.boot:spring-boot-starter-validation:${springBootVersion}") + implementation("org.springframework.security:spring-security-config:${springSecurityVersion}") + implementation("io.jsonwebtoken:jjwt:0.12.5") + implementation("com.nimbusds:nimbus-jose-jwt:9.37.3") + implementation("jakarta.validation:jakarta.validation-api:3.0.2") implementation("org.postgresql:postgresql:runtime") implementation("org.postgresql:postgresql:42.4.0") implementation("com.google.cloud:google-cloud-storage:2.10.0") implementation("org.apache.logging.log4j:log4j-api:${log4jVersion}") implementation("org.apache.logging.log4j:log4j-core:${log4jVersion}") implementation("org.apache.logging.log4j:log4j-web:${log4jVersion}") - implementation("com.google.cloud:libraries-bom:25.4.0") + implementation("com.google.cloud:libraries-bom:26.32.0") implementation("org.apache.httpcomponents:httpclient:4.5.13") implementation("com.google.cloud:google-cloud-storage:2.10.0") + implementation("org.apache.httpcomponents.client5:httpclient5:5.3") + testImplementation("org.springframework.boot:spring-boot-starter-test:${springBootVersion}") + testImplementation("org.projectlombok:lombok:${lombokVersion}") testImplementation("org.mockito:mockito-junit-jupiter:${mockito}") testImplementation("org.mockito:mockito-core:${mockito}") testImplementation("org.mockito:mockito-inline:${mockito}") - testImplementation("junit:junit:4.13.1") + testImplementation("junit:junit:4.13.2") //implementation("org.apache.logging.log4j:log4j-slf4j-impl:${log4jVersion}") } \ No newline at end of file diff --git a/services/identity/entrypoint.sh b/services/identity/entrypoint.sh index d2d5d22e..3287e05b 100755 --- a/services/identity/entrypoint.sh +++ b/services/identity/entrypoint.sh @@ -7,7 +7,6 @@ else echo "Loading default JWKS file." JWKS=$(openssl base64 -in /default_jwks.json -A) fi - java -jar /app/identity-service-1.0-SNAPSHOT.jar --app.jwksJson=$JWKS exec "$@" diff --git a/services/identity/gradle.properties b/services/identity/gradle.properties new file mode 100644 index 00000000..9e4c261f --- /dev/null +++ b/services/identity/gradle.properties @@ -0,0 +1,6 @@ +org.gradle.jvmargs= \ + --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \ + --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \ + --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \ + --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \ + --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED diff --git a/services/identity/gradle/wrapper/gradle-wrapper.properties b/services/identity/gradle/wrapper/gradle-wrapper.properties index 2e6e5897..59bc51a2 100644 --- a/services/identity/gradle/wrapper/gradle-wrapper.properties +++ b/services/identity/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/services/identity/src/main/java/com/crapi/config/JwtAuthEntryPoint.java b/services/identity/src/main/java/com/crapi/config/JwtAuthEntryPoint.java index fe97252d..5324f72e 100644 --- a/services/identity/src/main/java/com/crapi/config/JwtAuthEntryPoint.java +++ b/services/identity/src/main/java/com/crapi/config/JwtAuthEntryPoint.java @@ -14,10 +14,10 @@ package com.crapi.config; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.AuthenticationEntryPoint; import org.springframework.stereotype.Component; diff --git a/services/identity/src/main/java/com/crapi/config/JwtAuthTokenFilter.java b/services/identity/src/main/java/com/crapi/config/JwtAuthTokenFilter.java index 50b5f43a..08835184 100644 --- a/services/identity/src/main/java/com/crapi/config/JwtAuthTokenFilter.java +++ b/services/identity/src/main/java/com/crapi/config/JwtAuthTokenFilter.java @@ -16,12 +16,12 @@ import com.crapi.enums.EStatus; import com.crapi.service.Impl.UserDetailsServiceImpl; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.text.ParseException; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/services/identity/src/main/java/com/crapi/config/JwtProvider.java b/services/identity/src/main/java/com/crapi/config/JwtProvider.java index 5826b40f..c6f008c1 100644 --- a/services/identity/src/main/java/com/crapi/config/JwtProvider.java +++ b/services/identity/src/main/java/com/crapi/config/JwtProvider.java @@ -18,6 +18,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.nimbusds.jose.*; +import com.nimbusds.jose.crypto.MACVerifier; import com.nimbusds.jose.crypto.RSASSAVerifier; import com.nimbusds.jose.jwk.JWK; import com.nimbusds.jose.jwk.JWKSet; @@ -35,11 +36,13 @@ import java.security.KeyPair; import java.text.ParseException; import java.util.*; +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; +@Slf4j @Component public class JwtProvider { @@ -59,6 +62,7 @@ public JwtProvider(@Value("${app.jwksJson}") String jwksJson) { Base64.Decoder decoder = Base64.getDecoder(); InputStream jwksStream = new ByteArrayInputStream(decoder.decode(jwksJson)); JWKSet jwkSet = JWKSet.load(jwksStream); + jwksStream.close(); List keys = jwkSet.getKeys(); if (keys.size() != 1 || !Objects.equals(keys.get(0).getAlgorithm().getName(), "RS256")) { throw new RuntimeException("Invalid JWKS key passed!!!"); @@ -86,13 +90,15 @@ public String generateJwtToken(User user) { int jwtExpirationInt; if (jwtExpiration.contains("e+")) jwtExpirationInt = new BigDecimal(jwtExpiration).intValue(); else jwtExpirationInt = Integer.parseInt(jwtExpiration); - return Jwts.builder() - .setSubject((user.getEmail())) - .claim("role", user.getRole().getName()) - .setIssuedAt(new Date()) - .setExpiration(new Date((new Date()).getTime() + jwtExpirationInt)) - .signWith(SignatureAlgorithm.RS256, this.keyPair.getPrivate()) - .compact(); + JwtBuilder builder = + Jwts.builder() + .subject(user.getEmail()) + .issuedAt(new Date()) + .expiration(new Date((new Date()).getTime() + jwtExpirationInt)) + .claim("role", user.getRole().getName()) + .signWith(this.keyPair.getPrivate()); + String jwt = builder.compact(); + return jwt; } /** @@ -111,6 +117,7 @@ private RSAKey getKeyFromJkuHeader(JWSHeader header) { if (jku != null) { URLConnection connection = jku.toURL().openConnection(); JWKSet jwkSet = JWKSet.load(connection.getInputStream()); + connection.getInputStream().close(); logger.info("JWKSet from URL : " + jwkSet.toString(false)); JWK key = jwkSet.getKeyByKeyId(header.getKeyID()); if (key != null && Objects.equals(key.getAlgorithm().getName(), "RS256")) { @@ -155,10 +162,8 @@ public boolean validateJwtToken(String authToken) { if (Objects.equals(alg.getName(), "HS256")) { String secret = getJwtSecret(header); logger.info("JWT Secret: " + secret); - Jwts.parser() - .setSigningKey(secret.getBytes(StandardCharsets.UTF_8)) - .parseClaimsJws(authToken); - return true; + JWSVerifier verifier = new MACVerifier(secret.getBytes(StandardCharsets.UTF_8)); + return signedJWT.verify(verifier); } else { RSAKey verificationKey = getKeyFromJkuHeader(header); JWSVerifier verifier; diff --git a/services/identity/src/main/java/com/crapi/config/MailConfiguration.java b/services/identity/src/main/java/com/crapi/config/MailConfiguration.java index 9bd874ee..a425a8f3 100644 --- a/services/identity/src/main/java/com/crapi/config/MailConfiguration.java +++ b/services/identity/src/main/java/com/crapi/config/MailConfiguration.java @@ -16,12 +16,12 @@ import com.crapi.entity.ChangeEmailRequest; import com.crapi.exception.EntityNotFoundException; +import jakarta.mail.MessagingException; +import jakarta.mail.PasswordAuthentication; +import jakarta.mail.Session; +import jakarta.mail.internet.AddressException; import java.io.IOException; import java.util.Properties; -import javax.mail.MessagingException; -import javax.mail.PasswordAuthentication; -import javax.mail.Session; -import javax.mail.internet.AddressException; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -67,7 +67,7 @@ public Session sendmail() { Session session = Session.getInstance( props, - new javax.mail.Authenticator() { + new jakarta.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(email, password); } diff --git a/services/identity/src/main/java/com/crapi/config/MailHogConfiguration.java b/services/identity/src/main/java/com/crapi/config/MailHogConfiguration.java index 3ba56e6a..417673a4 100644 --- a/services/identity/src/main/java/com/crapi/config/MailHogConfiguration.java +++ b/services/identity/src/main/java/com/crapi/config/MailHogConfiguration.java @@ -14,12 +14,12 @@ package com.crapi.config; +import jakarta.mail.MessagingException; +import jakarta.mail.PasswordAuthentication; +import jakarta.mail.Session; +import jakarta.mail.internet.AddressException; import java.io.IOException; import java.util.Properties; -import javax.mail.MessagingException; -import javax.mail.PasswordAuthentication; -import javax.mail.Session; -import javax.mail.internet.AddressException; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -66,7 +66,7 @@ public Session sendmail() { Session session = Session.getInstance( props, - new javax.mail.Authenticator() { + new jakarta.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(email, password); } diff --git a/services/identity/src/main/java/com/crapi/config/SSLConfig.java b/services/identity/src/main/java/com/crapi/config/SSLConfig.java index f1abe370..a2550ec8 100644 --- a/services/identity/src/main/java/com/crapi/config/SSLConfig.java +++ b/services/identity/src/main/java/com/crapi/config/SSLConfig.java @@ -1,6 +1,6 @@ package com.crapi.config; -import javax.validation.constraints.AssertTrue; +import jakarta.validation.constraints.AssertTrue; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.validation.annotation.Validated; diff --git a/services/identity/src/main/java/com/crapi/config/WebSecurityConfig.java b/services/identity/src/main/java/com/crapi/config/WebSecurityConfig.java index 2cd6dee0..4715bd9c 100644 --- a/services/identity/src/main/java/com/crapi/config/WebSecurityConfig.java +++ b/services/identity/src/main/java/com/crapi/config/WebSecurityConfig.java @@ -20,47 +20,53 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.authentication.dao.DaoAuthenticationProvider; +import org.springframework.security.config.Customizer; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; @Configuration @EnableWebSecurity @ComponentScan(basePackages = {"com.crapi"}) @EnableGlobalMethodSecurity(prePostEnabled = true) -public class WebSecurityConfig extends WebSecurityConfigurerAdapter { +public class WebSecurityConfig { @Autowired UserDetailsServiceImpl userDetailsService; - @Autowired private JwtAuthEntryPoint unauthorizedHandler; + @Autowired JwtAuthEntryPoint unauthorizedHandler; @Bean public JwtAuthTokenFilter authenticationJwtTokenFilter() { return new JwtAuthTokenFilter(); } - /** - * @param authenticationManagerBuilder - * @throws Exception - */ - @Override - public void configure(AuthenticationManagerBuilder authenticationManagerBuilder) - throws Exception { - authenticationManagerBuilder - .userDetailsService(userDetailsService) - .passwordEncoder(passwordEncoder()); + @Bean + public DaoAuthenticationProvider authenticationProvider() { + DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider(); + + authProvider.setUserDetailsService(userDetailsService); + authProvider.setPasswordEncoder(passwordEncoder()); + + return authProvider; } @Bean - @Override - public AuthenticationManager authenticationManagerBean() throws Exception { - return super.authenticationManagerBean(); + public AuthenticationManager authenticationManager() throws Exception { + DaoAuthenticationProvider authProvider = authenticationProvider(); + return new AuthenticationManager() { + @Override + public org.springframework.security.core.Authentication authenticate( + org.springframework.security.core.Authentication authentication) + throws org.springframework.security.core.AuthenticationException { + return authProvider.authenticate(authentication); + } + }; } @Bean @@ -68,30 +74,30 @@ public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } - /** - * @param http - * @throws Exception - */ - @Override - protected void configure(HttpSecurity http) throws Exception { - http.cors() - .and() - .csrf() - .disable() - .authorizeRequests() - .antMatchers( - "/identity/api/auth/**", "/identity/health_check", "/identity/api/v2/user/dashboard") - .permitAll() - .anyRequest() - .authenticated() - .and() - .exceptionHandling() - .authenticationEntryPoint(unauthorizedHandler) - .and() - .sessionManagement() - .sessionCreationPolicy(SessionCreationPolicy.STATELESS); - + @Bean + public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { + http.cors(Customizer.withDefaults()) + .csrf( + (csrf) -> { + csrf.disable(); + }) + .authorizeHttpRequests( + (requests) -> + requests + .requestMatchers("/identity/api/auth/**") + .permitAll() + .requestMatchers("/identity/health_check") + .permitAll() + .requestMatchers("/identity/api/v2/user/dashboard") + .permitAll() + .anyRequest() + .authenticated()) + .sessionManagement( + session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) + .exceptionHandling(handling -> handling.authenticationEntryPoint(unauthorizedHandler)); + http.authenticationProvider(authenticationProvider()); http.addFilterBefore( authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class); + return http.build(); } } diff --git a/services/identity/src/main/java/com/crapi/controller/AuthController.java b/services/identity/src/main/java/com/crapi/controller/AuthController.java index 5329c446..529647fb 100644 --- a/services/identity/src/main/java/com/crapi/controller/AuthController.java +++ b/services/identity/src/main/java/com/crapi/controller/AuthController.java @@ -23,15 +23,17 @@ import com.crapi.service.OtpService; import com.crapi.service.UserRegistrationService; import com.crapi.service.UserService; +import jakarta.validation.Valid; import java.io.UnsupportedEncodingException; import java.util.ArrayList; -import javax.validation.Valid; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.authentication.BadCredentialsException; import org.springframework.web.bind.annotation.*; +@Slf4j @CrossOrigin @RestController @RequestMapping("/identity/api/auth") @@ -56,7 +58,6 @@ public ResponseEntity authenticateUser(@Valid @RequestBody LoginFor try { JwtResponse jwtToken = userService.authenticateUserLogin(loginForm); - if (jwtToken.getToken() != null) { return ResponseEntity.status(HttpStatus.OK).body(jwtToken); } else { diff --git a/services/identity/src/main/java/com/crapi/controller/ChangeEmailController.java b/services/identity/src/main/java/com/crapi/controller/ChangeEmailController.java index 7c1099d2..e2e32932 100644 --- a/services/identity/src/main/java/com/crapi/controller/ChangeEmailController.java +++ b/services/identity/src/main/java/com/crapi/controller/ChangeEmailController.java @@ -17,8 +17,8 @@ import com.crapi.model.CRAPIResponse; import com.crapi.model.ChangeEmailForm; import com.crapi.service.UserService; -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; diff --git a/services/identity/src/main/java/com/crapi/controller/ProfileController.java b/services/identity/src/main/java/com/crapi/controller/ProfileController.java index 1ef9319c..e0816bd7 100644 --- a/services/identity/src/main/java/com/crapi/controller/ProfileController.java +++ b/services/identity/src/main/java/com/crapi/controller/ProfileController.java @@ -20,7 +20,7 @@ import com.crapi.model.CRAPIResponse; import com.crapi.model.VideoForm; import com.crapi.service.ProfileService; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; diff --git a/services/identity/src/main/java/com/crapi/controller/UserController.java b/services/identity/src/main/java/com/crapi/controller/UserController.java index cd556a23..89e5060d 100644 --- a/services/identity/src/main/java/com/crapi/controller/UserController.java +++ b/services/identity/src/main/java/com/crapi/controller/UserController.java @@ -20,8 +20,8 @@ import com.crapi.model.DashboardResponse; import com.crapi.model.LoginForm; import com.crapi.service.UserService; +import jakarta.servlet.http.HttpServletRequest; import java.io.UnsupportedEncodingException; -import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -34,7 +34,7 @@ public class UserController { @Autowired UserService userService; - @Autowired private JwtProvider tokenProvider; + @Autowired JwtProvider tokenProvider; /** * @param request getting jwt token for user from request header diff --git a/services/identity/src/main/java/com/crapi/controller/VehicleController.java b/services/identity/src/main/java/com/crapi/controller/VehicleController.java index cebe6f92..9d8ce88e 100644 --- a/services/identity/src/main/java/com/crapi/controller/VehicleController.java +++ b/services/identity/src/main/java/com/crapi/controller/VehicleController.java @@ -22,10 +22,10 @@ import com.crapi.model.VehicleOwnership; import com.crapi.service.VehicleOwnershipService; import com.crapi.service.VehicleService; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.validation.Valid; import java.util.List; import java.util.UUID; -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; diff --git a/services/identity/src/main/java/com/crapi/entity/ChangeEmailRequest.java b/services/identity/src/main/java/com/crapi/entity/ChangeEmailRequest.java index 2772cde9..6d37a8a8 100644 --- a/services/identity/src/main/java/com/crapi/entity/ChangeEmailRequest.java +++ b/services/identity/src/main/java/com/crapi/entity/ChangeEmailRequest.java @@ -15,7 +15,7 @@ package com.crapi.entity; import com.crapi.enums.EStatus; -import javax.persistence.*; +import jakarta.persistence.*; import lombok.Data; @Entity diff --git a/services/identity/src/main/java/com/crapi/entity/Otp.java b/services/identity/src/main/java/com/crapi/entity/Otp.java index 162a40e6..9029da76 100644 --- a/services/identity/src/main/java/com/crapi/entity/Otp.java +++ b/services/identity/src/main/java/com/crapi/entity/Otp.java @@ -14,7 +14,7 @@ package com.crapi.entity; -import javax.persistence.*; +import jakarta.persistence.*; import lombok.Data; @Entity diff --git a/services/identity/src/main/java/com/crapi/entity/ProfileVideo.java b/services/identity/src/main/java/com/crapi/entity/ProfileVideo.java index 0d4338be..36996c7d 100644 --- a/services/identity/src/main/java/com/crapi/entity/ProfileVideo.java +++ b/services/identity/src/main/java/com/crapi/entity/ProfileVideo.java @@ -16,8 +16,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.persistence.*; import java.util.Base64; -import javax.persistence.*; @Entity @Table(name = "profile_Video") diff --git a/services/identity/src/main/java/com/crapi/entity/User.java b/services/identity/src/main/java/com/crapi/entity/User.java index a866d05b..50fc4c1f 100644 --- a/services/identity/src/main/java/com/crapi/entity/User.java +++ b/services/identity/src/main/java/com/crapi/entity/User.java @@ -15,8 +15,8 @@ package com.crapi.entity; import com.crapi.enums.ERole; +import jakarta.persistence.*; import java.time.LocalDate; -import javax.persistence.*; import lombok.Data; @Entity diff --git a/services/identity/src/main/java/com/crapi/entity/UserDetails.java b/services/identity/src/main/java/com/crapi/entity/UserDetails.java index 850b91cb..8313c110 100644 --- a/services/identity/src/main/java/com/crapi/entity/UserDetails.java +++ b/services/identity/src/main/java/com/crapi/entity/UserDetails.java @@ -16,8 +16,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.persistence.*; import java.util.Base64; -import javax.persistence.*; @Entity @Table(name = "user_details") diff --git a/services/identity/src/main/java/com/crapi/entity/VehicleCompany.java b/services/identity/src/main/java/com/crapi/entity/VehicleCompany.java index 932d1775..ecce0746 100644 --- a/services/identity/src/main/java/com/crapi/entity/VehicleCompany.java +++ b/services/identity/src/main/java/com/crapi/entity/VehicleCompany.java @@ -14,8 +14,8 @@ package com.crapi.entity; +import jakarta.persistence.*; import java.io.Serializable; -import javax.persistence.*; import lombok.Data; @Entity diff --git a/services/identity/src/main/java/com/crapi/entity/VehicleDetails.java b/services/identity/src/main/java/com/crapi/entity/VehicleDetails.java index 4665b4e7..7daac20e 100644 --- a/services/identity/src/main/java/com/crapi/entity/VehicleDetails.java +++ b/services/identity/src/main/java/com/crapi/entity/VehicleDetails.java @@ -16,11 +16,11 @@ import com.crapi.enums.EStatus; import com.crapi.model.VehicleOwnership; +import jakarta.persistence.*; import java.time.LocalDate; import java.util.Arrays; import java.util.List; import java.util.UUID; -import javax.persistence.*; import lombok.Data; @Entity @@ -45,7 +45,7 @@ public class VehicleDetails { @JoinColumn(name = "vehicle_model_id") private VehicleModel model; - @OneToOne(cascade = CascadeType.ALL) + @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "location_id") private VehicleLocation vehicleLocation; diff --git a/services/identity/src/main/java/com/crapi/entity/VehicleLocation.java b/services/identity/src/main/java/com/crapi/entity/VehicleLocation.java index 4a1ed0b8..8886f062 100644 --- a/services/identity/src/main/java/com/crapi/entity/VehicleLocation.java +++ b/services/identity/src/main/java/com/crapi/entity/VehicleLocation.java @@ -14,7 +14,7 @@ package com.crapi.entity; -import javax.persistence.*; +import jakarta.persistence.*; import lombok.Data; @Entity diff --git a/services/identity/src/main/java/com/crapi/entity/VehicleModel.java b/services/identity/src/main/java/com/crapi/entity/VehicleModel.java index b2ca69dd..56dea27c 100644 --- a/services/identity/src/main/java/com/crapi/entity/VehicleModel.java +++ b/services/identity/src/main/java/com/crapi/entity/VehicleModel.java @@ -15,8 +15,8 @@ package com.crapi.entity; import com.crapi.enums.EFuelType; +import jakarta.persistence.*; import java.io.Serializable; -import javax.persistence.*; import lombok.Data; @Entity diff --git a/services/identity/src/main/java/com/crapi/exception/ExceptionHandler.java b/services/identity/src/main/java/com/crapi/exception/ExceptionHandler.java index a8b14786..2a940e98 100644 --- a/services/identity/src/main/java/com/crapi/exception/ExceptionHandler.java +++ b/services/identity/src/main/java/com/crapi/exception/ExceptionHandler.java @@ -21,9 +21,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.context.request.WebRequest; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; @@ -47,14 +49,26 @@ private ResponseEntity handleCRAPIException(CRAPIExceptionHandler e) { return new ResponseEntity(cr, HttpStatus.valueOf(e.getStatus())); } + // @org.springframework.web.bind.annotation.ExceptionHandler({MethodArgumentNotValidException.class}) + // public ResponseEntity handleMethodArgumentNotValid( + // MethodArgumentNotValidException ex, + // HttpHeaders headers, + // HttpStatus status, + // WebRequest request) { + // // ErrorDetails errorDetails = + // // new ErrorDetails(, ); + // return ResponseEntity.status(INTERNAL_SERVER_ERROR).body("Validation Failed"); + // } + @Override + @ResponseBody protected ResponseEntity handleMethodArgumentNotValid( MethodArgumentNotValidException ex, HttpHeaders headers, - HttpStatus status, + HttpStatusCode status, WebRequest request) { - ErrorDetails errorDetails = - new ErrorDetails("Validation Failed", ex.getBindingResult().toString()); - return new ResponseEntity(errorDetails, HttpStatus.BAD_REQUEST); + String bindingResult = ex.getBindingResult().toString(); + ErrorDetails errorDetails = new ErrorDetails("Validation failed", bindingResult); + return new ResponseEntity(errorDetails, HttpStatus.BAD_REQUEST); } } diff --git a/services/identity/src/main/java/com/crapi/model/ChangeEmailForm.java b/services/identity/src/main/java/com/crapi/model/ChangeEmailForm.java index b8ba0a8d..9f9ea111 100644 --- a/services/identity/src/main/java/com/crapi/model/ChangeEmailForm.java +++ b/services/identity/src/main/java/com/crapi/model/ChangeEmailForm.java @@ -14,8 +14,8 @@ package com.crapi.model; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.Size; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; import lombok.Data; @Data diff --git a/services/identity/src/main/java/com/crapi/model/ForgetPassword.java b/services/identity/src/main/java/com/crapi/model/ForgetPassword.java index bf56efa7..26ebd105 100644 --- a/services/identity/src/main/java/com/crapi/model/ForgetPassword.java +++ b/services/identity/src/main/java/com/crapi/model/ForgetPassword.java @@ -14,10 +14,10 @@ package com.crapi.model; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; import java.io.Serializable; -import javax.validation.constraints.Email; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.Size; import lombok.Data; @Data diff --git a/services/identity/src/main/java/com/crapi/model/JwtTokenForm.java b/services/identity/src/main/java/com/crapi/model/JwtTokenForm.java index b1f06d08..1333fc55 100644 --- a/services/identity/src/main/java/com/crapi/model/JwtTokenForm.java +++ b/services/identity/src/main/java/com/crapi/model/JwtTokenForm.java @@ -14,7 +14,7 @@ package com.crapi.model; -import javax.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotBlank; import lombok.Data; @Data diff --git a/services/identity/src/main/java/com/crapi/model/LoginForm.java b/services/identity/src/main/java/com/crapi/model/LoginForm.java index c1b36055..2f0ca0e5 100644 --- a/services/identity/src/main/java/com/crapi/model/LoginForm.java +++ b/services/identity/src/main/java/com/crapi/model/LoginForm.java @@ -14,8 +14,8 @@ package com.crapi.model; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.Size; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; import lombok.Data; @Data diff --git a/services/identity/src/main/java/com/crapi/model/LoginWithEmailToken.java b/services/identity/src/main/java/com/crapi/model/LoginWithEmailToken.java index 5265ed36..b822f7ee 100644 --- a/services/identity/src/main/java/com/crapi/model/LoginWithEmailToken.java +++ b/services/identity/src/main/java/com/crapi/model/LoginWithEmailToken.java @@ -14,8 +14,8 @@ package com.crapi.model; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.Size; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; import lombok.Data; @Data diff --git a/services/identity/src/main/java/com/crapi/model/OtpForm.java b/services/identity/src/main/java/com/crapi/model/OtpForm.java index 7f7b5964..1df20559 100644 --- a/services/identity/src/main/java/com/crapi/model/OtpForm.java +++ b/services/identity/src/main/java/com/crapi/model/OtpForm.java @@ -14,8 +14,8 @@ package com.crapi.model; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.Size; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; import lombok.Data; @Data diff --git a/services/identity/src/main/java/com/crapi/model/SeedUser.java b/services/identity/src/main/java/com/crapi/model/SeedUser.java index 06362058..4af37dde 100644 --- a/services/identity/src/main/java/com/crapi/model/SeedUser.java +++ b/services/identity/src/main/java/com/crapi/model/SeedUser.java @@ -15,9 +15,9 @@ package com.crapi.model; import com.crapi.enums.ERole; -import javax.validation.constraints.Email; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.Size; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; import lombok.Data; @Data diff --git a/services/identity/src/main/java/com/crapi/model/SignUpForm.java b/services/identity/src/main/java/com/crapi/model/SignUpForm.java index 73d9aba4..032db702 100644 --- a/services/identity/src/main/java/com/crapi/model/SignUpForm.java +++ b/services/identity/src/main/java/com/crapi/model/SignUpForm.java @@ -14,9 +14,9 @@ package com.crapi.model; -import javax.validation.constraints.Email; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.Size; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; import lombok.Data; @Data diff --git a/services/identity/src/main/java/com/crapi/model/VehicleForm.java b/services/identity/src/main/java/com/crapi/model/VehicleForm.java index e6c1d123..a0b51cbf 100644 --- a/services/identity/src/main/java/com/crapi/model/VehicleForm.java +++ b/services/identity/src/main/java/com/crapi/model/VehicleForm.java @@ -14,8 +14,8 @@ package com.crapi.model; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.Size; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; import lombok.Data; @Data diff --git a/services/identity/src/main/java/com/crapi/service/Impl/OtpServiceImpl.java b/services/identity/src/main/java/com/crapi/service/Impl/OtpServiceImpl.java index 90a03c12..412253b7 100644 --- a/services/identity/src/main/java/com/crapi/service/Impl/OtpServiceImpl.java +++ b/services/identity/src/main/java/com/crapi/service/Impl/OtpServiceImpl.java @@ -28,7 +28,7 @@ import com.crapi.utils.MailBody; import com.crapi.utils.OTPGenerator; import com.crapi.utils.SMTPMailServer; -import javax.transaction.Transactional; +import jakarta.transaction.Transactional; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/services/identity/src/main/java/com/crapi/service/Impl/ProfileServiceImpl.java b/services/identity/src/main/java/com/crapi/service/Impl/ProfileServiceImpl.java index c203711c..178e258a 100644 --- a/services/identity/src/main/java/com/crapi/service/Impl/ProfileServiceImpl.java +++ b/services/identity/src/main/java/com/crapi/service/Impl/ProfileServiceImpl.java @@ -28,10 +28,10 @@ import com.crapi.service.UserService; import com.crapi.utils.BashCommand; import com.crapi.utils.ProfileValidator; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.transaction.Transactional; import java.io.IOException; import java.util.Optional; -import javax.servlet.http.HttpServletRequest; -import javax.transaction.Transactional; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/services/identity/src/main/java/com/crapi/service/Impl/UserDetailsServiceImpl.java b/services/identity/src/main/java/com/crapi/service/Impl/UserDetailsServiceImpl.java index 43dbfce7..d151aa09 100644 --- a/services/identity/src/main/java/com/crapi/service/Impl/UserDetailsServiceImpl.java +++ b/services/identity/src/main/java/com/crapi/service/Impl/UserDetailsServiceImpl.java @@ -17,7 +17,7 @@ import com.crapi.entity.User; import com.crapi.entity.UserPrinciple; import com.crapi.repository.UserRepository; -import javax.transaction.Transactional; +import jakarta.transaction.Transactional; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; diff --git a/services/identity/src/main/java/com/crapi/service/Impl/UserRegistrationServiceImpl.java b/services/identity/src/main/java/com/crapi/service/Impl/UserRegistrationServiceImpl.java index 312d45e3..b5c6906e 100644 --- a/services/identity/src/main/java/com/crapi/service/Impl/UserRegistrationServiceImpl.java +++ b/services/identity/src/main/java/com/crapi/service/Impl/UserRegistrationServiceImpl.java @@ -25,7 +25,7 @@ import com.crapi.service.VehicleService; import com.crapi.utils.MailBody; import com.crapi.utils.SMTPMailServer; -import javax.transaction.Transactional; +import jakarta.transaction.Transactional; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/services/identity/src/main/java/com/crapi/service/Impl/UserServiceImpl.java b/services/identity/src/main/java/com/crapi/service/Impl/UserServiceImpl.java index 88b5ae5e..66af7505 100644 --- a/services/identity/src/main/java/com/crapi/service/Impl/UserServiceImpl.java +++ b/services/identity/src/main/java/com/crapi/service/Impl/UserServiceImpl.java @@ -28,9 +28,9 @@ import com.crapi.utils.EmailTokenGenerator; import com.crapi.utils.MailBody; import com.crapi.utils.SMTPMailServer; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.transaction.Transactional; import java.text.ParseException; -import javax.servlet.http.HttpServletRequest; -import javax.transaction.Transactional; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.core.LoggerContext; import org.apache.logging.log4j.core.impl.Log4jContextFactory; diff --git a/services/identity/src/main/java/com/crapi/service/Impl/VehicleOwnershipServiceImpl.java b/services/identity/src/main/java/com/crapi/service/Impl/VehicleOwnershipServiceImpl.java index e1c82d80..57c56132 100644 --- a/services/identity/src/main/java/com/crapi/service/Impl/VehicleOwnershipServiceImpl.java +++ b/services/identity/src/main/java/com/crapi/service/Impl/VehicleOwnershipServiceImpl.java @@ -24,6 +24,7 @@ import java.security.NoSuchAlgorithmException; import java.util.*; import javax.net.ssl.SSLContext; +import org.apache.hc.client5.http.classic.HttpClient; import org.apache.http.conn.ssl.NoopHostnameVerifier; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.conn.ssl.TrustAllStrategy; @@ -74,8 +75,10 @@ public RestTemplate restTemplate() SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE); CloseableHttpClient httpClient = - HttpClients.custom().setSSLContext(sslContext).setSSLSocketFactory(csf).build(); - builder = builder.requestFactory(() -> new HttpComponentsClientHttpRequestFactory(httpClient)); + HttpClients.custom().setSSLSocketFactory(csf).setSSLContext(sslContext).build(); + builder = + builder.requestFactory( + () -> new HttpComponentsClientHttpRequestFactory((HttpClient) httpClient)); // Add basic auth header builder = builder.basicAuthentication(apiGatewayUsername, apiGatewayPassword); diff --git a/services/identity/src/main/java/com/crapi/service/Impl/VehicleServiceImpl.java b/services/identity/src/main/java/com/crapi/service/Impl/VehicleServiceImpl.java index 17188964..2a653158 100644 --- a/services/identity/src/main/java/com/crapi/service/Impl/VehicleServiceImpl.java +++ b/services/identity/src/main/java/com/crapi/service/Impl/VehicleServiceImpl.java @@ -27,9 +27,9 @@ import com.crapi.utils.GenerateVIN; import com.crapi.utils.MailBody; import com.crapi.utils.SMTPMailServer; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.transaction.Transactional; import java.util.*; -import javax.servlet.http.HttpServletRequest; -import javax.transaction.Transactional; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/services/identity/src/main/java/com/crapi/service/ProfileService.java b/services/identity/src/main/java/com/crapi/service/ProfileService.java index be087cac..9df14e84 100644 --- a/services/identity/src/main/java/com/crapi/service/ProfileService.java +++ b/services/identity/src/main/java/com/crapi/service/ProfileService.java @@ -18,7 +18,7 @@ import com.crapi.entity.UserDetails; import com.crapi.model.CRAPIResponse; import com.crapi.model.VideoForm; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequest; import org.springframework.web.multipart.MultipartFile; public interface ProfileService { diff --git a/services/identity/src/main/java/com/crapi/service/UserService.java b/services/identity/src/main/java/com/crapi/service/UserService.java index 86de22ad..2a0b4ef6 100644 --- a/services/identity/src/main/java/com/crapi/service/UserService.java +++ b/services/identity/src/main/java/com/crapi/service/UserService.java @@ -16,8 +16,8 @@ import com.crapi.entity.User; import com.crapi.model.*; +import jakarta.servlet.http.HttpServletRequest; import java.io.UnsupportedEncodingException; -import javax.servlet.http.HttpServletRequest; public interface UserService { diff --git a/services/identity/src/main/java/com/crapi/service/VehicleService.java b/services/identity/src/main/java/com/crapi/service/VehicleService.java index abc084d0..967247fc 100644 --- a/services/identity/src/main/java/com/crapi/service/VehicleService.java +++ b/services/identity/src/main/java/com/crapi/service/VehicleService.java @@ -18,9 +18,9 @@ import com.crapi.model.CRAPIResponse; import com.crapi.model.VehicleForm; import com.crapi.model.VehicleLocationResponse; +import jakarta.servlet.http.HttpServletRequest; import java.util.List; import java.util.UUID; -import javax.servlet.http.HttpServletRequest; public interface VehicleService { diff --git a/services/identity/src/main/java/com/crapi/utils/BashCommand.java b/services/identity/src/main/java/com/crapi/utils/BashCommand.java index 2eadab41..05cb56c3 100644 --- a/services/identity/src/main/java/com/crapi/utils/BashCommand.java +++ b/services/identity/src/main/java/com/crapi/utils/BashCommand.java @@ -46,13 +46,14 @@ public String executeBashCommand(String command) throws IOException { Process p = r.exec(commands); p.waitFor(); - b = new BufferedReader(new InputStreamReader(p.getInputStream())); - + InputStreamReader data = new InputStreamReader(p.getInputStream()); + b = new BufferedReader(data); String line = ""; output = new StringBuilder(); while ((line = b.readLine()) != null) { output.append(line + "\n"); } + b.close(); return (output != null ? String.valueOf(output) : "command not found"); } catch (Exception e) { logger.error("Failed to execute bash with command: " + command); diff --git a/services/identity/src/main/java/com/crapi/utils/SMTPMailServer.java b/services/identity/src/main/java/com/crapi/utils/SMTPMailServer.java index c1d57c14..9530e598 100644 --- a/services/identity/src/main/java/com/crapi/utils/SMTPMailServer.java +++ b/services/identity/src/main/java/com/crapi/utils/SMTPMailServer.java @@ -16,11 +16,11 @@ import com.crapi.config.MailConfiguration; import com.crapi.config.MailHogConfiguration; +import jakarta.mail.Message; +import jakarta.mail.Session; +import jakarta.mail.Transport; +import jakarta.mail.internet.*; import java.util.Date; -import javax.mail.Message; -import javax.mail.Session; -import javax.mail.Transport; -import javax.mail.internet.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired;