Skip to content

Commit

Permalink
Role analysis add useful method into rbac generator
Browse files Browse the repository at this point in the history
  • Loading branch information
tchrapovic committed Jun 26, 2024
1 parent 12874a5 commit f042480
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -449,26 +449,31 @@ public static PolyStringType getNameFromSet(PolyStringType initialName, Set<Stri
return PolyStringType.fromOrig(name);
}

public static <V> void addExtensionValue(
Containerable extContainer, String itemName, V... values) throws SchemaException {
public static <V> void addExtensionValue(
Containerable extContainer, String itemName, V... values) {
PrismContainerValue<?> pcv = extContainer.asPrismContainerValue();
ItemDefinition<?> itemDefinition =
pcv.getDefinition().findItemDefinition(new ItemName(itemName));

if (itemDefinition instanceof PrismReferenceDefinition) {
PrismReference ref = (PrismReference) itemDefinition.instantiate();
for (V value : values) {
ref.add(value instanceof PrismReferenceValue
? (PrismReferenceValue) value
: ((Referencable) value).asReferenceValue());
try {
if (itemDefinition instanceof PrismReferenceDefinition) {
PrismReference ref = (PrismReference) itemDefinition.instantiate();
for (V value : values) {
ref.add(value instanceof PrismReferenceValue
? (PrismReferenceValue) value
: ((Referencable) value).asReferenceValue());
}
pcv.add(ref);
} else {
//noinspection unchecked
PrismProperty<V> property = (PrismProperty<V>) itemDefinition.instantiate();
property.setRealValues(values);
pcv.add(property);
}
pcv.add(ref);
} else {
//noinspection unchecked
PrismProperty<V> property = (PrismProperty<V>) itemDefinition.instantiate();
property.setRealValues(values);
pcv.add(property);
} catch (SchemaException e) {
throw new RuntimeException("Cloud not add extension value", e);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.List;
import java.util.Set;

import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.ninja.action.mining.generator.GeneratorOptions;
Expand Down Expand Up @@ -47,4 +49,6 @@ void buildAndImportObjects(
@NotNull GeneratorOptions generatorOptions,
int total, Set<String> names,
@NotNull OperationResult result);

void additionalChanges(UserType user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
*/
package com.evolveum.midpoint.ninja.action.mining.generator.context;

import static com.evolveum.midpoint.ninja.action.mining.generator.context.ImportAction.importUserAndResolveAuxRoles;
import static com.evolveum.midpoint.ninja.action.mining.generator.context.RbacGeneratorUtils.*;
import static com.evolveum.midpoint.ninja.action.mining.generator.context.RbacObjectCategoryProcessor.*;
import static com.evolveum.midpoint.ninja.action.mining.generator.context.RbacObjectCategoryProcessor.Category.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.ninja.action.mining.generator.GeneratorOptions;
import com.evolveum.midpoint.ninja.action.mining.generator.object.InitialBusinessRole;
import com.evolveum.midpoint.ninja.action.mining.generator.object.InitialObjectsDefinition;
Expand All @@ -15,18 +26,6 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import static com.evolveum.midpoint.ninja.action.mining.generator.context.ImportAction.importUserAndResolveAuxRoles;
import static com.evolveum.midpoint.ninja.action.mining.generator.context.RbacGeneratorUtils.*;
import static com.evolveum.midpoint.ninja.action.mining.generator.context.RbacGeneratorUtils.createRoleAssignment;
import static com.evolveum.midpoint.ninja.action.mining.generator.context.RbacObjectCategoryProcessor.*;
import static com.evolveum.midpoint.ninja.action.mining.generator.context.RbacObjectCategoryProcessor.Category.*;

public class RbacObjectCategoryBuilder {

/**
Expand Down Expand Up @@ -109,6 +108,13 @@ public String getTitle() {
return null;
}

@Override
public void additionalChanges(UserType user) {
// user.extension(new ExtensionType());
// ExtensionType ext = user.getExtension();
// addExtensionValue(ext, "hatSize", "Mike");
}

@Override
protected String getDisplayName() {
return REGULR.getDisplayName();
Expand Down Expand Up @@ -179,6 +185,13 @@ public String getTitle() {
return getRandomlyJobTitlesWithNone();
}

@Override
public void additionalChanges(UserType user) {
// user.extension(new ExtensionType());
// ExtensionType ext = user.getExtension();
// addExtensionValue(ext, "hatSize", "Jan");
}

@Override
protected String getDisplayName() {
return SEMI_REGULAR.getDisplayName();
Expand Down Expand Up @@ -216,6 +229,13 @@ public String getTitle() {
return getRandomlyJobTitlesWithNone();
}

@Override
public void additionalChanges(UserType user) {
// user.extension(new ExtensionType());
// ExtensionType ext = user.getExtension();
// addExtensionValue(ext, "hatSize", "Jozef");
}

@Override
public String getCorrespondingArchetypeOid() {
return InitialObjectsDefinition.Archetypes.IRREGULAR_USER.getOidValue();
Expand Down Expand Up @@ -308,6 +328,13 @@ public String getTitle() {
return "manager";
}

@Override
public void additionalChanges(UserType user) {
// user.extension(new ExtensionType());
// ExtensionType ext = user.getExtension();
// addExtensionValue(ext, "hatSize", "Peter");
}

@Override
protected String getDisplayName() {
return MANAGERS.getDisplayName();
Expand Down Expand Up @@ -387,6 +414,13 @@ public String getTitle() {
return null;
}

@Override
public void additionalChanges(UserType user) {
// user.extension(new ExtensionType());
// ExtensionType ext = user.getExtension();
// addExtensionValue(ext, "hatSize", "Slavo");
}

@Override
protected String getDisplayName() {
return SALES.getDisplayName();
Expand Down Expand Up @@ -449,6 +483,13 @@ public String getTitle() {
return null;
}

@Override
public void additionalChanges(UserType user) {
// user.extension(new ExtensionType());
// ExtensionType ext = user.getExtension();
// addExtensionValue(ext, "hatSize", "Karol");
}

@Override
protected String getDisplayName() {
return SECURITY_OFFICERS.getDisplayName();
Expand Down Expand Up @@ -511,6 +552,13 @@ public String getTitle() {
return null;
}

@Override
public void additionalChanges(UserType user) {
// user.extension(new ExtensionType());
// ExtensionType ext = user.getExtension();
// addExtensionValue(ext, "hatSize", "Clark");
}

@Override
protected String getDisplayName() {
return CONTRACTORS.getDisplayName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public UserType build(@NotNull UserType user) {
}
}

additionalChanges(user);

InitialBusinessRole primaryRole = getPrimaryRole(true);
if (primaryRole != null) {
user.getAssignment().add(createRoleAssignment(primaryRole.getOidValue()));
Expand Down

0 comments on commit f042480

Please sign in to comment.