Ordering the group and role ids in the policy representation
Closes #28824 Signed-off-by: Pedro Igor <pigor.craveiro@gmail.com>
This commit is contained in:
parent
337a337bf9
commit
8e48bac278
4 changed files with 28 additions and 7 deletions
|
@ -21,7 +21,7 @@ import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -221,6 +221,8 @@ public class GroupPolicyProviderFactory implements PolicyProviderFactory<GroupPo
|
||||||
return Collections.emptySet();
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new HashSet<>(Arrays.asList(JsonSerialization.readValue(groups, GroupPolicyRepresentation.GroupDefinition[].class)));
|
return Arrays.stream(JsonSerialization.readValue(groups, GroupPolicyRepresentation.GroupDefinition[].class))
|
||||||
|
.sorted()
|
||||||
|
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,10 @@ import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:psilva@redhat.com">Pedro Igor</a>
|
* @author <a href="mailto:psilva@redhat.com">Pedro Igor</a>
|
||||||
|
@ -191,9 +193,10 @@ public class RolePolicyProviderFactory implements PolicyProviderFactory<RolePoli
|
||||||
private Set<RoleDefinition> getRoles(String rawRoles, RealmModel realm) {
|
private Set<RoleDefinition> getRoles(String rawRoles, RealmModel realm) {
|
||||||
if (rawRoles != null) {
|
if (rawRoles != null) {
|
||||||
try {
|
try {
|
||||||
Set<RoleDefinition> roles = new HashSet<>(Arrays.asList(JsonSerialization.readValue(rawRoles, RoleDefinition[].class)));
|
return Arrays.stream(JsonSerialization.readValue(rawRoles, RoleDefinition[].class))
|
||||||
roles.removeIf(definition -> getRole(definition, realm) == null);
|
.filter(definition -> getRole(definition, realm) != null)
|
||||||
return roles;
|
.sorted()
|
||||||
|
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("Could not parse roles from config: [" + rawRoles + "]", e);
|
throw new RuntimeException("Could not parse roles from config: [" + rawRoles + "]", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ public class GroupPolicyRepresentation extends AbstractPolicyRepresentation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class GroupDefinition {
|
public static class GroupDefinition implements Comparable<GroupDefinition> {
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
private String path;
|
private String path;
|
||||||
|
@ -136,5 +136,13 @@ public class GroupPolicyRepresentation extends AbstractPolicyRepresentation {
|
||||||
public void setExtendChildren(boolean extendChildren) {
|
public void setExtendChildren(boolean extendChildren) {
|
||||||
this.extendChildren = extendChildren;
|
this.extendChildren = extendChildren;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(GroupDefinition o) {
|
||||||
|
if (o.id == null || id == null) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return id.compareTo(o.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class RolePolicyRepresentation extends AbstractPolicyRepresentation {
|
||||||
this.fetchRoles = fetchRoles;
|
this.fetchRoles = fetchRoles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class RoleDefinition {
|
public static class RoleDefinition implements Comparable<RoleDefinition> {
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
private boolean required;
|
private boolean required;
|
||||||
|
@ -96,5 +96,13 @@ public class RolePolicyRepresentation extends AbstractPolicyRepresentation {
|
||||||
public void setRequired(boolean required) {
|
public void setRequired(boolean required) {
|
||||||
this.required = required;
|
this.required = required;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(RoleDefinition o) {
|
||||||
|
if (id == null || o.id == null) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return id.compareTo(o.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue