KEYCLOAK-18288 (#8096)
RealmsAdminResource now returns also a brief representation (not by default, to be backwards compatible) for realms[] if the appropriate flag is sent.
This commit is contained in:
parent
ac9e1f7f92
commit
8f09d34272
3 changed files with 17 additions and 5 deletions
|
@ -312,6 +312,16 @@ public class ModelToRepresentation {
|
|||
return rep;
|
||||
}
|
||||
|
||||
public static RealmRepresentation toBriefRepresentation(RealmModel realm) {
|
||||
RealmRepresentation rep = new RealmRepresentation();
|
||||
rep.setId(realm.getId());
|
||||
rep.setRealm(realm.getName());
|
||||
rep.setDisplayName(realm.getDisplayName());
|
||||
rep.setDisplayNameHtml(realm.getDisplayNameHtml());
|
||||
rep.setEnabled(realm.isEnabled());
|
||||
return rep;
|
||||
}
|
||||
|
||||
public static RealmRepresentation toRepresentation(KeycloakSession session, RealmModel realm, boolean internal) {
|
||||
RealmRepresentation rep = new RealmRepresentation();
|
||||
rep.setId(realm.getId());
|
||||
|
|
|
@ -36,12 +36,14 @@ import org.keycloak.services.resources.admin.permissions.AdminPermissionEvaluato
|
|||
import org.keycloak.services.resources.admin.permissions.AdminPermissions;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DefaultValue;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.NotFoundException;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.CacheControl;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
|
@ -93,16 +95,16 @@ public class RealmsAdminResource {
|
|||
@GET
|
||||
@NoCache
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Stream<RealmRepresentation> getRealms() {
|
||||
public Stream<RealmRepresentation> getRealms(@DefaultValue("false") @QueryParam("briefRepresentation") boolean briefRepresentation) {
|
||||
Stream<RealmRepresentation> realms = session.realms().getRealmsStream()
|
||||
.map(this::toRealmRep)
|
||||
.map(realm -> toRealmRep(realm, briefRepresentation))
|
||||
.filter(Objects::nonNull);
|
||||
return throwIfEmpty(realms, new ForbiddenException());
|
||||
}
|
||||
|
||||
protected RealmRepresentation toRealmRep(RealmModel realm) {
|
||||
protected RealmRepresentation toRealmRep(RealmModel realm, boolean briefRep) {
|
||||
if (AdminPermissions.realms(session, auth).canView(realm)) {
|
||||
return ModelToRepresentation.toRepresentation(session, realm, false);
|
||||
return briefRep ? ModelToRepresentation.toBriefRepresentation(realm) : ModelToRepresentation.toRepresentation(session, realm, false);
|
||||
} else if (AdminPermissions.realms(session, auth).isAdmin(realm)) {
|
||||
RealmRepresentation rep = new RealmRepresentation();
|
||||
rep.setRealm(realm.getName());
|
||||
|
|
|
@ -1561,7 +1561,7 @@ module.factory('Current', function(Realm, $route, $rootScope) {
|
|||
};
|
||||
|
||||
$rootScope.$on('$routeChangeStart', function() {
|
||||
current.realms = Realm.query(null, function(realms) {
|
||||
current.realms = Realm.query({briefRepresentation: true}, function(realms) {
|
||||
var currentRealm = null;
|
||||
if ($route.current.params.realm) {
|
||||
for (var i = 0; i < realms.length; i++) {
|
||||
|
|
Loading…
Reference in a new issue