Examples of IdentityException


Examples of org.picketlink.idm.common.exception.IdentityException

                }
            }
           
            em.remove(instance);
        } catch (NoResultException ex) {
            throw new IdentityException(String.format(
                    "Exception removing identity object - [%s] not found.",
                    identity), ex);
        }
    }
View Full Code Here

Examples of org.picketlink.idm.common.exception.IdentityException

                    credentialType.setValue(newCredential,
                            lookupCredentialTypeEntity(credential.getType().getName(), em));

                    em.persist(newCredential);
                } catch (IllegalAccessException ex) {
                    throw new IdentityException("Error updating credential - could " +
                            "not create credential instance", ex);
                } catch (InstantiationException ex) {
                    throw new IdentityException("Error updating credential - could " +
                            "not create credential instance", ex);
                }
            } else {
                // TODO there shouldn't be multiple credentials with the same type,
                // but if there are, we need to deal with it somehow.. for now just use the first one
View Full Code Here

Examples of org.picketlink.idm.common.exception.IdentityException

                        }
                    }
                }
            }
        } catch (Exception e) {
            throw new IdentityException("Error while adding attributes.", e);
        }
    }
View Full Code Here

Examples of org.picketlink.idm.common.exception.IdentityException

                                attributeTypeProp.setValue(attribute, ATTRIBUTE_TYPE_FLOAT);
                            } else if (Double.class.equals(value.getClass()) || Double.TYPE.equals(value.getClass())) {
                                attributeValueProp.setValue(attribute, ((Double) value).toString());
                                attributeTypeProp.setValue(attribute, ATTRIBUTE_TYPE_DOUBLE);
                            } else {
                                throw new IdentityException("Could not persist attribute value - unsupported attribute value type " +
                                        value.getClass());
                            }
                        } else {
                            attributeValueProp.setValue(attribute, value.toString());
                        }

                        em.persist(attribute);
                    }
                }
            }
        } catch (Exception e) {
            throw new IdentityException("Error while updating attributes.", e);
        }
    }
View Full Code Here

Examples of org.picketlink.idm.common.exception.IdentityException

      String clsName = configurationContext.getStoreConfigurationMetaData()
         .getOptionSingleValue(OPTION_IDENTITY_CLASS_NAME);

      if (clsName == null)
      {
         throw new IdentityException("Error bootstrapping JpaIdentityStore - identity entity class cannot be null");
      }
     
      try
      {
         identityClass = Reflections.classForName(clsName);
      }
      catch (ClassNotFoundException e)
      {
         throw new IdentityException("Error bootstrapping JpaIdentityStore - invalid identity entity class: " + clsName);
      }
     
      if (identityClass == null)
      {
         throw new IdentityException(
               "Error initializing JpaIdentityStore - identityClass not set");
      }
     
      clsName = configurationContext.getStoreConfigurationMetaData()
         .getOptionSingleValue(OPTION_CREDENTIAL_CLASS_NAME);
     
      if (clsName != null)
      {
         try
         {
            credentialClass = Class.forName(clsName);
         }
         catch (ClassNotFoundException e)
         {
            throw new IdentityException("Error bootstrapping JpaIdentityStore - invalid credential entity class: " + clsName);
         }
      }
     
      clsName = configurationContext.getStoreConfigurationMetaData()
         .getOptionSingleValue(OPTION_RELATIONSHIP_CLASS_NAME);
     
      try
      {
         relationshipClass = Class.forName(clsName);
      }
      catch (ClassNotFoundException e)
      {
         throw new IdentityException("Error bootstrapping JpaIdentityStore - invalid relationship entity class: " + clsName);
      }     
     
      boolean namedRelationshipsSupported = false;
     
      clsName = configurationContext.getStoreConfigurationMetaData()
         .getOptionSingleValue(OPTION_ROLE_TYPE_CLASS_NAME);
     
      if (clsName != null)
      {
         try
         {
            roleTypeClass = Class.forName(clsName);
            namedRelationshipsSupported = true;
         }
         catch (ClassNotFoundException e)
         {
            throw new IdentityException("Error bootstrapping JpaIdentityStore - invalid role type entity class: " + clsName);
         }
      }
     
      clsName = configurationContext.getStoreConfigurationMetaData()
         .getOptionSingleValue(OPTION_ATTRIBUTE_CLASS_NAME);
      if (clsName != null)
      {
         try
         {
            attributeClass = Class.forName(clsName);
         }
         catch (ClassNotFoundException e)
         {
            throw new IdentityException("Error bootstrapping JpaIdentityStore - invalid attribute entity class: " + clsName);
         }
      }
     
      configureIdentityId();
      configureIdentityName();
View Full Code Here

Examples of org.picketlink.idm.common.exception.IdentityException

      {
         modelProperties.put(PROPERTY_IDENTITY_ID, props.get(0));
      }
      else
      {
         throw new IdentityException("Error initializing JpaIdentityStore - no Identity ID found.");
      }
   }
View Full Code Here

Examples of org.picketlink.idm.common.exception.IdentityException

      {
         modelProperties.put(PROPERTY_IDENTITY_NAME, props.get(0));
      }
      else if (props.size() > 1)
      {
         throw new IdentityException(
               "Ambiguous identity name property in identity class " + identityClass.getName());
      }
      else
      {
         Property<Object> p = findNamedProperty(identityClass, "username", "userName", "name");
         if (p != null)
         {
            modelProperties.put(PROPERTY_IDENTITY_NAME, p);
         }
         else
         {
            // Last resort - check whether the entity class exposes a single String property
            // if so, let's assume it's the identity name
            props = PropertyQueries.createQuery(identityClass)
               .addCriteria(new TypedPropertyCriteria(String.class))
               .getResultList();
            if (props.size() == 1)
            {
               modelProperties.put(PROPERTY_IDENTITY_NAME, props.get(0));
            }
         }
      }

      if (!modelProperties.containsKey(PROPERTY_IDENTITY_NAME))
      {
         throw new IdentityException("Error initializing JpaIdentityStore - no valid identity name property found.");
      }
   }
View Full Code Here

Examples of org.picketlink.idm.common.exception.IdentityException

      {
         modelProperties.put(PROPERTY_IDENTITY_TYPE, props.get(0));
      }
      else if (props.size() > 1)
      {
         throw new IdentityException(
               "Ambiguous identity type property in identity class " + identityClass.getName());
      }
      else
      {
         Property<Object> p = findNamedProperty(identityClass, "identityObjectType",
               "identityType", "identityObjectTypeName", "identityTypeName",
               "typeName", "discriminator", "accountType", "userType", "type");
         if (p != null)
         {
            modelProperties.put(PROPERTY_IDENTITY_TYPE, props.get(0));
         }
         else
         {
            // Last resort - let's check all properties, and try to find one
            // with an entity type that has "type" in its name
            props = PropertyQueries.createQuery(identityClass).getResultList();
            search: for (Property<Object> typeProp : props)
            {
               if (typeProp.getJavaClass().isAnnotationPresent(Entity.class) &&
                     (typeProp.getJavaClass().getSimpleName().contains("type") ||
                           typeProp.getJavaClass().getSimpleName().contains("Type")))
               {
                  // we have a potential match, let's check if this entity has a name property
                  Property<Object> nameProp = findNamedProperty(typeProp.getJavaClass(),
                        "identityObjectTypeName", "identityTypeName", "typeName", "name");
                  if (nameProp != null)
                  {
                     modelProperties.put(PROPERTY_IDENTITY_TYPE, typeProp);
                     modelProperties.put(PROPERTY_IDENTITY_TYPE_NAME, nameProp);
                     break search;
                  }
               }
            }
         }        
      }     
     
      Property<?> typeProp = modelProperties.get(PROPERTY_IDENTITY_TYPE);
     
      if (typeProp == null)
      {
         throw new IdentityException("Error initializing JpaIdentityStore - no valid identity type property found.");
      }
     
      if (!String.class.equals(typeProp.getJavaClass()) &&
            !modelProperties.containsKey(PROPERTY_IDENTITY_TYPE_NAME))
      {
         // We're not dealing with a simple type name - validate the lookup type
         Property<Object> nameProp = findNamedProperty(typeProp.getJavaClass(),
               "identityObjectTypeName", "identityTypeName", "typeName", "name");
         if (nameProp != null)
         {
            modelProperties.put(PROPERTY_IDENTITY_TYPE_NAME, nameProp);
         }
         else
         {
            throw new IdentityException("Error initializing JpaIdentityStore - no valid identity type name property found.");
         }
      }
   }
View Full Code Here

Examples of org.picketlink.idm.common.exception.IdentityException

         {
            modelProperties.put(PROPERTY_CREDENTIAL_VALUE, props.get(0));
         }
         else if (props.size() > 1)
         {
            throw new IdentityException(
                  "Ambiguous credential value property in credential class " +
                  credentialClass.getName());
         }
         else
         {
            // Try scanning for a credential property also
            props = PropertyQueries.createQuery(credentialClass)
               .addCriteria(new PropertyTypeCriteria(PropertyType.CREDENTIAL))
               .getResultList();
            if (props.size() == 1)
            {
               modelProperties.put(PROPERTY_CREDENTIAL_VALUE, props.get(0));
            }
            else if (props.size() > 1)
            {
               throw new IdentityException(
                     "Ambiguous credential value property in credential class " +
                     credentialClass.getName());
            }
            else
            {
               Property<Object> p = findNamedProperty(credentialClass, "credentialValue",
                     "password", "passwordHash", "credential", "value");
               if (p != null) modelProperties.put(PROPERTY_CREDENTIAL_VALUE, p);
            }
         } 
        
         // Scan for the credential identity property
         props = PropertyQueries.createQuery(credentialClass)
            .addCriteria(new TypedPropertyCriteria(identityClass))
            .getResultList();
         if (props.size() == 1)
         {
            modelProperties.put(PROPERTY_CREDENTIAL_IDENTITY, props.get(0));
         }
         else if (props.size() > 1)
         {
            throw new IdentityException(
                  "Ambiguous identity property in credential class " +
                  credentialClass.getName());
         }
         else
         {
            // Scan for a named identity property
            props = PropertyQueries.createQuery(credentialClass)
               .addCriteria(new NamedPropertyCriteria("identity", "identityObject"))
               .getResultList();
            if (!props.isEmpty())
            {
               modelProperties.put(PROPERTY_CREDENTIAL_IDENTITY, props.get(0));
            }
            else
            {
               throw new IdentityException("Error initializing JpaIdentityStore - no credential identity property found.");
            }
         }
      }
      else
      {
         // The credentials may be stored in the identity class        
         List<Property<Object>> props = PropertyQueries.createQuery(identityClass)
            .addCriteria(new PropertyTypeCriteria(PropertyType.CREDENTIAL))
            .getResultList();
        
         if (props.size() == 1)
         {
            modelProperties.put(PROPERTY_CREDENTIAL_VALUE, props.get(0));
         }
         else if (props.size() > 1)
         {
            throw new IdentityException(
                  "Ambiguous credential property in identity class " +
                  identityClass.getName());
         }
         else
         {        
            Property<Object> p = findNamedProperty(identityClass, "credentialValue",
                  "password", "passwordHash", "credential", "value");
            if (p != null) modelProperties.put(PROPERTY_CREDENTIAL_VALUE, p);
         }
      }
           
      if (!modelProperties.containsKey(PROPERTY_CREDENTIAL_VALUE))
      {
         throw new IdentityException("Error initializing JpaIdentityStore - no credential value property found.");
      }           
           
      // Scan for a credential type property
      List<Property<Object>> props = PropertyQueries.createQuery(credentialClass)
         .addCriteria(new PropertyTypeCriteria(PropertyType.TYPE))
         .getResultList();
     
      if (props.size() == 1)
      {
         modelProperties.put(PROPERTY_CREDENTIAL_TYPE, props.get(0));
      }
      else if (props.size() > 1)
      {
         throw new IdentityException(
               "Ambiguous credential type property in credential class " +
               credentialClass.getName());
      }
      else
      {
         props = PropertyQueries.createQuery(credentialClass)
            .addCriteria(new PropertyTypeCriteria(PropertyType.CREDENTIAL_TYPE))
            .getResultList();
        
         if (props.size() == 1)
         {
            modelProperties.put(PROPERTY_CREDENTIAL_TYPE, props.get(0));
         }
         else if (props.size() > 1)
         {
            throw new IdentityException(
                  "Ambiguous credential type property in credential class " +
                  credentialClass.getName());           
         }
         else
         {        
            Property<Object> p = findNamedProperty(credentialClass, "credentialType",
                  "identityObjectCredentialType", "type");
            if (p != null) modelProperties.put(PROPERTY_CREDENTIAL_TYPE, p);
         }
      }     

      Property<?> typeProp = modelProperties.get(PROPERTY_CREDENTIAL_TYPE);     
     
      // If the credential type property isn't a String, then validate the lookup type
      if (!String.class.equals(typeProp.getJavaClass()))
      {
         Property<Object> nameProp = findNamedProperty(typeProp.getJavaClass(),
               "credentialObjectTypeName", "credentialTypeName", "typeName", "name");
         if (nameProp != null)
         {
            modelProperties.put(PROPERTY_CREDENTIAL_TYPE_NAME, nameProp);
         }
         else
         {
            throw new IdentityException("Error initializing JpaIdentityStore - no valid credential type name property found.");
         }
      }      
   }
View Full Code Here

Examples of org.picketlink.idm.common.exception.IdentityException

  
   protected void configureRelationships() throws IdentityException
   {
      if (relationshipClass == null)
      {
         throw new IdentityException("Error initializing JpaIdentityStore - relationshipClass not set.");
      }
     
      List<Property<Object>> props = PropertyQueries.createQuery(relationshipClass)
         .addCriteria(new TypedPropertyCriteria(identityClass))
         .addCriteria(new PropertyTypeCriteria(PropertyType.RELATIONSHIP_FROM))
         .getResultList();
     
      if (props.size() == 1)
      {
         modelProperties.put(PROPERTY_RELATIONSHIP_FROM, props.get(0));
      }
      else if (props.size() > 1)
      {
         throw new IdentityException(
               "Ambiguous relationshipFrom property in relationship class " +
               relationshipClass.getName());
      }
      else
      {
         Property<Object> p = findNamedProperty(relationshipClass, "relationshipFrom",
               "fromIdentityObject", "fromIdentity");
         if (p != null)
         {
            modelProperties.put(PROPERTY_RELATIONSHIP_FROM, p);
         }
         else
         {
            // Last resort - search for a property with a type of identityClass
            // and a "from" in its name
            props = PropertyQueries.createQuery(relationshipClass)
               .addCriteria(new TypedPropertyCriteria(identityClass))
               .getResultList();
           
            for (Property<Object> prop : props)
            {
               if (prop.getName().contains("from"))
               {
                  modelProperties.put(PROPERTY_RELATIONSHIP_FROM, prop);
                  break;
               }
            }
         }        
      }
 
     
      props = PropertyQueries.createQuery(relationshipClass)
         .addCriteria(new TypedPropertyCriteria(identityClass))
         .addCriteria(new PropertyTypeCriteria(PropertyType.RELATIONSHIP_TO))
         .getResultList();
  
      if (props.size() == 1)
      {
         modelProperties.put(PROPERTY_RELATIONSHIP_TO, props.get(0));
      }
      else if (props.size() > 1)
      {
         throw new IdentityException(
               "Ambiguous relationshipTo property in relationship class " +
               relationshipClass.getName());
      }
      else
      {
         Property<Object> p = findNamedProperty(relationshipClass, "relationshipTo",
               "toIdentityObject", "toIdentity");
         if (p != null)
         {
            modelProperties.put(PROPERTY_RELATIONSHIP_TO, p);
         }
         else
         {
            // Last resort - search for a property with a type of identityClass
            // and a "to" in its name
            props = PropertyQueries.createQuery(relationshipClass)
               .addCriteria(new TypedPropertyCriteria(identityClass))
               .getResultList();
           
            for (Property<Object> prop : props)
            {
               if (prop.getName().contains("to"))
               {
                  modelProperties.put(PROPERTY_RELATIONSHIP_TO, prop);
                  break;
               }
            }
         }        
      }     
     
      props = PropertyQueries.createQuery(relationshipClass)
         .addCriteria(new PropertyTypeCriteria(PropertyType.TYPE))
         .getResultList();
      if (props.size() == 1)
      {
         modelProperties.put(PROPERTY_RELATIONSHIP_TYPE, props.get(0));
      }
      else if (props.size() > 1)
      {
         throw new IdentityException(
               "Ambiguous relationshipType property in relationship class " +
               relationshipClass.getName());
      }
      else
      {
         Property<Object> p = findNamedProperty(relationshipClass,
               "identityRelationshipType", "relationshipType", "type");
         if (p != null)
         {
            modelProperties.put(PROPERTY_RELATIONSHIP_TYPE, p);
         }
         else
         {
            props = PropertyQueries.createQuery(relationshipClass)
               .getResultList();
            for (Property<Object> prop : props)
            {
               if (prop.getName().contains("type"))
               {
                  modelProperties.put(PROPERTY_RELATIONSHIP_TYPE, prop);
                  break;
               }
            }
         }
      }
     
      props = PropertyQueries.createQuery(relationshipClass)
         .addCriteria(new PropertyTypeCriteria(PropertyType.NAME))
         .addCriteria(new TypedPropertyCriteria(String.class))
         .getResultList();
     
      if (props.size() == 1)
      {
         modelProperties.put(PROPERTY_RELATIONSHIP_NAME, props.get(0));
      }
      else if (props.size() > 1)
      {
         throw new IdentityException(
               "Ambiguous relationship name property in relationship class " +
               relationshipClass.getName());
      }
      else
      {
         Property<Object> p = findNamedProperty(relationshipClass,
               "relationshipName", "name");
         if (p != null)
         {
            modelProperties.put(PROPERTY_RELATIONSHIP_NAME, p);
         }
      }
     
      if (!modelProperties.containsKey(PROPERTY_RELATIONSHIP_FROM))
      {
         throw new IdentityException(
            "Error initializing JpaIdentityStore - no valid relationship from property found.");
      }
     
      if (!modelProperties.containsKey(PROPERTY_RELATIONSHIP_TO))
      {
         throw new IdentityException(
            "Error initializing JpaIdentityStore - no valid relationship to property found.");
      }
     
      if (!modelProperties.containsKey(PROPERTY_RELATIONSHIP_TYPE))
      {
         throw new IdentityException(
            "Error initializing JpaIdentityStore - no valid relationship type property found.");
      }
     
      if (!modelProperties.containsKey(PROPERTY_RELATIONSHIP_NAME))
      {
         throw new IdentityException(
            "Error initializing JpaIdentityStore - no valid relationship name property found.");
      }
     
      Class<?> typeClass = modelProperties.get(PROPERTY_RELATIONSHIP_TYPE).getJavaClass();
      if (!String.class.equals(typeClass))
      {
         props = PropertyQueries.createQuery(typeClass)
            .addCriteria(new PropertyTypeCriteria(PropertyType.NAME))
            .addCriteria(new TypedPropertyCriteria(String.class))
            .getResultList();
        
         if (props.size() == 1)
         {
            modelProperties.put(PROPERTY_RELATIONSHIP_TYPE_NAME, props.get(0));
         }
         else if (props.size() > 1)
         {
            throw new IdentityException(
                  "Ambiguous relationship type name property in class " +
                  typeClass.getName());
         }
         else
         {
            Property<Object> p = findNamedProperty(typeClass, "relationshipTypeName",
                  "typeName", "name");
            if (p != null)
            {
               modelProperties.put(PROPERTY_RELATIONSHIP_TYPE_NAME, p);
            }
         }
        
         if (!modelProperties.containsKey(PROPERTY_RELATIONSHIP_TYPE_NAME))
         {
            throw new IdentityException(
                  "Error initializing JpaIdentityStore - no valid relationship type name property found");
         }
      }     
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.