Package javax.naming.ldap

Examples of javax.naming.ldap.LdapContext


        controls.setSearchScope( SearchControls.OBJECT_SCOPE );
        controls.setDerefLinkFlag( false );
        controls.setReturningAttributes( new String[]
            { "*", "+" } );

        LdapContext nullRootCtx = getRootContext( getService() );

        NamingEnumeration<SearchResult> list = nullRootCtx.search( "", "(objectClass=*)", controls );
        Attributes rootDse = null;

        while ( list.hasMore() )
        {
            SearchResult result = list.next();
View Full Code Here


    {
        SearchControls controls = new SearchControls();
        controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
        controls.setDerefLinkFlag( false );

        LdapContext nullRootCtx = getRootContext( getService() );

        NamingEnumeration<SearchResult> list = nullRootCtx.search( "", "(cn=*)", controls );
        HashMap<String, Attributes> map = new HashMap<String, Attributes>();

        while ( list.hasMore() )
        {
            SearchResult result = list.next();
View Full Code Here

        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
        controls.setDerefLinkFlag( false );
        controls.setReturningAttributes( new String[]
            { "*", "+" } );

        LdapContext nullRootCtx = getRootContext( getService() );

        NamingEnumeration<SearchResult> list = nullRootCtx.search( "", "(ou=testing01)", controls );
        Attributes rootDse = null;

        while ( list.hasMore() )
        {
            SearchResult result = list.next();
View Full Code Here

      String groupDN = ldapAttrMapping.groupDNKey + "=" + child.getGroupName() + "," + searchBase;
      String filter = ldapAttrMapping.groupNameAttr + "=" + child.getGroupName();

      SearchControls constraints = new SearchControls();
      constraints.setSearchScope(SearchControls.ONELEVEL_SCOPE);
      LdapContext ctx = ldapService.getLdapContext();
      try
      {
         NamingEnumeration<SearchResult> results = null;
         for (int err = 0;; err++)
         {
            try
            {
               results = ctx.search(searchBase, filter, constraints);

               if (results.hasMore())
               {
                  if (LOG.isDebugEnabled())
                  {
                     LOG.debug("Group " + child + ", parent  " + parent + " already exists. ");
                  }
                  throw new Exception("Group " + child + ", parent  " + parent + " already exists. ");
               }

               GroupImpl group = (GroupImpl)child;
               if (broadcast)
               {
                  preSave(group, true);
               }

               ctx.createSubcontext(groupDN, ldapAttrMapping.groupToAttributes(child));
               cacheHandler.put(child.getId(), group, CacheType.GROUP);

               if (broadcast)
               {
                  postSave(group, true);
View Full Code Here

   /**
    * {@inheritDoc}
    */
   public void saveGroup(Group group, boolean broadcast) throws Exception
   {
      LdapContext ctx = ldapService.getLdapContext();
      try
      {
         for (int err = 0;; err++)
         {
            try
            {
               Group parent = findGroupById(ctx, group.getParentId());
               setId(parent, group);
               String groupDN = ldapAttrMapping.groupDNKey + "=" + group.getGroupName() + "," + createSubDN(parent);

               ArrayList<ModificationItem> modifications = new ArrayList<ModificationItem>();
               ModificationItem mod =
                  new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(
                     ldapAttrMapping.ldapDescriptionAttr, group.getDescription()));
               modifications.add(mod);

               mod =
                  new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(ldapAttrMapping.groupLabelAttr,
                     group.getLabel()));
               modifications.add(mod);

               ModificationItem[] mods = new ModificationItem[modifications.size()];
               modifications.toArray(mods);
               if (broadcast)
                  preSave(group, true);
               ctx.modifyAttributes(groupDN, mods);
               if (broadcast)
                  postSave(group, true);

               cacheHandler.put(group.getId(), group, CacheType.GROUP);
               return;
View Full Code Here

            buffer.append(ldapAttrMapping.groupDNKey + "=" + dnParts[x] + ", ");
         }
      }
      buffer.append(groupsBaseDN);

      LdapContext ctx = ldapService.getLdapContext();
      String searchBase = buffer.toString();
      String filter = ldapAttrMapping.groupObjectClassFilter;
      SearchControls constraints = new SearchControls();
      constraints.setSearchScope(SearchControls.ONELEVEL_SCOPE);
      try
      {
         NamingEnumeration<SearchResult> results = null;
         for (int err = 0;; err++)
         {
            try
            {
               try
               {
                  results = ctx.search(searchBase, filter, constraints);
               }
               catch (NamingException e1)
               {
                  // if connection error let process it in common way
                  if (isConnectionError(e1))
View Full Code Here

   {
      String filter = ldapAttrMapping.groupNameAttr + "=" + group.getGroupName();
      String searchBase = this.createSubDN(group.getParentId());
      SearchControls constraints = new SearchControls();
      constraints.setSearchScope(SearchControls.ONELEVEL_SCOPE);
      LdapContext ctx = ldapService.getLdapContext();

      try
      {
         NamingEnumeration<SearchResult> results = null;
         for (int err = 0;; err++)
         {
            try
            {
               results = ctx.search(searchBase, filter, constraints);

               if (!results.hasMoreElements())
               {
                  if (LOG.isDebugEnabled())
                  {
View Full Code Here

    * {@inheritDoc}
    */
   public Collection<Group> findGroupByMembership(String userName, String membershipType) throws Exception
   {
      List<Group> groups = new ArrayList<Group>();
      LdapContext ctx = ldapService.getLdapContext();
      try
      {
         NamingEnumeration<SearchResult> results = null;
         for (int err = 0;; err++)
         {
            groups.clear();
            try
            {
               String userDN = getDNFromUsername(ctx, userName);
               if (userDN == null)
               {
                  return groups;
               }
               String filter =
                  "(&(" + ldapAttrMapping.membershipTypeMemberValue + "=" + userDN + ")("
                     + ldapAttrMapping.membershipTypeRoleNameAttr + "=" + membershipType + "))";
               SearchControls constraints = new SearchControls();
               constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);

               results = ctx.search(ldapAttrMapping.groupsURL, filter, constraints);
               while (results.hasMoreElements())
               {
                  SearchResult sr = results.next();
                  NameParser parser = ctx.getNameParser("");
                  Name entryNameName = parser.parse(new CompositeName(sr.getName()).get(0));
                  String entryName =
                     String.valueOf(entryNameName).substring(entryNameName.getSuffix(1).toString().length() + 1);
                  String groupDN = entryName + "," + ldapAttrMapping.groupsURL;
                  Group group = getGroupByDN(ctx, groupDN);
View Full Code Here

         buffer.append("/" + groupIdParts[x]);
         if (x == (groupIdParts.length - 2))
            parentId = buffer.toString();
      }
      String groupDN = getGroupDNFromGroupId(groupId);
      LdapContext ctx = ldapService.getLdapContext();
      try
      {
         for (int err = 0;; err++)
         {
            try
            {
               Attributes attrs = ctx.getAttributes(groupDN);
               group = ldapAttrMapping.attributesToGroup(attrs);
               ((GroupImpl)group).setId(groupId);
               ((GroupImpl)group).setParentId(parentId);

               if (group != null)
View Full Code Here

      List<Group> groups = new ArrayList<Group>();

      SearchControls constraints = new SearchControls();
      constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);

      LdapContext ctx = ldapService.getLdapContext();
      String groupName = "*";
      try
      {
         NamingEnumeration<SearchResult> results = null;
         for (int err = 0;; err++)
         {
            groups.clear();
            try
            {
               try
               {
                  results =
                     ctx.search(ldapAttrMapping.groupsURL, "(" + ldapAttrMapping.groupNameAttr + "=" + groupName + ")",
                        constraints);
               }
               catch (NamingException e1)
               {
                  // if connection error let process it in common way
                  if (isConnectionError(e1))
                     throw e1;
                  if (LOG.isDebugEnabled())
                     LOG.debug("Failed to get all groups. ", e1);
                  return groups;
               }
               while (results.hasMoreElements())
               {
                  SearchResult sr = results.next();
                  NameParser parser = ctx.getNameParser("");
                  CompositeName name = new CompositeName(sr.getName());
                  if (name.size() > 0)
                  {
                     Name entryName = parser.parse(name.get(0));
                     String groupDN = entryName + "," + ldapAttrMapping.groupsURL;
View Full Code Here

TOP

Related Classes of javax.naming.ldap.LdapContext

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.