From d189e005635aeecafa325cebc01b11e4548149eb Mon Sep 17 00:00:00 2001 From: Sathish Jayapal Date: Sun, 2 Jun 2024 16:24:11 -0500 Subject: [PATCH] config directory established --- .dockerignore | 2 + .github/workflows/main.yml | 13 +- .mvn/wrapper/maven-wrapper.properties | 2 + Dockerfile | 5 - pom.xml | 155 +++++++++++++----- .../BasicAuthBean.java | 11 +- ...athishProjectsConfigServerApplication.java | 3 - .../WebSecurityConfig.java | 62 ++++--- src/main/resources/application.yaml | 20 ++- ...shProjectConfigServerApplicationTests.java | 6 +- src/test/resources/application.yaml | 39 +++++ 11 files changed, 226 insertions(+), 92 deletions(-) create mode 100644 .dockerignore create mode 100644 .mvn/wrapper/maven-wrapper.properties delete mode 100644 Dockerfile create mode 100644 src/test/resources/application.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0af00ca --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +**/node_modules/ +**/*.log diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 254da8f..5868636 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,10 +13,10 @@ jobs: name: Checkout uses: actions/checkout@v3 - - name: Set up JDK 11 + name: Set up JDK 21 uses: actions/setup-java@v3 with: - java-version: '11' + java-version: '21' distribution: 'temurin' cache: maven - @@ -34,8 +34,7 @@ jobs: - name: Build and push uses: docker/build-push-action@v4 - with: - context: . - file: ./Dockerfile - push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/sathishprojects_config_server:latest + run: | + mvn clean package jib:dockerBuild -DskipTests + dockerlogin:login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.OCKERHUB_TOKEN }} + docker push ${{ secrets.DOCKERHUB_USERNAME }}/sathishprojects_config_server:latest diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..5f0536e --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 49d5719..0000000 --- a/Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -FROM eclipse-temurin:11-jre-focal -ADD target/*.jar sathishprojects_config_server.jar -RUN sh -c 'touch /sathishprojects_config_server.jar' -EXPOSE 8888 -ENTRYPOINT [ "sh", "-c", "java -jar /sathishprojects_config_server.jar --pass=sa --username=sathish" ] diff --git a/pom.xml b/pom.xml index a8b5f4c..6fdc8ae 100644 --- a/pom.xml +++ b/pom.xml @@ -1,24 +1,24 @@ - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.6.6 - - - me.sathish - sathishproject-config-server - +-0.0.1-SNAPSHOT - sathishproject-config-server - Sathish project Portal Config Server - - 11 - 2021.0.1 - - - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.2.1 + + + me.sathish + sathishproject-config-server + 0.0.1-SNAPSHOT + sathishproject-config-server + Sathish project Portal Config Server + + 21 + 2.37.0 + 2023.0.0 + + org.springframework.boot spring-boot-starter-actuator @@ -27,6 +27,10 @@ org.springframework.cloud spring-cloud-config-server + + org.springframework.cloud + spring-cloud-starter + org.springframework.boot spring-boot-starter-security @@ -41,28 +45,97 @@ org.springframework.boot spring-boot-starter-test test - - - - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - + + + org.springframework.boot + spring-boot-docker-compose + runtime + + + org.springframework.boot + spring-boot-starter-validation + + + org.springframework.boot + spring-boot-starter-web + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + - - sathishprojects_config_server - - - org.springframework.boot - spring-boot-maven-plugin - - - + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${java.version} + ${java.version} + + + + com.diffplug.spotless + spotless-maven-plugin + ${spotless.version} + + + + 1.17.0 + + + + + + + compile + + check + + + + + + com.google.cloud.tools + jib-maven-plugin + 3.4.2 + + + travelhelper0h/${project.artifactId}:latest + + + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + diff --git a/src/main/java/me/sathish/sathishprojectconfigserver/BasicAuthBean.java b/src/main/java/me/sathish/sathishprojectconfigserver/BasicAuthBean.java index f7902ce..8ab7ba0 100644 --- a/src/main/java/me/sathish/sathishprojectconfigserver/BasicAuthBean.java +++ b/src/main/java/me/sathish/sathishprojectconfigserver/BasicAuthBean.java @@ -1,14 +1,13 @@ package me.sathish.sathishprojectconfigserver; import org.springframework.beans.factory.annotation.Value; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Component; @Component public class BasicAuthBean { - @Value("${pass}") private String password; + @Value("${username}") private String username; @@ -21,14 +20,10 @@ public void setUsername(String username) { } public String getPassword() { - BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); - String encodedPassword = encoder.encode(this.password); - return encodedPassword; + return this.password; } public void setPassword(String password) { - BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); - String encodedPassword = encoder.encode(password); - this.password = encodedPassword; + this.password = password; } } diff --git a/src/main/java/me/sathish/sathishprojectconfigserver/SathishProjectsConfigServerApplication.java b/src/main/java/me/sathish/sathishprojectconfigserver/SathishProjectsConfigServerApplication.java index 910f9f0..30f07ad 100644 --- a/src/main/java/me/sathish/sathishprojectconfigserver/SathishProjectsConfigServerApplication.java +++ b/src/main/java/me/sathish/sathishprojectconfigserver/SathishProjectsConfigServerApplication.java @@ -8,9 +8,6 @@ @SpringBootApplication public class SathishProjectsConfigServerApplication { public static void main(String[] args) { - System.out.println("The args passed is " + args[0]); - System.out.println("Config server running for all Sathish Projects"); SpringApplication.run(SathishProjectsConfigServerApplication.class, args); } - } diff --git a/src/main/java/me/sathish/sathishprojectconfigserver/WebSecurityConfig.java b/src/main/java/me/sathish/sathishprojectconfigserver/WebSecurityConfig.java index 74c5cff..992e36f 100644 --- a/src/main/java/me/sathish/sathishprojectconfigserver/WebSecurityConfig.java +++ b/src/main/java/me/sathish/sathishprojectconfigserver/WebSecurityConfig.java @@ -1,38 +1,54 @@ package me.sathish.sathishprojectconfigserver; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.provisioning.InMemoryUserDetailsManager; +@Configuration @EnableWebSecurity(debug = true) -public class WebSecurityConfig extends WebSecurityConfigurerAdapter { - final - BasicAuthBean environment; +@EnableMethodSecurity(securedEnabled = true, jsr250Enabled = true) +public class WebSecurityConfig { + final BasicAuthBean environment; public WebSecurityConfig(BasicAuthBean environment) { this.environment = environment; } + @Value("${spring.security.debug:false}") + boolean securityDebug; - // - @Override - protected void configure(AuthenticationManagerBuilder auth) throws Exception { - auth.inMemoryAuthentication() - .passwordEncoder(new BCryptPasswordEncoder()) - .withUser(environment.getUsername()) - .password(environment.getPassword()) - .roles("ADMIN") - ; + @Bean + public BCryptPasswordEncoder bCryptPasswordEncoder() { + return new BCryptPasswordEncoder(); } - @Override - protected void configure(HttpSecurity http) throws Exception { - http.authorizeRequests() - .anyRequest().authenticated() - .and() - .httpBasic(); + @Bean + public UserDetailsService userDetailsService() { + InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); + manager.createUser( + User.withUsername(environment.getUsername()) + .password(bCryptPasswordEncoder().encode(environment.getPassword())) + .roles("USER") + .build()); + manager.createUser( + User.withUsername(environment.getUsername() + "Admin") + .password(bCryptPasswordEncoder().encode(environment.getPassword())) + .roles("USER", "ADMIN") + .build()); + return manager; } -} - + @Bean + public WebSecurityCustomizer webSecurityCustomizer() { + return web -> + web.debug(securityDebug) + .ignoring() + .requestMatchers("/css/**", "/js/**", "/img/**", "/lib/**", "/favicon.ico"); + } +} diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 11c89aa..1b5d853 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -1,6 +1,11 @@ spring: application: name: sathish-projects-git-config-server + h2: + console: + enabled: true + profiles: + active: git security: user: name: @@ -10,7 +15,11 @@ spring: server: git: uri: https://github.com/sathishjayapal/jubilant-memory + default-label: main + timeout: 5 + clone-on-start: true search-paths: + - '{application}' - 'resumes*' - 'wi-traffic*' - 'running/*' @@ -18,5 +27,14 @@ server: port: 8888 # http://localhost:8888/wi-traffic-alerts-url/dev/main dev here is the profile and main in the url # branch or the main branch name +management: + endpoint: + health: + show-details: always + endpoints: + web: + exposure: + include: "*" + encrypt: - key: + key: MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAK8GMsEw44Vw71MsofkIaS5PWKVP1A2yNCxoXNP31VEi4gCUt2ViRkan/c4/WXW7eAOP07Qh7Z287TfZFbgH2oNpVBakuTo5VdmpknZ3z89I4ah36l3+DwaY7JuSSVl0KzDs/xXesmJxBU8gxtNh9AzTvYxuR4bTGPZDMVJuBQ9nAgMBAAECgYAoxQbZnavCD7aP51uriNwHX5BEob3BmvswRPcqoRZdmgSPIhU+VpAMMWGbw4HxPMQOAFjOIwEYt0OCuNyoS5wIkJwYpu5skP5dZ02+TnzZ4LQpEIyLWZtK2BVK/PXTGmMh0zYBE4Ruvx4pwfb0A0nltzY5H5yCR72QMnZloR/T0QJBAPb5MDkobGB19rUezSxUAuCQeLEmdmH5BHD71jtS/EaPCKGkp4ifZ/SO5N8JibyN5MLZ/dDZ51GOWOY4LTn9hbsCQQC1a9DfBVvtJlgtg+aITZwV+rHLKlVP141RbOmoYWJwrubja4fmkQuqXJNfeei3LQ6XclvXHujq9LLCpvlo7cxFAkEAxusDlTXivHqmn1DUrhxoSNjz7LLu7JA1rI6aCSQYvvfbWt4Udez2PLqOyrmS74RVuT78uKeZMU32ek7K1odEmwJBALR8SXTGURjSD+FgGoW5qDHZkO2M9QiUafv6vU4NbDCsX/kaLj58SD25EchncNRjF+QlGicekhvFSt4J3ZC9Gn0CQQDVLHandZGEYx6M1jWzZU8VN/DVUuxrAy3a8kpjxWzCpHCPl2uPr4v4Up3bw8oZwrUG6A06mgV2+bZ4uxkSV7oZ diff --git a/src/test/java/me/sathish/sathishprojectconfigserver/SathishProjectConfigServerApplicationTests.java b/src/test/java/me/sathish/sathishprojectconfigserver/SathishProjectConfigServerApplicationTests.java index 624d0a1..f05eae1 100644 --- a/src/test/java/me/sathish/sathishprojectconfigserver/SathishProjectConfigServerApplicationTests.java +++ b/src/test/java/me/sathish/sathishprojectconfigserver/SathishProjectConfigServerApplicationTests.java @@ -6,8 +6,6 @@ @SpringBootTest class SathishProjectConfigServerApplicationTests { - @Test - void contextLoads() { - } - + @Test + void contextLoads() {} } diff --git a/src/test/resources/application.yaml b/src/test/resources/application.yaml new file mode 100644 index 0000000..05ce1dd --- /dev/null +++ b/src/test/resources/application.yaml @@ -0,0 +1,39 @@ +pass: Pass +username: Sathish +spring: + application: + name: sathish-projects-git-config-server + h2: + console: + enabled: true + profiles: + active: git + security: + user: + name: + password: + cloud: + config: + server: + git: + uri: https://github.com/sathishjayapal/jubilant-memory + default-label: main + timeout: 5 + clone-on-start: true + search-paths: + - '{application}' + - 'resumes*' + - 'wi-traffic*' + - 'running/*' +server: + port: 8888 +management: + endpoint: + health: + show-details: always + endpoints: + web: + exposure: + include: "*" +encrypt: + key: MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAK8GMsEw44Vw71MsofkIaS5PWKVP1A2yNCxoXNP31VEi4gCUt2ViRkan/c4/WXW7eAOP07Qh7Z287TfZFbgH2oNpVBakuTo5VdmpknZ3z89I4ah36l3+DwaY7JuSSVl0KzDs/xXesmJxBU8gxtNh9AzTvYxuR4bTGPZDMVJuBQ9nAgMBAAECgYAoxQbZnavCD7aP51uriNwHX5BEob3BmvswRPcqoRZdmgSPIhU+VpAMMWGbw4HxPMQOAFjOIwEYt0OCuNyoS5wIkJwYpu5skP5dZ02+TnzZ4LQpEIyLWZtK2BVK/PXTGmMh0zYBE4Ruvx4pwfb0A0nltzY5H5yCR72QMnZloR/T0QJBAPb5MDkobGB19rUezSxUAuCQeLEmdmH5BHD71jtS/EaPCKGkp4ifZ/SO5N8JibyN5MLZ/dDZ51GOWOY4LTn9hbsCQQC1a9DfBVvtJlgtg+aITZwV+rHLKlVP141RbOmoYWJwrubja4fmkQuqXJNfeei3LQ6XclvXHujq9LLCpvlo7cxFAkEAxusDlTXivHqmn1DUrhxoSNjz7LLu7JA1rI6aCSQYvvfbWt4Udez2PLqOyrmS74RVuT78uKeZMU32ek7K1odEmwJBALR8SXTGURjSD+FgGoW5qDHZkO2M9QiUafv6vU4NbDCsX/kaLj58SD25EchncNRjF+QlGicekhvFSt4J3ZC9Gn0CQQDVLHandZGEYx6M1jWzZU8VN/DVUuxrAy3a8kpjxWzCpHCPl2uPr4v4Up3bw8oZwrUG6A06mgV2+bZ4uxkSV7oZ