jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ho-Ki Au <hoki...@gmail.com>
Subject already tried to authenticate..., but still receiving: HTTP/1.1 401 Unauthorized
Date Wed, 20 Jul 2005 09:24:52 GMT
I was trying to write some cactus tests to test an ejb which required
authentication.  The application server used was jboss-4.0.2, with the
tomcat 5 web container.  I followed the instructions documented on the
official cactus web site and created a protected
ServletRedirectorSecure servlet to do it.  When I ran the tests, I got
an error message like:
    [cactus] -----------------------------------------------------------------
    [cactus] Running tests against JBoss 4.0.2
    [cactus] -----------------------------------------------------------------
    [cactus] (httpclient.HttpMethodBase           2543) Already tried
to authenticate with 'localhost:8080' authentication realm at
localhost, but still receiving: HTTP/1.1 401 Unauthorized
    [cactus] (httpclient.HttpMethodBase           2543) Already tried
to authenticate with 'localhost:8080' authentication realm at
localhost, but still receiving: HTTP/1.1 401 Unauthorized
    [cactus] Testsuite: com.saybot.directory.DirectoryTest
    [cactus] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.251 sec
    [cactus] 
    [cactus] Testcase: testBasicAuthentication took 0.2 sec
    [cactus] 	Caused an ERROR
    [cactus] Failed to get the test results at
[http://localhost:8080/directory/ServletRedirectorSecure]
    [cactus] org.apache.cactus.util.ChainedRuntimeException: Failed to
get the test results at
[http://localhost:8080/directory/ServletRedirectorSecure]
    [cactus] 	at
org.apache.cactus.internal.client.connector.http.DefaultHttpClient.doTest_aroundBody0(DefaultHttpClient.java:92)
    [cactus] 	at
org.apache.cactus.internal.client.connector.http.DefaultHttpClient.doTest_aroundBody1$advice(DefaultHttpClient.java:306)
    [cactus] 	at
org.apache.cactus.internal.client.connector.http.DefaultHttpClient.doTest(DefaultHttpClient.java)
    [cactus] 	at
org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runWebTest(HttpProtocolHandler.java:159)
    [cactus] 	at
org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runTest_aroundBody0(HttpProtocolHandler.java:80)
    [cactus] 	at
org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runTest_aroundBody1$advice(HttpProtocolHandler.java:306)
    [cactus] 	at
org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runTest(HttpProtocolHandler.java)
    [cactus] 	at
org.apache.cactus.internal.client.ClientTestCaseCaller.runTest(ClientTestCaseCaller.java:144)
    [cactus] 	at
org.apache.cactus.internal.AbstractCactusTestCase.runBareClient(AbstractCactusTestCase.java:215)
    [cactus] 	at
org.apache.cactus.internal.AbstractCactusTestCase.runBare(AbstractCactusTestCase.java:133)
    [cactus] org.apache.cactus.internal.client.ParsingException: Not a
valid response [401 Unauthorized]
    [cactus] 	at
org.apache.cactus.internal.client.connector.http.DefaultHttpClient.callGetResult(DefaultHttpClient.java:211)
    [cactus] 	at
org.apache.cactus.internal.client.connector.http.DefaultHttpClient.doTest_aroundBody0(DefaultHttpClient.java:87)
    [cactus] 	at
org.apache.cactus.internal.client.connector.http.DefaultHttpClient.doTest_aroundBody1$advice(DefaultHttpClient.java:306)
    [cactus] 	at
org.apache.cactus.internal.client.connector.http.DefaultHttpClient.doTest(DefaultHttpClient.java)
    [cactus] 	at
org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runWebTest(HttpProtocolHandler.java:159)
    [cactus] 	at
org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runTest_aroundBody0(HttpProtocolHandler.java:80)
    [cactus] 	at
org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runTest_aroundBody1$advice(HttpProtocolHandler.java:306)
    [cactus] 	at
org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runTest(HttpProtocolHandler.java)
    [cactus] 	at
org.apache.cactus.internal.client.ClientTestCaseCaller.runTest(ClientTestCaseCaller.java:144)
    [cactus] 	at
org.apache.cactus.internal.AbstractCactusTestCase.runBareClient(AbstractCactusTestCase.java:215)
    [cactus] 	at
org.apache.cactus.internal.AbstractCactusTestCase.runBare(AbstractCactusTestCase.java:133)
    [cactus] 
    [cactus] Testcase: testBasicAuthentication

That was when I used maven to run the test.  I got the same error when
I ran java
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner from shell.

My web.xml was like:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web
Application 2.3//EN"
                         "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
    <filter>
        <filter-name>FilterRedirector</filter-name>
        <filter-class>org.apache.cactus.server.FilterTestRedirector</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>FilterRedirector</filter-name>
        <url-pattern>/test/filterRedirector.jsp</url-pattern>
    </filter-mapping>
    <servlet>
        <servlet-name>ServletRedirector</servlet-name>
        <servlet-class>org.apache.cactus.server.ServletTestRedirector</servlet-class>
    </servlet>
    <servlet>
        <servlet-name>SerletRedirectorSecure</servlet-name>
        <servlet-class>org.apache.cactus.server.ServletTestRedirector</servlet-class>
    </servlet>
    <servlet>
        <servlet-name>JspRedirector</servlet-name>
        <jsp-file>/jspRedirector.jsp</jsp-file>
    </servlet>
    <servlet-mapping>
        <servlet-name>ServletRedirector</servlet-name>
        <url-pattern>/ServletRedirector</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>SerletRedirectorSecure</servlet-name>
        <url-pattern>/ServletRedirectorSecure</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>JspRedirector</servlet-name>
        <url-pattern>/JspRedirector</url-pattern>
    </servlet-mapping>
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Cactus Test Redirector</web-resource-name>
            <url-pattern>/ServletRedirectorSecure</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>User</role-name>
        </auth-constraint>
    </security-constraint>
    <login-config>
        <auth-method>BASIC</auth-method>
    </login-config>
    <security-role>
        <role-name>User</role-name>
    </security-role>
</web-app>

my test was just to test if I could get the principal in the test.  It
didn't even call any ejb:
    public void beginBasicAuthentication(WebRequest request) {
	request.setRedirectorName("ServletRedirectorSecure");
	request.setAuthentication(new BasicAuthentication("tester1",
	"tester1"));
    }

    public void testBasicAuthentication() {
	assertEquals("tester1", request.getUserPrincipal().getName());
	assertEquals("tester1", request.getRemoteUser());
	assertTrue(request.isUserInRole("User"));
    }

Can someone help me with this please?

When I used a browser to go to url
http://localhost:8080/directory/ServletRedirectorSecure?Cactus_Service=RUN_TEST
it popped up a dialog to ask me for username and password.  I entered
"tester1", "tester1", and it went to a blank page.  So that was
correct.  It didn't show me 401 error.

Your help is much appreciated.

-- 
-hoki

Mime
View raw message