private boolean isPartitionSupported(Class<?> type) { return Partition.class.isAssignableFrom(type) && this.store.getConfig().supportsPartition(); }
private boolean isPartitionSupported(Class<?> type) { return Partition.class.isAssignableFrom(type) && this.store.getConfig().supportsPartition(); }
private List<?> findAttributes(Object object) { Class<?> attributeClass = getConfig().getAttributeClass(); String identityProperty = getConfig().getAttributeIdentityProperty().getName(); EntityManager em = getEntityManager(); CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<?> criteria = builder.createQuery(attributeClass); Root<?> root = criteria.from(attributeClass); List<Predicate> predicates = new ArrayList<Predicate>(); predicates.add(builder.equal(root.get(identityProperty), object)); criteria.where(predicates.toArray(new Predicate[predicates.size()])); return em.createQuery(criteria).getResultList(); }
public JPACriteriaQueryBuilder(JPAIdentityStore identityStore, IdentityQuery<?> identityQuery) { this.identityStore = identityStore; this.identityQuery = identityQuery; this.config = identityStore.getConfig(); this.entityManager = identityStore.getEntityManager(); if(entityManager == null){ throw new IllegalStateException("Entity Manager is null"); } this.builder = this.entityManager.getCriteriaBuilder(); if(builder == null){ throw new IllegalStateException("Criteria Builder is null"); } Class<?> identityClass = this.config.getIdentityClass(); this.criteria = builder.createQuery(identityClass); this.root = criteria.from(identityClass); }
void setModelProperty(Object instance, String propertyName, Object value, boolean required) { if (getConfig().isModelPropertySet(propertyName)) { getConfig().getModelProperty(propertyName).setValue(instance, value); } else if (required) { throw new IdentityManagementException("Model property [" + propertyName + "] has not been configured."); } }
private List<?> findAttributes(IdentityType identityType, String idValue, Attribute<? extends Serializable> userAttribute) { Property<Object> attributeIdentityProperty = getConfig().getAttributeIdentityProperty(); EntityManager em = getEntityManager(); CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<?> criteria = builder.createQuery(getConfig().getAttributeClass()); Root<?> root = criteria.from(getConfig().getAttributeClass()); List<Predicate> predicates = new ArrayList<Predicate>(); Join<?, ?> join = root.join(attributeIdentityProperty.getName()); if (IDMUtil.isAgentType(identityType.getClass())) { predicates.add(builder.equal(join.get(getConfig().getIdentityIdProperty().getName()), idValue)); } else { predicates.add(builder.equal(join.get(getConfig().getModelProperty(PROPERTY_IDENTITY_NAME).getName()), idValue)); } predicates.add(builder.equal(root.get(getConfig().getAttributeNameProperty().getName()), userAttribute.getName())); criteria.where(predicates.toArray(new Predicate[predicates.size()])); return em.createQuery(criteria).getResultList(); }
<P> P getModelProperty(Class<P> propertyType, Object instance, String propertyName) { @SuppressWarnings("unchecked") Property<P> property = (Property<P>) getConfig().getModelProperty(propertyName); return property == null ? null : property.getValue(instance); }
private void removeAttributes(Object object) { EntityManager em = getEntityManager(); if (getConfig().getAttributeClass() != null) { List<?> results = findAttributes(object); for (Object result : results) { em.remove(result); } } }
@Override protected Agent doCreateIdentityType(Object identity, JPAIdentityStore store) { String idValue = store.getConfig().getModelProperty(PROPERTY_IDENTITY_ID).getValue(identity).toString(); Agent agent = new SimpleAgent(idValue); return agent; }
private void validateConfiguration() { Set<Class<? extends AttributedType>> supportedTypes = getConfig().getSupportedTypes().keySet(); validateTypeMapping(supportedTypes); validateAttributeMapping(); validateCredentialMapping(); }
private void validateConfiguration() { Set<Class<? extends AttributedType>> supportedTypes = getConfig().getSupportedTypes().keySet(); validateTypeMapping(supportedTypes); validateAttributeMapping(); validateCredentialMapping(); }
@Override protected Relationship doCreateIdentityType(Object identity, JPAIdentityStore store) { String name = store.getModelProperty(String.class, identity, PROPERTY_IDENTITY_NAME); Object relatesToInstance = store.getModelProperty(Object.class, identity, PROPERTY_IDENTITY_RELATES_TO); String relatesToDiscriminator = store.getConfig().getModelProperty(PROPERTY_IDENTITY_DISCRIMINATOR).getValue(relatesToInstance) .toString(); IdentityTypeHandler<? extends IdentityType> relatesToIdentityTypeManager = store.getConfig().getIdentityTypeManager(relatesToDiscriminator); IdentityType relatesToType = relatesToIdentityTypeManager.createIdentityType(null, relatesToInstance, store); Object relatedToInstance = store.getModelProperty(Object.class, identity, PROPERTY_IDENTITY_RELATED_TO); String relatedToDiscriminator = store.getConfig().getModelProperty(PROPERTY_IDENTITY_DISCRIMINATOR).getValue(relatesToInstance) .toString(); IdentityTypeHandler<? extends IdentityType> relatedToTypeManager = store.getConfig().getIdentityTypeManager(relatedToDiscriminator); IdentityType relatedToType = relatedToTypeManager.createIdentityType(null, relatedToInstance, store); SimpleRelationship relationship = new SimpleRelationship(name); relationship.setFrom(relatedToType); relationship.setTo(relatesToType); return relationship; }
private void configurePartition(Partition partition, Object identity, IdentityType identityType) { if (getConfig().isModelPropertySet(PROPERTY_IDENTITY_PARTITION)) { // TODO implement cache support for partitions Object partitionInstance = getModelProperty(Object.class, identity, PROPERTY_IDENTITY_PARTITION); identityType.setPartition(convertPartitionEntityToPartition(partitionInstance)); } else { identityType.setPartition(partition); } }
private void validateCredentialMapping() { if (getConfig().supportsCredential()) { for (EntityMapper entityMapper : getEntityMappers()) { ManagedCredential managedCredential = entityMapper.getEntityType().getAnnotation(ManagedCredential.class); if (managedCredential != null) { checkIfAnnotationIsDefinedForCredential(entityMapper, CredentialClass.class); checkIfAnnotationIsDefinedForCredential(entityMapper, EffectiveDate.class); checkIfAnnotationIsDefinedForCredential(entityMapper, ExpiryDate.class); return; } } throw MESSAGES.configJpaStoreMappedNoCredentialStorageMappingFound(); } }
private void validateCredentialMapping() { if (getConfig().supportsCredential()) { for (EntityMapper entityMapper : getEntityMappers()) { ManagedCredential managedCredential = entityMapper.getEntityType().getAnnotation(ManagedCredential.class); if (managedCredential != null) { checkIfAnnotationIsDefinedForCredential(entityMapper, CredentialClass.class); checkIfAnnotationIsDefinedForCredential(entityMapper, EffectiveDate.class); checkIfAnnotationIsDefinedForCredential(entityMapper, ExpiryDate.class); return; } } throw MESSAGES.configJpaStoreMappedNoCredentialStorageMappingFound(); } }
@Override protected User doCreateIdentityType(Object identity, JPAIdentityStore store) { JPAIdentityStoreConfiguration storeConfig = store.getConfig(); String idValue = storeConfig.getModelProperty(PROPERTY_IDENTITY_ID).getValue(identity).toString(); User user = new SimpleUser(idValue); user.setFirstName(store.getModelProperty(String.class, identity, PROPERTY_USER_FIRST_NAME)); user.setLastName(store.getModelProperty(String.class, identity, PROPERTY_USER_LAST_NAME)); user.setEmail(store.getModelProperty(String.class, identity, PROPERTY_USER_EMAIL)); return user; }
@Override public void update(IdentityType identityType) { checkInvalidIdentityType(identityType); IdentityTypeHandler<IdentityType> identityTypeManager = getConfig().getIdentityTypeManager(identityType.getClass()); Object identity = getIdentityObject(identityType); identityTypeManager.populateIdentityInstance(getContext().getRealm(), identity, identityType, this); updateAttributes(identityType, identity); EntityManager em = getEntityManager(); em.merge(identity); em.flush(); AbstractBaseEvent event = identityTypeManager.raiseUpdatedEvent(identityType, this); event.getContext().setValue(EVENT_CONTEXT_USER_ENTITY, identity); getContext().getEventBridge().raiseEvent(event); }
private void validateAttributeMapping() { if (getConfig().supportsAttribute()) { for (EntityMapper entityMapper : getEntityMappers()) { if (entityMapper.getProperty(AttributeClass.class) != null) { checkIfAnnotationIsDefinedForAttribute(entityMapper, AttributeName.class); checkIfAnnotationIsDefinedForAttribute(entityMapper, AttributeValue.class); checkIfAnnotationIsDefinedForAttribute(entityMapper, OwnerReference.class); return; } } throw MESSAGES.configJpaStoreMappedNoAttributeMappingFound(); } }
private void validateAttributeMapping() { if (getConfig().supportsAttribute()) { for (EntityMapper entityMapper : getEntityMappers()) { if (entityMapper.getProperty(AttributeClass.class) != null) { checkIfAnnotationIsDefinedForAttribute(entityMapper, AttributeName.class); checkIfAnnotationIsDefinedForAttribute(entityMapper, AttributeValue.class); checkIfAnnotationIsDefinedForAttribute(entityMapper, OwnerReference.class); return; } } throw MESSAGES.configJpaStoreMappedNoAttributeMappingFound(); } }
@Override public void add(IdentityType identityType) { checkInvalidIdentityType(identityType); if (lookupIdentityObjectById(identityType) != null) { throw new IdentityManagementException("IdentityType already exists."); } try { IdentityTypeHandler<IdentityType> identityTypeManager = getConfig().getIdentityTypeManager(identityType.getClass()); Object identity = identityTypeManager.createIdentityInstance(getContext().getRealm(), identityType, this); EntityManager em = getEntityManager(); em.persist(identity); em.flush(); updateAttributes(identityType, identity); AbstractBaseEvent event = identityTypeManager.raiseCreatedEvent(identityType, this); event.getContext().setValue(EVENT_CONTEXT_USER_ENTITY, identity); getContext().getEventBridge().raiseEvent(event); } catch (Exception ex) { throw new IdentityManagementException("Exception while creating IdentityType [" + identityType + "].", ex); } }