Package org.jboss.portal.identity

Examples of org.jboss.portal.identity.IdentityException


   protected Set getRoleSearchCtxDNs() throws IdentityException
   {
      Set searchCtx =  getIdentityConfiguration().getValues(IdentityConfiguration.GROUP_COMMON, IdentityConfiguration.ROLE_CONTEXT_DN);
      if (searchCtx == null || searchCtx.size() == 0)
      {
         throw new IdentityException(IdentityConfiguration.USER_CONTEXT_DN + " missing in configuration");
      }
      else
      {
         return searchCtx;
      }
View Full Code Here


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

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


         String filter = "(".concat(getRidAttributeID()).concat("=").concat(name).concat(")");
         log.debug("Search filter: " + filter);

         List sr = searchRoles(filter, null);
         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();
         ctx  = (DirContext)res.getObject();
         Role role = createRoleInstance(res.getAttributes(),ctx.getNameInNamespace());
         return role;

      }
      catch (NoSuchElementException e)
      {
         log.debug("No role found with name: " + name, e);
      }
      catch (NamingException e)
      {
         throw new IdentityException("Role search failed.", e);
      }
      finally
      {
         if (ctx != null)
         {
            try
            {
               ctx.close();
            }
            catch (NamingException e)
            {
               throw new IdentityException("Failed to close LDAP connection", 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

   public Role findRoleById(Object id) throws IdentityException, IllegalArgumentException
   {
      if (id == null)
      {
         throw new IdentityException("Cannot search role with null id");
      }
      if (!(id instanceof String))
      {
         throw new IdentityException("Only String id is suppoted");
      }
      return findRoleById((String)id);
   }
View Full Code Here

   public Role createRole(String name, String displayName) throws IdentityException, IllegalArgumentException
   {
      if (name == null)
      {
         throw new IdentityException("Role name cannot be null");
      }

      LdapContext ldapContext = getConnectionContext().createInitialContext();

      LdapContext ctx = null;

      try
      {
         //
         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);

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

         //attribute
         for (Iterator it1 = attributesToAdd.keySet().iterator(); it1.hasNext();)
         {
            String attributeName = (String)it1.next();
            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);
         }

         //role name
         attrs.put(getRidAttributeID(), name);

         //display name
         if (!getDisplayNameAttributeID().equals(getRidAttributeID()))
         {
            attrs.put(getDisplayNameAttributeID(), displayName);
         }

         String dn = getRidAttributeID().concat("=").concat(name);

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

      Role resultRole =  findRoleByName(name);
View Full Code Here

   {
      LDAPRoleImpl ldapr = (LDAPRoleImpl)findRoleById(id);

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

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

      LdapContext ldapContext = getConnectionContext().createInitialContext();

      try
      {
         log.debug("removing entry: " + ldapr.getDn());
         ldapContext.unbind(ldapr.getDn());

         fireRoleDestroyedEvent(ldapr.getId(), ldapr.getName());
      }
      catch (Exception e)
      {
         throw new IdentityException("Failed to remove role: ", e);
      }
      finally
      {
         try
         {
            ldapContext.close();
         }
         catch (NamingException e)
         {
            throw new IdentityException("Failed to close LDAP connection", e);
         }
      }
   }
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

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

      {
         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

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.