morgand 01/08/21 14:09:15 Modified: latka/conf suite.dtd latka/doc TestLatka.xml latka/src/java/org/apache/commons/latka/http Request.java RequestImpl.java latka/src/java/org/apache/commons/latka/xml RequestHandler.java latka/src/test-webapp/WEB-INF web.xml Added: latka/src/test-webapp/basicAuth Login.jsp Log: added basic authentication Revision Changes Path 1.12 +4 -2 jakarta-commons/latka/conf/suite.dtd Index: suite.dtd =================================================================== RCS file: /home/cvs/jakarta-commons/latka/conf/suite.dtd,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- suite.dtd 2001/08/21 17:08:19 1.11 +++ suite.dtd 2001/08/21 21:09:15 1.12 @@ -19,7 +19,7 @@ <!ATTLIST session sessionId CDATA #IMPLIED label CDATA #IMPLIED> -<!ELEMENT request (requestHeader*, param*, validate?)> +<!ELEMENT request (credentials?, requestHeader*, param*, validate?)> <!ATTLIST request path CDATA #REQUIRED method (post | get | head) "get" secure (true | false) "false" @@ -28,7 +28,9 @@ label CDATA #IMPLIED followRedirects (true | false) "true"> -<!-- basic authentication credentials are not supported for now --> +<!ELEMENT credentials EMPTY> +<!ATTLIST credentials userName CDATA #REQUIRED + password CDATA #REQUIRED> <!ELEMENT requestHeader EMPTY> <!ATTLIST requestHeader headerName CDATA #REQUIRED 1.2 +37 -0 jakarta-commons/latka/doc/TestLatka.xml Index: TestLatka.xml =================================================================== RCS file: /home/cvs/jakarta-commons/latka/doc/TestLatka.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- TestLatka.xml 2001/08/21 19:27:08 1.1 +++ TestLatka.xml 2001/08/21 21:09:15 1.2 @@ -54,4 +54,41 @@ </session> + <!-- end header checks --> + + <!-- start basic auth checks --> + + <!-- + does not work. HttpClient throws an exception rather than returning a 401 + seems wrong, because unauthorized ne error + --> + <request path="/latka-test/basicAuth/Login.jsp" label="not logged in"> + <validate> + <statusCode code="401" label="Without credentials, status code should be 401"/> + </validate> + </request> + + <!-- + in order for these tests to succeed, you must configure the latka roles + and MisterSmiley user in your servlet container. For tomcat, this is: + <user name="MisterSmiley" password="smiley!1" roles="latka-auth" /> + why doesn't this work? + --> + <session> + <request path="/latka-test/basicAuth/Login.jsp" label="logged in"> + <credentials userName="Mister Smiley" password="smiley!1" /> + <validate> + <regexp pattern="Logged in"/> + </validate> + </request> + + <request path="/latka-test/basicAuth/Login.jsp" label="cached credentials"> + <validate> + <regexp pattern="Logged in" label="should still be logged in"/> + </validate> + </request> + </session> + + <!-- end basic auth checks --> + </suite> 1.6 +8 -0 jakarta-commons/latka/src/java/org/apache/commons/latka/http/Request.java Index: Request.java =================================================================== RCS file: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/http/Request.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Request.java 2001/08/21 16:28:45 1.5 +++ Request.java 2001/08/21 21:09:15 1.6 @@ -87,4 +87,12 @@ * @return time it took to execute the request in millis */ public int getRequestTiming(); + + /** + * Sets the credentials for this request. + * + * @param userName + * @param password + */ + public void setCredentials(String userName, String password); } 1.8 +4 -0 jakarta-commons/latka/src/java/org/apache/commons/latka/http/RequestImpl.java Index: RequestImpl.java =================================================================== RCS file: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/http/RequestImpl.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- RequestImpl.java 2001/08/21 16:28:46 1.7 +++ RequestImpl.java 2001/08/21 21:09:15 1.8 @@ -7,6 +7,7 @@ import java.util.Date; import java.util.Iterator; +import org.apache.commons.httpclient.Credentials; import org.apache.commons.httpclient.State; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.methods.GetMethod; @@ -84,6 +85,9 @@ // Request Interface Methods // /////////////////////////////// + public void setCredentials(String userName, String password) { + _session._state.setDefaultCredentials(new Credentials(userName,password)); + } /** * Execute this HTTP request. 1.9 +2 -0 jakarta-commons/latka/src/java/org/apache/commons/latka/xml/RequestHandler.java Index: RequestHandler.java =================================================================== RCS file: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/xml/RequestHandler.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- RequestHandler.java 2001/08/21 16:30:45 1.8 +++ RequestHandler.java 2001/08/21 21:09:15 1.9 @@ -92,6 +92,8 @@ _listener.requestSkipped(new RequestSkippedEvent(_request,null)); log.info("request skipped"); } + } else if (localName.equals("credentials")) { + _request.setCredentials(atts.getValue("userName"),atts.getValue("password")); } else if (localName.equals("requestHeader")) { log.info("adding request headers"); RequestHeaderHandler headerHandler = new RequestHeaderHandler(_reader,_request); 1.2 +19 -0 jakarta-commons/latka/src/test-webapp/WEB-INF/web.xml Index: web.xml =================================================================== RCS file: /home/cvs/jakarta-commons/latka/src/test-webapp/WEB-INF/web.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- web.xml 2001/08/21 19:27:08 1.1 +++ web.xml 2001/08/21 21:09:15 1.2 @@ -6,4 +6,23 @@ <web-app> + <!-- if you want to test basic auth, you have to set it up the latka-auth + role in your servlet container's security interface --> + <security-constraint> + <web-resource-collection> + <web-resource-name>Protected Area</web-resource-name> + <!-- Define the context-relative URL(s) to be protected --> + <url-pattern>/basicAuth/*</url-pattern> + </web-resource-collection> + <auth-constraint> + <!-- Anyone with one of the listed roles may access this area --> + <role-name>latka-auth</role-name> + </auth-constraint> + </security-constraint> + + <login-config> + <auth-method>BASIC</auth-method> + <realm-name>latka-realm</realm-name> + </login-config> + </web-app> 1.1 jakarta-commons/latka/src/test-webapp/basicAuth/Login.jsp Index: Login.jsp =================================================================== Logged in