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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:35:36+00:00 2026-06-13T02:35:36+00:00

I have an application in which some operations are performed by MDB. These MDB

  • 0

I have an application in which some operations are performed by MDB. These MDB all use a @RunAs(SYSTEM) annotation to mark them as system elements.

One of these MDB has to run some code which is protecetd through @RolesAllowed(WORKSPACE), which the SYSTEM role doesn’t have, obviously, but which the user (a human being, mind you) that started the process has.

So, my question is quite simple : is there any way (through asynchronous invocation, as an example) to have my MDB to change its principal to be my user instead of SYSTEM ?

  • 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-13T02:35:37+00:00Added an answer on June 13, 2026 at 2:35 am

    Like Mike Braun answer suggest, this is not possible according to JavaEE specifications.

    And that is unfortunate. But, what is a little less unfortunate is that there is some code to do that kind of things (application-server specific), hidden in that application server implementation of @RunAs. In Glassfish, that particular code is in the com.sun.enterprise.security.auth.login.LoginContextDriver class, and particularly in its LoginContextDriver#loginPrincipal method.

    So, to have one part of code using a specific principal, I defined an interface

    public interface Sudoer {
        public <Result> Result sudo(String user, SudoOperation<Result> operation);
    }
    

    which I implemented for Glassfish as so :

    public class GlassfishSudoer implements Sudoer {
        @Override
        public <Result> Result sudo(String user, SudoOperation<Result> operation) {
            try {
                LoginContextDriver.loginPrincipal(user, "autocat");
                return operation.perform();
            } catch (Exception e) {
                throw new UnableToSudoException(e);
            } finally {
                LoginContextDriver.logout();
            }
        }
    }
    

    And when using it, the part which wants to have some code “sudoed” only has to provide an implementation of the SudoOperation, like

        component.sudo(userLogin, new SudoOperation<Void>() {
            public Void perform() {
                /* do some sudoed code */
                return null;
            }
        });
    

    Advantage of this method is that, provided the given application server has some code to handle @RunAs, you can use that code to implement your own sudoer (I’m thinking about extracting that into a sudo-ejb library …).

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

Sidebar

Related Questions

Well, I have a application which somehow requires some system resources, but how do
Hi All, I have a web-view in my application which displays some text with
I have a web application which would perform well if some database operations are
I have a C# application of which some parts are written using WPF (which
I just want to know that can i make an application which have some
I have a simple graphics application which draws some stuff on the screen. Before,
I have a classic ASP application which inserts some values into a word file
I have an application which supports multiple types and versions of some devices. It
I have Java application which sends pointer to function (callback) to some native dll
I have written very very simple console application which supports some command line options.

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.