Skip to content

Feat: add buffer file grpc #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Mar 31, 2025
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
4 changes: 4 additions & 0 deletions cart-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

Expand Down
4 changes: 4 additions & 0 deletions common-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
<target>21</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

Expand Down
39 changes: 24 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,48 @@ services:
networks:
- spring-cloud-network

identity-service:
build: ./identity-service
container_name: identity-service
protobuf:
build: ./protobuf
container_name: protobuf
restart: always
networks:
- spring-cloud-network

user-service:
build: ./user-service
container_name: user-service
ports:
- "18081:8081"
- "18080:18080" # HTTP
- "19090:19090" # gRPC
restart: always
environment:
- SPRING_DATASOURCE_URL
- GOOGLE_CLIENT_ID
- GOOGLE_CLIENT_SECRET
depends_on:
- postgres
networks:
- spring-cloud-network

user-service:
build: ./user-service
container_name: user-service
identity-service:
build: ./identity-service
container_name: identity-service
ports:
- "18080:8080"
- "18081:18081"
restart: always
environment:
- SPRING_DATASOURCE_URL
- GOOGLE_CLIENT_ID
- GOOGLE_CLIENT_SECRET
depends_on:
- postgres
- user-service
networks:
- spring-cloud-network

product-service:
build: ./product-service
container_name: product-service
ports:
- "18082:8082"
- "18082:18082"
restart: always
environment:
- SPRING_DATASOURCE_URL
Expand All @@ -91,7 +100,7 @@ services:
build: ./promotion-service
container_name: promotion-service
ports:
- "18084:8084"
- "18084:18084"
restart: always
environment:
- SPRING_DATASOURCE_URL
Expand All @@ -104,7 +113,7 @@ services:
build: ./cart-service
container_name: cart-service
ports:
- "18085:8085"
- "18085:18085"
restart: always
environment:
- SPRING_DATASOURCE_URL
Expand All @@ -117,7 +126,7 @@ services:
build: ./payment-service
container_name: payment-service
ports:
- "18086:8086"
- "18086:18086"
restart: always
environment:
- SPRING_DATASOURCE_URL
Expand All @@ -130,7 +139,7 @@ services:
build: ./rating-service
container_name: rating-service
ports:
- "18087:8087"
- "18087:18087"
restart: always
environment:
- SPRING_DATASOURCE_URL
Expand Down
50 changes: 26 additions & 24 deletions identity-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,10 @@
</properties>

<dependencies>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-data-jpa</artifactId>-->
<!-- </dependency>-->

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!--&lt;!&ndash; api gateway&ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-webflux</artifactId>-->
<!-- </dependency>-->

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
Expand All @@ -55,26 +43,15 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-security</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.security</groupId>-->
<!-- <artifactId>spring-security-test</artifactId>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>

<dependency>
<groupId>io.github.cdimascio</groupId>
<artifactId>dotenv-java</artifactId>
<version>3.0.0</version>
</dependency>

<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
Expand All @@ -85,13 +62,34 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>com.blubin</groupId>
<artifactId>common-service</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.blubin</groupId>
<artifactId>protobuf</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.devh</groupId>
<artifactId>grpc-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -122,6 +120,10 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M9</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.blubin.identityservice.model.SiteUser;
import com.blubin.identityservice.repository.SiteUserRepository;
import com.blubin.identityservice.utils.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
Expand All @@ -16,7 +17,7 @@
@Override
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
SiteUser user = userRepository.findByEmailAddress(email)
.orElseThrow(() -> new UsernameNotFoundException("User not found with email: " + email));
.orElseThrow(() -> new UsernameNotFoundException(Constants.ErrorCodes.USER_NOT_FOUND_WITH_EMAIL + email));

Check warning on line 20 in identity-service/src/main/java/com/blubin/identityservice/config/CustomUserDetailsService.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck

Line is longer than 120 characters (found 122).

return org.springframework.security.core.userdetails.User.builder()
.username(user.getEmailAddress())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package com.blubin.identityservice.config;

import com.blubin.identityservice.service.RefreshTokenService;
import com.blubin.identityservice.utils.JwtUtils;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import java.io.IOException;

Check warning on line 17 in identity-service/src/main/java/com/blubin/identityservice/config/JwtAuthenticationFilter.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck

Extra separation in import group before 'java.io.IOException'

Check warning on line 17 in identity-service/src/main/java/com/blubin/identityservice/config/JwtAuthenticationFilter.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck

Wrong lexicographical order for 'java.io.IOException' import. Should be before 'org.springframework.web.filter.OncePerRequestFilter'.

@Component
public class JwtAuthenticationFilter extends OncePerRequestFilter {
Expand All @@ -30,7 +33,7 @@
FilterChain filterChain) throws ServletException, IOException {
try {
String jwt = parseJwt(request);
if(jwt != null && jwtUtils.validateJwtToken(jwt)) {

Check warning on line 36 in identity-service/src/main/java/com/blubin/identityservice/config/JwtAuthenticationFilter.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAfterCheck

'if' is not followed by whitespace.

Check warning on line 36 in identity-service/src/main/java/com/blubin/identityservice/config/JwtAuthenticationFilter.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck

WhitespaceAround: 'if' is not followed by whitespace. Empty blocks may only be represented as {} when not part of a multi-block statement (4.1.3)
String email = jwtUtils.getEmailFromJwtToken(jwt);
var userDetails = userDetailsService.loadUserByUsername(email);
var authentication = new UsernamePasswordAuthenticationToken(
Expand All @@ -38,19 +41,43 @@
);
authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
SecurityContextHolder.getContext().setAuthentication(authentication);
System.out.println("Authenticated user: " + email);
String authHeader = request.getHeader("Authorization");
System.out.println("Authorization Header: " + authHeader);
}
} catch(Exception e) {

Check warning on line 48 in identity-service/src/main/java/com/blubin/identityservice/config/JwtAuthenticationFilter.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck

WhitespaceAround: 'catch' is not followed by whitespace. Empty blocks may only be represented as {} when not part of a multi-block statement (4.1.3)
logger.error("Cannot set user authentication}");
}

filterChain.doFilter(request, response);
}

// get JWT from header

Check warning on line 55 in identity-service/src/main/java/com/blubin/identityservice/config/JwtAuthenticationFilter.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.indentation.CommentsIndentationCheck

Comment has incorrect indentation level 0, expected is 4, indentation should be the same level as line 56.
private String parseJwt(HttpServletRequest request) {
String headerAuth = request.getHeader("Authorization");

if(headerAuth != null && headerAuth.startsWith("Bearer ")) {

Check warning on line 59 in identity-service/src/main/java/com/blubin/identityservice/config/JwtAuthenticationFilter.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAfterCheck

'if' is not followed by whitespace.

Check warning on line 59 in identity-service/src/main/java/com/blubin/identityservice/config/JwtAuthenticationFilter.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck

WhitespaceAround: 'if' is not followed by whitespace. Empty blocks may only be represented as {} when not part of a multi-block statement (4.1.3)
return headerAuth.substring(7);
}

return null;
}

// get JWT from header and cookie
// private String parseJwt(HttpServletRequest request) {
// String headerAuth = request.getHeader("Authorization");
// if (headerAuth != null && headerAuth.startsWith("Bearer ")) {
// return headerAuth.substring(7);
// }
//
// if (request.getCookies() != null) {
// for (Cookie cookie : request.getCookies()) {
// if ("SERVER_SESSION".equals(cookie.getName())) {
// return URLDecoder.decode(cookie.getValue(), StandardCharsets.UTF_8);
// }
// }
// }
//
// return null;
// }

Check warning on line 82 in identity-service/src/main/java/com/blubin/identityservice/config/JwtAuthenticationFilter.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.indentation.CommentsIndentationCheck

Comment has incorrect indentation level 0, expected is 4, indentation should be the same level as line 56.
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
package com.blubin.identityservice.config;

import com.blubin.identityservice.model.SiteUser;
import com.blubin.identityservice.repository.SiteUserRepository;
import com.blubin.identityservice.service.GrpcUserService;
import com.blubin.identityservice.service.RefreshTokenService;
import com.blubin.identityservice.utils.JwtUtils;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.core.oidc.user.OidcUser;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

import java.io.IOException;

Check warning on line 17 in identity-service/src/main/java/com/blubin/identityservice/config/OAuth2LoginSuccessHandler.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck

Extra separation in import group before 'java.io.IOException'

Check warning on line 17 in identity-service/src/main/java/com/blubin/identityservice/config/OAuth2LoginSuccessHandler.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck

Wrong lexicographical order for 'java.io.IOException' import. Should be before 'org.springframework.stereotype.Component'.
import java.net.URLEncoder;

Check warning on line 18 in identity-service/src/main/java/com/blubin/identityservice/config/OAuth2LoginSuccessHandler.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck

Wrong lexicographical order for 'java.net.URLEncoder' import. Should be before 'org.springframework.stereotype.Component'.
import java.nio.charset.StandardCharsets;

Check warning on line 19 in identity-service/src/main/java/com/blubin/identityservice/config/OAuth2LoginSuccessHandler.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck

Wrong lexicographical order for 'java.nio.charset.StandardCharsets' import. Should be before 'org.springframework.stereotype.Component'.

@Component
public class OAuth2LoginSuccessHandler implements AuthenticationSuccessHandler {

Check warning on line 22 in identity-service/src/main/java/com/blubin/identityservice/config/OAuth2LoginSuccessHandler.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.naming.AbbreviationAsWordInNameCheck

Abbreviation in name 'OAuth2LoginSuccessHandler' must contain no more than '1' consecutive capital letters.
private final JwtUtils jwtUtils;

@Autowired
private GrpcUserService grpcUserService;

@Autowired
private SiteUserRepository siteUserRepository;

@Autowired
private RefreshTokenService refreshTokenService;

public OAuth2LoginSuccessHandler(JwtUtils jwtUtils) {
this.jwtUtils = jwtUtils;
}
Expand All @@ -30,22 +44,37 @@
String email = oidcUser.getEmail();
String name = oidcUser.getAttribute("name");

SiteUser siteUser = new SiteUser();
siteUser.setEmailAddress(email);
siteUser.setUserName(name);
SiteUser siteUser = siteUserRepository.findByEmailAddress(email)
.orElseGet(() -> {
SiteUser newUser = new SiteUser();
newUser.setEmailAddress(email);
newUser.setUserName(name);
return siteUserRepository.save(newUser);
});

String token = jwtUtils.generateJwtToken(siteUser);
String refreshToken = refreshTokenService.createRefreshToken(siteUser.getId());
System.out.println(token);
System.out.println(refreshToken);
// Save JWT to Header

Check warning on line 59 in identity-service/src/main/java/com/blubin/identityservice/config/OAuth2LoginSuccessHandler.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.indentation.CommentsIndentationCheck

Comment has incorrect indentation level 0, expected is 8, indentation should be the same level as line 60.
response.setHeader("Access-Control-Expose-Headers", "Authorization");
response.setHeader("Authorization", "Bearer " + token);

Cookie cookie = new Cookie("SERVER_SESSION", URLEncoder.encode(token, StandardCharsets.UTF_8));
// Save JWT to Cookie

Check warning on line 63 in identity-service/src/main/java/com/blubin/identityservice/config/OAuth2LoginSuccessHandler.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.indentation.CommentsIndentationCheck

Comment has incorrect indentation level 0, expected is 8, indentation should be the same level as line 64.
Cookie cookie = new Cookie("SERVER_SESSION", URLEncoder.encode(refreshToken, StandardCharsets.UTF_8));
// XSS
cookie.setHttpOnly(true);
// cookie.setSecure(true);
// cookie.setHttpOnly(true);

Check warning on line 66 in identity-service/src/main/java/com/blubin/identityservice/config/OAuth2LoginSuccessHandler.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.indentation.CommentsIndentationCheck

Comment has incorrect indentation level 0, expected is 8, indentation should be the same level as line 67.
cookie.setSecure(true);
cookie.setPath("/");
cookie.setMaxAge(7 * 24 * 60 * 60);
// CSRF

Check warning on line 70 in identity-service/src/main/java/com/blubin/identityservice/config/OAuth2LoginSuccessHandler.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.indentation.CommentsIndentationCheck

Comment has incorrect indentation level 0, expected is 8, indentation should be the same level as line 71.
cookie.setAttribute("SameSite", "Lax");
response.addCookie(cookie);

String avatarUrl = oidcUser.getAttribute("picture");

grpcUserService.createUserProfile(siteUser, avatarUrl, name);

response.sendRedirect("/users");
}
}
Loading
Loading