Skip to content

Commit

Permalink
Role-mining fix loading extension properties
Browse files Browse the repository at this point in the history
  • Loading branch information
tchrapovic committed Apr 19, 2024
1 parent eaaf141 commit 0faa2f5
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,19 +386,21 @@ private static Set<String> resolveRefs(
List<?> definitions = itemDefinitionByFullPath.getDefinitions();

for (Object definition : definitions) {
if (definition instanceof PrismReferenceDefinition prismReferenceDefinition) {
RoleAnalysisAttributeDef attribute = createRoleAttribute(
prismReferenceDefinition);
attributes.add(attribute);
}
if (definition instanceof PrismPropertyDefinition<?> prismPropertyDefinition) {
Class<?> typeClass = prismPropertyDefinition.getTypeClass();
boolean isSingleValue = prismPropertyDefinition.isSingleValue();

ItemPath itemName = prismPropertyDefinition.getItemName();
String attributeName = itemName + " extension";
RoleAnalysisAttributeDef attribute = createRoleAttribute(
prismPropertyDefinition, typeClass, isSingleValue, attributeName);
prismPropertyDefinition);
if (attribute != null) {
attributes.add(attribute);
}
}
}

return attributes;
}

Expand All @@ -416,14 +418,15 @@ private static Set<String> resolveRefs(
List<?> definitions = itemDefinitionByFullPath.getDefinitions();

for (Object definition : definitions) {
if (definition instanceof PrismReferenceDefinition prismReferenceDefinition) {
RoleAnalysisAttributeDef attribute = createUserAttribute(
prismReferenceDefinition);
attributes.add(attribute);
}
if (definition instanceof PrismPropertyDefinition<?> prismPropertyDefinition) {
Class<?> typeClass = prismPropertyDefinition.getTypeClass();
boolean isSingleValue = prismPropertyDefinition.isSingleValue();

ItemPath itemName = prismPropertyDefinition.getItemName();
String attributeName = itemName + " extension";
RoleAnalysisAttributeDef attribute = createUserAttribute(
prismPropertyDefinition, typeClass, isSingleValue, attributeName);
prismPropertyDefinition);
if (attribute != null) {
attributes.add(attribute);
}
Expand All @@ -433,17 +436,49 @@ private static Set<String> resolveRefs(
return attributes;
}

private static @NotNull RoleAnalysisAttributeDef createUserAttribute(
@NotNull PrismReferenceDefinition prismReferenceDefinition) {
boolean isSingleValue = prismReferenceDefinition.isSingleValue();

ItemPath itemName = prismReferenceDefinition.getItemName();
String attributeName = itemName + " extension";

return new RoleAnalysisAttributeDef(
ItemPath.create(UserType.F_EXTENSION, itemName),
isSingleValue,
attributeName,
UserType.class,
RoleAnalysisAttributeDef.IdentifierType.OID) {
@Override
public ObjectQuery getQuery(String value) {
return PrismContext.get().queryFor(UserType.class)
.item(getPath()).ref(value)
.build();
}

@Override
public String resolveSingleValueItem(@NotNull PrismObject<?> prismObject, @NotNull ItemPath itemPath) {
return resolveRef(prismObject, itemPath);
}

@Override
public @NotNull Set<String> resolveMultiValueItem(@NotNull PrismObject<?> prismObject, @NotNull ItemPath itemPath) {
return resolveRefs(prismObject, itemPath);
}
};

}

private static @Nullable RoleAnalysisAttributeDef createUserAttribute(
@NotNull PrismPropertyDefinition<?> prismPropertyDefinition,
@NotNull Class<?> typeClass,
boolean isSingleValue,
@NotNull String attributeName) {
if (typeClass.equals(Integer.class)
|| typeClass.equals(Long.class)
|| typeClass.equals(Boolean.class)
|| typeClass.equals(Double.class)
|| typeClass.equals(String.class)
|| typeClass.equals(PolyString.class)) {
@NotNull PrismPropertyDefinition<?> prismPropertyDefinition) {

Class<?> typeClass = prismPropertyDefinition.getTypeClass();
boolean isSingleValue = prismPropertyDefinition.isSingleValue();

ItemPath itemName = prismPropertyDefinition.getItemName();
String attributeName = itemName + " extension";

if (isSupportedPropertyType(typeClass)) {

return new RoleAnalysisAttributeDef(
ItemPath.create(UserType.F_EXTENSION, prismPropertyDefinition.getItemName()),
Expand Down Expand Up @@ -487,20 +522,51 @@ public String resolveSingleValueItem(@NotNull PrismObject<?> prismObject, @NotNu
return null;
}

private static @NotNull RoleAnalysisAttributeDef createRoleAttribute(
@NotNull PrismReferenceDefinition prismReferenceDefinition) {
boolean isSingleValue = prismReferenceDefinition.isSingleValue();

ItemPath itemName = prismReferenceDefinition.getItemName();
String attributeName = itemName + " extension";

return new RoleAnalysisAttributeDef(
ItemPath.create(RoleType.F_EXTENSION, itemName),
isSingleValue,
attributeName,
RoleType.class,
RoleAnalysisAttributeDef.IdentifierType.OID) {
@Override
public ObjectQuery getQuery(String value) {
return PrismContext.get().queryFor(RoleType.class)
.item(getPath()).ref(value)
.build();
}

@Override
public String resolveSingleValueItem(@NotNull PrismObject<?> prismObject, @NotNull ItemPath itemPath) {
return resolveRef(prismObject, itemPath);
}

@Override
public @NotNull Set<String> resolveMultiValueItem(@NotNull PrismObject<?> prismObject, @NotNull ItemPath itemPath) {
return resolveRefs(prismObject, itemPath);
}
};

}

private static @Nullable RoleAnalysisAttributeDef createRoleAttribute(
@NotNull PrismPropertyDefinition<?> prismPropertyDefinition,
@NotNull Class<?> typeClass,
boolean isSingleValue,
@NotNull String attributeName) {
if (typeClass.equals(Integer.class)
|| typeClass.equals(Long.class)
|| typeClass.equals(Boolean.class)
|| typeClass.equals(Double.class)
|| typeClass.equals(String.class)
|| typeClass.equals(PolyString.class)) {
@NotNull PrismPropertyDefinition<?> prismPropertyDefinition) {

Class<?> typeClass = prismPropertyDefinition.getTypeClass();
boolean isSingleValue = prismPropertyDefinition.isSingleValue();

ItemPath itemName = prismPropertyDefinition.getItemName();
String attributeName = itemName + " extension";

if (isSupportedPropertyType(typeClass)) {
return new RoleAnalysisAttributeDef(
ItemPath.create(RoleType.F_EXTENSION, prismPropertyDefinition.getItemName()),
ItemPath.create(RoleType.F_EXTENSION, itemName),
isSingleValue,
attributeName,
RoleType.class,
Expand Down Expand Up @@ -540,6 +606,11 @@ public String resolveSingleValueItem(@NotNull PrismObject<?> prismObject, @NotNu
return null;
}

private static boolean isSupportedPropertyType(@NotNull Class<?> typeClass) {
return typeClass.equals(Integer.class) || typeClass.equals(Long.class) || typeClass.equals(Boolean.class)
|| typeClass.equals(Double.class) || typeClass.equals(String.class) || typeClass.equals(PolyString.class);
}

@Nullable
private static String resolveRef(@NotNull PrismObject<?> prismObject, @NotNull ItemPath itemPath) {
Item<PrismValue, ItemDefinition<?>> property = prismObject.findItem(itemPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,9 @@ public static String resolveClusterName(
if (attribute.getIdentifierType().equals(RoleAnalysisAttributeDef.IdentifierType.FINAL)) {
candidateName = itemPath + "-" + value;
} else {
Class<? extends ObjectType> classType = attribute.getTargetClassType();
PrismObject<? extends ObjectType> object = null;
if (classType != null) {
object = roleAnalysisService.getObject(classType, value, task, result);
}
PrismObject<? extends ObjectType> object;
object = roleAnalysisService.getObject(FocusType.class, value, task, result);

candidateName = object != null ? itemPath + "-" + object.getName() : itemPath + "-" + value;
}
candidateNames.add(candidateName);
Expand All @@ -123,11 +121,8 @@ public static String resolveClusterName(
if (attribute.getIdentifierType().equals(RoleAnalysisAttributeDef.IdentifierType.FINAL)) {
candidateName = itemPath + "-" + value;
} else {
Class<? extends ObjectType> classType = attribute.getTargetClassType();
PrismObject<? extends ObjectType> object = null;
if (classType != null) {
object = roleAnalysisService.getObject(classType, value, task, result);
}
PrismObject<? extends ObjectType> object;
object = roleAnalysisService.getObject(FocusType.class, value, task, result);
candidateName = object != null ? itemPath + "-" + object.getName() : itemPath + "-" + value;
}
candidateNames.add(candidateName);
Expand Down

0 comments on commit 0faa2f5

Please sign in to comment.