{
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.");
}
}
}