Package org.jboss.portal.identity

Examples of org.jboss.portal.identity.IdentityException


   protected LDAPConnectionContext getConnectionContext() throws IdentityException
   {
      if (connectionContext == null)
      {
         //this.connectionContext = (LDAPConnectionContext)getIdentityContext().getObject(IdentityContext.TYPE_CONNECTION_CONTEXT);
         throw new IdentityException("No LDAPConnectionContext available");
      }
      return connectionContext;
   }
View Full Code Here


   protected String getContainerDN() throws IdentityException
   {
      String cont = getIdentityConfiguration().getValue(IdentityConfiguration.USER_CONTAINER_DN);
      if (cont == null)
      {
         throw new IdentityException("Configuration option missing: " + IdentityConfiguration.USER_CONTAINER_DN);
      }
      return cont;
   }
View Full Code Here

   protected String getUserSearchFilter() throws IdentityException
   {
      String searchFilter =  getIdentityConfiguration().getValue(IdentityConfiguration.USER_SEARCH_FILTER);
      if (searchFilter == null)
      {
         throw new IdentityException(IdentityConfiguration.USER_SEARCH_FILTER + " missing in configuration");
      }
      else
      {
         return searchFilter;
      }
View Full Code Here

   protected String getUserSearchCtxDN() throws IdentityException
   {
      String searchCtx =  getIdentityConfiguration().getValue(IdentityConfiguration.USER_CONTEXT_DN);
      if (searchCtx == null)
      {
         throw new IdentityException(IdentityConfiguration.USER_CONTEXT_DN + " missing in configuration");
      }
      else
      {
         return searchCtx;
      }
View Full Code Here

   protected Map getAttributesToAdd() throws IdentityException
   {
      Map attributesToAdd = getIdentityConfiguration().getOptions(IdentityConfiguration.GROUP_USER_CREATE_ATTRIBUTES);
      if (attributesToAdd == null)
      {
         throw new IdentityException(IdentityConfiguration.GROUP_USER_CREATE_ATTRIBUTES + " missing in configuration");
      }
      return attributesToAdd;
   }
View Full Code Here

         {
            user = getUserModule().findUserById(user.getId());
         }
         catch(NoSuchUserException e)
         {
            throw new IdentityException("Illegal state - cached user doesn't exist in identity store: ", e);
         }
      }

      LDAPUserImpl ldapUser = null;

      if (user instanceof LDAPUserImpl)
      {
         ldapUser = (LDAPUserImpl)user;
      }
      else
      {
         throw new IllegalArgumentException("UserMembershipModuleImpl supports only LDAPUserImpl objects");
      }

      Set roles = new HashSet();

      LdapContext ldapContext = getConnectionContext().createInitialContext();

      try
      {
         log.debug("findRoles(): role = " + ldapUser.getDn());

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

         //obtain Role entry attributes from directory
         Attributes attrs = ldapContext.getAttributes(ldapUser.getDn(), new String[] {getMemberAttributeID()});

         //log.debug("User attributes: " + attrs);
         if (attrs == null )
         {
            throw new IdentityException("Cannot find User with DN: " + ldapUser.getDn());
         }

         Attribute memberOfAttribute = attrs.get(getMemberAttributeID());

         //if there are no members
         if (memberOfAttribute == null)
         {
            return roles;
         }

         //iterate over user names belonging to this role
         NamingEnumeration values = memberOfAttribute.getAll();
         while (values.hasMoreElements())
         {
            String value = values.nextElement().toString();
            String name = value;

            try
            {
               //if user is pointed as DN get only it's name
               if (isUidAttributeIsDN())
               {
                  roles.add(getRoleModule().findRoleByDN(name));
               }
               else
               {
                  roles.add(getRoleModule().findRoleByName(name));
               }
            }
            catch(IdentityException ie)
            {
               log.error("Failed to find role: " + name + "/" + value, ie);

            }
         }
      }
      catch (NamingException e)
      {
         throw new IdentityException("Resolving User Roles failed.", e);
      }
      finally
      {
         try
         {
            ldapContext.close();
         }
         catch (NamingException e)
         {
            throw new IdentityException("Failed to close LDAP connection", e);
         }
      }

      return roles;
View Full Code Here

               {
                  user = getUserModule().findUserById(user.getId());
               }
               catch(NoSuchUserException e)
               {
                  throw new IdentityException("Illegal state - cached user doesn't exist in identity store: ", e);
               }
            }

            LDAPUserImpl ldapUser = (LDAPUserImpl)user;

            userDNsToAdd.add(ldapUser.getDn());
         }
         catch(ClassCastException e)
         {
            throw new IdentityException("Can add only LDAPUserImpl objects", e);
         }
      }

      String memberOfName=null;

      //Find all the users that currently contain role as member (need to remove role from some of them)
      if (isUidAttributeIsDN())
      {
         memberOfName = ldapRole.getDn();
      }
      else
      {
         memberOfName = ldapRole.getName();
      }

      LdapContext ldapContext = getConnectionContext().createInitialContext();

      try
      {
         String filter = getMemberAttributeID().concat("=").concat(memberOfName);
         log.debug("Search filter: " + filter);

         List sr = getUserModule().searchUsers(filter, null);
         //iterate over users that contain a role
         for (Iterator iterator = sr.iterator(); iterator.hasNext();)
         {
            SearchResult res = (SearchResult)iterator.next();
            DirContext ctx = (DirContext)res.getObject();
            String userDN = ctx.getNameInNamespace();
            ctx.close();
            //if user is one which we want to add
            if (userDNsToAdd.contains(userDN))
            {
               //we do nothing but mark this user as added
               userDNsToAdd.remove(userDN);
               continue;
            }
            //if it's not on the list we need to remove role from it
            else
            {
               //obtain Role entry attributes from directory
               Attributes attrs = ldapContext.getAttributes(userDN, new String[] {getMemberAttributeID()});

               //log.debug("Role attributes: " + attrs);
               if (attrs == null)
               {
                  throw new IdentityException("Cannot find User with DN: " + userDN);
               }

               Attribute attr = attrs.get(getMemberAttributeID());

               attr.remove(memberOfName);

               //and replace attributes
               Attributes newAttrs = new BasicAttributes(true);
               //newAttrs.put(getMemberAttributeID(), attr);
               newAttrs.put(attr);

               ldapContext.modifyAttributes(userDN, DirContext.REPLACE_ATTRIBUTE, newAttrs);

               //and mark this role as done
               userDNsToAdd.remove(userDN);
            }
         }

         //now iterate over roles that left to process
         for (Iterator iterator = userDNsToAdd.iterator(); iterator.hasNext();)
         {
            String userDN = (String)iterator.next();

            //changes to make
            ModificationItem[] mods = new ModificationItem[1];
            mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE,
               new BasicAttribute(getMemberAttributeID(), memberOfName));
            // Perform the requested modifications on the named object
            ldapContext.modifyAttributes(userDN, mods);
         }

         fireMembershipChangedEvent(role, users);

         //and that should be all...
      }
      catch (NamingException e)
      {
         throw new IdentityException("Failed to assign users", e);
      }
      finally
      {
         try
         {
            ldapContext.close();
         }
         catch (NamingException e)
         {
            throw new IdentityException("Failed to close LDAP connection", e);
         }
      }

   }
View Full Code Here

         {
            user = getUserModule().findUserById(user.getId());
         }
         catch(NoSuchUserException e)
         {
            throw new IdentityException("Illegal state - cached user doesn't exist in identity store: ", e);
         }
      }

      LDAPUserImpl ldapUser = null;

      if (user instanceof LDAPUserImpl)
      {
         ldapUser = (LDAPUserImpl)user;
      }
      else
      {
         throw new IllegalArgumentException("UserMembershipModuleImpl supports only LDAPUserImpl objects");
      }

      LdapContext ldapContext = getConnectionContext().createInitialContext();

      try
      {
         log.debug("findRoles(): user = " + ldapUser.getDn());

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

         //construct new member attribute values
         Attributes attrs = new BasicAttributes(true);

         Attribute member = new BasicAttribute(getMemberAttributeID());
         for (Iterator iterator = roles.iterator(); iterator.hasNext();)
         {
            try
            {
               LDAPRoleImpl role = (LDAPRoleImpl)iterator.next();
               if (isUidAttributeIsDN())
               {
                  member.add(role.getDn());
               }
               else
               {
                  member.add(role.getName());
               }
            }
            catch (ClassCastException e)
            {
               throw new IdentityException("Only can add LDAPRoleImpl objects", e);
            }
         }
         attrs.put(member);

         ldapContext.modifyAttributes(ldapUser.getDn(), DirContext.REPLACE_ATTRIBUTE, attrs);

         fireMembershipChangedEvent(user, roles);
      }
      catch (NamingException e)
      {
         throw new IdentityException("Failed to change Role members", e);
      }
      finally
      {
         try
         {
            ldapContext.close();
         }
         catch (NamingException e)
         {
            throw new IdentityException("Failed to close LDAP connection", e);
         }
      }

   }
View Full Code Here

         return Tools.toSet(Tools.toList(users.iterator()).subList(offset, size).iterator());
      }
      else
      {
         throw new IdentityException("Role not found with roleName: " + roleName );
      }
   }
View Full Code Here

         {
            user = getUserModule().findUserById(user.getId());
         }
         catch(NoSuchUserException e)
         {
            throw new IdentityException("Illegal state - cached user doesn't exist in identity store: ", e);
         }
      }

      LDAPUserImpl ldapUser = 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.