Adding a column to list policies associated with a permission.

This commit is contained in:
Pedro Igor 2016-06-29 20:11:47 -03:00
parent 2db41ef052
commit 01f3dddd91
3 changed files with 33 additions and 6 deletions

View File

@ -16,6 +16,7 @@
*/
package org.keycloak.representations.idm.authorization;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -34,6 +35,7 @@ public class PolicyRepresentation {
private DecisionStrategy decisionStrategy = DecisionStrategy.UNANIMOUS;
private Map<String, String> config = new HashMap();
private List<PolicyRepresentation> dependentPolicies;
private List<PolicyRepresentation> associatedPolicies = new ArrayList<>();
public String getId() {
return this.id;
@ -91,6 +93,14 @@ public class PolicyRepresentation {
this.description = description;
}
public List<PolicyRepresentation> getAssociatedPolicies() {
return associatedPolicies;
}
public void setAssociatedPolicies(List<PolicyRepresentation> associatedPolicies) {
this.associatedPolicies = associatedPolicies;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;

View File

@ -162,13 +162,22 @@ public final class Models {
return representation1;
}).collect(Collectors.toList()));
List<String> obj = model.getAssociatedPolicies().stream().map(new Function<Policy, String>() {
@Override
public String apply(Policy policy) {
return policy.getId();
}
List<PolicyRepresentation> associatedPolicies = new ArrayList<>();
List<String> obj = model.getAssociatedPolicies().stream().map(policy -> {
PolicyRepresentation representation1 = new PolicyRepresentation();
representation1.setId(policy.getId());
representation1.setName(policy.getName());
representation1.setType(policy.getType());
associatedPolicies.add(representation1);
return policy.getId();
}).collect(Collectors.toList());
representation.setAssociatedPolicies(associatedPolicies);
try {
representation.getConfig().put("applyPolicies", JsonSerialization.writeValueAsString(obj));
} catch (IOException e) {

View File

@ -3,7 +3,6 @@
<kc-tabs-resource-server></kc-tabs-resource-server>
<table class="table table-striped table-bordered">
<caption class="hidden">Table of identity providers</caption>
<thead>
<tr>
<th class="kc-table-actions" colspan="5">
@ -34,6 +33,7 @@
<th>Permission Name</th>
<th>Description</th>
<th>Type</th>
<th>Associated Policies</th>
</tr>
</thead>
<tbody>
@ -41,6 +41,14 @@
<td><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server/permission/{{policy.type}}/{{policy.id}}">{{policy.name}}</a></td>
<td>{{policy.description}}</td>
<td>{{policy.type}}</td>
<td>
<span data-ng-show="!policy.associatedPolicies.length">No policies assigned.</span>
<span data-ng-show="policy.associatedPolicies.length > 0">
<span ng-repeat="policy in policy.associatedPolicies">
<a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server/policy/{{policy.type}}/{{policy.id}}">{{policy.name}}</a>{{$last ? '' : ', '}}
</span>
</span>
</td>
</tr>
<tr data-ng-show="(policies | filter:search).length == 0">
<td class="text-muted" colspan="3" data-ng-show="search.name">No results</td>