Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2006, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
 package org.jboss.naming;
 
 
 
Creating a JNDI connection using JBoss Remoting. If Context.SECURITY_PRINCIPAL and Context.SECURITY_CREDENTIALS are set, this InitialContextFactory implementation combines the authentication phase with the InitialContext creation. During the getInitialContext callback from the JNDI naming, layer security context identity is populated with the username obtained from the Context.SECURITY_PRINCIPAL env property and the credentials from the Context.SECURITY_CREDENTIALS env property. There is no actual authentication of this information. It is merely made available to the jboss transport layer for incorporation into subsequent invocations. Authentication and authorization will occur on the server. If Context.SECURITY_PROTOCOL is provided as well as the principal and credentials, then a JAAS login will be performed instead using the security domain provided with the SECURITY_PROTOCOL variable.

Author(s):
Bill Burke
Scott Stark
adrian@jboss.org
Version:
$Revision: 37459 $
 
 {
    static void associateSecurityInformation(Object principalObject credentials)
    {
       Principal securityPrincipal;
       // See if the principal is a Principal or String
       ifprincipal instanceof Principal )
       {
          securityPrincipal = (Principalprincipal;
       }
       else
       {
          // Simply convert this to a name using toString
          String username = principal.toString();
          securityPrincipal = new SimplePrincipal(username);
       }
       // Associate this security context
       SecurityAssociationActions.setPrincipalInfo(securityPrincipalcredentials);
    }
 
    static void login(Object principalObject credentialsObject propthrows AuthenticationException
    {
       String protocol = prop.toString();
       try
       {
          // Get the principal username
          String username;
          ifprincipal instanceof Principal )
          {
            Principal p = (Principalprincipal;
            username = p.getName();
         }
         else
         {
            username = principal.toString();
         }
         UsernamePasswordHandler handler = new UsernamePasswordHandler(username,
            credentials);
         // Do the JAAS login
         LoginContext lc = new LoginContext(protocolhandler);
         lc.login();
      }
      catch(LoginException e)
      {
         AuthenticationException ex = new AuthenticationException("Failed to login using protocol="+protocol);
         ex.setRootCause(e);
         throw ex;
      }
   }
   // InitialContextFactory implementation
   {
      Class[] interfaces = {Naming.class};
      Interceptor[] interceptors;
      Naming naming;
      // Get the login principal and credentials from the JNDI env
      Object credentials = env.get(.);
      Object principal = env.get(.);
      Object protocol = env.get(.);
      if (principal != null && credentials != null)
      {
         if (protocol != null)
         {
            login(principalcredentialsprotocol);
         }
         else
         {
            associateSecurityInformation(principalcredentials);
         }
         interceptors = tmp;
      }
      else
      {
         interceptors = tmp;
      }
      if (. != nullreturn new NamingContext(envnull.);
      String providerUrl = (Stringenv.get(.);
      if (providerUrl == null)
      {
         throw new RuntimeException("PROVIDER_URL not provided in jndi.properties.  Automatic discovery not implemented yet.");
      }
      try
      {
         naming = (Naming) Remoting.createPojiProxy("JNDI"interfacesproviderUrlinterceptors);
      }
      catch (Exception e)
      {
         throw new RuntimeException("Unable to create Naming proxy"e);
      }
      return new NamingContext(envnullnaming);
   }
   // ObjectFactory implementation ----------------------------------
   public Object getObjectInstance(Object obj,
                                   Name name,
                                   Context nameCtx,
                                   Hashtable environment)
           throws Exception
   {
      Context ctx = getInitialContext(environment);
      Reference ref = (Referenceobj;
      return ctx.lookup((Stringref.get("URL").getContent());
   }
New to GrepCode? Check out our FAQ X