Avatar billede fredand Forsker
11. december 2017 - 12:26 Der er 4 kommentarer

EJB-local lookup with user authentication

Hello!
We are migrating from JBoss 5 to JBoss 6.
We got a MDB that call's a EJB.
But in the EJB we check that the user got some roles.

In Jboss 5 we did
    private InitialContext getInitialContext(final String pProviderUrl, final String pPrinciple, final String pCredentials) throws NamingException {
          final Properties properties = new Properties();
          properties.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
          properties.put(Context.PROVIDER_URL, pProviderUrl);
          if(pPrinciple != null && pCredentials != null) {
              properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.security.jndi.JndiLoginInitialContextFactory");
              properties.put(Context.SECURITY_PRINCIPAL, pPrinciple);
              properties.put(Context.SECURITY_CREDENTIALS, pCredentials);
          }
          else {
              properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
          }
          return new InitialContext(properties);
    }
...then to roles was present.

But In Jboss 6 I can not find out how to do the same.
I found this clue:
https://developer.jboss.org/thread/202291
...but when I get to:
SecurityContextAssociation.setPrincipal and SecurityContextAssociation.setCredential
...the compiler says that the method is undefind:
The method setCredential(String) is undefined for the type SecurityContextAssociation

Do you guys got any idea how to solve this in Jboss 6?
Best regards
Fredrik
Avatar billede arne_v Ekspert
11. december 2017 - 17:34 #1
First question: what is the problem using the old code?
Avatar billede fredand Forsker
11. december 2017 - 19:29 #2
Hello
I acctually do not think it is supposed that I should use this code in Jboss 6:
Context.INITIAL_CONTEXT_FACTORY, "org.jboss.security.jndi.JndiLoginInitialContextFactory
I think it is deprecated? Correct me If I am wrong.
Best regards
Fredrik
Avatar billede arne_v Ekspert
11. december 2017 - 19:57 #3
Ah - that is true.

What about:

        props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
        props.put(Context.INITIAL_CONTEXT_FACTORY,  "org.jboss.naming.remote.client.InitialContextFactory");

?
Avatar billede fredand Forsker
11. december 2017 - 21:21 #4
Hello!
Since you mention that I will try it again. But yesterday I tried the following (see below) but I had a hard time to get the dependencies right. Finally I gave in since I thought I on on the wrong track. I got doubt that "org.jboss.naming.remote.client.InitialContextFactory" is very expensive to use and only should be used in a remote context. But that is just a feeling I got.

Perhaps the old "org.jboss.security.jndi.JndiLoginInitialContextFactory" is used in a remote context too?

How ever this was my attempt yesterday.
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
properties.put(Context.PROVIDER_URL, "remote://localhost:4447");
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
properties.put(Context.SECURITY_PRINCIPAL, pPrinciple);
properties.put(Context.SECURITY_CREDENTIALS, pCredentials);
properties.put("jboss.naming.client.ejb.context", "true");

I will try to look into it again.
Best regards
Fredrik
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester