Package org.jboss.identity.idm.exception

Examples of org.jboss.identity.idm.exception.IdentityException


         //Handle only those credentials that implement SPI

         if (!(credential instanceof IdentityObjectCredential))
         {
            throw new IdentityException("Unsupported Credential implementation: " + credential.getClass());
         }

         ioc = (IdentityObjectCredential)credential;

         // All credentials must pass
View Full Code Here


      {
         getRepository().updateCredential(getInvocationContext(), createIdentityObject(identity), (IdentityObjectCredential)credential);
      }
      else
      {
         throw new IdentityException("Unsupported Credential implementation: " + credential.getClass());
      }
   }
View Full Code Here

                                              IdentityObjectType type,
                                              Map<String, String[]> attributes) throws IdentityException
   {
      if (name == null)
      {
         throw new IdentityException("Name cannot be null");
      }

      checkIOType(type);

      if (log.isLoggable(Level.FINER))
      {
         log.finer(toString() + ".createIdentityObject with name: " + name + " and type: " + type.getName());
      }

      LdapContext ldapContext = getLDAPContext(invocationCtx);

      try
      {
         //  If there are many contexts specified in the configuration the first one is used
         LdapContext ctx = (LdapContext)ldapContext.lookup(getTypeConfiguration(invocationCtx, type).getCtxDNs()[0]);

         //We store new entry using set of attributes. This should give more flexibility then
         //extending identity object from ContextDir - configure what objectClass place there
         Attributes attrs = new BasicAttributes(true);

         //create attribute using provided configuration
         Map<String, String[]> attributesToAdd = getTypeConfiguration(invocationCtx, type).getCreateEntryAttributeValues();

         //merge
         if (attributes != null)
         {
            for (Map.Entry<String, String[]> entry : attributes.entrySet())
            {

               if (!attributesToAdd.containsKey(entry.getKey()))
               {
                  attributesToAdd.put(entry.getKey(), entry.getValue());
               }
               else
               {
                  List<String> list1 = Arrays.asList(attributesToAdd.get(entry.getKey()));
                  List<String> list2 = Arrays.asList(entry.getValue());

                  list1.addAll(list2);

                  String[] vals = list1.toArray(new String[list1.size()]);

                  attributesToAdd.put(entry.getKey(), vals);

               }
            }
         }

         //attributes
         for (Iterator it1 = attributesToAdd.keySet().iterator(); it1.hasNext();)
         {
            String attributeName = (String)it1.next();


            Attribute attr = new BasicAttribute(attributeName);
            String[] attributeValues = attributesToAdd.get(attributeName);

            //values

            for (String attrValue : attributeValues)
            {
               attr.add(attrValue);
            }

            attrs.put(attr);
         }

         // Make it RFC 2253 compliant
         LdapName validLDAPName = new LdapName(getTypeConfiguration(invocationCtx, type).getIdAttributeName().concat("=").concat(name));

         log.finer("creating ldap entry for: " + validLDAPName + "; " + attrs);
         ctx.createSubcontext(validLDAPName, attrs);
      }
      catch (Exception e)
      {
         throw new IdentityException("Failed to create identity object", e);
      }
      finally
      {
         try
         {
            ldapContext.close();
         }
         catch (NamingException e)
         {
            throw new IdentityException("Failed to close LDAP connection", e);
         }
      }                                                                 

      return findIdentityObject(invocationCtx, name, type);
View Full Code Here

      String dn = ldapIdentity.getDn();

      if (dn == null)
      {
         throw new IdentityException("Cannot obtain DN of identity");
      }

      LdapContext ldapContext = getLDAPContext(invocationCtx);

      try
      {
         log.finer("removing entry: " + dn);
         ldapContext.unbind(dn);
      }
      catch (Exception e)
      {
         throw new IdentityException("Failed to remove identity: ", e);
      }
      finally
      {
         try
         {
            ldapContext.close();
         }
         catch (NamingException e)
         {
            throw new IdentityException("Failed to close LDAP connection", e);
         }
      }

   }
View Full Code Here

      {
         //log.debug("No identity object found", e);
      }
      catch (Exception e)
      {
         throw new IdentityException("User search failed.", e);
      }
      return 0;
   }
View Full Code Here

      {
         //log.debug("name = " + name);

         if (name == null)
         {
            throw new IdentityException("Identity object name canot be null");
         }

         String filter = getTypeConfiguration(invocationCtx, type).getEntrySearchFilter();
         List sr = null;


         String[] entryCtxs = getTypeConfiguration(invocationCtx, type).getCtxDNs();


         if (filter != null && filter.length() > 0)
         {
            Object[] filterArgs = {name};
            sr = searchIdentityObjects(invocationCtx,
               entryCtxs,
               filter,
               filterArgs,
               new String[]{getTypeConfiguration(invocationCtx, type).getIdAttributeName()},
               null);
         }
         else
         {
            //search all entries
            filter = "(".concat(getTypeConfiguration(invocationCtx, type).getIdAttributeName()).concat("=").concat(name).concat(")");
            sr = searchIdentityObjects(invocationCtx,
               entryCtxs,
               filter,
               null,
               new String[]{getTypeConfiguration(invocationCtx, type).getIdAttributeName()},
               null);
         }

         //log.debug("Search filter: " + filter);

         if (sr.size() > 1)
         {
            throw new IdentityException("Found more than one identity object with name: " + name +
               "; Posible data inconsistency");
         }
         SearchResult res = (SearchResult)sr.iterator().next();
         ctx = (Context)res.getObject();
         String dn = ctx.getNameInNamespace();
         IdentityObject io = createIdentityObjectInstance(invocationCtx, type, res.getAttributes(), dn);
         ctx.close();
         return io;

      }
      catch (NoSuchElementException e)
      {
         //log.debug("No identity object found with name: " + name, e);
      }
      catch (NamingException e)
      {
         throw new IdentityException("IdentityObject search failed.", e);
      }
      finally
      {
         try
         {
            if (ctx != null)
            {
               ctx.close();
            }
         }
         catch (NamingException e)
         {
            throw new IdentityException("Failed to close LDAP connection", e);
         }
      }

      return null;
   }
View Full Code Here

      try
      {
         if (id == null)
         {
            throw new IdentityException("identity id cannot be null");
         }

         String dn = id;

         IdentityObjectType type = null;

         //Recognize the type by ctx DN

         IdentityObjectType[] possibleTypes = getConfiguration(ctx).getConfiguredTypes();

         for (IdentityObjectType possibleType : possibleTypes)
         {
            String[] typeCtxs = getTypeConfiguration(ctx, possibleType).getCtxDNs();

            for (String typeCtx : typeCtxs)
            {
               if (dn.endsWith(typeCtx))
               {
                  type = possibleType;
                  break;
               }
            }
            if (type != null)
            {
               break;
            }
         }

         if (type == null)
         {
            throw new IdentityException("Cannot recognize identity object type by its DN: " + dn);
         }

         // Grab entry

         Attributes attrs = ldapContext.getAttributes(dn);

         if (attrs == null)
         {
            throw new IdentityException("Can't find identity entry with DN: " + dn);
         }

         return createIdentityObjectInstance(ctx, type, attrs, dn);

      }
      catch (NoSuchElementException e)
      {
         //log.debug("No identity object found with dn: " + dn, e);
      }
      catch (NamingException e)
      {
         throw new IdentityException("Identity object search failed.", e);
      }
      finally
      {
         try
         {
            ldapContext.close();
         }
         catch (NamingException e)
         {
            throw new IdentityException("Failed to close LDAP connection", e);
         }
      }
      return null;
   }
View Full Code Here

      {
         //log.debug("No identity object found with name: " + name, e);
      }
      catch (Exception e)
      {
         throw new IdentityException("IdentityObject search failed.", e);
      }
      finally
      {
         try
         {
            if (ctx != null)
            {
               ctx.close();
            }
         }
         catch (NamingException e)
         {
            throw new IdentityException("Failed to close LDAP connection", e);
         }
      }

      if (constraints != null && constraints.isPaged())
      {
View Full Code Here

         // 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 (constraints != null && constraints.getFilter() != null)
                     {
                        String name = Tools.stripDnToName(memberRef);
                        String regex = Tools.wildcardToRegex(constraints.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 (constraints != null && constraints.getFilter() != null)
               {
                  nameFilter = constraints.getFilter();
               }

               Control[] requestControls = null;

               StringBuilder af = new StringBuilder();

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

                  for (Map.Entry<String, String[]> stringEntry : constraints.getValues().entrySet())
                  {
                     for (String value : stringEntry.getValue())
                     {
                        af.append("(")
                           .append(stringEntry.getKey())
                           .append("=")
                           .append(value)
                           .append(")");
                     }
                  }

                  af.append(")");
               }

               // Add filter to search only parents of the given entry
               af.append("(")
                  .append(parentTypeConfiguration.getMembershipAttributeName())
                  .append("=");
               if (parentTypeConfiguration.isMembershipAttributeDN())
               {
                  af.append(ldapFromIO.getDn());
               }
               else
               {
                  //TODO: this doesn't make much sense unless parent/child are same identity types and resides in the same LDAP context
                  af.append(ldapFromIO.getName());
               }
               af.append(")");


               String filter = parentTypeConfiguration.getEntrySearchFilter();
               List<SearchResult> sr = null;

               String[] entryCtxs = parentTypeConfiguration.getCtxDNs();

               if (filter != null && filter.length() > 0)
               {

                  Object[] filterArgs = {nameFilter};
                  sr = searchIdentityObjects(ctx,
                     entryCtxs,
                     "(&(" + filter + ")" + af.toString() + ")",
                     filterArgs,
                     new String[]{parentTypeConfiguration.getIdAttributeName()},
                     requestControls);
               }
               else
               {
                  filter = "(".concat(parentTypeConfiguration.getIdAttributeName()).concat("=").concat(nameFilter).concat(")");
                  sr = searchIdentityObjects(ctx,
                     entryCtxs,
                     "(&(" + filter + ")" + af.toString() + ")",
                     null,
                     new String[]{parentTypeConfiguration.getIdAttributeName()},
                     requestControls);
               }

               for (SearchResult res : sr)
               {
                  LdapContext ldapCtx = (LdapContext)res.getObject();
                  String dn = ldapCtx.getNameInNamespace();

                  objects.add(createIdentityObjectInstance(ctx, parentType, res.getAttributes(), dn));
               }
            }


         }

      }
      catch (NamingException e)
      {
         throw new IdentityException("Failed to resolve relationship", e);
      }
      finally
      {
         try
         {
            ldapContext.close();
         }
         catch (NamingException e)
         {
            throw new IdentityException("Failed to close LDAP connection", e);
         }
      }

      if (constraints != null && constraints.isPaged())
      {
View Full Code Here

         }

      }
      catch (NamingException e)
      {
         throw new IdentityException("Failed to resolve relationship", e);
      }
      finally
      {
         try
         {
            ldapContext.close();
         }
         catch (NamingException e)
         {
            throw new IdentityException("Failed to close LDAP connection", e);
         }
      }


      return relationships;
View Full Code Here

TOP

Related Classes of org.jboss.identity.idm.exception.IdentityException

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.