<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>
  <parent>
    <groupId>org.dataconservancy.pass</groupId>
    <artifactId>pass-authz</artifactId>
    <version>0.3.0</version>
  </parent>
  <artifactId>pass-authz-integration</artifactId>

  <properties>
    <fcrepo.cxtPath>fcrepo</fcrepo.cxtPath>
    <FCREPO_HOST>localhost</FCREPO_HOST>
    <ES_HOST>localhost</ES_HOST>
    <activemq.user>messaging</activemq.user>
    <activemq.password>moo</activemq.password>
    <pass.user.token.key>BETKPFHWGGDIEWIIYKYQ33LUS4</pass.user.token.key>
  </properties>


  <profiles>
    <profile>
      <id>standard</id>
      <properties>
        <ES_PORT>9200</ES_PORT>
        <FCREPO_PORT>8080</FCREPO_PORT>
        <JMS_PORT>61616</JMS_PORT>
        <STOMP_PORT>61613</STOMP_PORT>
      </properties>
    </profile>
  </profiles>


  <build>
    <plugins>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.1.0</version>
        <executions>
          <execution>
            <id>copy</id>
            <phase>process-test-resources</phase>
            <goals>
              <goal>copy</goal>
            </goals>
          </execution>
          <execution>
            <goals>
              <goal>properties</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <artifactItems>
            <artifactItem>
              <groupId>org.dataconservancy.pass</groupId>
              <artifactId>pass-authz-core</artifactId>
              <version>${project.version}</version>
              <type>jar</type>
              <overWrite>false</overWrite>
              <classifier>shaded</classifier>
              <outputDirectory>${project.build.testOutputDirectory}/docker</outputDirectory>
              <destFileName>pass-authz-core-shaded.jar</destFileName>
            </artifactItem>
            <artifactItem>
              <groupId>org.dataconservancy.pass</groupId>
              <artifactId>pass-user-service</artifactId>
              <version>${project.version}</version>
              <type>war</type>
              <overWrite>false</overWrite>
              <outputDirectory>${project.build.testOutputDirectory}/docker</outputDirectory>
              <destFileName>pass-user-service.war</destFileName>
            </artifactItem>
            <artifactItem>
              <groupId>org.dataconservancy.pass</groupId>
              <artifactId>pass-authz-roles</artifactId>
              <version>${project.version}</version>
              <type>jar</type>
              <overWrite>false</overWrite>
              <outputDirectory>${project.build.testOutputDirectory}/docker</outputDirectory>
              <destFileName>pass-authz-roles.jar</destFileName>
            </artifactItem>
          </artifactItems>
          <outputDirectory>${project.build.directory}/wars</outputDirectory>
          <overWriteReleases>false</overWriteReleases>
          <overWriteSnapshots>true</overWriteSnapshots>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>reserve-port</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>reserve-network-port</goal>
            </goals>
            <configuration>
              <portNames>
                <portName>FCREPO_PORT</portName>
                <portName>JMS_PORT</portName>
                <portName>STOMP_PORT</portName>
                <portName>ES_PORT</portName>
              </portNames>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <systemPropertyVariables>
            <FCREPO_PORT>${FCREPO_PORT}</FCREPO_PORT>
            <fcrepo.cxtPath>${fcrepo.cxtPath}</fcrepo.cxtPath>
            <project.basedir>${project.basedir}</project.basedir>
            <pass.fedora.baseurl>http://${FCREPO_HOST}:${FCREPO_PORT}/fcrepo/rest/</pass.fedora.baseurl>
            <pass.elasticsearch.url>http://${ES_HOST}:${ES_PORT}</pass.elasticsearch.url>
            <jms.brokerUrl>failover:(tcp://localhost:${JMS_PORT})?trackMessages=true</jms.brokerUrl>
            <authz.listener.jar>${org.dataconservancy.pass:pass-authz-listener:jar:exe}</authz.listener.jar>
            <authz.containerPermissions.jar>${org.dataconservancy.pass:pass-authz-tools:jar:container-permissions-exe}</authz.containerPermissions.jar>
            <pass.authz.queue>Consumer.authz.VirtualTopic.pass.authz</pass.authz.queue>
            <jms.username>${activemq.user}</jms.username>
            <jms.password>${activemq.password}</jms.password>
            <pass.backend.role>http://oapass.org/ns/roles/johnshopkins.edu#pass-backend</pass.backend.role>
            <pass.grantadmin.role>http://oapass.org/ns/roles/johnshopkins.edu#admin</pass.grantadmin.role>
            <pass.submitter.role>http://oapass.org/ns/roles/johnshopkins.edu#submitter</pass.submitter.role>
            <pass.user.token.key>${pass.user.token.key}</pass.user.token.key>
          </systemPropertyVariables>
        </configuration>
      </plugin>

      <plugin>
        <groupId>io.fabric8</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <configuration>
          <autoCreateCustomNetworks>true</autoCreateCustomNetworks>
          <autoPull>true</autoPull>
          <images>

            <image>
              <alias>activemq</alias>
              <name>oapass/activemq:20180618</name>
              <run>
                <namingStrategy>alias</namingStrategy>
                <ports>
                  <port>${JMS_PORT}:61616</port>
                  <port>${STOMP_PORT}:61613</port>
                </ports>
                <network>
                  <mode>custom</mode>
                  <name>pass</name>
                  <alias>activemq</alias>
                </network>
              </run>
            </image>

            <image>
              <alias>indexer</alias>
              <name>oapass/indexer:0.0.15-3.1-SNAPSHOT</name>
              <run>
                <namingStrategy>alias</namingStrategy>
                <env>
                  <PI_FEDORA_USER>fedoraAdmin</PI_FEDORA_USER>
                  <PI_FEDORA_PASS>moo</PI_FEDORA_PASS>
                  <PI_FEDORA_INTERNAL_BASE>http://${FCREPO_HOST}:${FCREPO_PORT}/fcrepo/rest/</PI_FEDORA_INTERNAL_BASE>
                  <PI_ES_BASE>http://elasticsearch:9200/</PI_ES_BASE>
                  <PI_ES_INDEX>http://elasticsearch:9200/pass/</PI_ES_INDEX>
                  <PI_FEDORA_JMS_QUEUE>Consumer.indexer.VirtualTopic.pass.authz</PI_FEDORA_JMS_QUEUE>
                  <PI_TYPE_PREFIX>http://oapass.org/ns/pass#</PI_TYPE_PREFIX>
                  <PI_LOG_LEVEL>DEBUG</PI_LOG_LEVEL>
                  <SPRING_ACTIVEMQ_BROKER_URL>failover:(tcp://activemq:61616)?trackMessages=true</SPRING_ACTIVEMQ_BROKER_URL>
                  <SPRING_ACTIVEMQ_USER>${activemq.user}</SPRING_ACTIVEMQ_USER>
                  <SPRING_ACTIVEMQ_PASSWORD>${activemq.password}</SPRING_ACTIVEMQ_PASSWORD>
                </env>
                <links>
                  <link>fcrepo:localhost</link>
                  <link>elasticsearch</link>
                </links>
                <volumes>
                  <bind>./src/test/resources/docker/hosts:/etc/hosts</bind>
                </volumes>
                <network>
                  <mode>custom</mode>
                  <name>pass</name>
                  <alias>indexer</alias>
                </network>
                <dependsOn>
                  <container>activemq</container>
                  <container>fcrepo</container>
                  <container>elasticsearch</container>
                </dependsOn>
                <wait>
                  <time>10000</time>
                </wait>
              </run>
            </image>

            <image>
              <alias>fcrepo</alias>
              <name>oapass/pass-authz-fcrepo:${project.version}</name>
              <build>
                <dockerFileDir>${project.build.testOutputDirectory}/docker</dockerFileDir>
              </build>
              <run>
                <hostname>fcrepo</hostname>
                <namingStrategy>alias</namingStrategy>
                <env>
                  <LOG_org_dataconservancy>DEBUG</LOG_org_dataconservancy>
                  <FCREPO_AUTH_LOG_LEVEL>DEBUG</FCREPO_AUTH_LOG_LEVEL>
                  <FCREPO_HOST>${FCREPO_HOST}</FCREPO_HOST>
                  <FCREPO_PORT>${FCREPO_PORT}</FCREPO_PORT>
                  <FCREPO_JMS_BASEURL>http://${FCREPO_HOST}:${FCREPO_PORT}/fcrepo/rest</FCREPO_JMS_BASEURL>
                  <PASS_FEDORA_BASEURL>http://localhost:${FCREPO_PORT}/fcrepo/rest/</PASS_FEDORA_BASEURL>
                  <PASS_ELASTICSEARCH_URL>http://elasticsearch:9200</PASS_ELASTICSEARCH_URL>
                  <PASS_FEDORA_USER>fedoraAdmin</PASS_FEDORA_USER>
                  <PASS_FEDORA_PASSWORD>moo</PASS_FEDORA_PASSWORD>
                  <PASS_USER_TOKEN_KEY>${pass.user.token.key}</PASS_USER_TOKEN_KEY>
                  <AUTHZ_SHIB_USE_HEADERS>true</AUTHZ_SHIB_USE_HEADERS>
                  <AUTHZ_ALLOW_EXTERNAL_ROLES>true</AUTHZ_ALLOW_EXTERNAL_ROLES>
                  <FCREPO_JMS_CONFIGURATION>classpath:/pass-jms-external.xml</FCREPO_JMS_CONFIGURATION>
                  <FCREPO_JMS_DESTINATION>VirtualTopic.pass.authz</FCREPO_JMS_DESTINATION>
                  <SPRING_ACTIVEMQ_BROKER_URL>failover:(tcp://activemq:61616)?trackMessages=true</SPRING_ACTIVEMQ_BROKER_URL>
                  <SPRING_ACTIVEMQ_USER>messaging</SPRING_ACTIVEMQ_USER>
                  <SPRING_ACTIVEMQ_PASSWORD>moo</SPRING_ACTIVEMQ_PASSWORD>
                </env>
                <ports>
                  <port>${FCREPO_PORT}:${FCREPO_PORT}</port>
                </ports>
                <network>
                  <mode>custom</mode>
                  <name>pass</name>
                  <alias>fcrepo</alias>
                  <alias>localhost</alias>
                </network>
                <wait>
                  <http>
                    <url>http://fedoraAdmin:moo@${FCREPO_HOST}:${FCREPO_PORT}/fcrepo/rest</url>
                  </http>
                  <time>120000</time>
                </wait>
                <dependsOn>
                  <container>activemq</container>
                </dependsOn>
              </run>
            </image>

            <image>
              <alias>elasticsearch</alias>
              <name>docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.3</name>
              <run>
                <namingStrategy>alias</namingStrategy>
                <env>
                  <discovery.type>single-node</discovery.type>
                  <bootstrap.memory_lock>true</bootstrap.memory_lock>
                  <ES_JAVA_OPTS>-Xms512m -Xmx512m</ES_JAVA_OPTS>
                </env>
                <ports>
                  <port>${ES_PORT}:9200</port>
                </ports>
                <network>
                  <mode>custom</mode>
                  <name>pass</name>
                  <alias>elasticsearch</alias>
                </network>
                <wait>
                  <http>
                    <url>http://${ES_HOST}:${ES_PORT}/</url>
                  </http>
                  <time>120000</time>
                </wait>
              </run>
            </image>

          </images>
        </configuration>
        <executions>
          <execution>
            <id>build-image</id>
            <phase>package</phase>
            <goals>
              <goal>build</goal>
            </goals>
          </execution>
          <execution>
            <id>start-docker-its</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>start</goal>
            </goals>
          </execution>
          <execution>
            <id>stop-docker-its</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>stop</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>

    <testResources>
      <testResource>
        <directory>src/test/resources</directory>
        <filtering>true</filtering>
      </testResource>
    </testResources>
  </build>

  <dependencies>

    <dependency>
      <groupId>org.dataconservancy.pass</groupId>
      <artifactId>pass-authz-core</artifactId>
      <version>${project.version}</version>
      <classifier>shaded</classifier>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.dataconservancy.pass</groupId>
      <artifactId>pass-authz-acl</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.dataconservancy.pass</groupId>
      <artifactId>pass-user-service</artifactId>
      <version>${project.version}</version>
      <type>war</type>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.dataconservancy.pass</groupId>
      <artifactId>pass-authz-roles</artifactId>
      <version>${project.version}</version>
      <type>jar</type>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.dataconservancy.pass</groupId>
      <artifactId>pass-authz-tools</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.dataconservancy.pass</groupId>
      <artifactId>pass-authz-listener</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
      <classifier>exe</classifier>
    </dependency>

    <dependency>
      <groupId>org.dataconservancy.pass</groupId>
      <artifactId>pass-authz-tools</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
      <classifier>container-permissions-exe</classifier>
    </dependency>
    
    <dependency>
      <groupId>org.dataconservancy.pass</groupId>
      <artifactId>pass-authz-usertoken</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.dataconservancy.fcrepo</groupId>
      <artifactId>jsonld-addon-filters</artifactId>
      <version>0.0.6</version>
      <classifier>shaded</classifier>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.fcrepo</groupId>
      <artifactId>fcrepo-webapp</artifactId>
      <type>war</type>
      <version>${fcrepo.version}</version>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <groupId>*</groupId>
          <artifactId>*</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>org.dataconservancy.pass</groupId>
      <artifactId>pass-data-client</artifactId>
    </dependency>

    <dependency>
      <groupId>com.squareup.okhttp3</groupId>
      <artifactId>okhttp</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <scope>test</scope>
    </dependency>

  </dependencies>
</project>
