Return-Path: Delivered-To: apmail-jakarta-cactus-user-archive@www.apache.org Received: (qmail 21163 invoked from network); 8 Jan 2009 08:00:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 8 Jan 2009 08:00:23 -0000 Received: (qmail 88091 invoked by uid 500); 8 Jan 2009 08:00:23 -0000 Delivered-To: apmail-jakarta-cactus-user-archive@jakarta.apache.org Received: (qmail 87799 invoked by uid 500); 8 Jan 2009 08:00:22 -0000 Mailing-List: contact cactus-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Cactus Users List" Reply-To: "Cactus Users List" Delivered-To: mailing list cactus-user@jakarta.apache.org Received: (qmail 87787 invoked by uid 99); 8 Jan 2009 08:00:22 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Jan 2009 00:00:22 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [203.11.83.254] (HELO mail1.ardec.com.au) (203.11.83.254) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Jan 2009 08:00:15 +0000 Received: from optimus.ms.a2end.com (optimus.adl.ardec.com.au [192.168.1.70]) by mail1.ardec.com.au (8.14.1/8.14.1) with ESMTP id n087xoYU024899 for ; Thu, 8 Jan 2009 18:29:51 +1030 (CST) Received: from optimus.ms.a2end.com ([192.168.1.70]) by optimus.ms.a2end.com ([192.168.1.70]) with mapi; Thu, 8 Jan 2009 18:29:50 +1030 From: Nicole Luneburg To: Cactus Users List Date: Thu, 8 Jan 2009 18:29:47 +1030 Subject: RE: How to set user principal in setUp() Thread-Topic: How to set user principal in setUp() Thread-Index: AclwqJQQTDQnJuakR+uiP/dXiYkq2wAu2SSA Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Virus-Scanned: ClamAV 0.92/8842/Thu Jan 8 00:36:50 2009 on mizaru.adl.ardec.com.au X-Virus-Status: Clean X-SMTP-Vilter-Version: 1.3.6 X-Spamd-Symbols: ALL_TRUSTED,AWL,BAYES_00 X-SMTP-Vilter-Spam-Backend: spamd X-Spam-Score: -4.4 X-Spam-Threshold: 5.0 X-Spam-Probability: -0.9 X-Virus-Checked: Checked by ClamAV on apache.org Hi Petar, Thanks once again for your reply. I thought I would spend today trying to resolve my issues before I responde= d ... So I've stripped all my code (commented out, rather!!!) so see what you wer= e referring to below. (I should have seen that here: http://jakarta.apache.org/cactus/how_it_work= s.html . sorry, i've been reading so much on the net for days that docos ha= ve begun melting in front of me!) Ok so I understand what you said about the Authentication object. I thought I was doing that with the WebRequest? (see below) I hope I'm not taking up too much of yours or anyone else's time :( I'm really stuck! Before I explain what I have, just a quick word on how I run my test. I create my ear file and deploy that to JBoss. I cactify my project war and deploy that to JBoss. I then run my test through my web browser by accessing: http://localhost:8080/myapp/ServletTestRunner?suite=3DMyAppTestSuite (I know the docs somewhere say to do it other ways, but I can't even get th= at far!) So this is what I have: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D cactus.properties: cactus.contextURL=3Dhttp://localhost:8080/myapp cactus.port=3D8080 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D build.xml: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D MyAppTestSuite.java: public class MyAppTestSuite extends junit.framework.TestCase { public static Test suite() { final junit.framework.TestSuite suite =3D new junit.framewo= rk.TestSuite (); suite.addTestSuite(MyTest.class); return suite; } } =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D MyTest.java: public class MyTest extends org.apache.cactus.ServletTestCase { public void begin(WebRequest theRequest) { theRequest.setRedirectorName("ServletRedirectorSecure"); theRequest.setAuthentication(new FormAuthentication("admin1", "= admin1")); } public void setUp() throws Exception { Context context =3D new InitialContext(); MyEJB3ServiceBean myService =3D (MyEJB3ServiceBean) context= .lookup(...); If(myService.checkPermissions()) { //IT FAILS RIGHT HERE!!!= !!!!!!!!!!!!!!! //do something } } public void tearDown() throws Exception { //no code } } =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D MyEJB3ServiceBean.java: @Stateless public class MyEJB3ServiceBean { @Resource protected SessionContext context; public boolean checkPermissions () { if(this.context.getCallerPrincipal().getName() =3D=3D "admi= n1") { return true; } else { return false; } } } =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D I can see through some log info statements that it does it exactly in the s= equence you specified: begin ... setUp ... tearDown ... (I didn't specify an endXXX method) So you see my dilemma, my test fails because I need to check who is logged = in (with that getCallerPrincipal() ... call) But in able to do that, I need to log someone in, namely "admin1" as seen i= n my begin method. I thought I could "log" someone in by using the WebRequest in the beginXXX = method. I am obviously doing this wrong, but I am really at a dead end as to how I = am to go about this ... I hope my problem makes more sense :( Thnks again, nic -----Original Message----- From: Petar Tahchiev [mailto:paranoiabla@gmail.com] Sent: Wednesday, 7 January 2009 7:45 PM To: Cactus Users List Subject: Re: How to set user principal in setUp() Hi Nicole, I think you misunderstand the purpose of Cactus. Your test will always be executed in the server side. This means that the testXXX methods are executed on the server side. You can, however, execute two methods - beginXXX and endXXX on the client side. This means the execution flow would be this: beginXXX() - >client side startUp() -> serverside testXXX() -> serverside tearDown() ->serverside endXXX() -> client side. If you see the documentation of the WebRequest (the one you use in beginXXX methods) there is no set-up for a caller principal. You can, however setup an Authentication object. HTH, Petar. The contents of this email are confidential and may be subject to legal or = professional privilege and copyright. No representation is made that this e= mail is free of viruses or other defects. If you have received this communi= cation in error, you may not copy or distribute any part of it or otherwise= disclose its contents to anyone. Please advise the sender of your incorrec= t receipt of this correspondence. --------------------------------------------------------------------- To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: cactus-user-help@jakarta.apache.org