Package javax.naming.directory

Examples of javax.naming.directory.DirContext


    throws UnknownHostException
  {
    List<Inet6Address>  result = new ArrayList<Inet6Address>();

    try{     
      DirContext context = getInitialDirContext();
     
      Attributes attrs = context.getAttributes( host, new String[]{ "AAAA" });
     
      if ( attrs != null ){
     
        Attribute attr = attrs.get( "aaaa" );
     
View Full Code Here


    this.isRoot = isRoot;
    log = realm.getLog();
   
    if (!isRoot) {
      PooledConnection connImpl = null;
      DirContext ctx = null;
      boolean tribeFound = false;
   
      try {
        connImpl = realm.getConnection();
        ctx = (DirContext)connImpl.getConnection();
   
        ctx.getAttributes(dn, new String[] { "cn" });
        tribeFound = true;
      } catch (NameNotFoundException nnfe) {
        //not found
 
      } catch (Exception e) {
View Full Code Here

 
  private Object fetchChildren(boolean isTribe)
  {
    PooledConnection connImpl = null;
    DirContext ctx = null;
    ArrayList result = new ArrayList();
 
    try {
      connImpl = realm.getConnection();
      ctx = (DirContext)connImpl.getConnection();
 
      if (isRoot) {
        NamingEnumeration enu = ctx.list(isTribe? "ou=groups" : "ou=users");
 
        while (enu.hasMore()) {
          String name = ((NameClassPair)enu.next()).getName();
          name = name.substring(name.indexOf("=")+1);
          if (isTribe) {
            result.add( realm.getTribe(name) );
          } else {
            result.add( realm.getCitizen(name) );
          }
         
        }
      } else {

        Attributes a = ctx.getAttributes(dn, new String[] { "uniquemember" });
        Attribute memberAttr = a.get("uniquemember");
       
        if (memberAttr != null) {
          for (NamingEnumeration de=memberAttr.getAll(); de.hasMore(); ) {
            String val = (String)de.next();
View Full Code Here

  {
    if (isRoot) {
      throw new OperationFailedException("Attach operation isn't allowed for synthetic root tribe!");
    }
    PooledConnection connImpl = null;
    DirContext ctx = null;
 
    try {
      connImpl = realm.getConnection();
      ctx = (DirContext)connImpl.getConnection();
 
      //check that this tribe isn't a member of the tribe being attached
      if (res instanceof LDAPTribe) {
        LDAPTribe parentCand = (LDAPTribe)res;
        String parentFail = parentCand.containsName(ctx, parentCand.fetchMembers(ctx), this.dn);
        if (parentFail != null) {
          throw new OperationFailedException("Loops not allowed, '"+dn+"' is parent of of '"+this.dn+"'");
        }
      }
     
      Attribute currMembers = fetchMembers(ctx);
      String failer = containsName(ctx, currMembers, dn);
      if (failer == null) {
        currMembers.add(dn);
        Attributes attrs = new BasicAttributes();
        attrs.put(currMembers);
       
        ctx.modifyAttributes(this.dn, DirContext.REPLACE_ATTRIBUTE, attrs);
        return true;
      }
 
    } catch (Exception e) {
      throw new OperationFailedException(e);
View Full Code Here

  {
    if (isRoot) {
      throw new OperationFailedException("Detach operation isn't allowed for synthetic root tribe!");
    }
    PooledConnection connImpl = null;
    DirContext ctx = null;
 
    try {
      connImpl = realm.getConnection();
      ctx = (DirContext)connImpl.getConnection();
 
      Attribute currMembers = fetchMembers(ctx);
      String result = containsName(ctx, currMembers, dn);
      if (result != null) {
        currMembers.remove(result);
        Attributes attrs = new BasicAttributes();
        attrs.put(currMembers);
     
        ctx.modifyAttributes(this.dn, DirContext.REPLACE_ATTRIBUTE, attrs);
       
        return true;
      }
 
    } catch (Exception e) {
View Full Code Here


  public void remove() throws OperationFailedException
  {
    PooledConnection connImpl = null;
    DirContext ctx = null;
 
    try {
      connImpl = realm.getConnection();
      ctx = (DirContext)connImpl.getConnection();
 
      ctx.unbind(dn);
 
    } catch (NameNotFoundException e) {
      throw new OperationFailedException("Tribe '"+name+"' not found!");

    } catch (Exception e) {
View Full Code Here

    /*
     * Execute the given LDAP requests
     */
    Vector requests = extractRequests((Document) callData);
    NamingEnumeration results = null;
    DirContext context = connection.getContext();
    SearchControls controls = connection.getSearchControls();

    for (Iterator it = requests.iterator(); it.hasNext();)
    {
      RequestContainer request = (RequestContainer) it.next();
      String requestType = request.getType();
      try
      {
        if (requestType.equals(SEARCH_STRING))
        {
          results = context.search(request.getContext(),
              (String) request.getRequest(), controls);
          addResultSearch(results, retDocument, SEARCH_STRING,
              request.getContext(), request.toString());
        }
        else if (requestType.equals(SEARCH_ATTRIBUTES))
        {
          results = context.search(request.getContext(),
              (Attributes) request.getRequest());
          addResultSearch(results, retDocument, SEARCH_ATTRIBUTES,
              request.getContext(), request.toString());
        }
      }
View Full Code Here

    log.info("Server: " + baseURI);
    log.info("filter: " + queryString);
    log.info("get attributes: " + join(toGet, ","));
   

    DirContext context = new InitialDirContext();
   
    NamingEnumeration<SearchResult> results = null;
   
    if ("".equals(queryString)) // We aren't searching, just get attributes
    {
      Attributes attrs = context.getAttributes(baseURI, (String[]) toGet
          .toArray(new String[] {}));
      // Wrap this to fit this method's contract
      SearchResult sr = new SearchResult(null, null, attrs);
      sr.setNameInNamespace(uriToName(baseURI));
      results = new SingletonNamingEnumeration<SearchResult>(sr);
    }
    else // An actual query
    {
      SearchControls sc = new SearchControls();
      sc.setReturningAttributes(toGet.toArray(new String[] {}));
      sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
     
      results = context.search(baseURI, queryString, sc);
    }

    return results;
  }
View Full Code Here

      NamingEnumeration<? extends Attribute> theAttributes = attributes.getAll();
      while (theAttributes.hasMore())
      {
        Attribute attribute = theAttributes.next();
        log.info("Attribute: " + attribute.getID());
        DirContext foo = attribute.getAttributeSyntaxDefinition();
        assertNotNull("I have a syntax definition", foo);
        Attributes lister = foo.getAttributes("");
        if (lister.get("numericoid").get().equals("1.3.6.1.4.1.1466.115.121.1.12"))
        {
          String bar = (String) attribute.get();
          log.info("Points to: " + bar);
          log.info(context.getAttributes(directory + bar));
        }
        foo.close();
       
        NamingEnumeration<?> vals = attribute.getAll();
        while (vals.hasMore())
        {
          Object val = vals.next();
View Full Code Here

     *
     * @return A JNDI DirContext, or null.
     */
    protected DirContext getResources(HttpServletRequest hreq) {

        DirContext result = null;
        // Try the servlet context
        try {
            result = (DirContext) getServletContext()
                .getAttribute(Globals.RESOURCES_ATTR);
        } catch (ClassCastException e) {
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.