Accessing the clients principal inside an ejb method

I need to access the clients principal (username ) inside a ejb method. I don't want to add it as a parameter. Tryed adding them to Context object like ;

prop.add(Context.SECURITY_AUTHENTICATION,"user")
prop.add(Context.SECURITY_CREDENTIALS,"pass")

but trying to access them inside the method like; @Resource private SessionContext ctx;

public void someMethod() {
    Principal principal = ctx.getCallerPrincipal();
    //returns anonymous

still give me the annoymous user.

Working on weblogic, any pointers ?

Thanks

Answers


Similar issue...I am testing with a client cert along with a custom UserNameMapper. My UserNameMapper returns "steve", but the principal within the EJB was returning "<anonymous>" until I added a "steve" user via the console.

Environment env = new Environment();
env.setInitialContextFactory(Environment.DEFAULT_INITIAL_CONTEXT_FACTORY);
//  env.setSecurityPrincipal("user");
//  env.setSecurityCredentials("pass");
env.setProviderUrl("t3s://localhost:7002");

InputStream key = new PEMInputStream(new FileInputStream(CERT_KEYFILE));
InputStream cert = new PEMInputStream(new FileInputStream(CERT_CERTFILE));
env.setSSLClientCertificate(new InputStream[] {key, cert});
env.setSSLClientKeyPassword(CERT_KEYPASSWORD);

Same issue when using a JAAS client with the UsernamePasswordLoginModule. Fixed by setting the username/password within the InitialContext lookup within the PrivilegedAction. The EJB references the latter as the principal as it can be a different username/password.


Need Your Help

ios mpvolumeview route button not vertically centered on ios 7.1 update

ios uislider mpvolumeview

i am making an app that play audio files. i am showing mpvolumeview which is working fine.

How to add title to svg rectangle using pure javascript (not d3.js)?

javascript json svg

I made changes to the code.Are they in the right manner, because tooltip or title are still not showing up.