-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved support for Shadow Marks protected flags to provisioning instea…
…d of model Provisioning-impl manages loading and synchronization of shadows and original determination of ptotectedObject flag,so it makes sense to unify it there instead of SynchronizationService. Original support in SynchronizationService would not prevent modification of protected shadows in cases, where provisioningService is accessed directly.
- Loading branch information
1 parent
a2d36ef
commit 6a439ca
Showing
12 changed files
with
834 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...sioning-impl/src/main/java/com/evolveum/midpoint/provisioning/impl/ShadowMarkManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.evolveum.midpoint.provisioning.impl; | ||
|
||
import static com.evolveum.midpoint.schema.util.ObjectTypeUtil.asObjectables; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.annotation.PreDestroy; | ||
|
||
import org.apache.commons.lang3.BooleanUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.evolveum.midpoint.prism.PrismContext; | ||
import com.evolveum.midpoint.prism.query.ObjectQuery; | ||
import com.evolveum.midpoint.repo.api.RepositoryService; | ||
import com.evolveum.midpoint.schema.result.OperationResult; | ||
import com.evolveum.midpoint.util.exception.SchemaException; | ||
import com.evolveum.midpoint.util.exception.SystemException; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowProvisioningPolicyType; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemObjectsType; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.TagType; | ||
|
||
@Component | ||
public class ShadowMarkManager { | ||
|
||
private static ShadowMarkManager instance = null; | ||
|
||
@Autowired @Qualifier("cacheRepositoryService") private RepositoryService cacheRepositoryService; | ||
@Autowired private PrismContext prismContext; | ||
|
||
|
||
@PostConstruct | ||
public void init() { | ||
instance = this; | ||
} | ||
|
||
@PreDestroy | ||
public void destroy() { | ||
instance = null; | ||
} | ||
|
||
public Collection<TagType> getShadowMarks(List<ObjectReferenceType> tagRefs, @NotNull OperationResult result) { | ||
// FIXME: Consider caching of all shadow marks and doing post-filter only | ||
if (!cacheRepositoryService.supportsTags() || tagRefs.isEmpty()) { | ||
return List.of(); | ||
} | ||
String[] tagRefIds = tagRefs.stream().map(t -> t.getOid()).collect(Collectors.toList()).toArray(new String[0]); | ||
ObjectQuery query = prismContext.queryFor(TagType.class) | ||
//.item(TagType.F_ARCHETYPE_REF).ref(SystemObjectsType.ARCHETYPE_SHADOW_MARK.value()) | ||
// Tag is Shadow Marks | ||
.item(TagType.F_ASSIGNMENT, AssignmentType.F_TARGET_REF).ref(SystemObjectsType.ARCHETYPE_SHADOW_MARK.value()) | ||
.and() | ||
// Tag is assigned to shadow | ||
.id(tagRefIds) | ||
.build(); | ||
try { | ||
return asObjectables(cacheRepositoryService.searchObjects(TagType.class, query, null, result)); | ||
} catch (SchemaException e) { | ||
throw new SystemException(e); | ||
} | ||
} | ||
|
||
public ShadowProvisioningPolicyType getShadowMarkPolicy(List<ObjectReferenceType> tagRefs, @NotNull OperationResult result) { | ||
var ret = new ShadowProvisioningPolicyType(); | ||
Collection<TagType> marks = getShadowMarks(tagRefs, result); | ||
|
||
// Account is protected if any of shadow marks set it to protected. | ||
boolean isProtected = marks.stream().anyMatch( | ||
t -> t.getProvisioningPolicy() != null && | ||
BooleanUtils.isTrue(t.getProvisioningPolicy().isProtected())); | ||
ret.setProtected(isProtected); | ||
|
||
return ret; | ||
} | ||
|
||
public static ShadowMarkManager get() { | ||
return instance; | ||
} | ||
|
||
public boolean isProtectedShadow(ShadowType shadow, @NotNull OperationResult result) { | ||
return getShadowMarkPolicy(shadow.getTagRef(), result).isProtected(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.