Package org.jboss.portal.identity

Examples of org.jboss.portal.identity.IdentityException


      {
         log.debug("findUserByUserName(): username = " + userName);

         if (userName == null)
         {
            throw new IdentityException("User name canot be null");
         }


         String filter = "(".concat(getUidAttributeID()).concat("=").concat(userName).concat(")");
         log.debug("Search filter: " + filter);

         List sr = searchUsers(filter, null);
         if (sr.size() > 1)
         {
            throw new IdentityException("Found more than one user with id: " + userName + "" +
               "Posible data inconsistency");
         }
         SearchResult res = (SearchResult)sr.iterator().next();
         ctx = (Context)res.getObject();
         String dn = ctx.getNameInNamespace();
         User user = createUserInstance(res.getAttributes(), dn);
         ctx.close();
         return user;

      }
      catch (NoSuchElementException e)
      {
         log.debug("No user found with name: " + userName, e);

      }
      catch (NamingException e)
      {
         throw new IdentityException("User search failed.", e);
      }
      finally
      {
         try
         {
            if (ctx != null)
            {
               ctx.close();
            }
         }
         catch (NamingException e)
         {
            throw new IdentityException("Failed to close LDAP connection", e);
         }
      }
      throw new NoSuchUserException("No user found with name: " + userName);

   }
View Full Code Here


   public User findUserById(Object id) throws IdentityException, IllegalArgumentException, NoSuchUserException
   {
      if (id == null)
      {
         throw new IdentityException("Cannot search user with null id");
      }
      if (!(id instanceof String))
      {
         throw new IdentityException("Only String id is suppoted");
      }
      return findUserByDN(id.toString());

   }
View Full Code Here

   public User createUser(String userName, String password) throws IdentityException, IllegalArgumentException
   {

      if (userName == null)
      {
         throw new IdentityException("User name cannot be null");
      }
      /*if (realEmail == null)
      {
         throw new IdentityException("User email cannot be null");
      }*/
      if (password == null)
      {
         throw new IdentityException("User password cannot be null");
      }

      log.debug("Creating user: " + userName);


      LdapContext ldapContext = getConnectionContext().createInitialContext();

      try
      {
         //
         LdapContext ctx = (LdapContext)ldapContext.lookup(getContainerDN());

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

         //create attribute using provided configuration
         Map attributesToAdd = getAttributesToAdd();

         //attributes
         for (Iterator it1 = attributesToAdd.keySet().iterator(); it1.hasNext();)
         {
            String attributeName = (String)it1.next();
            if (getUidAttributeID().equals(attributeName))
            {
               continue;
            }
            log.debug("adding attribute: " + attributeName);
            Attribute attr = new BasicAttribute(attributeName);
            Set attributeValues = (Set)attributesToAdd.get(attributeName);

            //values
            for (Iterator it2 = attributeValues.iterator(); it2.hasNext();)
            {
               String attrValue = (String)it2.next();
               log.debug("adding attribute value: " + attrValue);
               attr.add(attrValue);
            }
            attrs.put(attr);
         }

         if (!isSetPasswordAfterUserCreate())
         {
            attrs.put(getPasswordAttributeId(), password);
         }

         String validUserName = LDAPTools.encodeRfc2253Name(userName);

         String dn = getUidAttributeID().concat("=").concat(validUserName);

         log.debug("creating ldap entry for: " + dn + "; " + attrs);
         ctx.createSubcontext(dn, attrs);


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

      LDAPUserImpl u =  (LDAPUserImpl)findUserByUserName(userName);

View Full Code Here

      String userName = ldapu.getUserName();

      if (ldapu == null)
      {
         throw new IdentityException("Cannot find user for removal");
      }

      if (ldapu.getDn() == null)
      {
         throw new IdentityException("Cannot obtain DN of user");
      }

      LdapContext ldapContext = getConnectionContext().createInitialContext();

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


      //user was successfull removed so fire events
View Full Code Here

      //log.info("Current implementation of findUsersFilteredByUserName returns all users and is not \"offset\" and \"limit\" sensitive ");

      if (limit == 0)
      {
         throw new IdentityException("Search limit shouldn't be set to 0");
      }

      List uf = new LinkedList();
      Enumeration results = null;


      if (filter.length() == 0)
      {
         filter = "*";
      }
      else if (!(filter.length() == && filter.equals("*")))
      {
         filter = "*" + filter + "*";
      }

      try
      {
         //search all entries containing "uid" attribute
         String ldap_filter = "(".concat(getUidAttributeID()).concat("=").concat(filter).concat(")");
         log.debug("Search filter: " + filter);



         uf = searchUsers(ldap_filter, null);

         int size = uf.size();
         if (offset == 0 && size <= limit)
         {
            return processUsers(uf);
         }

         Collections.sort(uf, new UserEntryComparator());

         if (offset + limit <= size)
         {
            return processUsers(uf.subList(offset, offset + limit));
         }
         else if (offset >= size)
         {
            return new HashSet();
         }

         return processUsers(uf.subList(offset, size));
      }
      catch (NoSuchElementException e)
      {
         log.debug("No users found", e);
      }
      catch (Throwable e)
      {
         throw new IdentityException("User search failed.", e);
      }

      //won't happen
      return null;

View Full Code Here

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

      {
         log.debug("findRoleByName(): name = " + name);

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


         String filter = getRoleSearchFilter();
         log.debug("Search filter: " + filter);


         Object[] filterArgs = {name};
        
         List sr = searchRoles(filter, filterArgs);
         if (sr.size() > 1)
         {
            throw new IdentityException("Found more than one role with id: " + name + "" +
               "Posible data inconsistency");
         }
         if (sr.size() == 0)
         {
            throw new IdentityException("No such role " + name);
         }
         SearchResult res = (SearchResult)sr.iterator().next();
         DirContext ctx  = (DirContext)res.getObject();
         Role role = createRoleInstance(res.getAttributes(),ctx.getNameInNamespace());
         ctx.close();
         return role;

      }
      catch (NoSuchElementException e)
      {
         log.debug("No role found with name: " + name, e);
      }
      catch (NamingException e)
      {
         throw new IdentityException("Role search failed.", e);
      }
      throw new IdentityException("No role found with name: " + name);
   }
View Full Code Here

            ctx.close();
         }
      }
      catch (Exception e)
      {
         throw new IdentityException("Can't retreive roles", e);
      }

      return roles;

   }
View Full Code Here

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

      {
         log.debug("No roles found", e);
      }
      catch (Exception e)
      {
         throw new IdentityException("Role search failed.", e);
      }
      return rf;
   }
View Full Code Here

TOP

Related Classes of org.jboss.portal.identity.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.