[jboss-user] [Beginners Corner] - Re: EJB3 Initialization Parameter

pdgillen do-not-reply at jboss.com
Fri Oct 19 16:06:12 EDT 2007


-------- in ejb-jar.xml -------------------------------------

-------- inside the  tag defining the EJB -------------

      <env-entry>

         <env-entry-name>SECURITY_PRINCIPAL</env-entry-name>

         <env-entry-type>java.lang.String</env-entry-type>

         <env-entry-value>foo</env-entry-value>

      </env-entry>

      <env-entry>

         <env-entry-name>SECURITY_CREDENTIALS</env-entry-name>

         <env-entry-type>java.lang.String</env-entry-type>

         <env-entry-value>bar</env-entry-value>

      </env-entry>

-------- inside my EJB -------------------------

      @Resource

      (

            name="SECURITY_PRINCIPAL",    

            type=java.lang.String.class, 

            shareable=true 

      )

      String secPrincipal;

      

      @Resource

      (

            name="SECURITY_CREDENTIALS", 

            type=java.lang.String.class, 

            shareable=true 

      )

      String secCredentials; 

      private   InitialContext   secureCtx   = null;

---- then the method --------    

    private void getSecurityContext()

    throws Exception

    {

      Properties   sctxProps = new Properties();        

      sctxProps.setProperty(InitialContext.SECURITY_PRINCIPAL, secPrincipal);

      sctxProps.setProperty(InitialContext.SECURITY_CREDENTIALS, secCredentials);

      sctxProps.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY, 

            "org.jboss.security.jndi.JndiLoginInitialContextFactory");        

      secureCtx   = new InitialContext(sctxProps);

    }

--- and then inside the other method

        try

        {   

            getSecurityContext();

            Object   fbObj   = secureCtx.lookup("foo/bar/Manager");

            tem               = (FooBar) PortableRemoteObject.narrow(fbObj,

               FooBar.class);

        }

        catch(Exception e)

        {

            e.printStackTrace();

            throw new RemoteException(""+e);

        }      

------------------



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4097109#4097109

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4097109



More information about the jboss-user mailing list