<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>io.netfoundry</groupId>
  <artifactId>authorization</artifactId>
  <version>2.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>NetFoundry Authorization Service</name>


  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.0.3</version>
  </parent>


  <properties>
    <!-- Timestamp and application version number are injected into the application
      and bootstrap properties files, and used for logging purposes ... to track
      build version that the logs were made against. -->
    <timestamp>${maven.build.timestamp}</timestamp>
    <maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
    <maven.compiler.release>17</maven.compiler.release>
    <java.version>17</java.version>
    <application.version.number>${project.version}</application.version.number>

    <!-- Basic settings -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

    <!-- Sonar, Lint, Java Code Coverage settings. These apply to build time only. -->
    <skip.dump>true</skip.dump>
    <jacoco.version>0.8.8</jacoco.version>
    <sonar.jacoco.reportPaths>${basedir}/target/jacoco.exec,${basedir}/target/jacoco-it.exec</sonar.jacoco.reportPaths>
    <sonar.projectKey>io.netfoundry:authorization</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.exclusions>
      src/main/asciidoc/**,
      src/main/java/lombok.config,
      src/main/resources/**,
      src/test/**
    </sonar.exclusions>
    <skip.dump>true</skip.dump>
    <snippetsDirectory>${project.build.directory}/generated-snippets</snippetsDirectory>
  </properties>


  <!-- 
    Many of this Auth Serive's dependencies are marked as OPTIONAL, which causes maven to not 
    automatically include them in a project that depends on this project.  That includes projects
    which depend on the client jar produced by this project (and which is the only reason another
    project would include this service as a dependency.)
   -->
  <dependencies>

    <!-- NF common dependencies -->

    <dependency>
      <groupId>io.netfoundry</groupId>
      <artifactId>common-util-framework</artifactId>
        <version>2.0.0</version>
    </dependency>


    <!-- Spring dependencies -->

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      <scope>provided</scope>
    </dependency>

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

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-aop</artifactId>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-jdbc</artifactId>
      <scope>provided</scope>
    </dependency>
    
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
      <scope>provided</scope>
    </dependency>
    
    <dependency>
      <groupId>org.springframework.data</groupId>
      <artifactId>spring-data-commons</artifactId>
    </dependency>
    
    <dependency>
      <groupId>org.springframework.retry</groupId>
      <artifactId>spring-retry</artifactId>
    </dependency>

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


    <!-- Misc project dependencies -->

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

    <dependency>
      <groupId>com.vdurmont</groupId>
      <artifactId>semver4j</artifactId>
      <version>[3.1.0,)</version>
    </dependency>

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

    <dependency>  <!-- Required by RestServiceClient in common -->
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpclient</artifactId>
    </dependency>

    <dependency>
      <groupId>net.logstash.logback</groupId>
      <artifactId>logstash-logback-encoder</artifactId>
      <version>7.2</version>
      <scope>provided</scope>
    </dependency>
    
    
    <!-- JWT handling support -->

    <dependency>
      <groupId>org.bitbucket.b_c</groupId>
      <artifactId>jose4j</artifactId>
      <version>0.9.3</version>
    </dependency>

    <dependency>
      <groupId>com.auth0</groupId>
      <artifactId>java-jwt</artifactId>
      <version>4.2.2</version>
    </dependency>

    <dependency>
      <groupId>com.auth0</groupId>
      <artifactId>jwks-rsa</artifactId>
      <version>0.21.3</version>
    </dependency>
    
    <dependency> <!-- Required by jwks-rsa -->
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>31.1-jre</version>
    </dependency>

    <dependency> <!-- JWKS public keys are stored in redis -->
      <groupId>org.redisson</groupId>
      <artifactId>redisson-spring-boot-starter</artifactId>
      <version>3.19.0</version>
      <scope>provided</scope>
    </dependency>


    <!-- Database dependencies -->

    <dependency>
      <groupId>com.mchange</groupId>
      <artifactId>c3p0</artifactId>
      <version>0.9.5.5</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.31</version>
      <scope>provided</scope>
    </dependency>

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

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


    <!-- Testing dependencies -->

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

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

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-test-autoconfigure</artifactId>
      <scope>test</scope>
    </dependency>

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

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

    <dependency>
      <groupId>org.skyscreamer</groupId>
      <artifactId>jsonassert</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>com.jayway.jsonpath</groupId>
      <artifactId>json-path</artifactId>
      <scope>test</scope>
    </dependency>

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

    <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
      <scope>test</scope>
    </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.mockito</groupId>
      <artifactId>mockito-core</artifactId>
      <scope>test</scope>
    </dependency>

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




  <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>
      </plugin>

      <!-- Add the client jar as an artifact of the build.  -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>jar</goal>
            </goals>
            <configuration>
              <classifier>client</classifier>
              <includes>
                <include>io/netfoundry/auth/client/**</include>
                <include>io/netfoundry/auth/clientv2/**</include>
                <include>io/netfoundry/auth/domain/**</include>
                <exclude>io/netfoundry/auth/domain/*Service.class</exclude>
                <exclude>io/netfoundry/auth/domain/*Repository.class</exclude>
                <include>io/netfoundry/auth/domainv2/**</include>
                <exclude>io/netfoundry/auth/domainv2/*Service.class</exclude>
                <exclude>io/netfoundry/auth/domainv2/*Repository.class</exclude>
                <include>io/netfoundry/auth/service/controller/**/*Controller$*.class</include>
                <include>io/netfoundry/auth/service/controller/**/*Request.class</include>
                <include>io/netfoundry/auth/service/controller/**/*Response.class</include>
                <include>io/netfoundry/auth/service/controller/**/*Command.class</include>
                <include>org/springframework/restdocs/**</include>
              </includes>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.flywaydb</groupId>
        <artifactId>flyway-maven-plugin</artifactId>
        <configuration>
          <url>jdbc:h2:file:./target/data;MODE=mysql</url>
          <user>sa</user>
          <schemas>
            <schema>auth</schema>
          </schemas>
          <locations>
            <location>filesystem:./src/main/resources/database/migration</location>
          </locations>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>5.2.4</version>
          </dependency>
        </dependencies>
      </plugin>


      <plugin>
        <groupId>org.asciidoctor</groupId>
        <artifactId>asciidoctor-maven-plugin</artifactId>
        <version>1.6.0</version>
        <executions>
          <execution>
            <id>generate-docs</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>process-asciidoc</goal>
            </goals>
            <configuration>
              <backend>html</backend>
              <doctype>book</doctype>
              <sourceDocumentName>index.adoc</sourceDocumentName>
              <attributes>
                <snippets>${snippetsDirectory}</snippets>
              </attributes>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-resources</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>
                ${project.build.outputDirectory}/static/docs
              </outputDirectory>
              <resources>
                <resource>
                  <directory>
                    ${project.build.directory}/generated-docs
                  </directory>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <extensions>true</extensions>
        <executions>
          <execution>
            <id>generate-javadoc-json</id>
            <phase>compile</phase>
            <goals>
              <goal>javadoc-no-fork</goal>
            </goals>
            <configuration>
              <doclet>capital.scalable.restdocs.jsondoclet.ExtractDocumentationAsJsonDoclet</doclet>
              <docletArtifact>
                <groupId>capital.scalable</groupId>
                <artifactId>spring-auto-restdocs-json-doclet-jdk9</artifactId>
                <version>2.0.11</version>
              </docletArtifact>
              <destDir>generated-javadoc-json</destDir>
              <reportOutputDirectory>${project.build.directory}</reportOutputDirectory>
              <useStandardDocletOptions>false</useStandardDocletOptions>
              <show>package</show>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>${jacoco.version}</version>
        <executions>
          <execution>
            <id>pre-unit-test</id>
            <goals>
              <goal>prepare-agent</goal>
            </goals>
          </execution>
          <execution>
            <id>prepare-agent</id>
            <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>
          <execution>
            <id>pre-integration-test</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>prepare-agent</goal>
            </goals>
            <configuration>
              <destFile>${project.build.directory}/jacoco-it.exec</destFile>
              <append>true</append>
              <propertyName>failsafe.argLine</propertyName>
            </configuration>
          </execution>
          <execution>
            <id>post-integration-test</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>report-aggregate</goal>
            </goals>
          </execution>
          <execution>
            <id>pull-test-data</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>dump</goal>
            </goals>
            <configuration>
              <destFile>${project.build.directory}/jacoco-it-${app.host}:${app.port}.exec</destFile>
              <address>${app.host}</address>
              <port>${app.port}</port>
              <reset>false</reset>
              <skip>${skip.dump}</skip>
            </configuration>
          </execution>
          <execution>
            <id>merge-test-data</id>
            <goals>
              <goal>merge</goal>
            </goals>
            <configuration>
              <destFile>target/jacoco-it.exec</destFile>
              <skip>${skip.dump}</skip>
              <fileSets>
                <fileSet
                  implementation="org.apache.maven.shared.model.fileset.FileSet">
                  <directory>target</directory>
                  <includes>
                    <include>*it*.exec</include>
                    <include>jacoco.exec</include>
                  </includes>
                </fileSet>
              </fileSets>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <append>true</append>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>3.2.2</version>
          </dependency>
        </dependencies>
      </plugin>
      <plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-jacoco</id>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
            <phase>compile</phase>
            <configuration>
              <includeArtifactIds>org.jacoco.agent</includeArtifactIds>
              <includeClassifiers>runtime</includeClassifiers>
              <outputDirectory>${project.build.directory}/jacoco-agent</outputDirectory>
              <stripVersion>false</stripVersion>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <!-- checks dependencies for vulnerabilities -->
      <plugin>
        <groupId>org.owasp</groupId>
        <artifactId>dependency-check-maven</artifactId>
        <version>7.4.4</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>
          <!-- Am I the latest version? -->
          <versionCheckEnabled>true</versionCheckEnabled>
          <!--suppression Files -->
          <suppressionFiles>src/main/resources/suppressed.xml</suppressionFiles>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>xml-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>transform</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <transformationSets>
            <transformationSet>
              <dir>${project.build.directory}</dir>
              <includes>
                <include>dependency-check-report.xml</include>
              </includes>
              <stylesheet>src/main/resources/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>
          <dependency>
            <groupId>org.owasp</groupId>
            <artifactId>dependency-check-core</artifactId>
            <version>7.4.4</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.sonarsource.scanner.maven</groupId>
          <artifactId>sonar-maven-plugin</artifactId>
          <version>3.9.1.2184</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

</project>
