In the project I’m working on, we are using OpenEJB as a framework to test our EJB. We construct an InitialContext programatically, and use it to get the transaction manager and the various EJB.
However, the EJB I have to test now has the @RolesAllowed annotation, and so OpenEJB refuses to get that EJB, arguing I don’t have the permissions required.
How can I specify to OpenEJB the user this test is supposed to simulate, and the role associated with him?
The
@RunAssuggestion bkail mentions is definitely a good way to go. The second approach that doesn’t involve inner classes is to login in the testcase.Login approach
When you bootstrap OpenEJB, specify the user/pass in the
InitialContextproperties as follows:Then perhaps test again as a different user:
Test users and groups
You can configure test users and groups by putting a
users.propertiesandgroups.propertiesfile in the classpath of the testcase. In maven that’d be at the following locations:The
users.propertiesfile might look like thisAnd
groups.propertieslike so