// CAS sample build file apply plugin: 'war' apply plugin: 'jetty' apply plugin: 'groovy' def excludeModules = ['spring-security-acl', 'jsr250-api', 'spring-jdbc', 'spring-tx'] def jettyVersion = '7.1.6.v20100715' def keystore = "$rootDir/samples/certificates/server.jks" def password = 'password' configurations { casServer excludeModules.each {name -> runtime.exclude module: name } runtime.exclude group: 'org.aspectj' integrationTestCompile.extendsFrom groovy } sourceSets.integrationTest { groovy.srcDir file('src/integration-test/groovy') } eclipseClasspath { plusConfigurations += configurations.integrationTestRuntime } dependencies { groovy 'org.codehaus.groovy:groovy:1.7.7' casServer "org.jasig.cas:cas-server-webapp:3.4.3.1@war" providedCompile 'javax.servlet:servlet-api:2.5@jar' compile project(':spring-security-core'), project(':spring-security-cas'), "org.jasig.cas.client:cas-client-core:3.1.12" runtime project(':spring-security-web'), project(':spring-security-config'), "org.slf4j:jcl-over-slf4j:$slf4jVersion", "ch.qos.logback:logback-classic:$logbackVersion" integrationTestCompile project(':spring-security-cas'), 'org.seleniumhq.selenium:selenium-htmlunit-driver:2.0a7', 'org.spockframework:spock-core:0.4-groovy-1.7', 'org.codehaus.geb:geb-spock:0.5.1', 'commons-httpclient:commons-httpclient:3.1', "org.eclipse.jetty:jetty-server:$jettyVersion", "org.eclipse.jetty:jetty-servlet:$jettyVersion" } [jettyRun, jettyRunWar]*.configure { contextPath = "/cas-sample" def httpConnector = new org.mortbay.jetty.nio.SelectChannelConnector(); httpConnector.port = 8080 httpConnector.confidentialPort = 8443 def httpsConnector = new org.mortbay.jetty.security.SslSocketConnector(); httpsConnector.port = 8443 httpsConnector.keystore = httpsConnector.truststore = keystore httpsConnector.keyPassword = httpsConnector.trustPassword = password connectors = [httpConnector, httpsConnector] doFirst() { System.setProperty('cas.server.host', casServer.httpsHost) System.setProperty('cas.service.host', jettyRunWar.httpsHost) } } task casServerOverlay(type: Sync) { war = configurations.casServer.resolve().toArray()[0] warName = war.name.replace('.war','-custom') overlayDir = file('src/cas-server-overlay/webapp') explodedWar = file("$buildDir/tmp/${warName}") customWar = file("$buildDir/tmp/${warName}.war") inputs.files(war, overlayDir) outputs.files(customWar, explodedWar, file("$buildDir/tmp/expandedArchives")) from zipTree(war) from overlayDir into explodedWar doLast { if(customWar.exists()) { customWar.delete() } ant.zip(destfile: customWar, baseDir: explodedWar) } } task casServer (type: org.gradle.api.plugins.jetty.JettyRunWar, dependsOn: 'casServerOverlay') { contextPath = "/cas" connectors = [new org.mortbay.jetty.security.SslSocketConnector()] connectors[0].port = 9443 connectors[0].keystore = connectors[0].truststore = keystore connectors[0].keyPassword = connectors[0].trustPassword = password connectors[0].wantClientAuth = true connectors[0].needClientAuth = false webApp = casServerOverlay.customWar inputs.file casServerOverlay.customWar doFirst() { System.setProperty('javax.net.ssl.trustStore', keystore) System.setProperty('javax.net.ssl.trustStorePassword', password) } } task cas (dependsOn: [jettyRunWar, casServer]) { } integrationTest.dependsOn cas integrationTest.doFirst { systemProperties['cas.server.host'] = casServer.httpsHost systemProperties['cas.service.host'] = jettyRunWar.httpsHost systemProperties['jar.path'] = jar.archivePath systemProperties['javax.net.ssl.trustStore'] = keystore systemProperties['javax.net.ssl.trustStorePassword'] = password } gradle.taskGraph.whenReady {graph -> if (graph.hasTask(cas)) { jettyRunWar.dependsOn(casServer) casServer.daemon = true } if(graph.hasTask(integrationTest)) { jettyRunWar.daemon = true jettyRunWar.httpConnector.port = availablePort() jettyRunWar.httpsConnector.port = jettyRunWar.httpConnector.confidentialPort = availablePort() casServer.httpsConnector.port = availablePort() } } [casServer,jettyRunWar]*.metaClass*.getHttpsConnector {-> delegate.connectors.find { it instanceof org.mortbay.jetty.security.SslSocketConnector } } [casServer,jettyRunWar]*.metaClass*.getHttpsHost {-> "localhost:"+delegate.httpsConnector.port } jettyRunWar.metaClass.getHttpConnector {-> delegate.connectors.find { it instanceof org.mortbay.jetty.nio.SelectChannelConnector } } def availablePort() { ServerSocket server = new ServerSocket(0) int port = server.localPort server.close() port }