Package javax.naming.directory

Examples of javax.naming.directory.DirContext


        path = normalize(path);
        if (path == null)
            return (null);

        DirContext resources = context.getResources();
        if (resources != null) {
            return (getResourcePathsInternal(resources, path));
        }
        return (null);
View Full Code Here


        if (started) {
            throw new IllegalStateException
                (sm.getString("standardContext.resources.started"));
        }

        DirContext oldResources = this.webappResources;
        if (oldResources == resources)
            return;

        if (resources instanceof BaseDirContext) {
            ((BaseDirContext) resources).setCached(isCachingAllowed());
View Full Code Here

        }
    }

    protected boolean authenticate(String username, String password) throws Exception {

        DirContext context = null;
        context = open();

        try {

            String filter = userSearchMatchingFormat.format(new String[]{username});
            SearchControls constraints = new SearchControls();
            if (userSearchSubtreeBool) {
                constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
            } else {
                constraints.setSearchScope(SearchControls.ONELEVEL_SCOPE);
            }

            //setup attributes
            ArrayList list = new ArrayList();
            if (userRoleName != null) {
                list.add(userRoleName);
            }
            String[] attribs = new String[list.size()];
            list.toArray(attribs);
            constraints.setReturningAttributes(attribs);


            NamingEnumeration results = context.search(userBase, filter, constraints);

            if (results == null || !results.hasMore()) {
                return false;
            }

            SearchResult result = (SearchResult) results.next();

            if (results.hasMore()) {
                //ignore for now
            }
            NameParser parser = context.getNameParser("");
            Name contextName = parser.parse(context.getNameInNamespace());
            Name baseName = parser.parse(userBase);
            Name entryName = parser.parse(result.getName());
            Name name = contextName.addAll(baseName);
            name = name.addAll(entryName);
            String dn = name.toString();
View Full Code Here

        if (started) {
            throw new IllegalStateException
                (sm.getString("standardContext.resources.started"));
        }

        DirContext oldResources = this.webappResources;
        if (oldResources == resources)
            return;

        if (resources instanceof BaseDirContext) {
            ((BaseDirContext) resources).setCached(isCachingAllowed());
View Full Code Here

                    "' for URI '" + taglibs[i] + "'");
            }
            resourcePaths.add(resourcePath);
        }

        DirContext resources = context.getResources();
        if (resources != null) {
            tldScanResourcePathsWebInf(resources, "/WEB-INF", resourcePaths);
        }

        // Return the completed set
View Full Code Here

        }

        // 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

    env.put(Context.SECURITY_CREDENTIALS,pw); // the actual password.
   

        // Get the environment properties (props) for creating
   
    DirContext ctx = null;

    try
    {
      ctx = new InitialDirContext(env);
      logger.info("SUCCESSFUL");
    }
    catch(AuthenticationException e)
    {
      throw e;
    }
    catch(Exception e)
    {
      e.printStackTrace();
      throw e;
    }
    finally{
      if (ctx != null){
        try {
          ctx.close();
        } catch (NamingException e) {
          e.printStackTrace();
          throw e;
        }
      }
View Full Code Here

    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

        if (started) {
            throw new IllegalStateException
                (sm.getString("standardContext.resources.started"));
        }

        DirContext oldResources = this.webappResources;
        if (oldResources == resources)
            return;

        if (resources instanceof BaseDirContext) {
            ((BaseDirContext) resources).setCached(isCachingAllowed());
View Full Code Here

        props.setProperty(Context.URL_PKG_PREFIXES, URL_CONTEXT_PREFIX);
        props.setProperty(Context.REFERRAL, REFERRALS_IGNORE);
        props.setProperty(Context.SECURITY_AUTHENTICATION,
            SEARCH_SECURITY_LEVEL);

        DirContext ctx = new InitialDirContext(props);
        return ctx;
    }
View Full Code Here

TOP

Related Classes of javax.naming.directory.DirContext

Copyright © 2018 www.massapicom. 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.