openejb-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thiago Veronezi <thi...@veronezi.org>
Subject Re: JUnit: Sessioncontext.isCallerInRole allways returns false
Date Thu, 03 Feb 2011 14:57:24 GMT
Hi,
You can use a custom "login.config". To load this custom file, you can use
the "System.setProperty" method...

final ClassLoader ctxCl = Thread.currentThread().getContextClassLoader();
URL resource = ctxCl.getResource("login.config");
System.setProperty("java.security.auth.login.config",
resource.toExternalForm());

Your custom "login.config" could be something like..

SQLLogin {
    org.apache.openejb.core.security.jaas.SQLLoginModule required
     jdbcURL="jdbc:hsqldb:hsql://localhost/xdb"
     userSelect="SELECT account, '1234' FROM user WHERE account = ?"
     groupSelect="SELECT u.account, ur.role FROM user AS u, user_roles AS ur
WHERE u.uid = ur.user_id AND u.account = ?";
};

...
And to get your initial context...


final Properties props = new Properties();
props.setProperty(Context.SECURITY_PRINCIPAL, user);
props.setProperty(Context.SECURITY_CREDENTIALS, "1234");
props.setProperty("openejb.authentication.realmName", "SQLLogin");
return new InitialContext(props);

This way you make a connection to your embedded openejb server using the
"user" account.
Check this link for more info about jaas...

http://openejb.apache.org/3.0/security.html

[]s,
Thiago.


On Thu, Feb 3, 2011 at 9:41 AM, ndegraev <nick.degraeve@telenet.be> wrote:

>
> Ah, pity.
>
> How would I then best test functionality which relies on the caller
> Principal?
>
> What I'm planning to do is create a class that implements SessionContext
> and
> on which I can set roles. The isCallerInRoles() will check the parameter
> against the set roles. Via reflection I then set this context on my EJB for
> the tests.
>
> Do you know a better way?
>
> Thanks,
>
> Nick
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/JUnit-Sessioncontext-isCallerInRole-allways-returns-false-tp3257408p3258218.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message