@Override protected Builder<LDAPMappingConfiguration> readFrom(LDAPMappingConfiguration fromConfiguration) { this.mappedClass = fromConfiguration.getMappedClass(); this.objectClasses.addAll(fromConfiguration.getObjectClasses()); this.baseDN = fromConfiguration.getBaseDN(); if (fromConfiguration.getIdProperty() != null) { this.idPropertyName = fromConfiguration.getIdProperty().getName(); } this.mappedProperties.putAll(fromConfiguration.getMappedProperties()); this.readOnlyAttributes.addAll(fromConfiguration.getReadOnlyAttributes()); this.parentMapping.putAll(fromConfiguration.getParentMapping()); this.relatedAttributedType = fromConfiguration.getRelatedAttributedType(); this.parentMembershipAttributeName = fromConfiguration.getParentMembershipAttributeName(); this.hierarchySearchDepth = fromConfiguration.getHierarchySearchDepth(); return this; }
public String getBindingDN(AttributedType attributedType, boolean appendBaseDN) { LDAPMappingConfiguration mappingConfig = getMappingConfig(attributedType.getClass()); Property<String> idProperty = mappingConfig.getIdProperty(); String baseDN; if (mappingConfig.getBaseDN() == null || !appendBaseDN) { baseDN = ""; } else { baseDN = COMMA + getBaseDN(attributedType); } Property<String> bindingProperty = mappingConfig.getBindingProperty(); String bindingAttribute; String dn; if (bindingProperty == null) { bindingAttribute = mappingConfig.getMappedProperties().get(idProperty.getName()); dn = idProperty.getValue(attributedType); } else { bindingAttribute = mappingConfig.getMappedProperties().get(bindingProperty.getName()); dn = mappingConfig.getBindingProperty().getValue(attributedType); } return bindingAttribute + EQUAL + dn + baseDN; }
public Class<? extends AttributedType> getSupportedTypeByBaseDN(String entryDN, List<String> objectClasses) { String entryBaseDN = entryDN.substring(entryDN.indexOf(COMMA) + 1); for (LDAPMappingConfiguration mappingConfig : this.mappingConfig.values()) { if (mappingConfig.getBaseDN() != null) { if (!Relationship.class.isAssignableFrom(mappingConfig.getMappedClass())) { if (mappingConfig.getBaseDN().equalsIgnoreCase(entryDN) || mappingConfig.getParentMapping().values().contains(entryDN)) { return mappingConfig.getMappedClass(); } if (mappingConfig.getBaseDN().equalsIgnoreCase(entryBaseDN) || mappingConfig.getParentMapping().values().contains(entryBaseDN)) { return mappingConfig.getMappedClass(); } } } } for (LDAPMappingConfiguration mappingConfig : this.mappingConfig.values()) { if (!Relationship.class.isAssignableFrom(mappingConfig.getMappedClass())) { for (String objectClass : objectClasses) { if (mappingConfig.getObjectClasses().contains(objectClass)) { return mappingConfig.getMappedClass(); } } } } throw new IdentityManagementException("No type found with Base DN [" + entryDN + "] or objectClasses [" + objectClasses + "."); }
private List<String> getReturningAttributes(final LDAPMappingConfiguration mappingConfiguration) { List<String> returningAttributes = new ArrayList<String>(); if (mappingConfiguration != null) { returningAttributes.addAll(mappingConfiguration.getMappedProperties().values()); returningAttributes.add(mappingConfiguration.getParentMembershipAttributeName()); for (LDAPMappingConfiguration relationshipConfig : this.config.getRelationshipConfigs()) { if (relationshipConfig.getRelatedAttributedType().equals(mappingConfiguration.getMappedClass())) { returningAttributes.addAll(relationshipConfig.getMappedProperties().values()); } } } else { returningAttributes.add("*"); } returningAttributes.add(getUniqueIdentifierAttributeName()); returningAttributes.add(CREATE_TIMESTAMP); returningAttributes.add(LDAPConstants.OBJECT_CLASS); return returningAttributes; } }
@Override protected void removeFromRelationships(final IdentityContext context, final IdentityType identityType) { String bindingDN = getBindingDN(identityType, true); for (LDAPMappingConfiguration relationshipConfig : getConfig().getRelationshipConfigs()) { for (String attributeName : relationshipConfig.getMappedProperties().values()) { StringBuilder filter = new StringBuilder(); filter.append("(&(").append(attributeName).append(EQUAL).append("").append(bindingDN).append("))"); try { List<SearchResult> search = this.operationManager.search(getMappingConfig(relationshipConfig.getRelatedAttributedType()).getBaseDN(), filter.toString(), getMappingConfig(relationshipConfig.getRelatedAttributedType())); for (SearchResult result : search) { Attributes attributes = result.getAttributes(); Attribute relationshipAttribute = attributes.get(attributeName); if (relationshipAttribute != null && relationshipAttribute.contains(bindingDN)) { relationshipAttribute.remove(bindingDN); if (relationshipAttribute.size() == 0) { relationshipAttribute.add(EMPTY_ATTRIBUTE_VALUE); } this.operationManager.modifyAttribute(result.getNameInNamespace(), relationshipAttribute); } } } catch (NamingException e) { throw new IdentityManagementException("Could not remove " + identityType + " from relationship " + relationshipConfig.getMappedClass(), e); } } } }
protected BasicAttributes extractAttributes(AttributedType attributedType, boolean isCreate) { BasicAttributes entryAttributes = new BasicAttributes(); LDAPMappingConfiguration mappingConfig = getMappingConfig(attributedType.getClass()); Map<String, String> mappedProperties = mappingConfig.getMappedProperties(); if (!mappingConfig.getReadOnlyAttributes().contains(propertyName) && (isCreate || !mappingConfig.getBindingProperty().getName().equals(propertyName))) { Property<Object> property = PropertyQueries .<Object>createQuery(attributedType.getClass()) for (String objectClassValue : ldapEntryConfig.getObjectClasses()) { objectClassAttribute.add(objectClassValue);
private String getBaseDN(AttributedType attributedType) { LDAPMappingConfiguration mappingConfig = getMappingConfig(attributedType.getClass()); String baseDN = mappingConfig.getBaseDN(); String parentDN = mappingConfig.getParentMapping().get(mappingConfig.getIdProperty().getValue(attributedType)); if (parentDN != null) { baseDN = parentDN; } else { Property<AttributedType> parentProperty = PropertyQueries .<AttributedType>createQuery(attributedType.getClass()) .addCriteria(new TypedPropertyCriteria(attributedType.getClass())).getFirstResult(); if (parentProperty != null) { AttributedType parentType = parentProperty.getValue(attributedType); if (parentType != null) { Property<String> parentIdProperty = getMappingConfig(parentType.getClass()).getIdProperty(); String parentId = parentIdProperty.getValue(parentType); String parentBaseDN = mappingConfig.getParentMapping().get(parentId); if (parentBaseDN != null) { baseDN = parentBaseDN; } else { baseDN = getBaseDN(parentType); } } } } if (baseDN == null) { baseDN = getConfig().getBaseDN(); } return baseDN; }
if (hierarchyDepthCount > mappingConfig.getHierarchySearchDepth()) { return null; attributedType.setId(this.operationManager.decodeEntryUUID(attributeValue)); } else { String attributeName = findAttributeName(mappingConfig.getMappedProperties(), ldapAttributeName); if (mappingConfig.getParentMembershipAttributeName() != null) { StringBuilder filter = new StringBuilder("(&"); String entryBaseDN = entryDN.substring(entryDN.indexOf(COMMA) + 1); .append(")") .append("(") .append(mappingConfig.getParentMembershipAttributeName()) .append(EQUAL).append("") .append(getBindingDN(attributedType, false))
private <V extends Relationship> List<V> fetchRelationships(final RelationshipQuery<V> query, final LDAPMappingConfiguration mappingConfig) { List<V> results = new ArrayList<V>(); Class<V> relationshipClass = (Class<V>) mappingConfig.getMappedClass(); Map<QueryParameter, Object[]> parameters = query.getParameters(); LDAPMappingConfiguration relatedTypeConfig = getMappingConfig(mappingConfig.getRelatedAttributedType()); StringBuilder filter = new StringBuilder(); attributeName = mappingConfig.getMappedProperties().get(relationshipQueryParameter.getName()); } else if (Relationship.IDENTITY.equals(queryParameter)) { IdentityType identityType = (IdentityType) values[0]; if (!mappingConfig.getRelatedAttributedType().isInstance(identityType)) { attributeName = getRelationshipMappedProperty(identityType.getClass(), mappingConfig); bindingDN = result.getNameInNamespace(); if (!attributedType.getClass().equals(relatedTypeConfig.getMappedClass())) { entriesToFilter.add(bindingDN); boolean filterByOwner = attributedType.getClass().equals(relatedTypeConfig.getMappedClass()); filterByOwner = property.getJavaClass().equals(relatedTypeConfig.getMappedClass()); for (Entry<String, String> memberAttribute : mappingConfig.getMappedProperties().entrySet()) { String attributeName = memberAttribute.getValue(); Attribute attribute = ownerAttributes.get(attributeName); .addCriteria(new TypedPropertyCriteria(mappingConfig.getRelatedAttributedType())) .getSingleResult();
private String getRelationshipMappedProperty(Class<? extends IdentityType> identityType, LDAPMappingConfiguration mappingConfig) { final Property<Object> property = PropertyQueries.createQuery(mappingConfig.getMappedClass()).addCriteria(new TypedPropertyCriteria(identityType, MatchOption.ALL)).getFirstResult(); if (property == null) { return null; } return mappingConfig.getMappedProperties().get(property.getName()); }
.<String>createQuery(getMappedClass()) .addCriteria(new NamedPropertyCriteria(idPropertyName)).getFirstResult(); } else { bindingProperty = getBindingProperty(bindingPropertyName);
public LDAPMappingConfiguration getMappingConfig(Class<? extends AttributedType> attributedType) { for (LDAPMappingConfiguration mappingConfig : this.mappingConfig.values()) { if (attributedType.equals(mappingConfig.getMappedClass())) { return mappingConfig; } } return null; }
Attributes entryAttributes = this.operationManager.getAttributes(ownerType.getId(), getBaseDN(ownerType), mappingConfig); for (String relationshipTypeProperty : mappingConfig.getMappedProperties().keySet()) { Property<AttributedType> relationshipProperty = PropertyQueries .<AttributedType>createQuery(relationship.getClass()) .getSingleResult(); Attribute attribute = entryAttributes.get(mappingConfig.getMappedProperties().get(relationshipTypeProperty));
private StringBuilder getObjectClassesFilter(final LDAPMappingConfiguration ldapEntryConfig) { StringBuilder builder = new StringBuilder(); if (ldapEntryConfig != null && !ldapEntryConfig.getObjectClasses().isEmpty()) { for (String objectClass : ldapEntryConfig.getObjectClasses()) { builder.append("(").append(OBJECT_CLASS).append(EQUAL).append(objectClass).append(")"); } } else { builder.append("(").append(OBJECT_CLASS).append(EQUAL).append("*").append(")"); } return builder; }
protected void addToParentAsMember(final AttributedType attributedType) { LDAPMappingConfiguration entryConfig = getMappingConfig(attributedType.getClass()); if (entryConfig.getParentMembershipAttributeName() != null) { Property<AttributedType> parentProperty = PropertyQueries .<AttributedType>createQuery(attributedType.getClass()) .addCriteria(new TypedPropertyCriteria(attributedType.getClass())) .getFirstResult(); if (parentProperty != null) { AttributedType parentType = parentProperty.getValue(attributedType); if (parentType != null) { Attributes attributes = this.operationManager.getAttributes(parentType.getId(), getBaseDN(parentType), entryConfig); Attribute attribute = attributes.get(entryConfig.getParentMembershipAttributeName()); attribute.add(getBindingDN(attributedType, true)); this.operationManager.modifyAttribute(getBindingDN(parentType, true), attribute); } } } }
private List<String> getReturningAttributes(final LDAPMappingConfiguration mappingConfiguration) { List<String> returningAttributes = new ArrayList<String>(); if (mappingConfiguration != null) { returningAttributes.addAll(mappingConfiguration.getMappedProperties().values()); returningAttributes.add(mappingConfiguration.getParentMembershipAttributeName()); for (LDAPMappingConfiguration relationshipConfig : this.config.getRelationshipConfigs()) { if (relationshipConfig.getRelatedAttributedType().equals(mappingConfiguration.getMappedClass())) { returningAttributes.addAll(relationshipConfig.getMappedProperties().values()); } } } else { returningAttributes.add("*"); } returningAttributes.add(getUniqueIdentifierAttributeName()); returningAttributes.add(CREATE_TIMESTAMP); returningAttributes.add(LDAPConstants.OBJECT_CLASS); return returningAttributes; } }
public Class<? extends AttributedType> getSupportedTypeByBaseDN(String entryDN, List<String> objectClasses) { String entryBaseDN = entryDN.substring(entryDN.indexOf(COMMA) + 1); for (LDAPMappingConfiguration mappingConfig : this.mappingConfig.values()) { if (mappingConfig.getBaseDN() != null) { if (!Relationship.class.isAssignableFrom(mappingConfig.getMappedClass())) { if (mappingConfig.getBaseDN().equalsIgnoreCase(entryDN) || mappingConfig.getParentMapping().values().contains(entryDN)) { return mappingConfig.getMappedClass(); } if (mappingConfig.getBaseDN().equalsIgnoreCase(entryBaseDN) || mappingConfig.getParentMapping().values().contains(entryBaseDN)) { return mappingConfig.getMappedClass(); } } } } for (LDAPMappingConfiguration mappingConfig : this.mappingConfig.values()) { if (!Relationship.class.isAssignableFrom(mappingConfig.getMappedClass())) { for (String objectClass : objectClasses) { if (mappingConfig.getObjectClasses().contains(objectClass)) { return mappingConfig.getMappedClass(); } } } } throw new IdentityManagementException("No type found with Base DN [" + entryDN + "] or objectClasses [" + objectClasses + "."); }
@Override protected void removeFromRelationships(final IdentityContext context, final IdentityType identityType) { String bindingDN = getBindingDN(identityType, true); for (LDAPMappingConfiguration relationshipConfig : getConfig().getRelationshipConfigs()) { for (String attributeName : relationshipConfig.getMappedProperties().values()) { StringBuilder filter = new StringBuilder(); filter.append("(&(").append(attributeName).append(EQUAL).append("").append(bindingDN).append("))"); try { List<SearchResult> search = this.operationManager.search(getMappingConfig(relationshipConfig.getRelatedAttributedType()).getBaseDN(), filter.toString(), getMappingConfig(relationshipConfig.getRelatedAttributedType())); for (SearchResult result : search) { Attributes attributes = result.getAttributes(); Attribute relationshipAttribute = attributes.get(attributeName); if (relationshipAttribute != null && relationshipAttribute.contains(bindingDN)) { relationshipAttribute.remove(bindingDN); if (relationshipAttribute.size() == 0) { relationshipAttribute.add(EMPTY_ATTRIBUTE_VALUE); } this.operationManager.modifyAttribute(result.getNameInNamespace(), relationshipAttribute); } } } catch (NamingException e) { throw new IdentityManagementException("Could not remove " + identityType + " from relationship " + relationshipConfig.getMappedClass(), e); } } } }
protected BasicAttributes extractAttributes(AttributedType attributedType, boolean isCreate) { BasicAttributes entryAttributes = new BasicAttributes(); LDAPMappingConfiguration mappingConfig = getMappingConfig(attributedType.getClass()); Map<String, String> mappedProperties = mappingConfig.getMappedProperties(); if (!mappingConfig.getReadOnlyAttributes().contains(propertyName) && (isCreate || !mappingConfig.getBindingProperty().getName().equals(propertyName))) { Property<Object> property = PropertyQueries .<Object>createQuery(attributedType.getClass()) for (String objectClassValue : ldapEntryConfig.getObjectClasses()) { objectClassAttribute.add(objectClassValue);