2
0

runall.sh 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. #! /bin/sh
  2. #
  3. # This script is intended for rapid checking of the sample application configurations
  4. # to ensure they are working. It is for development use only.
  5. #
  6. # To run the web application samples, build them as described on the web site and deploy
  7. # them to a servlet container, such as Apache Tomcat.
  8. #
  9. # See http://curl.netmirror.org/docs/httpscripting.html
  10. #
  11. set -o nounset
  12. set -o errexit
  13. ROOT_URL="http://localhost:8080"
  14. CONTENT=response.txt
  15. servlet_path=""
  16. cleanup() {
  17. find . -name cookies.txt | xargs rm
  18. find . -name $CONTENT | xargs rm
  19. find . -name runall.log | xargs rm
  20. }
  21. start_jetty()
  22. {
  23. gradle -d jettyRun > runall.log &
  24. until (grep "Started Jetty Server" runall.log)
  25. do
  26. echo "- Waiting for server to start... -"
  27. sleep 3
  28. done
  29. }
  30. stop_jetty() {
  31. kill $!
  32. until (grep "Jetty server exiting" runall.log)
  33. do
  34. echo "- Waiting for server to stop... -"
  35. sleep 2
  36. done
  37. }
  38. get() {
  39. if [ -z "$1" ] # Is parameter #1 zero length?
  40. then
  41. echo "- URL argument is required -"
  42. exit -1
  43. else
  44. echo "- GET \"$servlet_path$1\" -"
  45. fi
  46. curl -b cookies.txt -c cookies.txt -i -o $CONTENT "$servlet_path$1"
  47. # We don't expect any 50x errors
  48. if grep -q "HTTP/1.1 50" $CONTENT
  49. then
  50. echo "$CONTENT"
  51. exit -1
  52. fi
  53. echo "- Done -"
  54. }
  55. post() {
  56. if [ $# -ne 2 ] # Is parameter #1 zero length?
  57. then
  58. echo "- Parameters and URL argument required -"
  59. exit -1
  60. else
  61. echo "- POST \"$servlet_path$2\" -"
  62. fi
  63. curl -b cookies.txt -c cookies.txt -i -o $CONTENT -d $1 "$servlet_path$2"
  64. echo "- Done -"
  65. }
  66. assert() {
  67. if [ -z "$1" ]
  68. then
  69. echo "-'Expected text' argument is required.-"
  70. exit -1
  71. fi
  72. if ! grep -q "$1" $CONTENT
  73. then
  74. echo "- '$1' was not found in response... -"
  75. exit -1
  76. fi
  77. }
  78. cleanup
  79. #
  80. # Run the tests
  81. #
  82. cd tutorial
  83. servlet_path="$ROOT_URL/tutorial"
  84. echo "- Running tutorial app... -"
  85. start_jetty
  86. get /index.jsp
  87. assert "Home Page"
  88. assert "Your principal object is....: null"
  89. get /secure/index.jsp
  90. assert "HTTP/1.1 302 Found"
  91. assert "Location:.*/spring_security_login"
  92. get /spring_security_login
  93. assert "Login with Username and Password"
  94. get "/j_spring_security_check?j_username=rod&j_password=koala"
  95. assert "HTTP/1.1 302 Found"
  96. assert "Location:.*/spring_security_login?login_error"
  97. get /spring_security_login?login_error
  98. assert "Authentication method not supported: GET"
  99. echo "- Logging in as Rod -"
  100. post "j_username=rod&j_password=koala" "/j_spring_security_check"
  101. assert "HTTP/1.1 302 Found"
  102. assert "Location:.*/secure/index.jsp"
  103. get /secure/index.jsp
  104. assert "Secure Page"
  105. assert "You are a supervisor!"
  106. get "/listAccounts.html"
  107. assert "Accounts"
  108. # Rod can break his overdraft limit
  109. get "/post.html?id=1&amount=-200.00"
  110. assert "Accounts"
  111. get "/j_spring_security_logout"
  112. echo "- Logging in as Peter -"
  113. post "j_username=peter&j_password=opal" "/j_spring_security_check"
  114. assert "HTTP/1.1 302 Found"
  115. assert "Location:.*/tutorial/"
  116. # Peter can't do anything
  117. get "/post.html?id=4&amount=-20.00"
  118. assert "HTTP/1.1 403 Access is denied"
  119. get "/j_spring_security_logout"
  120. echo "- Logging in as Dianne -"
  121. post "j_username=dianne&j_password=emu" "/j_spring_security_check"
  122. # Dianne can't exceed overdraft
  123. get "/post.html?id=4&amount=-100.00"
  124. assert "Accounts"
  125. get "/post.html?id=4&amount=-20.00"
  126. assert "HTTP/1.1 403 Access is denied"
  127. get "/j_spring_security_logout"
  128. stop_jetty
  129. echo "- Running contacts app... -"
  130. cd ../contacts
  131. servlet_path="$ROOT_URL/contacts"
  132. start_jetty
  133. servlet_path="$ROOT_URL/contacts"
  134. get /hello.htm
  135. assert "Contacts Security Demo"
  136. get /secure/index.htm
  137. assert "HTTP/1.1 302 Found"
  138. assert "Location:.*/login.jsp"
  139. echo "- Logging in as Rod -"
  140. post "j_username=rod&j_password=koala" "/j_spring_security_check"
  141. assert "HTTP/1.1 302 Found"
  142. get /secure/index.htm
  143. assert "rod's Contacts"
  144. assert "John Smith"
  145. get "/secure/del.htm?contactId=1"
  146. assert "Deleted"
  147. assert "john@somewhere.com"
  148. get /secure/index.htm
  149. get "/secure/adminPermission.htm?contactId=4"
  150. assert "Administer Permissions"
  151. get "/secure/addPermission.htm?contactId=4"
  152. assert "Add Permission"
  153. post "recipient=bill&permission=16" "/secure/addPermission.htm?contactId=4"
  154. get "/secure/adminPermission.htm?contactId=4"
  155. assert "PrincipalSid\[bill\].*A....=16\]"
  156. get /secure/index.htm
  157. get "/j_spring_security_logout"
  158. stop_jetty
  159. echo "- Running ldap app... -"
  160. cd ../ldap
  161. start_jetty
  162. servlet_path="$ROOT_URL/ldap"
  163. get "/"
  164. assert "Home Page"
  165. get "/secure/"
  166. assert "HTTP/1.1 302 Found"
  167. assert "Location:.*/spring_security_login"
  168. echo "- Logging in as Rod -"
  169. post "j_username=rod&j_password=koala" "/j_spring_security_check"
  170. assert "HTTP/1.1 302 Found"
  171. assert "Location:.*/secure"
  172. get "/secure/"
  173. assert "Secure Page"
  174. get "/j_spring_security_logout"
  175. stop_jetty
  176. echo "- Running preauth app... -"
  177. cd ../preauth
  178. servlet_path="$ROOT_URL/preauth"
  179. start_jetty
  180. get "/"
  181. assert "HTTP/1.1 401 Unauthorized"
  182. assert "WWW-Authenticate: Basic realm=\"Preauth Realm\""
  183. curl -b cookies.txt -c cookies.txt -u rod:koala -i -o $CONTENT "$servlet_path/"
  184. assert "Home Page"
  185. get "/j_spring_security_logout"
  186. stop_jetty
  187. cd ../cas
  188. if [[ -e ./server/cas-server-webapp-3.3.5.war ]]
  189. then
  190. echo "Found cas server war. Running cas sample"
  191. cd server
  192. mvn jetty:run-war &
  193. SERVERPID=$!
  194. cd ../client
  195. start_jetty
  196. get "/"
  197. assert "Home Page"
  198. get "/secure/index.jsp"
  199. assert "HTTP/1.1 302 Found"
  200. assert "Location: https://localhost:9443/cas/login?service=https%3A%2F%2Flocalhost%3A8443%2Fcas-sample%2Fj_spring_cas_security_check"
  201. get "https://localhost:9443/cas/login?service=https%3A%2F%2Flocalhost%3A8443%2Fcas-sample%2Fj_spring_cas_security_check"
  202. kill $SERVERPID
  203. stop_jetty
  204. fi
  205. cd ..
  206. cleanup