public boolean isMappedType(Class mappedClass) { for (EntityMapper entityMapper : getEntityMappers()) { if (entityMapper.getEntityType().equals(mappedClass)) { return true; } } return false; }
public boolean isMappedType(Class mappedClass) { for (EntityMapper entityMapper : getEntityMappers()) { if (entityMapper.getEntityType().equals(mappedClass)) { return true; } } return false; }
private List<EntityMapper> getPermissionMappers() { List<EntityMapper> mappers = new ArrayList<EntityMapper>(); for (EntityMapper entityMapper: getEntityMappers()) { if (entityMapper.getEntityType().isAnnotationPresent(PermissionManaged.class)) { mappers.add(entityMapper); } } if (mappers == null) { throw MESSAGES.configJpaStoreNoPermissionEntityClassProvided(); } return mappers; }
private List<EntityMapper> getPermissionMappers() { List<EntityMapper> mappers = new ArrayList<EntityMapper>(); for (EntityMapper entityMapper: getEntityMappers()) { if (entityMapper.getEntityType().isAnnotationPresent(PermissionManaged.class)) { mappers.add(entityMapper); } } if (mappers == null) { throw MESSAGES.configJpaStoreNoPermissionEntityClassProvided(); } return mappers; }
@Override protected void removeCredentials(IdentityContext context, Account account) { EntityManager entityManager = getEntityManager(context); List entities = new ArrayList(); for (EntityMapper attributeMapper : getEntityMappers()) { if (attributeMapper.getEntityType().isAnnotationPresent(ManagedCredential.class)) { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<?> criteria = builder.createQuery(attributeMapper.getEntityType()); Root<?> root = criteria.from(attributeMapper.getEntityType()); Object agentInstance = getRootEntity(account, entityManager); Property identityTypeProperty = attributeMapper.getProperty(OwnerReference.class).getValue(); criteria.where(builder.equal(root.get(identityTypeProperty.getName()), agentInstance)); Property effectiveProperty = attributeMapper.getProperty(EffectiveDate.class).getValue(); criteria.orderBy(builder.desc(root.get(effectiveProperty.getName()))); List result = entityManager.createQuery(criteria).getResultList(); for (Object storageEntity : result) { entities.add(storageEntity); } } } for (Object credentialEntity : entities) { entityManager.remove(credentialEntity); } }
private EntityMapper getPermissionMapperForResource(Class resourceClass) { int score = -1; EntityMapper mapper = null; for (EntityMapper entityMapper: getEntityMappers()) { if (entityMapper.getEntityType().isAnnotationPresent(PermissionManaged.class)) { EntityMapping mapping = entityMapper.getMappingsFor(resourceClass); if (mapping != null) { Class<?> supportedType = mapping.getSupportedType(); if (supportedType.isAssignableFrom(resourceClass)) { int currentScore = 0; Class<?> currentClass = resourceClass; while (!currentClass.equals(supportedType) && !Object.class.equals(currentClass)) { currentScore++; currentClass = currentClass.getSuperclass(); } if (mapper == null || score == -1 || currentScore < score) { score = currentScore; mapper = entityMapper; } } } } } if (mapper == null) { throw MESSAGES.configJpaStoreNoPermissionEntityClassProvided(); } return mapper; }
private EntityMapper getPermissionMapperForResource(Class resourceClass) { int score = -1; EntityMapper mapper = null; for (EntityMapper entityMapper: getEntityMappers()) { if (entityMapper.getEntityType().isAnnotationPresent(PermissionManaged.class)) { EntityMapping mapping = entityMapper.getMappingsFor(resourceClass); if (mapping != null) { Class<?> supportedType = mapping.getSupportedType(); if (supportedType.isAssignableFrom(resourceClass)) { int currentScore = 0; Class<?> currentClass = resourceClass; while (!currentClass.equals(supportedType) && !Object.class.equals(currentClass)) { currentScore++; currentClass = currentClass.getSuperclass(); } if (mapper == null || score == -1 || currentScore < score) { score = currentScore; mapper = entityMapper; } } } } } if (mapper == null) { throw MESSAGES.configJpaStoreNoPermissionEntityClassProvided(); } return mapper; }
@Override protected void removeCredentials(IdentityContext context, Account account) { EntityManager entityManager = getEntityManager(context); List entities = new ArrayList(); for (EntityMapper attributeMapper : getEntityMappers()) { if (attributeMapper.getEntityType().isAnnotationPresent(ManagedCredential.class)) { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<?> criteria = builder.createQuery(attributeMapper.getEntityType()); Root<?> root = criteria.from(attributeMapper.getEntityType()); Object agentInstance = getRootEntity(account, entityManager); Property identityTypeProperty = attributeMapper.getProperty(OwnerReference.class).getValue(); criteria.where(builder.equal(root.get(identityTypeProperty.getName()), agentInstance)); Property effectiveProperty = attributeMapper.getProperty(EffectiveDate.class).getValue(); criteria.orderBy(builder.desc(root.get(effectiveProperty.getName()))); List result = entityManager.createQuery(criteria).getResultList(); for (Object storageEntity : result) { entities.add(storageEntity); } } } for (Object credentialEntity : entities) { entityManager.remove(credentialEntity); } }
private List<?> findIdentityTypeRelationships(IdentityContext context, Class<? extends Relationship> relationshipType, IdentityType identityType) { List<Object> relationships = new ArrayList<Object>(); for (EntityMapper relationshipMemberMapper : getEntityMappers()) { Entry<Property, Property> property = relationshipMemberMapper.getProperty(RelationshipMember.class); if (property != null) { EntityManager em = getEntityManager(context); CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<?> criteria = builder.createQuery(relationshipMemberMapper.getEntityType()); Root<?> root = criteria.from(relationshipMemberMapper.getEntityType()); Property<Object> identityTypeProperty = relationshipMemberMapper.getProperty(RelationshipMember.class).getValue(); if (identityTypeProperty.getJavaClass().equals(String.class)) { criteria.where(builder.equal(root.get(identityTypeProperty.getName()), IdentityTypeUtil.formatId(identityType))); } else { criteria.where(builder.equal(root.get(identityTypeProperty.getName()), em.find(identityTypeProperty.getJavaClass(), identityType.getId()))); } List<?> result = em.createQuery(criteria).getResultList(); Property<Object> ownerProperty = relationshipMemberMapper.getProperty(OwnerReference.class).getValue(); for (Object object : result) { relationships.add(ownerProperty.getValue(object)); } } } return relationships; }
private List<?> findIdentityTypeRelationships(IdentityContext context, Class<? extends Relationship> relationshipType, IdentityType identityType) { List<Object> relationships = new ArrayList<Object>(); for (EntityMapper relationshipMemberMapper : getEntityMappers()) { Entry<Property, Property> property = relationshipMemberMapper.getProperty(RelationshipMember.class); if (property != null) { EntityManager em = getEntityManager(context); CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<?> criteria = builder.createQuery(relationshipMemberMapper.getEntityType()); Root<?> root = criteria.from(relationshipMemberMapper.getEntityType()); Property<Object> identityTypeProperty = relationshipMemberMapper.getProperty(RelationshipMember.class).getValue(); if (identityTypeProperty.getJavaClass().equals(String.class)) { criteria.where(builder.equal(root.get(identityTypeProperty.getName()), IdentityTypeUtil.formatId(identityType))); } else { criteria.where(builder.equal(root.get(identityTypeProperty.getName()), em.find(identityTypeProperty.getJavaClass(), identityType.getId()))); } List<?> result = em.createQuery(criteria).getResultList(); Property<Object> ownerProperty = relationshipMemberMapper.getProperty(OwnerReference.class).getValue(); for (Object object : result) { relationships.add(ownerProperty.getValue(object)); } } } return relationships; }
private <V extends IdentityType> IdentityType lookupIdentityTypeById(IdentityContext context, Class<V> type, String identifier) { EntityManager entityManager = getEntityManager(context); if (IdentityType.class.equals(type)) { // when querying based on the IdentityType base type, we try to load the instance from all available mappers. for (EntityMapper entityMapper : getEntityMappers()) { if (entityMapper.getMappingsFor(type) != null && entityMapper.isRoot()) { Object entity = entityManager.find(entityMapper.getEntityType(), identifier); V identityType = entityMapper.<V>createType(entity, entityManager); if (identityType != null) { return identityType; } } } } else { // we know the right type, we just lookup based on its root mapper Object entity = entityManager.find(getRootMapper(type).getEntityType(), identifier); if (entity != null) { return getRootMapperForEntity(entity.getClass()).<V>createType(entity, entityManager); } } return null; }
private <V extends IdentityType> IdentityType lookupIdentityTypeById(IdentityContext context, Class<V> type, String identifier) { EntityManager entityManager = getEntityManager(context); if (IdentityType.class.equals(type)) { // when querying based on the IdentityType base type, we try to load the instance from all available mappers. for (EntityMapper entityMapper : getEntityMappers()) { if (entityMapper.getMappingsFor(type) != null && entityMapper.isRoot()) { Object entity = entityManager.find(entityMapper.getEntityType(), identifier); V identityType = entityMapper.<V>createType(entity, entityManager); if (identityType != null) { return identityType; } } } } else { // we know the right type, we just lookup based on its root mapper Object entity = entityManager.find(getRootMapper(type).getEntityType(), identifier); if (entity != null) { return getRootMapperForEntity(entity.getClass()).<V>createType(entity, entityManager); } } return null; }
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(); } }
for (EntityMapper entityMapper : getEntityMappers()) { if (entityMapper.getMappingsFor(IdentityType.class) != null && entityMapper.isRoot()) { IdentityType identityType = entityMapper.<IdentityType>createType(owner, em);
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(); } }
for (EntityMapper entityMapper : getEntityMappers()) { if (entityMapper.getMappingsFor(IdentityType.class) != null && entityMapper.isRoot()) { IdentityType identityType = entityMapper.<IdentityType>createType(owner, em);