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 9084303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:58:02+00:00 2026-06-16T20:58:02+00:00

I have a @RolesAllowed protected @Stateless EJB that I’m trying to JUnit-4 test with

  • 0

I have a @RolesAllowed protected @Stateless EJB that I’m trying to JUnit-4 test with embedded GlassFish container. The most recent hurdle I’ve overcoming has been GlassFish domain configuration for persistence unit and security realm.

Map<String, Object> properties = new HashMap<String, Object>();
properties.put(EJBContainer.MODULES, new File("build/classes"));
properties.put("org.glassfish.ejb.embedded.glassfish.configuration.file", 
     "test-resource/domain.xml");
ec = javax.ejb.embeddable.EJBContainer.createEJBContainer(properties);

Embedded GlassFish starts, my application deploys, and everything seems to work as expected until I call a EJB method with a @RolesAllowed annotation.

javax.ejb.AccessLocalException: Client not authorized for this invocation

For some reason I can not figure out how to set the container’s role to pass the security check. What am I missing?

  • 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-16T20:58:04+00:00Added an answer on June 16, 2026 at 8:58 pm

    You can use the com.sun.appserv.security.ProgrammaticLogin class to help you out with this. This is specific to GlassFish, and not a Java EE 6 API; if you’re using a different embedded container, you’ll need to find the equivalent one.

    ProgrammaticLogin enables you to login as a user and establish a security principal for the current thread. An example of it’s usage would be:

    ProgrammaticLogin login = new ProgrammaticLogin();
    login.login("user", "password", "file", true);
    

    where user and password are the credentials to be used to login as a user in the file realm. This allows you to establish a security principal to be utilized when invoking an EJB deployed in the embedded container. The absence of this would result in the anonymous principal being used for as the principal (thus resulting in an exception when the container enforces the RolesAllowed constraints).

    Note, that this also requires you to use an existing security realm. It is recommended that you use a custom GlassFish install root (or instance root) that contains a pre-configured domain.xml file with the security realm used by your application.

    Some more details on how to use the ProgrammaticLogin API can be found in this Oracle blog entry.

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

Sidebar

Related Questions

I have been trying to secure an application, which is deployed to glassfish 3
I have a jboss webservice like this: @Stateless @SecurityDomain(SecurityDomain) @RolesAllowed(RolesAllowed) @WebContext(urlPattern = /*, authMethod
Have created an android test project and currently trying to write android unit tests
Have a painfully simple blog Post creator, and I'm trying to check if the
have a nice day. I got problem when trying to create an image from
I read most of the documentation, I only see the use of @RolesAllowed or
Have a simple form that has a PictureBox in one location. I want to
Have a photography site that I want to prevent image copying from. How can
Have a problem that seems easy on paper but i'm having a big problem
I have an simple (webprofile) EJB 3.1 Application and try do determine the current

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.