<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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.4.5</version>
    <relativePath />
  </parent>

  <groupId>io.netfoundry</groupId>
  <artifactId>network-auth</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>network auth</name>
  <description>Network Auth Service, providing Ziti JWT and (future) CA support.</description>

  <properties>
    <maven.compiler.release>${java.version}</maven.compiler.release>
    <spring-cloud.version>2024.0.1</spring-cloud.version>
    <jacoco.version>0.8.11</jacoco.version>
    <flyway.version>11.20.3</flyway.version>
    <sonar.projectKey>netfoundry_network-auth</sonar.projectKey>
    <sonar.organization>netfoundry</sonar.organization>
    <sonar.sources>src/main</sonar.sources>
    <sonar.tests>src/test</sonar.tests>
    <sonar.host.url>https://sonarcloud.io</sonar.host.url>
    <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
    <sonar.coverage.exclusions>
      **/config/*, **/service/**/*
    </sonar.coverage.exclusions>
    <java.version>21</java.version>
  </properties>

  <dependencies>

    <!-- NetFoundry Dependencies -->
    <dependency>
      <groupId>io.netfoundry</groupId>
      <artifactId>common-util-framework</artifactId>
      <version>4.0.0</version>
    </dependency>

    <dependency>
      <groupId>io.netfoundry</groupId>
      <artifactId>authorization</artifactId>
      <version>2.5.1</version>
      <classifier>client</classifier>
      <exclusions>
        <!-- Excluding default (4.0) version of httpclient in favor of the newer one (5.0) below -->
        <exclusion>
          <groupId>org.apache.httpcomponents</groupId>
          <artifactId>httpclient</artifactId>
        </exclusion>
        <exclusion>
          <groupId>io.netfoundry</groupId>
          <artifactId>common-util-framework</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>io.netfoundry</groupId>
      <artifactId>messaging-framework</artifactId>
      <version>0.9.0</version>
    </dependency>


    <!-- Spring Dependencies -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-validation</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

    <dependency>
      <groupId>io.micrometer</groupId>
      <artifactId>micrometer-tracing-bridge-brave</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-hateoas</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>


    <!-- Spring Cloud -->
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-bootstrap</artifactId>
    </dependency>


    <!-- JWT handling, Crypto, ... -->
    <dependency>
      <groupId>org.bitbucket.b_c</groupId>
      <artifactId>jose4j</artifactId>
      <version>0.9.6</version>
    </dependency>

    <dependency> <!-- Caching -->
      <groupId>com.github.ben-manes.caffeine</groupId>
      <artifactId>caffeine</artifactId>
    </dependency>

    <!-- JWT Key Ids are created using this lib's NanoIdUtils class' -->
    <dependency>
      <groupId>com.aventrix.jnanoid</groupId>
      <artifactId>jnanoid</artifactId>
      <version>2.0.0</version>
    </dependency>


    <!-- Persistence Dependencies -->
    <dependency>
      <groupId>com.mysql</groupId>
      <artifactId>mysql-connector-j</artifactId>
    </dependency>

    <dependency>
      <groupId>org.flywaydb</groupId>
      <artifactId>flyway-core</artifactId>
    </dependency>

    <dependency>
      <groupId>org.flywaydb</groupId>
      <artifactId>flyway-mysql</artifactId>
    </dependency>


    <!-- Misc -->
    <dependency>
      <groupId>org.apache.httpcomponents.client5</groupId>
      <artifactId>httpclient5</artifactId>
    </dependency>

    <dependency>  <!-- semantic version parsing and comparison -->
      <groupId>com.vdurmont</groupId>
      <artifactId>semver4j</artifactId>
      <version>3.1.0</version>
    </dependency>

    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <scope>provided</scope>
    </dependency>

    <dependency>  <!-- Range support -->
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>33.4.8-jre</version>
    </dependency>

    <dependency>
      <groupId>net.logstash.logback</groupId>
      <artifactId>logstash-logback-encoder</artifactId>
      <version>7.4</version>
    </dependency>

    <dependency>
      <groupId>com.fasterxml.jackson.dataformat</groupId>
      <artifactId>jackson-dataformat-yaml</artifactId>
    </dependency>

    <dependency>
      <groupId>com.fasterxml.jackson.dataformat</groupId>
      <artifactId>jackson-dataformat-csv</artifactId>
    </dependency>

    <dependency>
      <groupId>org.jacoco</groupId>
      <artifactId>org.jacoco.agent</artifactId>
      <version>${jacoco.version}</version>
      <classifier>runtime</classifier>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId>
      <scope>provided</scope>
    </dependency>

    <!-- Testing -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-core</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-junit-jupiter</artifactId>
      <scope>test</scope>
    </dependency>

    <!-- Documentation Dependencies -->

    <dependency>
      <groupId>capital.scalable</groupId>
      <artifactId>spring-auto-restdocs-core</artifactId>
      <version>2.0.5</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.springframework.restdocs</groupId>
      <artifactId>spring-restdocs-mockmvc</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>


  <dependencyManagement>
    <!-- Some dependencies have many internal parts.  Instead of importing lots of dependencies, we use a
         Build of Materials (BOM) POM file here which will let us manage one cohesive version number.  -->
    <dependencies>
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>${spring-cloud.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <build>
    <plugins>
      <!--  provides Spring Boot support in Maven, letting you package executable jar or war archives and run an application “in-place” -->
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>build-info</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <!-- will provide git information in the healthcheck endpoint -->
      <plugin>
        <groupId>pl.project13.maven</groupId>
        <artifactId>git-commit-id-plugin</artifactId>
        <version>4.9.10</version>
      </plugin>
    </plugins>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.sonarsource.scanner.maven</groupId>
          <artifactId>sonar-maven-plugin</artifactId>
          <version>3.10.0.2594</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

<profiles>
    <profile>
      <id>test</id>
      <build>
        <plugins>
          <plugin>
            <groupId>pl.project13.maven</groupId>
            <artifactId>git-commit-id-plugin</artifactId>
            <configuration>
              <skip>true</skip>
            </configuration>
          </plugin>

          <!-- Surefire Plugin is used during the test phase of the build lifecycle to execute the unit tests of an application. It generates reports. -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.2.5</version>
            <configuration>
              <includes>
                <include>**/*Test.java,*Test.java</include>
              </includes>
              <systemPropertyVariables>
                <org.springframework.restdocs.outputDir>
                  ${project.build.directory}/generated-snippets
                </org.springframework.restdocs.outputDir>
                <org.springframework.restdocs.javadocJsonDir>
                  ${project.build.directory}/generated-javadoc-json
                </org.springframework.restdocs.javadocJsonDir>
              </systemPropertyVariables>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>${jacoco.version}</version>
            <executions>
              <execution>
                <goals>
                  <goal>prepare-agent</goal>
                </goals>
              </execution>
              <execution>
                <id>report</id>
                <phase>prepare-package</phase>
                <goals>
                  <goal>report</goal>
                </goals>
              </execution>
              <execution>
                <id>post-unit-test</id>
                <phase>verify</phase>
                <goals>
                  <goal>report</goal>
                </goals>
                <configuration>
                  <!-- Sets the path to the file which contains the execution
                    data. -->
                  <dataFile>target/jacoco.exec</dataFile>
                  <!-- Sets the output directory for the code coverage report. -->
                  <outputDirectory>target/jacoco-ut</outputDirectory>
                </configuration>
              </execution>
            </executions>
            <dependencies>
              <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-core</artifactId>
                <version>2.16.1</version>
              </dependency>
              <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>2.16.1</version>
              </dependency>
            </dependencies>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>dependency_check</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.owasp</groupId>
            <artifactId>dependency-check-maven</artifactId>
            <version>9.0.9</version>
            <configuration>
              <!-- Fail Build On CVSS core more then 8.0 which is HIGH-->
              <!-- <failBuildOnCVSS>8</failBuildOnCVSS> -->
              <!-- Generate all report formats -->
              <format>ALL</format>
              <!-- Don't use Nexus Analyzer -->
              <centralAnalyzerEnabled>false</centralAnalyzerEnabled>
              <ossindexAnalyzerEnabled>false</ossindexAnalyzerEnabled>
              <!-- Am I the latest version? -->
              <versionCheckEnabled>true</versionCheckEnabled>
              <!--suppression Files -->
              <suppressionFiles>owasp/suppressed.xml</suppressionFiles>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>xml-maven-plugin</artifactId>
            <configuration>
              <transformationSets>
                <transformationSet>
                  <dir>${project.build.directory}</dir>
                  <includes>
                    <include>dependency-check-report.xml</include>
                  </includes>
                  <stylesheet>owasp/dependencycheck_to_pmd.xsl</stylesheet>
                  <outputDir>target</outputDir>
                  <fileMappers>
                    <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.MergeFileMapper">
                      <targetName>dependency-check-report-pmd.xml</targetName>
                    </fileMapper>
                  </fileMappers>
                </transformationSet>
              </transformationSets>
            </configuration>
            <dependencies>
              <dependency>
                <groupId>net.sf.saxon</groupId>
                <artifactId>saxon</artifactId>
                <version>8.7</version>
              </dependency>
            </dependencies>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
