| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 | #! /bin/sh## This script is intended for rapid checking of the sample application configurations# to ensure they are working. It is for development use only.## To run the web application samples, build them as described on the web site and deploy# them to a servlet container, such as Apache Tomcat.## See http://curl.netmirror.org/docs/httpscripting.html#set -o nounsetset -o errexitROOT_URL="http://localhost:8080"CONTENT=response.txtservlet_path=""cleanup() {  find . -name cookies.txt | xargs rm  find . -name $CONTENT | xargs rm    find . -name runall.log | xargs rm}start_jetty(){  gradle -d jettyRun > runall.log &  until (grep "Started Jetty Server" runall.log)  do    echo "- Waiting for server to start... -"    sleep 3      done}stop_jetty() {  kill $!  until (grep "Jetty server exiting" runall.log)  do    echo "- Waiting for server to stop... -"    sleep 2      done  }get() {    if [ -z "$1" ]                           # Is parameter #1 zero length?    then      echo "- URL argument is required -"      exit -1    else      echo "- GET \"$servlet_path$1\" -"    fi        curl -b cookies.txt -c cookies.txt -i -o $CONTENT "$servlet_path$1"# We don't expect any 50x errors    if grep -q "HTTP/1.1 50" $CONTENT    then      echo "$CONTENT"      exit -1    fi        echo "- Done -"}post() {    if [ $# -ne 2 ]                           # Is parameter #1 zero length?    then      echo "- Parameters and URL argument required -"      exit -1    else      echo "- POST \"$servlet_path$2\" -"    fi    curl -b cookies.txt -c cookies.txt -i -o $CONTENT -d $1 "$servlet_path$2"    echo "- Done -"    }assert() {    if [ -z "$1" ]    then      echo "-'Expected text' argument is required.-"      exit -1          fi        if ! grep -q "$1" $CONTENT    then      echo "- '$1' was not found in response... -"      exit -1    fi}cleanup## Run the tests# cd tutorialservlet_path="$ROOT_URL/tutorial"echo "- Running tutorial app... -"start_jettyget /index.jspassert "Home Page"assert "Your principal object is....: null"get /secure/index.jspassert "HTTP/1.1 302 Found"assert "Location:.*/spring_security_login"get /spring_security_loginassert "Login with Username and Password"get "/j_spring_security_check?j_username=rod&j_password=koala"assert "HTTP/1.1 302 Found"assert "Location:.*/spring_security_login?login_error"get /spring_security_login?login_errorassert "Authentication method not supported: GET"echo "- Logging in as Rod -"post "j_username=rod&j_password=koala" "/j_spring_security_check"assert "HTTP/1.1 302 Found"assert "Location:.*/secure/index.jsp"get /secure/index.jspassert "Secure Page"assert "You are a supervisor!"get "/listAccounts.html"assert "Accounts" # Rod can break his overdraft limitget "/post.html?id=1&amount=-200.00"assert "Accounts"get "/j_spring_security_logout"echo "- Logging in as Peter -"post "j_username=peter&j_password=opal" "/j_spring_security_check"assert "HTTP/1.1 302 Found"assert "Location:.*/tutorial/"# Peter can't do anythingget "/post.html?id=4&amount=-20.00"assert "HTTP/1.1 403 Access is denied"get "/j_spring_security_logout"echo "- Logging in as Dianne -"post "j_username=dianne&j_password=emu" "/j_spring_security_check"# Dianne can't exceed overdraftget "/post.html?id=4&amount=-100.00"assert "Accounts"get "/post.html?id=4&amount=-20.00"assert "HTTP/1.1 403 Access is denied"get "/j_spring_security_logout"stop_jettyecho "- Running contacts app... -"cd ../contactsservlet_path="$ROOT_URL/contacts"start_jettyservlet_path="$ROOT_URL/contacts"get /hello.htmassert "Contacts Security Demo"get /secure/index.htmassert "HTTP/1.1 302 Found"assert "Location:.*/login.jsp"echo "- Logging in as Rod -"post "j_username=rod&j_password=koala" "/j_spring_security_check"assert "HTTP/1.1 302 Found"get /secure/index.htmassert "rod's Contacts"assert "John Smith"get "/secure/del.htm?contactId=1"assert "Deleted"assert "john@somewhere.com"get /secure/index.htmget "/secure/adminPermission.htm?contactId=4"assert "Administer Permissions"get "/secure/addPermission.htm?contactId=4"assert "Add Permission"post "recipient=bill&permission=16" "/secure/addPermission.htm?contactId=4"get "/secure/adminPermission.htm?contactId=4"assert "PrincipalSid\[bill\].*A....=16\]"get /secure/index.htmget "/j_spring_security_logout"stop_jettyecho "- Running ldap app... -"cd ../ldapstart_jettyservlet_path="$ROOT_URL/ldap"get "/"assert "Home Page"get "/secure/"assert "HTTP/1.1 302 Found"assert "Location:.*/spring_security_login"echo "- Logging in as Rod -"post "j_username=rod&j_password=koala" "/j_spring_security_check"assert "HTTP/1.1 302 Found"assert "Location:.*/secure"get "/secure/"assert "Secure Page"get "/j_spring_security_logout"stop_jettyecho "- Running preauth app... -"cd ../preauthservlet_path="$ROOT_URL/preauth"start_jettyget "/"assert "HTTP/1.1 401 Unauthorized"assert "WWW-Authenticate: Basic realm=\"Preauth Realm\""curl -b cookies.txt -c cookies.txt -u rod:koala -i -o $CONTENT "$servlet_path/"assert "Home Page"get "/j_spring_security_logout"stop_jettycd ../casif [[ -e ./server/cas-server-webapp-3.3.5.war ]]then   echo "Found cas server war. Running cas sample"   cd server   mvn jetty:run-war &   SERVERPID=$!   cd ../client   start_jetty   get "/"   assert "Home Page"   get "/secure/index.jsp"   assert "HTTP/1.1 302 Found"   assert "Location: https://localhost:9443/cas/login?service=https%3A%2F%2Flocalhost%3A8443%2Fcas-sample%2Fj_spring_cas_security_check"   get "https://localhost:9443/cas/login?service=https%3A%2F%2Flocalhost%3A8443%2Fcas-sample%2Fj_spring_cas_security_check"   kill $SERVERPID   stop_jettyficd ..cleanup
 |