Examples of InitialDirContext


Examples of javax.naming.directory.InitialDirContext

        final Hashtable env = new Hashtable();
        env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
        env.put( Context.SECURITY_AUTHENTICATION, "none" );
        env.put( Context.PROVIDER_URL, uri );

        final DirContext context = new InitialDirContext( env );

        return build( context );
    }
View Full Code Here

Examples of javax.naming.directory.InitialDirContext

        env.put(Context.SECURITY_AUTHENTICATION, "simple");
        env.put(Context.SECURITY_PRINCIPAL, name);
        env.put(Context.SECURITY_CREDENTIALS, password);

        InitialDirContext ctx = null;
        try
        {
            ctx = createInitialDirContext(env);

            //Authentication succeeded
View Full Code Here

Examples of javax.naming.directory.InitialDirContext

                existingContextClassloader = Thread.currentThread().getContextClassLoader();
                env.put(JAVA_NAMING_LDAP_FACTORY_SOCKET, _sslSocketFactoryOverrideClass.getName());
                Thread.currentThread().setContextClassLoader(_sslSocketFactoryOverrideClass.getClassLoader());
                revertContentClassLoader = true;
            }
            return new InitialDirContext(env);
        }
        finally
        {
            if (revertContentClassLoader)
            {
View Full Code Here

Examples of javax.naming.directory.InitialDirContext

    private void validateInitialDirContext()
    {
        Hashtable<String,Object> env = createInitialDirContextEnvironment(_providerSearchURL);
        env.put(Context.SECURITY_AUTHENTICATION, "none");

        InitialDirContext ctx = null;
        try
        {
            ctx = createInitialDirContext(env);
        }
        catch (NamingException e)
View Full Code Here

Examples of javax.naming.directory.InitialDirContext

    private String getNameFromId(String id) throws NamingException
    {
        Hashtable<String,Object> env = createInitialDirContextEnvironment(_providerSearchURL);

        env.put(Context.SECURITY_AUTHENTICATION, "none");
        InitialDirContext ctx = createInitialDirContext(env);

        try
        {
            SearchControls searchControls = new SearchControls();
            searchControls.setReturningAttributes(new String[] {});
            searchControls.setCountLimit(1l);
            searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
            NamingEnumeration<?> namingEnum = null;
            String name = null;

            namingEnum = ctx.search(_searchContext, _searchFilter, new String[] { id }, searchControls);
            if(namingEnum.hasMore())
            {
                SearchResult result = (SearchResult) namingEnum.next();
                name = result.getNameInNamespace();
            }
View Full Code Here

Examples of javax.naming.directory.InitialDirContext

                env.put(Context.SECURITY_CREDENTIALS, connectionPassword);
            }
            env.put(Context.SECURITY_PROTOCOL, connectionProtocol);
            env.put(Context.PROVIDER_URL, connectionURL);
            env.put(Context.SECURITY_AUTHENTICATION, authentication);
            context = new InitialDirContext(env);

        } catch (NamingException e) {
            log.error(e);
            throw e;
        }
View Full Code Here

Examples of javax.naming.directory.InitialDirContext

        }

        // Get the environment properties (props) for creating initial
        // context and specifying LDAP service provider parameters..
       
        DirContext ctx = new InitialDirContext(props);
       

        // Search the named object and all of its descendants.
        SearchControls constraints = new SearchControls();
        constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);

        // Retrieve the specified attributes only..
        String[] al = new String[ attributeList.size() ];
        attributeList.toArray(al);
        constraints.setReturningAttributes(al);

        String filter = USER_FILTER +"="+userId;
       
        logger.info("LDAP search '" + filter + "' ");

        // Search the context specified in the String object "base".
        try {
          NamingEnumeration<?> results = ctx.search(BASE, filter, constraints);
         
          if (results.hasMoreElements()) {
            logger.info("has returned results..\n");
              user = new JSONObject();
              // Since UID is unique across the entire directory,
              // the search results should contain only one entry.
              SearchResult sr = (SearchResult) results.next();
              // we need the DN to authenticate the user
              NameParser parser = ctx.getNameParser(BASE);
          Name userDN = parser.parse(BASE);

          if (userDN == (Name) null)
          // This should not happen in theory
          throw new NameNotFoundException();
          else
          userDN.addAll(parser.parse(sr.getName()));
          user.put("userDN", userDN.toString());
                   
              // Get all available attribute types and their associated values.
          // we can build a user object to return.
              Attributes attributes = sr.getAttributes();

              Attribute attr;
              NamingEnumeration<?> ne;

              // Iterate through the attributes.
              //String json = "{";
              for (NamingEnumeration<?> a = attributes.getAll(); a.hasMore();) {
                  attr = (Attribute)a.next();
                 
                  //json = json + attr.getID() + ": { ";
                  String json = "";
                  ne = attr.getAll();
                  while (ne.hasMore()) {
                      json = json + ne.next(); // should only be one entry for the attributes we retreive + ", ";
                  }

                  //json = json + "\n";
                  user.put(attr.getID(), json);
              }
              //json = json + "}";
              //user.put("jsonAttrib", json);
          }
          else {
            logger.info("has returned no results..");
         
          }
        }
        catch(Exception e)
    {
      e.printStackTrace();
    }
    finally{
      ctx.close();
    }
        return user;
     
    }
View Full Code Here

Examples of javax.naming.directory.InitialDirContext

   
    DirContext ctx = null;

    try
    {
      ctx = new InitialDirContext(env);
      logger.info("SUCCESSFUL");
    }
    catch(AuthenticationException e)
    {
      throw e;
View Full Code Here

Examples of javax.naming.directory.InitialDirContext

    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, "cn=Manager,dc=test,dc=platformlayer,dc=org");
    env.put(Context.SECURITY_CREDENTIALS, adminPassword.plaintext());

    DirContext ctx = new InitialDirContext(env);

    NamingEnumeration results = ctx.list("dc=test,dc=platformlayer,dc=org");
    while (results.hasMore()) {
      NameClassPair sr = (NameClassPair) results.next();
      System.out.println(sr.getNameInNamespace());
    }

    ctx.close();
  }
View Full Code Here

Examples of javax.naming.directory.InitialDirContext

   
    private String[] getSMTPServerByJNDI(String to) throws Exception
      String host=getDomainFromAddress(to);
        Properties jndiEnvironmentProperties = new Properties()
        jndiEnvironmentProperties.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory")
        InitialDirContext initialDirContext = new InitialDirContext(jndiEnvironmentProperties)
        Attributes attributes = initialDirContext.getAttributes(host, new String[] {"MX"})
       
        Attribute attribute = attributes.get("MX")
        String[] servers = new String[attribute.size()]
        for (int i = 0; i < attribute.size(); i++) { 
            servers[i] = attribute.get(i).toString()
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.