use of org.keycloak.representations.idm.ClientMappingsRepresentation in project keycloak by keycloak.
the class ScopeMappedResource method getScopeMappings.
/**
* Get all scope mappings for the client
*
* @return
* @deprecated the method is not used neither from admin console or from admin client. It may be removed in future releases.
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@NoCache
@Deprecated
public MappingsRepresentation getScopeMappings() {
viewPermission.require();
if (scopeContainer == null) {
throw new NotFoundException("Could not find client");
}
MappingsRepresentation all = new MappingsRepresentation();
List<RoleRepresentation> realmRep = scopeContainer.getRealmScopeMappingsStream().map(ModelToRepresentation::toBriefRepresentation).collect(Collectors.toList());
if (!realmRep.isEmpty()) {
all.setRealmMappings(realmRep);
}
Stream<ClientModel> clients = realm.getClientsStream();
Map<String, ClientMappingsRepresentation> clientMappings = clients.map(c -> ScopeMappedUtil.toClientMappingsRepresentation(c, scopeContainer)).filter(Objects::nonNull).collect(Collectors.toMap(ClientMappingsRepresentation::getClient, Function.identity()));
if (!clientMappings.isEmpty()) {
all.setClientMappings(clientMappings);
}
return all;
}
use of org.keycloak.representations.idm.ClientMappingsRepresentation in project keycloak by keycloak.
the class ScopeMappedUtil method toClientMappingsRepresentation.
public static ClientMappingsRepresentation toClientMappingsRepresentation(ClientModel client, ScopeContainerModel scopeContainer) {
Set<RoleModel> roleMappings = KeycloakModelUtils.getClientScopeMappings(client, scopeContainer);
if (!roleMappings.isEmpty()) {
ClientMappingsRepresentation mappings = new ClientMappingsRepresentation();
mappings.setId(client.getId());
mappings.setClient(client.getClientId());
List<RoleRepresentation> roles = new LinkedList<>();
mappings.setMappings(roles);
for (RoleModel role : roleMappings) {
roles.add(ModelToRepresentation.toBriefRepresentation(role));
}
return mappings;
} else {
return null;
}
}
use of org.keycloak.representations.idm.ClientMappingsRepresentation in project keycloak by keycloak.
the class RoleMapperResource method getRoleMappings.
/**
* Get role mappings
*
* @return
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@NoCache
public MappingsRepresentation getRoleMappings() {
viewPermission.require();
List<RoleRepresentation> realmRolesRepresentation = new ArrayList<>();
Map<String, ClientMappingsRepresentation> appMappings = new HashMap<>();
final AtomicReference<ClientMappingsRepresentation> mappings = new AtomicReference<>();
roleMapper.getRoleMappingsStream().forEach(roleMapping -> {
RoleContainerModel container = roleMapping.getContainer();
if (container instanceof RealmModel) {
realmRolesRepresentation.add(ModelToRepresentation.toBriefRepresentation(roleMapping));
} else if (container instanceof ClientModel) {
ClientModel clientModel = (ClientModel) container;
mappings.set(appMappings.get(clientModel.getClientId()));
if (mappings.get() == null) {
mappings.set(new ClientMappingsRepresentation());
mappings.get().setId(clientModel.getId());
mappings.get().setClient(clientModel.getClientId());
mappings.get().setMappings(new ArrayList<>());
appMappings.put(clientModel.getClientId(), mappings.get());
}
mappings.get().getMappings().add(ModelToRepresentation.toBriefRepresentation(roleMapping));
}
});
MappingsRepresentation all = new MappingsRepresentation();
if (!realmRolesRepresentation.isEmpty())
all.setRealmMappings(realmRolesRepresentation);
if (!appMappings.isEmpty())
all.setClientMappings(appMappings);
return all;
}
Aggregations