Return-Path: Delivered-To: apmail-openejb-users-archive@www.apache.org Received: (qmail 37193 invoked from network); 8 Feb 2011 12:06:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 8 Feb 2011 12:06:11 -0000 Received: (qmail 95524 invoked by uid 500); 8 Feb 2011 12:06:10 -0000 Delivered-To: apmail-openejb-users-archive@openejb.apache.org Received: (qmail 95339 invoked by uid 500); 8 Feb 2011 12:06:08 -0000 Mailing-List: contact users-help@openejb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openejb.apache.org Delivered-To: mailing list users@openejb.apache.org Received: (qmail 95328 invoked by uid 99); 8 Feb 2011 12:06:07 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Feb 2011 12:06:07 +0000 X-ASF-Spam-Status: No, hits=3.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_NEUTRAL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [209.85.216.48] (HELO mail-qw0-f48.google.com) (209.85.216.48) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Feb 2011 12:05:59 +0000 Received: by qwe4 with SMTP id 4so4156226qwe.35 for ; Tue, 08 Feb 2011 04:05:37 -0800 (PST) MIME-Version: 1.0 Received: by 10.229.221.17 with SMTP id ia17mr12061472qcb.6.1297166737445; Tue, 08 Feb 2011 04:05:37 -0800 (PST) Received: by 10.229.250.15 with HTTP; Tue, 8 Feb 2011 04:05:37 -0800 (PST) X-Originating-IP: [70.81.2.208] In-Reply-To: <1297160656820-3275679.post@n4.nabble.com> References: <1296717849351-3257408.post@n4.nabble.com> <1296744081018-3258218.post@n4.nabble.com> <1296833876039-3260388.post@n4.nabble.com> <1297160656820-3275679.post@n4.nabble.com> Date: Tue, 8 Feb 2011 08:05:37 -0400 Message-ID: Subject: Re: JUnit: Sessioncontext.isCallerInRole allways returns false From: Thiago Veronezi To: users@openejb.apache.org Content-Type: multipart/alternative; boundary=001636284298999307049bc42acc X-Virus-Checked: Checked by ClamAV on apache.org --001636284298999307049bc42acc Content-Type: text/plain; charset=ISO-8859-1 Hi! It seems that you just found a bug. :O) If you add a dummy method with the "RolesAllowed" annotation, your methods get back to work. I've changed the example to fit your needs. Ill investigate this problem later today, in the meantime you can use this workaround. Check the new example here: http://people.apache.org/~tveronezi/security.zip []s, Thiago On Tue, Feb 8, 2011 at 6:24 AM, ndegraev wrote: > > Thanks for the project. When I run it's as expected. > > Now I'm trying to apply your examples on my test project and it fails. I > don't know why. It's probably something small but I just don't see it. Can > you have a look? > > MyTest.java: > > @Local > public interface MyTest { > > boolean hasRole(String role); > > boolean isCallerAdmin(); > > } > > MyTestBean.java: > > @Stateless > public class MyTestBean implements MyTest { > > @Resource > private SessionContext sessionContext; > > public boolean hasRole(final String role) { > return this.sessionContext.isCallerInRole(role); > } > > public boolean isCallerAdmin() { > return this.sessionContext.isCallerInRole("admins"); > } > > } > > MyTestCase.java: > > public class MyTestCase { > > @Before > public void setUp() throws Exception { > final ClassLoader contextClassLoader = > Thread.currentThread().getContextClassLoader(); > final URL resource = contextClassLoader.getResource("login.config"); > System.setProperty("java.security.auth.login.config", > resource.toExternalForm()); > > final Properties properties = new Properties(); > properties.setProperty("openejb.authentication.realmName", > "PropertiesLogin"); > new InitialContext(properties); > } > > @Test > public void test1() throws NamingException { > System.out.println("test 1..."); > final Context ctx = getCtx("user", "user_pass"); > final MyTest myTest = (MyTest) ctx.lookup("MyTestBeanLocal"); > System.out.println("Is admin? " + myTest.isCallerAdmin()); > System.out.println("Is in 'admins'? " + myTest.hasRole("admins")); > System.out.println("Is in 'users'? " + myTest.hasRole("users")); > } > > @Test > public void test2() throws NamingException { > System.out.println("test 2..."); > final Context ctx = getCtx("admin", "admin_pass"); > final MyTest myTest = (MyTest) ctx.lookup("MyTestBeanLocal"); > System.out.println("Is admin? " + myTest.isCallerAdmin()); > System.out.println("Is in role 'admins'? " + > myTest.hasRole("admins")); > System.out.println("Is in role 'users'? " + > myTest.hasRole("users")); > } > > private Context getCtx(final String user, final String pass) throws > NamingException { > final Properties properties = new Properties(); > properties.setProperty(Context.SECURITY_PRINCIPAL, user); > properties.setProperty(Context.SECURITY_CREDENTIALS, pass); > return new InitialContext(properties); > } > > } > > groups.properties, users.properties, login.config and jndi.properties are > copied over from your project. > > When I run it I get this output: > > Apache OpenEJB 3.1.4 build: 20101112-03:32 > http://openejb.apache.org/ > INFO - openejb.home = C:\dvl\test-openejb > INFO - openejb.base = C:\dvl\test-openejb > INFO - Configuring Service(id=Default Security Service, > type=SecurityService, provider-id=Default Security Service) > INFO - Configuring Service(id=Default Transaction Manager, > type=TransactionManager, provider-id=Default Transaction Manager) > INFO - Found EjbModule in classpath: C:\dvl\test-openejb\target\classes > INFO - Beginning load: C:\dvl\test-openejb\target\classes > INFO - Configuring enterprise application: classpath.ear > INFO - Configuring Service(id=Default Stateless Container, type=Container, > provider-id=Default Stateless Container) > INFO - Auto-creating a container for bean MyTestBean: > Container(type=STATELESS, id=Default Stateless Container) > INFO - Using 'openejb.validation.output.level=VERBOSE' > INFO - Enterprise application "classpath.ear" loaded. > INFO - Assembling app: classpath.ear > INFO - Jndi(name=MyTestBeanLocal) --> Ejb(deployment-id=MyTestBean) > INFO - Created Ejb(deployment-id=MyTestBean, ejb-name=MyTestBean, > container=Default Stateless Container) > INFO - Deployed Application(path=classpath.ear) > test 1... > INFO - Logging in > Is admin? false > Is in 'admins'? false > Is in 'users'? false > test 2... > INFO - Logging in > Is admin? false > Is in role 'admins'? false > Is in role 'users'? false > -- > View this message in context: > http://openejb.979440.n4.nabble.com/JUnit-Sessioncontext-isCallerInRole-allways-returns-false-tp3257408p3275679.html > Sent from the OpenEJB User mailing list archive at Nabble.com. > --001636284298999307049bc42acc--