diff --git a/.github/workflows/aws-eks-deployment.yml b/.github/workflows/aws-eks-deployment.yml new file mode 100644 index 0000000..b4e64a9 --- /dev/null +++ b/.github/workflows/aws-eks-deployment.yml @@ -0,0 +1,34 @@ +name: AWS EKS Deployment +run-name: ${{ github.actor }} is pushing docker image to AWS EKS + +# 1 +on: + push: + branches: + - main + +#2 +env: + DOCKER_REGISTRY_USERNAME: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} + DOCKER_REGISTRY_PASSWORD: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} + +#3 +jobs: + build_and_push_image: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Java + uses: actions/setup-java@v3 + with: + java-version: 21 + distribution: 'temurin' + cache: 'maven' + + # - name: Set App Version + # run: mvn versions:set -DnewVersion=${{ github.sha }} + + - name: Build with Maven + # run: mvn --batch-mode --update-snapshots clean test + run: mvn --batch-mode --update-snapshots clean spring-boot:build-image -Dspring-boot.build-image.imageName=registry.digitalocean.com/naturalprogrammer/np-spring-mvc-demo:app diff --git a/src/main/java/com/naturalprogrammer/springmvc/config/security/SecurityConfig.java b/src/main/java/com/naturalprogrammer/springmvc/config/security/SecurityConfig.java index 6785b8f..cbfc709 100644 --- a/src/main/java/com/naturalprogrammer/springmvc/config/security/SecurityConfig.java +++ b/src/main/java/com/naturalprogrammer/springmvc/config/security/SecurityConfig.java @@ -41,7 +41,7 @@ public class SecurityConfig { public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { return http - .cors(AbstractHttpConfigurer::disable) + //.cors(customizer -> customizer.configurationSource()) .csrf(AbstractHttpConfigurer::disable) .securityContext(customizer -> customizer.securityContextRepository(new NullSecurityContextRepository())) .sessionManagement(configurer -> configurer.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) diff --git a/src/main/java/com/naturalprogrammer/springmvc/config/sociallogin/HttpCookieOAuth2AuthorizationRequestRepository.java b/src/main/java/com/naturalprogrammer/springmvc/config/sociallogin/HttpCookieOAuth2AuthorizationRequestRepository.java index 393af82..0de5955 100644 --- a/src/main/java/com/naturalprogrammer/springmvc/config/sociallogin/HttpCookieOAuth2AuthorizationRequestRepository.java +++ b/src/main/java/com/naturalprogrammer/springmvc/config/sociallogin/HttpCookieOAuth2AuthorizationRequestRepository.java @@ -34,7 +34,7 @@ public class HttpCookieOAuth2AuthorizationRequestRepository implements Authoriza private static final int COOKIE_EXPIRY_SECONDS = 60; public static final String AUTHORIZATION_REQUEST_COOKIE_NAME = "my_oauth2_authorization_request"; public static final String REDIRECT_URI_COOKIE_PARAM_NAME = "myRedirectUri"; - public static final String CLIENT_ID_COOKIE_PARAM_NAME = "myClientId"; + public static final String CLIENT_ID_COOKIE_PARAM_NAME = "myAttemptId"; /** * Load authorization request from cookie diff --git a/src/main/java/com/naturalprogrammer/springmvc/user/features/login/ResourceTokenExchangeRequest.java b/src/main/java/com/naturalprogrammer/springmvc/user/features/login/ResourceTokenExchangeRequest.java index b47334c..7bcb43a 100644 --- a/src/main/java/com/naturalprogrammer/springmvc/user/features/login/ResourceTokenExchangeRequest.java +++ b/src/main/java/com/naturalprogrammer/springmvc/user/features/login/ResourceTokenExchangeRequest.java @@ -7,7 +7,7 @@ record ResourceTokenExchangeRequest( @NotBlank - String myClientId, + String myAttemptId, Long resourceTokenValidForMillis ) { diff --git a/src/main/java/com/naturalprogrammer/springmvc/user/features/login/ResourceTokenExchanger.java b/src/main/java/com/naturalprogrammer/springmvc/user/features/login/ResourceTokenExchanger.java index 346725d..14f8a0b 100644 --- a/src/main/java/com/naturalprogrammer/springmvc/user/features/login/ResourceTokenExchanger.java +++ b/src/main/java/com/naturalprogrammer/springmvc/user/features/login/ResourceTokenExchanger.java @@ -55,11 +55,11 @@ private Either exchangeValidated( .map(cookie -> Either.right(cookie.getValue())) .orElseGet(() -> cookieNotFound(userId, exchangeRequest)) .filter((String cookieValue) -> cookieMatchesRequest(cookieValue, exchangeRequest, userId)) - .flatMap(myClientId -> exchangeResourceToken(userId, exchangeRequest.resourceTokenValidForMillis(), request, response)); + .flatMap(attemptId -> exchangeResourceToken(userId, exchangeRequest.resourceTokenValidForMillis(), request, response)); } private Optional cookieMatchesRequest(String cookieValue, ResourceTokenExchangeRequest exchangeRequest, UUID userId) { - if (exchangeRequest.myClientId().equals(cookieValue)) + if (exchangeRequest.myAttemptId().equals(cookieValue)) return Optional.empty(); log.warn("{} cookie {} different from the given {} for user {}", CLIENT_ID_COOKIE_PARAM_NAME, cookieValue, exchangeRequest, userId); diff --git a/src/main/resources/config/application-default.yml b/src/main/resources/config/application-default.yml index 3c8c84c..c7483ed 100644 --- a/src/main/resources/config/application-default.yml +++ b/src/main/resources/config/application-default.yml @@ -19,6 +19,8 @@ logging.level: org.apache.kafka: OFF my: + # homepage: http://localhost:5173 + # oauth2-authentication-success-url: http://localhost:5173/social-login-success?userId=%s&resourceToken=%s homepage: http://localhost:8080 oauth2-authentication-success-url: http://localhost:8080?userId=%s&resourceToken=%s jws: diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml index 31d7f8a..6e1822a 100644 --- a/src/main/resources/config/application.yml +++ b/src/main/resources/config/application.yml @@ -17,6 +17,16 @@ spring: use-new-id-generator-mappings: false ddl-auto: validate + cors: + origins: + - ${my.homepage} + methods: + # - GET + - POST + - PUT + - DELETE + - OPTIONS + maxAge: 3600 security: strategy: MODE_INHERITABLETHREADLOCAL oauth2: diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html index c38eed6..83506df 100644 --- a/src/main/resources/static/index.html +++ b/src/main/resources/static/index.html @@ -14,7 +14,7 @@