Package org.jboss.identity.idm.impl.api

Examples of org.jboss.identity.idm.impl.api.AttributeFilterSearchControl


      //TODO: page control with LDAP request control

      PageSearchControl pageSearchControl = null;
      SortByNameSearchControl sortSearchControl = null;
      AttributeFilterSearchControl attributeFilterSearchControl = null;
      NameFilterSearchControl nameFilterSearchControl = null;

      if (controls != null)
      {
         for (IdentityObjectSearchControl control : controls)
         {
            if (control instanceof PageSearchControl)
            {
               pageSearchControl = (PageSearchControl)control;
            }
            else if (control instanceof SortByNameSearchControl)
            {
               sortSearchControl = (SortByNameSearchControl)control;
            }
            else if (control instanceof AttributeFilterSearchControl)
            {
               attributeFilterSearchControl = (AttributeFilterSearchControl)control;
            }
            else if (control instanceof NameFilterSearchControl)
            {
               nameFilterSearchControl = (NameFilterSearchControl)control;
            }

         }
      }

      String nameFilter = "*";

      //Filter by name
      if (nameFilterSearchControl != null)
      {
         nameFilter = nameFilterSearchControl.getFilter();
      }


      LdapContext ctx = getLDAPContext(invocationCtx);


      checkIOType(type);

      LinkedList<IdentityObject> objects = new LinkedList<IdentityObject>();

      LDAPIdentityObjectTypeConfiguration typeConfiguration = getTypeConfiguration(invocationCtx, type);

      try
      {
         Control[] requestControls = null;

         // Sort control
         if (sortSearchControl != null)
         {
            //TODO: make criticallity optional
            requestControls = new Control[]{
               new SortControl(typeConfiguration.getIdAttributeName(), Control.NONCRITICAL)
            };
         }

         StringBuilder af = new StringBuilder();

         // Filter by attribute values
         if (attributeFilterSearchControl != null)
         {
            af.append("(&");

            for (Map.Entry<String, String[]> stringEntry : attributeFilterSearchControl.getValues().entrySet())
            {
               for (String value : stringEntry.getValue())
               {
                  af.append("(")
                     .append(stringEntry.getKey())
View Full Code Here


      checkControls(controls);

      PageSearchControl pageSearchControl = null;
      SortByNameSearchControl sortSearchControl = null;
      AttributeFilterSearchControl attributeFilterSearchControl = null;
      NameFilterSearchControl nameFilterSearchControl = null;

      if (controls != null)
      {
         for (IdentityObjectSearchControl control : controls)
         {
            if (control instanceof PageSearchControl)
            {
               pageSearchControl = (PageSearchControl)control;
            }
            else if (control instanceof SortByNameSearchControl)
            {
               sortSearchControl = (SortByNameSearchControl)control;
            }
            else if (control instanceof AttributeFilterSearchControl)
            {
               attributeFilterSearchControl = (AttributeFilterSearchControl)control;
            }
            else if (control instanceof NameFilterSearchControl)
            {
               nameFilterSearchControl = (NameFilterSearchControl)control;
            }

         }
      }

      LDAPIdentityObjectImpl ldapFromIO = getSafeLDAPIO(ctx, identity);

      LDAPIdentityObjectTypeConfiguration typeConfig = getTypeConfiguration(ctx, identity.getIdentityType());

      LdapContext ldapContext = getLDAPContext(ctx);

      List<IdentityObject> objects = new LinkedList<IdentityObject>();

      try
      {

         // If parent simply look for all its members
         if (parent)
         {
            Attributes attrs = ldapContext.getAttributes(ldapFromIO.getDn());
            Attribute member = attrs.get(typeConfig.getMembershipAttributeName());

            if (member != null)
            {
               NamingEnumeration memberValues = member.getAll();
               while (memberValues.hasMoreElements())
               {
                  String memberRef = memberValues.nextElement().toString();

                  if (typeConfig.isMembershipAttributeDN())
                  {
                     //TODO: use direct LDAP query instaed of other find method and add attributesFilter

                     if (nameFilterSearchControl != null)
                     {
                        String name = Tools.stripDnToName(memberRef);
                        String regex = Tools.wildcardToRegex(nameFilterSearchControl.getFilter());

                        if (Pattern.matches(regex, name))
                        {
                           objects.add(findIdentityObject(ctx, memberRef));
                        }
                     }
                     else
                     {
                        objects.add(findIdentityObject(ctx, memberRef));
                     }
                  }
                  else
                  {
                     //TODO: if relationships are not refered with DNs and only names its not possible to map
                     //TODO: them to proper IdentityType and keep name uniqnes per type. Workaround needed
                     throw new NotYetImplementedException("LDAP limitation. If relationship targets are not refered with FQDNs " +
                        "and only names, it's not possible to map them to proper IdentityType and keep name uniqnes per type. " +
                        "Workaround needed");
                  }
                  //break;
               }
            }
         }

         // if not parent then all parent entries need to be found
         else
         {
            // Search in all other type contexts
            for (IdentityObjectType parentType : configuration.getConfiguredTypes())
            {
               checkIOType(parentType);

               LDAPIdentityObjectTypeConfiguration parentTypeConfiguration = getTypeConfiguration(ctx, parentType);

               List<String> allowedTypes = Arrays.asList(parentTypeConfiguration.getAllowedMembershipTypes());

               // Check if given identity type can be parent
               if (!allowedTypes.contains(identity.getIdentityType().getName()))
               {
                  continue;
               }

               String nameFilter = "*";

               //Filter by name
               if (nameFilterSearchControl != null)
               {
                  nameFilter = nameFilterSearchControl.getFilter();
               }

               Control[] requestControls = null;

               StringBuilder af = new StringBuilder();

               // Filter by attribute values
               if (attributeFilterSearchControl != null)
               {
                  af.append("(&");

                  for (Map.Entry<String, String[]> stringEntry : attributeFilterSearchControl.getValues().entrySet())
                  {
                     for (String value : stringEntry.getValue())
                     {
                        af.append("(")
                           .append(stringEntry.getKey())
View Full Code Here

      checkControls(controls);

      PageSearchControl pageSearchControl = null;
      SortByNameSearchControl sortSearchControl = null;
      AttributeFilterSearchControl attributeFilterControl = null;
      NameFilterSearchControl nameFilterSearchControl = null;

      if (controls != null)
      {
         for (IdentityObjectSearchControl control : controls)
         {
            if (control instanceof PageSearchControl)
            {
               pageSearchControl = (PageSearchControl)control;
            }
            else if (control instanceof SortByNameSearchControl)
            {
               sortSearchControl = (SortByNameSearchControl)control;
            }
            else if (control instanceof AttributeFilterSearchControl)
            {
               attributeFilterControl = (AttributeFilterSearchControl)control;
            }
            else if (control instanceof NameFilterSearchControl)
            {
               nameFilterSearchControl = (NameFilterSearchControl)control;
            }
         }
      }

      HibernateIdentityObjectType hibernateType = getHibernateIdentityObjectType(ctx, identityType);

      List<IdentityObject> results;

      HibernateEntityManager em = getHibernateEntityManager(ctx);

      try
      {

         Query q = null;

         if (sortSearchControl != null)
         {
            if (sortSearchControl.isAscending())
            {
               q = em.createNamedQuery("findIdentityObjectsByTypeOrderedByNameAsc");
            }
            else
            {
               q = em.createNamedQuery("findIdentityObjectsByTypeOrderedByNameDesc");
            }
         }
         else
         {
            q = em.createNamedQuery("findIdentityObjectsByType");
         }

         if (pageSearchControl != null)
         {
            if (pageSearchControl.getLimit() > 0)
            {
               q.setMaxResults(pageSearchControl.getLimit());
            }
            q.setFirstResult(pageSearchControl.getOffset());

         }

         q.setParameter("realm", getRealm(em, ctx))
          .setParameter("typeName", hibernateType.getName());

         if (nameFilterSearchControl != null)
         {
            q.setParameter("nameFilter", nameFilterSearchControl.getFilter().replaceAll("\\*", "%"));
         }
         else
         {
            q.setParameter("nameFilter", "%");
         }



         results = (List<IdentityObject>)q.getResultList();

      }
      catch (Exception e)
      {
         throw new IdentityException("Cannot find IdentityObjects with type '" + identityType.getName() + "'", e);
      }

      if (attributeFilterControl != null)
      {
         filterByAttributesValues(results, attributeFilterControl.getValues());
      }

      return results;
   }
View Full Code Here

      checkControls(controls);

      PageSearchControl pageSearchControl = null;
      SortByNameSearchControl sortSearchControl = null;
      AttributeFilterSearchControl attributeFilterControl = null;
      NameFilterSearchControl nameFilterSearchControl = null;

      if (controls != null)
      {
         for (IdentityObjectSearchControl control : controls)
         {
            if (control instanceof PageSearchControl)
            {
               pageSearchControl = (PageSearchControl)control;
            }
            else if (control instanceof SortByNameSearchControl)
            {
               sortSearchControl = (SortByNameSearchControl)control;
            }
            else if (control instanceof AttributeFilterSearchControl)
            {
               attributeFilterControl = (AttributeFilterSearchControl)control;
            }
            else if (control instanceof NameFilterSearchControl)
            {
               nameFilterSearchControl = (NameFilterSearchControl)control;
            }
         }
      }

      boolean orderByName = false;
      boolean ascending = true;

      if (sortSearchControl != null)
      {
         orderByName = true;
         ascending = sortSearchControl.isAscending();
      }

      try
      {
         org.hibernate.Query q = null;

         StringBuilder hqlString = new StringBuilder("");

         if (orderByName)
         {
            hqlString.append(" orderBy ior.toIdentityObject.name");
            if (ascending)
            {
               hqlString.append(" asc");
            }
         }

         if (parent)
         {
            hqlString.append("select ior.toIdentityObject from HibernateIdentityObjectRelationship ior where " +
               "ior.toIdentityObject.name like :nameFilter and ior.type.name like :relType and ior.fromIdentityObject like :identity");

            if (orderByName)
            {
               hqlString.append(" orderBy ior.toIdentityObject.name");
               if (ascending)
               {
                  hqlString.append(" asc");
               }
            }
         }
         else
         {
            hqlString.append("select ior.fromIdentityObject from HibernateIdentityObjectRelationship ior where " +
               "ior.fromIdentityObject.name like :nameFilter and ior.type.name like :relType and ior.toIdentityObject like :identity");


            if (orderByName)
            {
               hqlString.append(" orderBy ior.toIdentityObject.name");
               if (ascending)
               {
                  hqlString.append(" asc");
               }
            }
         }



         q = getHibernateEntityManager(ctx).getSession().createQuery(hqlString.toString())
            .setParameter("relType", relationshipType.getName())
            .setParameter("identity",hibernateObject);

         if (nameFilterSearchControl != null)
         {
            q.setParameter("nameFilter", nameFilterSearchControl.getFilter().replaceAll("\\*", "%"));
         }
         else
         {
            q.setParameter("nameFilter", "%");
         }

        
         if (pageSearchControl != null)
         {
            q.setFirstResult(pageSearchControl.getOffset());
            if (pageSearchControl.getLimit() > 0)
            {
               q.setMaxResults(pageSearchControl.getLimit());
            }
         }



          results = q.list();


      }
      catch (Exception e)
      {
         throw new IdentityException("Cannot find IdentityObjects", e);
      }

      if (attributeFilterControl != null)
      {
         filterByAttributesValues(results, attributeFilterControl.getValues());
      }

      return results;
   }
View Full Code Here

      checkControls(controls);

      PageSearchControl pageSearchControl = null;
      SortByNameSearchControl sortSearchControl = null;
      AttributeFilterSearchControl attributeFilterControl = null;
      NameFilterSearchControl nameFilterSearchControl = null;

      if (controls != null)
      {
         for (IdentityObjectSearchControl control : controls)
View Full Code Here

      //TODO: page control with LDAP request control

      PageSearchControl pageSearchControl = null;
      SortByNameSearchControl sortSearchControl = null;
      AttributeFilterSearchControl attributeFilterSearchControl = null;
      NameFilterSearchControl nameFilterSearchControl = null;

      if (controls != null)
      {
         for (IdentityObjectSearchControl control : controls)
         {
            if (control instanceof PageSearchControl)
            {
               pageSearchControl = (PageSearchControl)control;
            }
            else if (control instanceof SortByNameSearchControl)
            {
               sortSearchControl = (SortByNameSearchControl)control;
            }
            else if (control instanceof AttributeFilterSearchControl)
            {
               attributeFilterSearchControl = (AttributeFilterSearchControl)control;
            }
            else if (control instanceof NameFilterSearchControl)
            {
               nameFilterSearchControl = (NameFilterSearchControl)control;
            }

         }
      }

      String nameFilter = "*";

      //Filter by name
      if (nameFilterSearchControl != null)
      {
         nameFilter = nameFilterSearchControl.getFilter();
      }


      LdapContext ctx = getLDAPContext(invocationCtx);


      checkIOType(type);

      LinkedList<IdentityObject> objects = new LinkedList<IdentityObject>();

      LDAPIdentityObjectTypeConfiguration typeConfiguration = getTypeConfiguration(invocationCtx, type);

      try
      {
         Control[] requestControls = null;

         // Sort control
         if (sortSearchControl != null)
         {
            //TODO: make criticallity optional
            requestControls = new Control[]{
               new SortControl(typeConfiguration.getIdAttributeName(), Control.NONCRITICAL)
            };
         }

         StringBuilder af = new StringBuilder();

         // Filter by attribute values
         if (attributeFilterSearchControl != null)
         {
            af.append("(&");

            for (Map.Entry<String, String[]> stringEntry : attributeFilterSearchControl.getValues().entrySet())
            {
               for (String value : stringEntry.getValue())
               {
                  af.append("(")
                     .append(stringEntry.getKey())
View Full Code Here

      checkControls(controls);

      PageSearchControl pageSearchControl = null;
      SortByNameSearchControl sortSearchControl = null;
      AttributeFilterSearchControl attributeFilterSearchControl = null;
      NameFilterSearchControl nameFilterSearchControl = null;

      if (controls != null)
      {
         for (IdentityObjectSearchControl control : controls)
         {
            if (control instanceof PageSearchControl)
            {
               pageSearchControl = (PageSearchControl)control;
            }
            else if (control instanceof SortByNameSearchControl)
            {
               sortSearchControl = (SortByNameSearchControl)control;
            }
            else if (control instanceof AttributeFilterSearchControl)
            {
               attributeFilterSearchControl = (AttributeFilterSearchControl)control;
            }
            else if (control instanceof NameFilterSearchControl)
            {
               nameFilterSearchControl = (NameFilterSearchControl)control;
            }

         }
      }

      LDAPIdentityObjectImpl ldapFromIO = getSafeLDAPIO(ctx, identity);

      LDAPIdentityObjectTypeConfiguration typeConfig = getTypeConfiguration(ctx, identity.getIdentityType());

      LdapContext ldapContext = getLDAPContext(ctx);

      List<IdentityObject> objects = new LinkedList<IdentityObject>();

      try
      {

         // If parent simply look for all its members
         if (parent)
         {
            if (typeConfig.getMembershipAttributeName() == null)
            {
               throw new IdentityException("Membership attribute name not configured. Given IdentityObjectType cannot have" +
                  "members: " + identity.getIdentityType().getName());
            }

            Attributes attrs = ldapContext.getAttributes(ldapFromIO.getDn());
            Attribute member = attrs.get(typeConfig.getMembershipAttributeName());

            if (member != null)
            {
               NamingEnumeration memberValues = member.getAll();
               while (memberValues.hasMoreElements())
               {
                  String memberRef = memberValues.nextElement().toString();

                  if (typeConfig.isMembershipAttributeDN())
                  {
                     //TODO: use direct LDAP query instaed of other find method and add attributesFilter

                     if (nameFilterSearchControl != null)
                     {
                        String name = Tools.stripDnToName(memberRef);
                        String regex = Tools.wildcardToRegex(nameFilterSearchControl.getFilter());

                        if (Pattern.matches(regex, name))
                        {
                           objects.add(findIdentityObject(ctx, memberRef));
                        }
                     }
                     else
                     {
                        objects.add(findIdentityObject(ctx, memberRef));
                     }
                  }
                  else
                  {
                     //TODO: if relationships are not refered with DNs and only names its not possible to map
                     //TODO: them to proper IdentityType and keep name uniqnes per type. Workaround needed
                     throw new NotYetImplementedException("LDAP limitation. If relationship targets are not refered with FQDNs " +
                        "and only names, it's not possible to map them to proper IdentityType and keep name uniqnes per type. " +
                        "Workaround needed");
                  }
                  //break;
               }
            }
         }

         // if not parent then all parent entries need to be found
         else
         {
            // Search in all other type contexts
            for (IdentityObjectType parentType : configuration.getConfiguredTypes())
            {
               checkIOType(parentType);

               LDAPIdentityObjectTypeConfiguration parentTypeConfiguration = getTypeConfiguration(ctx, parentType);

               List<String> allowedTypes = Arrays.asList(parentTypeConfiguration.getAllowedMembershipTypes());

               // Check if given identity type can be parent
               if (!allowedTypes.contains(identity.getIdentityType().getName()))
               {
                  continue;
               }

               String nameFilter = "*";

               //Filter by name
               if (nameFilterSearchControl != null)
               {
                  nameFilter = nameFilterSearchControl.getFilter();
               }

               Control[] requestControls = null;

               StringBuilder af = new StringBuilder();

               // Filter by attribute values
               if (attributeFilterSearchControl != null)
               {
                  af.append("(&");

                  for (Map.Entry<String, String[]> stringEntry : attributeFilterSearchControl.getValues().entrySet())
                  {
                     for (String value : stringEntry.getValue())
                     {
                        af.append("(")
                           .append(stringEntry.getKey())
View Full Code Here

      checkControls(controls);

      PageSearchControl pageSearchControl = null;
      SortByNameSearchControl sortSearchControl = null;
      AttributeFilterSearchControl attributeFilterControl = null;
      NameFilterSearchControl nameFilterSearchControl = null;

      if (controls != null)
      {
         for (IdentityObjectSearchControl control : controls)
         {
            if (control instanceof PageSearchControl)
            {
               pageSearchControl = (PageSearchControl)control;
            }
            else if (control instanceof SortByNameSearchControl)
            {
               sortSearchControl = (SortByNameSearchControl)control;
            }
            else if (control instanceof AttributeFilterSearchControl)
            {
               attributeFilterControl = (AttributeFilterSearchControl)control;
            }
            else if (control instanceof NameFilterSearchControl)
            {
               nameFilterSearchControl = (NameFilterSearchControl)control;
            }
         }
      }

      HibernateIdentityObjectType hibernateType = getHibernateIdentityObjectType(ctx, identityType);

      List<IdentityObject> results;

      Session hibernateSession = getHibernateSession(ctx);

      try
      {

         Query q = null;

         if (sortSearchControl != null)
         {
            if (sortSearchControl.isAscending())
            {
               q = hibernateSession.createQuery(HibernateIdentityObject.findIdentityObjectsByTypeOrderedByNameAsc);
            }
            else
            {
               q = hibernateSession.createQuery(HibernateIdentityObject.findIdentityObjectsByTypeOrderedByNameDesc);
            }
         }
         else
         {
            q = hibernateSession.createQuery(HibernateIdentityObject.findIdentityObjectsByType);
         }

         if (pageSearchControl != null)
         {
            if (pageSearchControl.getLimit() > 0)
            {
               q.setMaxResults(pageSearchControl.getLimit());
            }
            q.setFirstResult(pageSearchControl.getOffset());

         }

         q.setParameter("realm", getRealm(hibernateSession, ctx))
          .setParameter("typeName", hibernateType.getName());

         if (nameFilterSearchControl != null)
         {
            q.setParameter("nameFilter", nameFilterSearchControl.getFilter().replaceAll("\\*", "%"));
         }
         else
         {
            q.setParameter("nameFilter", "%");
         }



         results = (List<IdentityObject>)q.list();

      }
      catch (Exception e)
      {
         throw new IdentityException("Cannot find IdentityObjects with type '" + identityType.getName() + "'", e);
      }

      if (attributeFilterControl != null)
      {
         filterByAttributesValues(results, attributeFilterControl.getValues());
      }

      return results;
   }
View Full Code Here

      checkControls(controls);

      PageSearchControl pageSearchControl = null;
      SortByNameSearchControl sortSearchControl = null;
      AttributeFilterSearchControl attributeFilterControl = null;
      NameFilterSearchControl nameFilterSearchControl = null;

      if (controls != null)
      {
         for (IdentityObjectSearchControl control : controls)
         {
            if (control instanceof PageSearchControl)
            {
               pageSearchControl = (PageSearchControl)control;
            }
            else if (control instanceof SortByNameSearchControl)
            {
               sortSearchControl = (SortByNameSearchControl)control;
            }
            else if (control instanceof AttributeFilterSearchControl)
            {
               attributeFilterControl = (AttributeFilterSearchControl)control;
            }
            else if (control instanceof NameFilterSearchControl)
            {
               nameFilterSearchControl = (NameFilterSearchControl)control;
            }
         }
      }

      boolean orderByName = false;
      boolean ascending = true;

      if (sortSearchControl != null)
      {
         orderByName = true;
         ascending = sortSearchControl.isAscending();
      }

      try
      {
         org.hibernate.Query q = null;

         StringBuilder hqlString = new StringBuilder("");

//         if (orderByName)
//         {
//            hqlString.append(" orderBy ior.toIdentityObject.name");
//            if (ascending)
//            {
//               hqlString.append(" asc");
//            }
//         }

         if (parent)
         {

            if (relationshipType != null)
            {

               hqlString.append("select distinct ior.toIdentityObject from HibernateIdentityObjectRelationship ior where " +
                  "ior.toIdentityObject.name like :nameFilter and ior.type.name like :relType and ior.fromIdentityObject like :identity");
            }
            else
            {
               hqlString.append("select distinct ior.toIdentityObject from HibernateIdentityObjectRelationship ior where " +
                  "ior.toIdentityObject.name like :nameFilter and ior.fromIdentityObject like :identity");
            }
            if (orderByName)
            {
               hqlString.append(" orderBy ior.toIdentityObject.name");
               if (ascending)
               {
                  hqlString.append(" asc");
               }
            }
         }
         else
         {
            if (relationshipType != null)
            {
               hqlString.append("select distinct ior.fromIdentityObject from HibernateIdentityObjectRelationship ior where " +
                  "ior.fromIdentityObject.name like :nameFilter and ior.type.name like :relType and ior.toIdentityObject like :identity");
            }
            else
            {
              hqlString.append("select distinct ior.fromIdentityObject from HibernateIdentityObjectRelationship ior where " +
                  "ior.fromIdentityObject.name like :nameFilter and ior.toIdentityObject like :identity");
            }

            if (orderByName)
            {
               hqlString.append(" orderBy ior.toIdentityObject.name");
               if (ascending)
               {
                  hqlString.append(" asc");
               }
            }
         }



         q = getHibernateSession(ctx).createQuery(hqlString.toString())
            .setParameter("identity",hibernateObject);

         if (relationshipType != null)
         {
            q.setParameter("relType", relationshipType.getName());
         }

         if (nameFilterSearchControl != null)
         {
            q.setParameter("nameFilter", nameFilterSearchControl.getFilter().replaceAll("\\*", "%"));
         }
         else
         {
            q.setParameter("nameFilter", "%");
         }

        
         if (pageSearchControl != null)
         {
            q.setFirstResult(pageSearchControl.getOffset());
            if (pageSearchControl.getLimit() > 0)
            {
               q.setMaxResults(pageSearchControl.getLimit());
            }
         }



          results = q.list();


      }
      catch (Exception e)
      {
         throw new IdentityException("Cannot find IdentityObjects", e);
      }

      if (attributeFilterControl != null)
      {
         filterByAttributesValues(results, attributeFilterControl.getValues());
      }

      return results;
   }
View Full Code Here

      checkControls(controls);

      PageSearchControl pageSearchControl = null;
      SortByNameSearchControl sortSearchControl = null;
      AttributeFilterSearchControl attributeFilterControl = null;
      NameFilterSearchControl nameFilterSearchControl = null;

      if (controls != null)
      {
         for (IdentityObjectSearchControl control : controls)
View Full Code Here

TOP

Related Classes of org.jboss.identity.idm.impl.api.AttributeFilterSearchControl

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.