Skip to content
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

feature/vylepšení pipeliny #92

Merged
merged 25 commits into from
May 16, 2024
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
45 changes: 19 additions & 26 deletions .github/workflows/build-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ run-name: "Run ${{github.run_id}}, triggered by ${{github.actor}}"

on:
push:
branches: ["main"]
branches: [ "main" ]
pull_request:
branches: ["main"]
branches: [ "main" ]

jobs:
backend:
Expand All @@ -16,29 +16,22 @@ jobs:
run:
working-directory: backend
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Set up JDK 17 for backend
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
- name: Build and test backend
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: 'gradle'
cache-dependency-path: |
backend/*.gradle*
backend/**/gradle-wrapper.properties
- run: ./gradlew build --no-daemon

- name: setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
generate-job-summary: true
add-job-summary-as-pr-comment: on-failure
cache-disabled: true
- name: Set execute permissions for backend gradlew
run: chmod +x gradlew

- name: Build backend and run tests with Gradle Wrapper
run: ./gradlew build

- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: backend
file: backend/build/reports/jacoco/test/html/jacocoTestReport.xml
- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: backend
file: backend/build/reports/jacoco/test/html/jacocoTestReport.xml
11 changes: 5 additions & 6 deletions .github/workflows/build-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ run-name: "Run ${{github.run_id}}, triggered by ${{github.actor}}"

on:
push:
branches: ["main"]
branches: [ "main" ]
pull_request:
branches: ["main"]
branches: [ "main" ]

jobs:
build:
Expand All @@ -17,14 +17,13 @@ jobs:
working-directory: frontend
steps:
- uses: actions/checkout@v3
- name: Use Node.js 20.x

- name: Install dependencies
uses: actions/setup-node@v3
with:
node-version: 20.x
node-version: 20
cache: 'npm'
cache-dependency-path: frontend/package-lock.json

- name: Install dependencies
run: npm install

- name: Build
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/deploy-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: ${{ secrets.HEROKU_BACKEND_NAME }}
heroku_email: ${{ secrets.HEROKU_EMAIL }}
healthcheck: false
branch: 'main'
appdir: 'backend'
procfile: 'web: java $JAVA_OPTS -Dserver.port=$PORT -jar build/libs/backend-1.0.0.jar --spring.profiles.active=prod'
Expand All @@ -30,6 +29,5 @@ jobs:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: ${{ secrets.HEROKU_FRONTEND_NAME }}
heroku_email: ${{ secrets.HEROKU_EMAIL }}
healthcheck: false
branch: 'main'
appdir: 'frontend'
Empty file modified backend/gradlew
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio
import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.stereotype.Component
import org.springframework.web.filter.OncePerRequestFilter
import io.github.oshai.kotlinlogging.KotlinLogging

private val log = KotlinLogging.logger {}

@Component
class JwtAuthenticationFilter(
Expand All @@ -21,7 +23,7 @@ class JwtAuthenticationFilter(
filterChain: FilterChain
) {
val validClaims = tokenFilter.validateRequest(request)

log.error { "Claims: $validClaims" }
if (validClaims != null) {
val authToken = UsernamePasswordAuthenticationToken(validClaims, null, listOf(validClaims.authUserRole))
SecurityContextHolder.getContext().authentication = authToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import io.jsonwebtoken.Jwts
import io.jsonwebtoken.io.Decoders
import io.jsonwebtoken.security.Keys


class JwtService(
secret: String
) {
Expand Down Expand Up @@ -37,4 +36,4 @@ class JwtService(
null
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import com.tul.backend.auth.base.dto.AccessTokenClaims
import jakarta.servlet.http.HttpServletRequest
import org.springframework.stereotype.Component
import org.springframework.web.util.WebUtils
import io.github.oshai.kotlinlogging.KotlinLogging

private val log = KotlinLogging.logger {}

@Component
class TokenFilter(
Expand All @@ -12,7 +15,7 @@ class TokenFilter(

fun validateRequest(request: HttpServletRequest): AccessTokenClaims? {
val token = WebUtils.getCookie(request, accessTokenService.COOKIE_NAME)

log.error { "Token: $token" }
if (token != null) {
return accessTokenService.extractClaims(token.value)
}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ spring:
password: ${SECURITY_PASSWORD}
jwt:
secure: true
sameSite: "none"
sameSite: "Lax"
duration: 86400000 # 1 day
secret: ${JWT_SECRET}
2 changes: 1 addition & 1 deletion backend/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ spring:
default_schema: public
jwt:
secure: true
sameSite: "none"
sameSite: "Lax"
duration: 86400000 # 1 day
secret: "7A25432A462D4A614E645267556B58703272357538782F413F4428472B4B6250" # random string in base64, should be changed in production
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {inject, Injectable} from "@angular/core";
import {catchError, Observable, throwError} from "rxjs";
import {NotificationService} from "../../notification/service/notification.service";
import {Router} from "@angular/router";
import {AuthService} from "../../../auth/service/auth.service";

@Injectable()
export class HttpErrorInterceptor implements HttpInterceptor {
Expand All @@ -14,6 +15,7 @@ export class HttpErrorInterceptor implements HttpInterceptor {
catchError((error: HttpErrorResponse) => {
if (error.status == 401) {
this.notificationService.errorNotification("You do not have access to this feature, please login")
sessionStorage.removeItem('auth')
this.router.navigate(['/signIn'])
}
return throwError(error)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const environment = {
baseUrl: 'https://moc-backend-weather-app-d8c5764193db.herokuapp.com/',
baseUrl: 'http://www.weather-app-backend.moc-backend.cz/',
production: true,
version: '1.0.0'
};