Skip to content

Commit 11ce4f8

Browse files
Merge pull request #1 from gopinathsjsu/authService-initial-commit
Auth service initial commit
2 parents fb84cea + eb03b9c commit 11ce4f8

33 files changed

+858
-8
lines changed

.DS_Store

-6 KB
Binary file not shown.

backend/authService/build.gradle

+28-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ plugins {
22
id 'java'
33
id 'org.springframework.boot' version '3.4.3'
44
id 'io.spring.dependency-management' version '1.1.7'
5+
id 'jacoco'
56
}
67

78
group = 'org.sjsu'
@@ -27,26 +28,35 @@ ext {
2728
set('springCloudVersion', "2024.0.0")
2829
}
2930

31+
jacoco {
32+
toolVersion = "0.8.11"
33+
}
34+
35+
jacocoTestReport {
36+
reports {
37+
html.required = true
38+
xml.required = true
39+
}
40+
}
41+
3042
dependencies {
31-
implementation 'org.springframework.boot:spring-boot-starter-data-elasticsearch'
3243
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
33-
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
34-
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
3544
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
3645
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
3746
implementation 'org.springframework.boot:spring-boot-starter-security'
3847
implementation 'org.springframework.boot:spring-boot-starter-web'
39-
implementation 'org.apache.kafka:kafka-streams'
4048
implementation 'org.springframework.cloud:spring-cloud-starter-gateway-mvc'
41-
implementation 'org.springframework.kafka:spring-kafka'
49+
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
50+
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
51+
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'
52+
implementation "com.twilio.sdk:twilio:10.6.10"
4253
compileOnly 'org.projectlombok:lombok'
4354
developmentOnly 'org.springframework.boot:spring-boot-devtools'
4455
developmentOnly 'org.springframework.boot:spring-boot-docker-compose'
4556
runtimeOnly 'com.mysql:mysql-connector-j'
4657
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
4758
annotationProcessor 'org.projectlombok:lombok'
4859
testImplementation 'org.springframework.boot:spring-boot-starter-test'
49-
testImplementation 'org.springframework.kafka:spring-kafka-test'
5060
testImplementation 'org.springframework.security:spring-security-test'
5161
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
5262
}
@@ -64,3 +74,15 @@ tasks.named('bootBuildImage') {
6474
tasks.named('test') {
6575
useJUnitPlatform()
6676
}
77+
78+
jacocoTestCoverageVerification {
79+
violationRules {
80+
rule {
81+
limit {
82+
minimum = 0.7 // Require 70% coverage
83+
}
84+
}
85+
}
86+
}
87+
88+
check.dependsOn jacocoTestCoverageVerification

backend/authService/src/main/java/org/sjsu/authservice/AuthServiceApplication.java backend/authService/src/main/java/com/sjsu/authservice/config/AuthServiceApplication.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.sjsu.authservice;
1+
package com.sjsu.authservice.config;
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.sjsu.authservice.controller;
2+
3+
import com.sjsu.authservice.service.UserService;
4+
import org.springframework.web.bind.annotation.PostMapping;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.RestController;
7+
8+
@RestController
9+
@RequestMapping("/auth")
10+
public class AuthController {
11+
12+
private final UserService userService;
13+
14+
public AuthController(UserService userService) {
15+
this.userService = userService;
16+
}
17+
18+
@PostMapping("/register")
19+
public String registerUser(@RequestBody User user) {
20+
userService.registerUser(user);
21+
// Hash the password before saving
22+
user.setPassword(passwordEncoder.encode(user.getPassword()));
23+
24+
// Save user in database
25+
userRepository.save(user);
26+
27+
return "User registered successfully!";
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.sjsu.authservice.model;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
import org.springframework.data.relational.core.mapping.Table;
8+
9+
@Data
10+
@NoArgsConstructor
11+
@AllArgsConstructor
12+
@Builder
13+
@Table(name = "user")
14+
public class User {
15+
16+
private Long id;
17+
private String email;
18+
private String phoneNumber;
19+
private String firstName;
20+
private String lastName;
21+
22+
23+
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.sjsu.authservice.service;
2+
3+
import com.sjsu.authservice.model.User;
4+
import lombok.RequiredArgsConstructor;
5+
import org.springframework.stereotype.Component;
6+
7+
@Component
8+
@RequiredArgsConstructor
9+
public class EmailVerificationService implements VerificationService {
10+
11+
@Override
12+
public Object initiateUserVerification(User user) {
13+
return null;
14+
}
15+
16+
@Override
17+
public Object verifyUser(User user) {
18+
return null;
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.sjsu.authservice.service;
2+
3+
import com.sjsu.authservice.model.User;
4+
import com.twilio.Twilio;
5+
import com.twilio.rest.verify.v2.service.Verification;
6+
import com.twilio.rest.verify.v2.service.VerificationCheck;
7+
import lombok.RequiredArgsConstructor;
8+
import lombok.extern.slf4j.Slf4j;
9+
import org.springframework.beans.factory.annotation.Value;
10+
import org.springframework.stereotype.Component;
11+
12+
@Component
13+
@RequiredArgsConstructor
14+
@Slf4j
15+
public class MobileVerificationService implements VerificationService {
16+
17+
@Value("${twilio.account_sid}")
18+
private String accountSid;
19+
20+
@Value("${twilio.auth_token}")
21+
private String authToken;
22+
23+
@Value("${twilio.verify_sid}")
24+
private String verifySid;
25+
26+
@Override
27+
public Object initiateUserVerification(User user) {
28+
Twilio.init(accountSid, authToken);
29+
Verification verification = Verification.creator(verifySid, user.getPhoneNumber(), Verification.Channel.SMS.toString()).create();
30+
return verification;
31+
}
32+
33+
@Override
34+
public Object verifyUser(User user) {
35+
VerificationCheck verificationCheck = VerificationCheck.creator(verifySid)
36+
.setTo(user.getPhoneNumber())
37+
.setCode("otp")
38+
.create();
39+
40+
return verificationCheck;
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.sjsu.authservice.service;
2+
3+
public interface UserService {
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.sjsu.authservice.service;
2+
3+
import com.sjsu.authservice.model.User;
4+
5+
public interface VerificationService {
6+
7+
public Object initiateUserVerification(User user);
8+
9+
public Object verifyUser(User user);
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"properties": [
3+
{
4+
"name": "twilio.account_sid",
5+
"type": "java.lang.String",
6+
"description": "twilio account SID."
7+
},
8+
{
9+
"name": "twilio.auth_token",
10+
"type": "java.lang.String",
11+
"description": "twilio auth token."
12+
},
13+
{
14+
"name": "twilio.verify_sid",
15+
"type": "java.lang.String",
16+
"description": "SID for twilio verify app."
17+
}
18+
]
19+
}
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1+
server.port=8081
12
spring.application.name=authService
3+
4+
# Twilio Verification
5+
twilio.account_sid=${TWILIO_ACCOUNT_SID}
6+
twilio.auth_token=${TWILIO_ACCOUNT_AUTH}
7+
twilio.verify_sid=${TWILIO_VERIFY_SID}

backend/authService/src/test/java/org/sjsu/authservice/AuthServiceApplicationTests.java backend/authService/src/test/java/com/sjsu/authservice/AuthServiceApplicationTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.sjsu.authservice;
1+
package com.sjsu.authservice;
22

33
import org.junit.jupiter.api.Test;
44
import org.springframework.boot.test.context.SpringBootTest;

backend/bookTable/.dockerignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.env
2+
docker-compose.yml
3+
*.md
4+
.git
5+
.gitignore
6+
build/
7+
!build/libs/bookTable-0.0.1-SNAPSHOT.jar

backend/bookTable/.gitignore

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#Global ignores
2+
HELP.md
3+
.DS_Store
4+
.env
5+
6+
# Ignore all Gradle-related files
7+
**/.gradle
8+
**/build/
9+
!**/gradle/wrapper/gradle-wrapper.jar
10+
!**/src/main/**/build/
11+
!**/src/test/**/build/
12+
13+
# STS (Spring Tool Suite) ignores
14+
**/.apt_generated
15+
**/.classpath
16+
**/.factorypath
17+
**/.project
18+
**/.settings
19+
**/.springBeans
20+
**/.sts4-cache
21+
**/bin/
22+
!**/src/main/**/bin/
23+
!**/src/test/**/bin/
24+
25+
# IntelliJ IDEA ignores
26+
**/.idea
27+
**/*.iws
28+
**/*.iml
29+
**/*.ipr
30+
**/out/
31+
!**/src/main/**/out/
32+
!**/src/test/**/out/
33+
34+
# Java build artifacts (for all backend services)
35+
backend/**/target/
36+
backend/**/.mvn/
37+
backend/**/*.log
38+
39+
# Elastic Beanstalk Files
40+
.elasticbeanstalk/*
41+
!.elasticbeanstalk/*.cfg.yml
42+
!.elasticbeanstalk/*.global.yml

backend/bookTable/Dockerfile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Use official openjdk image as base image
2+
FROM openjdk:17-jdk-slim AS base
3+
4+
# Set working directory in container
5+
WORKDIR /app
6+
7+
# Copy the jar file from the target folder to the container
8+
COPY build/libs/bookTable-0.0.1-SNAPSHOT.jar app.jar
9+
10+
# Expose the port Spring Boot is running on
11+
EXPOSE 8080
12+
13+
# Run the application
14+
ENTRYPOINT ["java", "-jar", "app.jar"]

backend/bookTable/Dockerrun.aws.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"AWSEBDockerrunVersion": "1", "Image": {"Name": "061039807046.dkr.ecr.us-west-1.amazonaws.com/booktable-app:latest", "Update": "true"}, "Ports": [{"ContainerPort": 8080, "HostPort": 80}]}

backend/bookTable/app.zip

344 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)