Package org.picketlink.idm.common.exception

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


            em.persist(roleTypeInstance);
            em.flush();
            return name;
        } catch (Exception ex) {
            throw new IdentityException("Error creating relationship name", ex);
        }
    }
View Full Code Here


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

                    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

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

                                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

      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

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

      {
         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

      {
         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

         {
            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

TOP

Related Classes of org.picketlink.idm.common.exception.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.