Skip to content

Commit

Permalink
Improve RBAC data generator
Browse files Browse the repository at this point in the history
1. Add possibility to disable plankton roles
  • Loading branch information
tchrapovic committed Apr 15, 2024
1 parent 8f86c62 commit c1a4d53
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,15 @@ public class BaseGeneratorOptions {
public static final String P_ADDITION_NOISE = "-an";
public static final String P_ADDITION_NOISE_LONG = "--addition-noise";

public static final String P_PLANKTON_DISABLE = "-pd";
public static final String P_PLANKTON_DISABLE_LONG = "--plankton-disable";

@Parameter(names = { P_PLANKTON_DISABLE, P_PLANKTON_DISABLE_LONG }, descriptionKey = "baseGeneratorOptions.planktonDisable")
private boolean isPlanktonDisable = false;

@Parameter(names = { P_ADDITION_NOISE, P_ADDITION_NOISE_LONG }, descriptionKey = "baseGeneratorOptions.forget.noise")
private int forgetNoise = 0;

@Parameter(names = { P_FORGET_NOISE, P_FORGET_NOISE_LONG }, descriptionKey = "baseGeneratorOptions.addition.noise")
private int additionNoise = 0;

Expand All @@ -61,13 +68,16 @@ public class BaseGeneratorOptions {

@Parameter(names = { P_ARCHETYPE_ROLE, P_ARCHETYPE_ROLE_LONG }, descriptionKey = "baseGeneratorOptions.archetypeRole")
private boolean isArchetypeRoleEnable = false;

@Parameter(names = { P_ARCHETYPE_USER, P_ARCHETYPE_USER_LONG }, descriptionKey = "baseGeneratorOptions.archetypeUser")
private boolean isArchetypeUserEnable = false;

@Parameter(names = { P_IMPORT, P_IMPORT_LONG }, descriptionKey = "baseGeneratorOptions.import")
private boolean isImport = false;

@Parameter(names = { P_NAME_CSV_FILE, P_NAME_CSV_FILE_LONG }, descriptionKey = "baseGeneratorOptions.nameCsvFile")
private String csvPath;

@Parameter(names = { P_TRANSFORM, P_TRANSFORM_LONG }, descriptionKey = "baseGeneratorOptions.transform")
private boolean isTransform = false;

Expand Down Expand Up @@ -124,4 +134,8 @@ public int getAdditionNoise() {
return additionNoise;
}

public boolean isPlanktonDisable() {
return isPlanktonDisable;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.io.Reader;
import java.util.*;

import com.evolveum.midpoint.ninja.action.mining.generator.GeneratorOptions;

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
Expand Down Expand Up @@ -75,10 +77,16 @@ public class RbacGeneratorUtils {
* Retrieves a list of randomly selected plankton abstract roles.
*
* @param minRoles The minimum number of roles to select.
* @param generatorOptions The generator options to consider.
* @return A list of randomly selected plankton abstract roles.
*/
protected static @NotNull List<InitialObjectsDefinition.PlanktonApplicationBusinessAbstractRole> getRandomPlanktonRoles(
int minRoles) {
int minRoles, GeneratorOptions generatorOptions) {

if (generatorOptions.isPlanktonDisable()) {
return new ArrayList<>();
}

int maxRoles = InitialObjectsDefinition.PlanktonApplicationBusinessAbstractRole.values().length;

Random random = new Random();
Expand Down Expand Up @@ -262,7 +270,6 @@ static void resolveAuxRoles(@NotNull UserType user) {
}
}


/**
* Determines whether a role should be forgotten based on a given chance.
* The chance is a percentage value between 0 and 100.
Expand Down
1 change: 1 addition & 0 deletions tools/ninja/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,5 @@ baseGeneratorOptions.userDivision=User division regular:semi-regular:irregular:m
baseGeneratorOptions.includeAux=Include aux roles
baseGeneratorOptions.forget.noise=Forget noise in percent (int). Chance that we will forget about some roles.
baseGeneratorOptions.addition.noise=Addition noise in percent (int). Chance that we will add some noise roles.
baseGeneratorOptions.planktonDisable=Specify if plankton roles should be enabled or disabled

0 comments on commit c1a4d53

Please sign in to comment.