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 + "."); }
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 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; }
@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; }
@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); } } } }
@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); } } } }
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 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; }
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; }
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; }
public String getBindingDN(AttributedType attributedType) { LDAPMappingConfiguration mappingConfig = getMappingConfig(attributedType.getClass()); if (attributedType.getId() != null) { String baseDN = mappingConfig.getBaseDN(); if (baseDN == null) { baseDN = getConfig().getBaseDN(); } SearchResult searchResult = operationManager.lookupById(baseDN, attributedType.getId(), mappingConfig); if (searchResult == null) { throw MESSAGES.storeLdapEntryNotFoundWithId(attributedType.getId(), baseDN); } return searchResult.getNameInNamespace(); } return getBindingDN(attributedType, true); }
public String getBindingDN(AttributedType attributedType) { LDAPMappingConfiguration mappingConfig = getMappingConfig(attributedType.getClass()); if (attributedType.getId() != null) { String baseDN = mappingConfig.getBaseDN(); if (baseDN == null) { baseDN = getConfig().getBaseDN(); } SearchResult searchResult = operationManager.lookupById(baseDN, attributedType.getId(), mappingConfig); if (searchResult == null) { throw MESSAGES.storeLdapEntryNotFoundWithId(attributedType.getId(), baseDN); } return searchResult.getNameInNamespace(); } return getBindingDN(attributedType, true); }