Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8262683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:50:07+00:00 2026-06-08T03:50:07+00:00

My environment is Jboss AS 7.1.0. I am using JUnit and Arquillian for unit

  • 0

My environment is Jboss AS 7.1.0. I am using JUnit and Arquillian for unit testing. I have SSBs that use getUserPrincipal(), and isCallerInRole() methods in my ejbs. In order to unit test these ejb methods, I have to simulate log-in from the unit test case and then call the ejb.

Here is an example of EJB method that I am trying to test:

@RolesAllowed({"user","admin"})
public User getMyUserDetails() throws BadInputDataException {
    String userName = ctx.getCallerPrincipal().getName();
    return findUser(userName);
}

How do I write a JUnit test case to test this method? I appreciate your help in advance.

Updates on 07/19 (based on Tair’s solution below):

My security domain configuration is as under:

<security-domains>
    <security-domain name="other" cache-type="default">
         <authentication>
             <login-module code="Remoting" flag="optional">
                 <module-option name="password-stacking" value="useFirstPass"/>
             </login-module>
             <login-module code="Database" flag="required">
                 <module-option name="dsJndiName" value="java:jboss/datasources/MysqlDS"/>
                 <module-option name="principalsQuery" value="select Password from Principals where PrincipalID=?"/>
                 <module-option name="rolesQuery" value="select Role, RoleGroup from Roles where PrincipalID=?"/>
                 <module-option name="password-stacking" value="useFirstPass"/>
                 <module-option name="hashAlgorithm" value="MD5"/>
                 <module-option name="hashEncoding" value="RFC2617"/>
                 <module-option name="hashUserPassword" value="false"/>
                 <module-option name="hashStorePassword" value="true"/>
                 <module-option name="passwordIsA1Hash" value="true"/>
                 <module-option name="storeDigestCallback" value="org.jboss.security.auth.callback.RFC2617Digest"/>
             </login-module>
         </authentication>
     </security-domain>

I changed the JBossLoginConfigFactory shown in Tair’s solution below to use org.jboss.security.auth.spi.DatabaseServerLoginModule.

I have changed the JBossLoginConfigFactory to use the following method for DatabaseServerLoginModule.

private AppConfigurationEntry createDatabaseModuleConfigEntry() {
    Map<String, String> options = new HashMap<String, String>();
    options.put("dsJndiName", "java:jboss/datasources/MysqlDS");
    options.put("hashAlgorithm", "MD5");
    options.put("hashEncoding", "RFC2617");
    options.put("hashUserPassword", "false");
    options.put("hashStorePassword", "true");
    options.put("passwordIsA1Hash", "true");
    options.put("storeDigestCallback", "org.jboss.security.auth.callback.RFC2617Digest");
    options.put("principalsQuery", "select Password from Principals where PrincipalID=?");
    options.put("rolesQuery", "select Role, RoleGroup from Roles where PrincipalID=?");

    return new AppConfigurationEntry("org.jboss.security.auth.spi.DatabaseServerLoginModule",
                AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, options);
}

and I am invoking this method instead of createUsersRolesLoginModuleConfigEntry(). The loginContext.login() in the test case now fails due to:

Caused by: java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: org.jboss.security.auth.callback.MapCallback

Not sure what I should change now!

Update 07/20/2012: Complete solution to the issue is below.
If your solution does not require DatabaseServerLoginModule, just refer the solution in Tair’s reply and that is good enough.

In my case I have database as the JaaS authentication and also digest authentication. Hence I had to make the following code changes to the above example.

  1. I have modified the code (JBossLoginContextFactory) to support “org.jboss.security.auth.spi.DatabaseServerLoginModule” as shown below. I am calling this method instead of createUsersRolesLoginModuleConfigEntry() while creating AppConfigurationEntry[].

    private AppConfigurationEntry createDatabaseModuleConfigEntry() {
    Map options = new HashMap();
    options.put(“dsJndiName”, “java:jboss/datasources/MysqlDS”);
    options.put(“principalsQuery”, “select Password from Principals where PrincipalID=?”);
    options.put(“rolesQuery”, “select Role, RoleGroup from Roles where PrincipalID=?”);
    return new AppConfigurationEntry(“org.jboss.security.auth.spi.DatabaseServerLoginModule”,
    AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, options);
    }

  2. As I am using digest authentication, my password is encrypted in the database. So while passing the password from my test case, I am encrypting and passing the password as shown below.
    LoginContext loginContext = JBossLoginContextFactory.createLoginContext(“username”, md5Hex(“my_username”+”:”+PropertyManager.getProp(“realm”)+”:”+”my_password”));

Now the log-in is successful !!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:50:10+00:00Added an answer on June 8, 2026 at 3:50 am

    Your case is covered in this example. Basically it boils down to:

    1. Use arquillianContext to build a Context with pre-set values for Context.SECURITY_PRINCIPAL and Context.SECURITY_CREDENTIALS
    2. Use that context to obtain reference to you EJB
    3. Test it.

    Good luck!

    UPDATE: looks like much have changed in Arquillian since then, luckily we have another solution. I tested it and confirm that it works!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a network server that was implemented using Jboss Netty. It servers the
We have a large web app installation, using Apache/Tomcat/Jasper and jboss. In development environment,
I am using JBoss 4.2.2.GA app server in a development environment. I have a
I've got a problem using Richfaces-3.3.3 with JBoss-Seam 2.2 as my environment: I have
In our Production environment we have JBoss running in a clustered mode with 4+
I'm using Jboss 4/5 and have some .war .properties files with default configuration settings
I am using EJBs (on JBoss) and Wicket as the UI layer. I added
Environment: I have that User entity : @Entity public class User implements Serializable {
Environment: Server : Jboss 4.2.3.GA We are using c3p0 0.9.1.2 for connection pooling. Whenever
We use jBoss in our development environment to deploy to. There are many applications

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.