Package org.jboss.portal.identity

Examples of org.jboss.portal.identity.IdentityException


   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

   public void start() throws Exception
   {
      if (getConnectionJNDIName() == null)
      {
         throw new IdentityException("Cannot obtain ldap connection context JNDI name");
      }

      try
      {
         connectionContext = (LDAPConnectionContext)new InitialContext().lookup(getConnectionJNDIName());
View Full Code Here

   public void updatePassword(LDAPUserImpl ldapu, String password) throws IdentityException
   {
      if ((password == null || password.length() == 0) && !isAllowEmptyPasswords())
      {
         throw new IdentityException("Cannot update password with empty value - please set proper option to allow this");
      }

      String attributeName = getPasswordAttributeId();

      LdapContext ldapContext = getConnectionContext().createInitialContext();

      String passwordString = password;

      if (getEnclosePasswordWith() != null)
      {
         String enc = getEnclosePasswordWith();
         passwordString = enc + passwordString + enc;
      }

      byte[] encodedPassword = null;

      if (getPasswordEncoding() != null && passwordString != null)
      {
         try
         {
            encodedPassword = passwordString.getBytes(getPasswordEncoding());
         }
         catch (UnsupportedEncodingException e)
         {
            throw new IdentityException("Error while encoding password with configured setting: " + getPasswordEncoding(),
               e);
         }
      }

     



      try
      {
         //TODO: maybe perform a schema check if this attribute is allowed for such entry

         Attributes attrs = new BasicAttributes(true);
         Attribute attr = new BasicAttribute(attributeName);
         if (encodedPassword != null)
         {

            attr.add(encodedPassword);
         }
         else
         {
            attr.add(passwordString);
         }
         attrs.put(attr);

         if(getUpdatePasswordAttributeValues() != null && getUpdatePasswordAttributeValues().size() > 0)
         {
            Map<String, Set<String>>  attributesToAdd = getUpdatePasswordAttributeValues();
            for (Map.Entry<String, Set<String>> entry : attributesToAdd.entrySet())
            {
               Attribute additionalAttr = new BasicAttribute(entry.getKey());
               for (String val : entry.getValue())
               {
                  additionalAttr.add(val);
               }
               attrs.put(additionalAttr);
            }

         }

         ldapContext.modifyAttributes(ldapu.getDn(), DirContext.REPLACE_ATTRIBUTE,attrs);
      }
      catch (NamingException e)
      {
         throw new IdentityException("Cannot set user password value.", e);
      }
      finally
      {
         try
         {
            ldapContext.close();
         }
         catch (NamingException e)
         {
            throw new IdentityException("Failed to close LDAP connection", e);
         }
      }

   }
View Full Code Here

         {
            ldapContext.close();
         }
         catch (NamingException e)
         {
            throw new IdentityException("Failed to close LDAP connection", e);
         }
      }
      return false;
   }
View Full Code Here


         Attribute uida = attrs.get(getUidAttributeID());
         if (uida == null)
         {
            throw new IdentityException("LDAP entry doesn't contain proper attribute:" + getUidAttributeID());
         }

         //ldapu = new LDAPUserImpl(dn,getIdentityContext(), uida.get().toString());

         //make DN as user ID
         ldapu = new LDAPUserImpl(dn,getIdentityContext(), dn);

         if (isUserNameToLowerCase())
         {
            ldapu.setUserName(uida.get().toString().toLowerCase());
         }
         else
         {
            ldapu.setUserName(uida.get().toString());
         }

         log.debug("user uid: " + ldapu.getId());
         log.debug("user dn: " + ldapu.getDn());


      }
      catch (Exception e)
      {
         throw new IdentityException("Couldn't create LDAPUserImpl object from ldap entry (SearchResult)", e);
      }

      return ldapu;
   }
View Full Code Here

      {
         log.debug("findUserByDN(): DN = " + dn);

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

         Attributes attrs = ldapContext.getAttributes(dn);

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

         return createUserInstance(attrs, dn);

      }
      catch (NoSuchElementException e)
      {
         log.debug("No user found with dn: " + dn, e);
      }
      catch (NamingException e)
      {
         throw new IdentityException("User 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

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.