apply plugin: 'io.spring.convention.spring-sample-war'

def keystore = "$rootDir/samples/certificates/server.jks"
def password = 'password'

dependencies {
	compile project(':spring-security-cas')
	compile project(':spring-security-core')
	compile 'org.jasig.cas.client:cas-client-core'

	providedCompile 'javax.servlet:javax.servlet-api'

	runtime project(':spring-security-config')
	runtime project(':spring-security-web')
	runtime 'ch.qos.logback:logback-classic'
	runtime 'net.sf.ehcache:ehcache'
	runtime 'org.slf4j:jcl-over-slf4j'
	runtime 'org.springframework:spring-context-support'

	integrationTestCompile project(':spring-security-cas')
	integrationTestCompile seleniumDependencies
	integrationTestCompile 'org.eclipse.jetty:jetty-server'
	integrationTestCompile 'org.eclipse.jetty:jetty-servlet'
	integrationTestCompile 'org.slf4j:jcl-over-slf4j'
}

integrationTest {
	dependsOn { casServer().tasks.appBeforeIntegrationTest }
	doFirst {
		def casServiceHost = 'localhost:' + gretty.httpsPort
		def casServerHost = 'localhost:' + casServer().gretty.httpsPort
		systemProperties['cas.server.host'] = casServerHost
		systemProperties['cas.service.host'] = casServiceHost
		systemProperties['jar.path'] = jar.archivePath
		systemProperties['javax.net.ssl.trustStore'] = keystore
		systemProperties['javax.net.ssl.trustStorePassword'] = password
	}
	finalizedBy { casServer().tasks.appAfterIntegrationTest }
}

prepareAppServerForIntegrationTests {
	dependsOn { casServer().tasks.appBeforeIntegrationTest }
	doLast {
		def casServiceHost = 'localhost:' + project.gretty.httpsPort
		def casServerHost = 'localhost:' + casServer().gretty.httpsPort
		gretty.jvmArgs += ["-Dcas.server.host=${casServerHost}", "-Dcas.service.host=${casServiceHost}"]
	}
}

gretty {
	contextPath = '/cas-sample/'
	httpsEnabled = true
	httpsPort = 8443
	sslKeyStorePath = keystore
	sslKeyStorePassword = password
	jvmArgs = ["-Djavax.net.ssl.trustStore=${keystore}", "-Djavax.net.ssl.trustStorePassword=${password}"]
}

def casServer() {
	project(':spring-security-samples-xml-casserver')
}
