Skip to content
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
77 changes: 77 additions & 0 deletions .github/workflows/dockerHub-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: CI/CD Pipeline

on:
push:
branches:
- dev-yesitha

jobs:
build:
runs-on: ubuntu-latest

services:
db:
image: postgres
env:
POSTGRES_DB: itgura
POSTGRES_USER: postgres
POSTGRES_PASSWORD: root
ports:
- 5432:5432
options: --health-cmd "pg_isready -U postgres" --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up JDK 17
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '17'

- name: Wait for PostgreSQL
run: |
echo "Waiting for PostgreSQL to be ready..."
until pg_isready -h localhost -p 5432 -U postgres; do
sleep 1
done

- name: Initialize Database
run: |
psql -v ON_ERROR_STOP=1 --host=localhost --username=postgres --dbname=itgura <<-EOSQL
CREATE SCHEMA resource_management;
CREATE SCHEMA payment_service;
CREATE SCHEMA auth_service;
EOSQL
env:
PGPASSWORD: root

- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Build and publish Docker image
run: mvn clean package -P build-docker-image
env:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

# deploy:
# needs: build
# runs-on: ubuntu-latest

# steps:
# - name: Checkout code
# uses: actions/checkout@v2

# - name: Deploy to Server
# run: |
# ssh user@your-server "docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/your-image-name:latest && docker-compose up -d"
# env:
# DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
# DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
# SERVER_SSH_USERNAME: ${{ secrets.SERVER_SSH_USERNAME }}
# SERVER_SSH_PASSWORD: ${{ secrets.SERVER_SSH_PASSWORD }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ auth-service/mvnw.cmd
resource-management/resource-management-all/target/resource-management-all-1.0.0.jar.original
*.lst
/target/*
auth-service/src/main/resources/application.properties
66 changes: 48 additions & 18 deletions auth-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.5</version>
<relativePath/> <!-- lookup parent from repository -->
<groupId>com.itgura.lms</groupId>
<artifactId>lms</artifactId>
<version>1.0.0</version>

</parent>
<groupId>com.itgura</groupId>
<packaging>jar</packaging>
<artifactId>auth-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>auth-service</name>
Expand Down Expand Up @@ -40,11 +40,7 @@
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down Expand Up @@ -93,6 +89,11 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.cloud</groupId>-->
<!-- <artifactId>spring-cloud-starter-kubernetes</artifactId>-->
<!-- <version>1.1.10.RELEASE</version>-->
<!-- </dependency>-->
</dependencies>
<dependencyManagement>
<dependencies>
Expand All @@ -106,19 +107,48 @@
</dependencies>
</dependencyManagement>

<!-- <build>-->
<!-- <plugins>-->
<!-- <plugin>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-maven-plugin</artifactId>-->
<!-- <configuration>-->
<!-- <excludes>-->
<!-- <exclude>-->
<!-- <groupId>org.projectlombok</groupId>-->
<!-- <artifactId>lombok</artifactId>-->
<!-- </exclude>-->
<!-- </excludes>-->
<!-- </configuration>-->
<!-- </plugin>-->
<!-- </plugins>-->
<!-- </build>-->
<profiles>
<profile>
<id>build-docker-image</id>
<build>
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ public static void main(String[] args) {
}

}


Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ protected void doFilterInternal(@NonNull HttpServletRequest request,
final String authHeader = request.getHeader("Authorization");
final String jwt;
final String userEmail;
if(StringUtils.isEmpty(authHeader) || StringUtils.startsWith(authHeader,"Bearer ")){

if (StringUtils.isEmpty(authHeader) || !StringUtils.startsWith(authHeader, "Bearer ")) {
filterChain.doFilter(request, response);
return;

}
jwt = authHeader.substring(7);//Bearer length is 7
userEmail = jwtService.extractUserName(jwt);//todo extract userEmail from jwt Token
if(StringUtils.isNotEmpty(userEmail) && SecurityContextHolder.getContext().getAuthentication() == null){
UserDetails userDetails = this.userDetailsService.loadUserByUsername(userEmail);
if(jwtService.isTokenValid(jwt, userDetails)){
UsernamePasswordAuthenticationToken authToken =new UsernamePasswordAuthenticationToken(userDetails,null,userDetails.getAuthorities());
authToken.setDetails(
new WebAuthenticationDetailsSource().buildDetails(request)
);
SecurityContextHolder.getContext().setAuthentication(authToken);
}
if (StringUtils.isNotEmpty(userEmail) && SecurityContextHolder.getContext().getAuthentication() == null) {
UserDetails userDetails = this.userDetailsService.loadUserByUsername(userEmail);
if (jwtService.isTokenValid(jwt, userDetails)) {
UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
authToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
SecurityContextHolder.getContext().setAuthentication(authToken);
}
}
filterChain.doFilter(request,response);
filterChain.doFilter(request, response);

}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package com.itgura.authservice.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@CrossOrigin(origins = "*", allowedHeaders = "*")
@RestController
@RequestMapping("api/v1/admin")
@RequiredArgsConstructor

public class AdminController {

@PostMapping("/testAdmin")
public ResponseEntity<String> seyHello() {
return ResponseEntity.ok("Hello from Admin Controller!");
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@

import com.itgura.authservice.dto.request.AuthenticationRequest;
import com.itgura.authservice.dto.request.RegisterRequest;
import com.itgura.authservice.dto.request.changeRoleRequest;
import com.itgura.authservice.dto.response.AuthenticationResponse;
import com.itgura.authservice.services.AuthenticationService;
import com.itgura.dto.AppResponse;
import com.itgura.exception.ApplicationException;
import com.itgura.exception.ValueNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin(origins = "*", allowedHeaders = "*")
@RequestMapping("/api/v1/auth-service")
@RequiredArgsConstructor
public class AuthenticationController {
Expand Down Expand Up @@ -63,5 +67,22 @@ public AppResponse<Boolean> validateToken(@RequestParam("token") String token){
}
}

//ToDo: Remove this endpoint after testing

@PostMapping("/changeUserRole")
public AppResponse<String> changeUserRole(@RequestBody changeRoleRequest role) {
{
try {
return AppResponse.ok(authenticationService.changeUserRole(role));
} catch (ValueNotFoundException e) {
return AppResponse.error(null, "Value not found", "404", "", e.getMessage());
} catch (ApplicationException e) {
return AppResponse.error(null, "Application Error", "500", "", e.getMessage());
}


}
}


}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.itgura.authservice.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin(origins = "*", allowedHeaders = "*")
@RequestMapping("api/v1/student")
@RequiredArgsConstructor
public class StudentController {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.itgura.authservice.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin(origins = "*", allowedHeaders = "*")
@RequestMapping("api/v1/teacher")
@RequiredArgsConstructor
public class TeacherController {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.itgura.dto.request;
package com.itgura.authservice.dto.request;


import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -9,7 +10,6 @@
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class AuthenticationRequest {
private String email;
private String password;
public class changeRoleRequest {
private String changeRole;
}
Loading
Loading