Refactored server-info and updated admin console
This commit is contained in:
parent
204dfd52c8
commit
d1964c20ab
15 changed files with 681 additions and 762 deletions
|
@ -82,8 +82,8 @@ module.config([ '$routeProvider', function($routeProvider) {
|
|||
realm : function(RealmLoader) {
|
||||
return RealmLoader();
|
||||
},
|
||||
serverInfo : function(ServerInfoLoader) {
|
||||
return ServerInfoLoader();
|
||||
serverInfo : function(ServerInfo) {
|
||||
return ServerInfo.delay;
|
||||
}
|
||||
},
|
||||
controller : 'RealmLoginSettingsCtrl'
|
||||
|
@ -1135,11 +1135,20 @@ module.config([ '$routeProvider', function($routeProvider) {
|
|||
.when('/server-info', {
|
||||
templateUrl : resourceUrl + '/partials/server-info.html',
|
||||
resolve : {
|
||||
serverInfoPage : function(ServerInfoPageLoader) {
|
||||
return ServerInfoPageLoader();
|
||||
serverInfo : function(ServerInfoLoader) {
|
||||
return ServerInfoLoader();
|
||||
}
|
||||
},
|
||||
controller : 'ServerInfoPageCtrl'
|
||||
controller : 'ServerInfoCtrl'
|
||||
})
|
||||
.when('/server-info/providers', {
|
||||
templateUrl : resourceUrl + '/partials/server-info-providers.html',
|
||||
resolve : {
|
||||
serverInfo : function(ServerInfoLoader) {
|
||||
return ServerInfoLoader();
|
||||
}
|
||||
},
|
||||
controller : 'ServerInfoCtrl'
|
||||
})
|
||||
.when('/logout', {
|
||||
templateUrl : resourceUrl + '/partials/home.html',
|
||||
|
|
|
@ -549,7 +549,7 @@ module.controller('ClientDetailCtrl', function($scope, realm, client, $route, se
|
|||
"bearer-only"
|
||||
];
|
||||
|
||||
$scope.protocols = serverInfo.protocols;
|
||||
$scope.protocols = Object.keys(serverInfo.providers['login-protocol'].providers);
|
||||
|
||||
$scope.signatureAlgorithms = [
|
||||
"RSA_SHA1",
|
||||
|
|
|
@ -7,9 +7,6 @@ module.controller('GlobalCtrl', function($scope, $http, Auth, WhoAmI, Current, $
|
|||
$scope.resourceUrl = resourceUrl;
|
||||
$scope.auth = Auth;
|
||||
$scope.serverInfo = ServerInfo.get();
|
||||
$scope.serverInfoUpdate = function() {
|
||||
$scope.serverInfo = ServerInfo.get();
|
||||
};
|
||||
|
||||
function hasAnyAccess() {
|
||||
var realmAccess = Auth.user && Auth.user['realm_access'];
|
||||
|
@ -125,18 +122,23 @@ module.controller('RealmTabCtrl', function(Dialog, $scope, Current, Realm, Notif
|
|||
};
|
||||
});
|
||||
|
||||
module.controller('ServerInfoPageCtrl', function($scope, ServerInfoPage) {
|
||||
$scope.serverInfoPage = ServerInfoPage.get();
|
||||
$scope.serverInfoPageUpdate = function() {
|
||||
$scope.serverInfoPage = ServerInfoPage.get();
|
||||
};
|
||||
});
|
||||
module.controller('ServerInfoCtrl', function($scope, ServerInfo) {
|
||||
ServerInfo.reload();
|
||||
|
||||
module.controller('ServerInfoPageCtrl', function($scope, ServerInfoPage) {
|
||||
$scope.serverInfoPage = ServerInfoPage.get();
|
||||
$scope.serverInfoPageUpdate = function() {
|
||||
$scope.serverInfoPage = ServerInfoPage.get();
|
||||
};
|
||||
$scope.serverInfo = ServerInfo.get();
|
||||
|
||||
$scope.$watch($scope.serverInfo, function() {
|
||||
$scope.providers = [];
|
||||
for(var spi in $scope.serverInfo.providers) {
|
||||
var p = angular.copy($scope.serverInfo.providers[spi]);
|
||||
p.name = spi;
|
||||
$scope.providers.push(p)
|
||||
}
|
||||
});
|
||||
|
||||
$scope.serverInfoReload = function() {
|
||||
ServerInfo.reload();
|
||||
}
|
||||
});
|
||||
|
||||
module.controller('RealmListCtrl', function($scope, Realm, Current) {
|
||||
|
@ -1231,7 +1233,7 @@ module.controller('RealmEventsConfigCtrl', function($scope, eventsConfig, RealmE
|
|||
}
|
||||
});
|
||||
|
||||
$scope.eventListeners = serverInfo.eventListeners;
|
||||
$scope.eventListeners = Object.keys(serverInfo.providers.eventsListener.providers);
|
||||
|
||||
$scope.eventSelectOptions = {
|
||||
'multiple': true,
|
||||
|
|
|
@ -35,12 +35,10 @@ module.factory('RealmListLoader', function(Loader, Realm, $q) {
|
|||
return Loader.get(Realm);
|
||||
});
|
||||
|
||||
module.factory('ServerInfoLoader', function(Loader, ServerInfo, $q) {
|
||||
return Loader.get(ServerInfo);
|
||||
});
|
||||
|
||||
module.factory('ServerInfoPageLoader', function(Loader, ServerInfoPage, $q) {
|
||||
return Loader.get(ServerInfoPage);
|
||||
module.factory('ServerInfoLoader', function(Loader, ServerInfo) {
|
||||
return function() {
|
||||
return ServerInfo.promise;
|
||||
};
|
||||
});
|
||||
|
||||
module.factory('RealmLoader', function(Loader, Realm, $route, $q) {
|
||||
|
|
|
@ -215,12 +215,26 @@ module.factory('RealmLDAPConnectionTester', function($resource) {
|
|||
return $resource(authUrl + '/admin/realms/:realm/testLDAPConnection');
|
||||
});
|
||||
|
||||
module.factory('ServerInfo', function($resource) {
|
||||
return $resource(authUrl + '/admin/serverinfo');
|
||||
});
|
||||
module.service('ServerInfo', function($resource, $q, $http) {
|
||||
var info = {};
|
||||
var delay = $q.defer();
|
||||
|
||||
module.factory('ServerInfoPage', function($resource) {
|
||||
return $resource(authUrl + '/admin/serverinfopage');
|
||||
$http.get(authUrl + '/admin/serverinfo').success(function(data) {
|
||||
info = data;
|
||||
delay.resolve(info);
|
||||
});
|
||||
|
||||
return {
|
||||
get: function() {
|
||||
return info;
|
||||
},
|
||||
reload: function() {
|
||||
$http.get(authUrl + '/admin/serverinfo').success(function(data) {
|
||||
angular.copy(data, info);
|
||||
});
|
||||
},
|
||||
promise: delay.promise
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
<div class="col-sm-9 col-md-10 col-sm-push-3 col-md-push-2">
|
||||
<h1>
|
||||
Server Info
|
||||
<i id="serverInfoReload" class="pficon pficon-restart clickable" data-ng-click="serverInfoReload()"></i>
|
||||
</h1>
|
||||
|
||||
<ul class="nav nav-tabs">
|
||||
<li><a href="#/server-info">Info</a></li>
|
||||
<li class="active"><a href="#/server-info/providers">Providers</a></li>
|
||||
</ul>
|
||||
|
||||
<table class="table table-striped table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="kc-table-actions" colspan="5">
|
||||
<div class="form-inline">
|
||||
<div class="form-group">
|
||||
<div class="input-group">
|
||||
<input type="text" placeholder="Search..." data-ng-model="search" class="form-control search" onkeyup="if(event.keyCode == 13){$(this).next('I').click();}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th width="20%">SPI</th>
|
||||
<th>Providers</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr data-ng-repeat="spi in (providers | orderBy:'name' | filter:search)">
|
||||
<td>{{spi.name}}</td>
|
||||
<td>
|
||||
<div data-ng-repeat="(providerName, provider) in spi.providers">
|
||||
{{providerName}}
|
||||
<span ng-show="provider.operationalInfo">
|
||||
<button type="button" class="btn btn-default btn-xs" ng-click="collapseRep = !collapseRep">
|
||||
<span class="glyphicon glyphicon-plus" data-ng-show="!collapseRep"></span>
|
||||
<span class="glyphicon glyphicon-minus" data-ng-show="collapseRep"></span>
|
||||
</button>
|
||||
<table ng-show="collapseRep" class="table table-striped table-bordered" style="margin-top: 0px;">
|
||||
<tr ng-repeat="(key, value) in provider.operationalInfo">
|
||||
<td width="20%">{{key}}</td>
|
||||
<td>{{value}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<kc-menu></kc-menu>
|
|
@ -1,174 +1,104 @@
|
|||
<div class="col-md-12">
|
||||
<h1>Server Info</h1>
|
||||
<div class="col-sm-9 col-md-10 col-sm-push-3 col-md-push-2">
|
||||
<h1>
|
||||
Server Info
|
||||
<i id="serverInfoReload" class="pficon pficon-restart clickable" data-ng-click="serverInfoReload()"></i>
|
||||
</h1>
|
||||
|
||||
<table class="table table-striped table-bordered">
|
||||
<tr>
|
||||
<td width="20%">Keycloak Version</td>
|
||||
<td>{{serverInfoPage.version}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Server Time</td>
|
||||
<td>{{serverInfoPage.serverTime}} (<a style="cursor: pointer" data-ng-click="serverInfoPageUpdate()">update</a>)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Server Uptime</td>
|
||||
<td>{{serverInfoPage.serverUptime}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="active"><a href="#/server-info">Info</a></li>
|
||||
<li><a href="#/server-info/providers">Providers</a></li>
|
||||
</ul>
|
||||
|
||||
<table class="table table-striped table-bordered">
|
||||
<tr>
|
||||
<td width="20%">Keycloak Version</td>
|
||||
<td>{{serverInfo.systemInfo.version}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Server Time</td>
|
||||
<td>{{serverInfo.systemInfo.serverTime}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Server Uptime</td>
|
||||
<td>{{serverInfo.systemInfo.uptime}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<fieldset>
|
||||
<legend>Java VM Memory Statistics</legend>
|
||||
<div class="form-group">
|
||||
<table class="table table-striped table-bordered" style="margin-top: 0px;">
|
||||
<tr>
|
||||
<td width="20%">Total Memory</td>
|
||||
<td>{{serverInfoPage.memoryInfo.totalFormated}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Free Memory</td>
|
||||
<td>{{serverInfoPage.memoryInfo.freeFormated}} ({{serverInfoPage.memoryInfo.freePercentage}}%)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Used Memory</td>
|
||||
<td>{{serverInfoPage.memoryInfo.usedFormated}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<legend collapsed>System Info</legend>
|
||||
<div class="form-group">
|
||||
<table class="table table-striped table-bordered" style="margin-top: 0px;">
|
||||
<tr>
|
||||
<td width="20%">Current Working Directory</td>
|
||||
<td>{{serverInfoPage.systemInfo.userDir}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Java Version</td>
|
||||
<td>{{serverInfoPage.systemInfo.javaVersion}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Java Vendor</td>
|
||||
<td>{{serverInfoPage.systemInfo.javaVendor}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Java Runtime</td>
|
||||
<td>{{serverInfoPage.systemInfo.javaRuntime}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Java VM</td>
|
||||
<td>{{serverInfoPage.systemInfo.javaVm}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Java VM Version</td>
|
||||
<td>{{serverInfoPage.systemInfo.javaVmVersion}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Java Home</td>
|
||||
<td>{{serverInfoPage.systemInfo.javaHome}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>User Name</td>
|
||||
<td>{{serverInfoPage.systemInfo.userName}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>User Timezone</td>
|
||||
<td>{{serverInfoPage.systemInfo.userTimezone}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>User Locale</td>
|
||||
<td>{{serverInfoPage.systemInfo.userLocale}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>System Encoding</td>
|
||||
<td>{{serverInfoPage.systemInfo.fileEncoding}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Operating System</td>
|
||||
<td>{{serverInfoPage.systemInfo.osName}} {{serverInfoPage.systemInfo.osVersion}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OS Architecture</td>
|
||||
<td>{{serverInfoPage.systemInfo.osArchitecture}}</td>
|
||||
</tr>
|
||||
<legend>Memory</legend>
|
||||
<table class="table table-striped table-bordered" style="margin-top: 0;">
|
||||
<tr>
|
||||
<td width="20%">Total Memory</td>
|
||||
<td>{{serverInfo.memoryInfo.totalFormated}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Free Memory</td>
|
||||
<td>{{serverInfo.memoryInfo.freeFormated}} ({{serverInfo.memoryInfo.freePercentage}}%)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Used Memory</td>
|
||||
<td>{{serverInfo.memoryInfo.usedFormated}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</fieldset>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<legend collapsed>Providers</legend>
|
||||
|
||||
<div class="form-group">
|
||||
<h3>Public SPIs</h3>
|
||||
<kc-tooltip>For public SPIs there are built-in providers, but it's also supported to write your own custom providers.</kc-tooltip>
|
||||
|
||||
<table class="table table-striped table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="20%">SPI</th>
|
||||
<th>Providers</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr data-ng-repeat="spi in (serverInfoPage.providers | filter:{internal:false} | orderBy:'name')">
|
||||
<td>{{spi.name}}</td>
|
||||
<td>
|
||||
<div data-ng-repeat="provider in (spi.implementations | orderBy:'name')">
|
||||
{{provider.name}}
|
||||
<span ng-show="provider.operationalInfo">
|
||||
<button type="button" class="btn btn-default btn-xs" ng-click="collapseRep = !collapseRep">
|
||||
<span class="glyphicon glyphicon-plus" data-ng-show="!collapseRep"></span>
|
||||
<span class="glyphicon glyphicon-minus" data-ng-show="collapseRep"></span>
|
||||
</button>
|
||||
<table ng-show="collapseRep" class="table table-striped table-bordered" style="margin-top: 0px;">
|
||||
<tr ng-repeat="(key, value) in provider.operationalInfo">
|
||||
<td width="20%">{{key}}</td>
|
||||
<td>{{value}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<h3>Internal SPIs</h3>
|
||||
<kc-tooltip>For internal SPIs there are only built-in providers. It's not recommended to write your own custom providers as internal SPIs may change or be removed without notice.</kc-tooltip>
|
||||
|
||||
<table class="table table-striped table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="20%">SPI</th>
|
||||
<th>Providers</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr data-ng-repeat="spi in (serverInfoPage.providers | filter:{internal:true} | orderBy:'name')">
|
||||
<td>{{spi.name}}</td>
|
||||
<td>
|
||||
<div data-ng-repeat="provider in (spi.implementations | orderBy:'name')">
|
||||
{{provider.name}}
|
||||
<span ng-show="provider.operationalInfo">
|
||||
<button type="button" class="btn btn-default btn-xs" ng-click="collapseRep = !collapseRep">
|
||||
<span class="glyphicon glyphicon-plus" data-ng-show="!collapseRep"></span>
|
||||
<span class="glyphicon glyphicon-minus" data-ng-show="collapseRep"></span>
|
||||
</button>
|
||||
<table ng-show="collapseRep" class="table table-striped table-bordered" style="margin-top: 0px;">
|
||||
<tr ng-repeat="(key, value) in provider.operationalInfo">
|
||||
<td width="20%">{{key}}</td>
|
||||
<td>{{value}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<legend>System</legend>
|
||||
<table class="table table-striped table-bordered" style="margin-top: 0;">
|
||||
<tr>
|
||||
<td width="20%">Current Working Directory</td>
|
||||
<td>{{serverInfo.systemInfo.userDir}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Java Version</td>
|
||||
<td>{{serverInfo.systemInfo.javaVersion}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Java Vendor</td>
|
||||
<td>{{serverInfo.systemInfo.javaVendor}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Java Runtime</td>
|
||||
<td>{{serverInfo.systemInfo.javaRuntime}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Java VM</td>
|
||||
<td>{{serverInfo.systemInfo.javaVm}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Java VM Version</td>
|
||||
<td>{{serverInfo.systemInfo.javaVmVersion}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Java Home</td>
|
||||
<td>{{serverInfo.systemInfo.javaHome}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>User Name</td>
|
||||
<td>{{serverInfo.systemInfo.userName}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>User Timezone</td>
|
||||
<td>{{serverInfo.systemInfo.userTimezone}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>User Locale</td>
|
||||
<td>{{serverInfo.systemInfo.userLocale}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>System Encoding</td>
|
||||
<td>{{serverInfo.systemInfo.fileEncoding}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Operating System</td>
|
||||
<td>{{serverInfo.systemInfo.osName}} {{serverInfo.systemInfo.osVersion}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OS Architecture</td>
|
||||
<td>{{serverInfo.systemInfo.osArchitecture}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<kc-menu></kc-menu>
|
|
@ -20,6 +20,7 @@ import org.keycloak.services.managers.AppAuthManager;
|
|||
import org.keycloak.services.managers.AuthenticationManager;
|
||||
import org.keycloak.services.managers.RealmManager;
|
||||
import org.keycloak.services.resources.Cors;
|
||||
import org.keycloak.services.resources.admin.info.ServerInfoAdminResource;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
|
@ -218,32 +219,6 @@ public class AdminRoot {
|
|||
return adminResource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Operational information about the server for "Server Info" page
|
||||
*
|
||||
* @param headers
|
||||
* @return
|
||||
*/
|
||||
@Path("serverinfopage")
|
||||
public ServerInfoPageAdminResource getServerInfoPage(@Context final HttpHeaders headers) {
|
||||
handlePreflightRequest();
|
||||
|
||||
AdminAuth auth = authenticateRealmAdminRequest(headers);
|
||||
if (!isAdmin(auth)) {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
|
||||
if (auth != null) {
|
||||
logger.debug("authenticated admin access for: " + auth.getUser().getUsername());
|
||||
}
|
||||
|
||||
Cors.add(request).allowedOrigins(auth.getToken()).allowedMethods("GET", "PUT", "POST", "DELETE").auth().build(response);
|
||||
|
||||
ServerInfoPageAdminResource adminResource = new ServerInfoPageAdminResource();
|
||||
ResteasyProviderFactory.getInstance().injectProperties(adminResource);
|
||||
return adminResource;
|
||||
}
|
||||
|
||||
protected boolean isAdmin(AdminAuth auth) {
|
||||
|
||||
RealmManager realmManager = new RealmManager(session);
|
||||
|
|
|
@ -1,375 +0,0 @@
|
|||
package org.keycloak.services.resources.admin;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.core.Context;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
import org.keycloak.Version;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.provider.ServerInfoAwareProviderFactory;
|
||||
import org.keycloak.provider.Spi;
|
||||
|
||||
/**
|
||||
* REST endpoint which return info for "Server Info" page.
|
||||
*
|
||||
* @author Vlastimil Elias (velias at redhat dot com)
|
||||
*/
|
||||
public class ServerInfoPageAdminResource {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(ServerInfoPageAdminResource.class);
|
||||
|
||||
@Context
|
||||
private KeycloakSession session;
|
||||
|
||||
/**
|
||||
* Returns a list of providers and other operational info about the page.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GET
|
||||
public ServerInfoRepresentation getInfo() {
|
||||
ServerInfoRepresentation info = new ServerInfoRepresentation();
|
||||
info.version = Version.VERSION;
|
||||
info.serverTime = new Date().toString();
|
||||
info.serverStartupTime = session.getKeycloakSessionFactory().getServerStartupTimestamp();
|
||||
info.memoryInfo = (new MemoryInfo()).init(Runtime.getRuntime());
|
||||
info.systemInfo = (new SystemInfo()).init();
|
||||
setProviders(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
private void setProviders(ServerInfoRepresentation info) {
|
||||
List<SpiInfoRepresentation> providers = new LinkedList<>();
|
||||
for (Spi spi : ServiceLoader.load(Spi.class)) {
|
||||
SpiInfoRepresentation spiRep = new SpiInfoRepresentation();
|
||||
spiRep.setName(spi.getName());
|
||||
spiRep.setInternal(spi.isInternal());
|
||||
spiRep.setSystemInfo(ServerInfoAwareProviderFactory.class.isAssignableFrom(spi.getProviderFactoryClass()));
|
||||
Set<String> s = session.listProviderIds(spi.getProviderClass());
|
||||
Set<SpiImplementationRepresentation> srs = new HashSet<>();
|
||||
|
||||
if(s!=null){
|
||||
for(String name: s){
|
||||
SpiImplementationRepresentation sr = new SpiImplementationRepresentation(name);
|
||||
if(spiRep.isSystemInfo()){
|
||||
sr.setOperationalInfo(((ServerInfoAwareProviderFactory)session.getKeycloakSessionFactory().getProviderFactory(spi.getProviderClass(), name)).getOperationalInfo());
|
||||
}
|
||||
srs.add(sr);
|
||||
}
|
||||
}
|
||||
spiRep.setImplementations(srs);
|
||||
providers.add(spiRep);
|
||||
}
|
||||
info.providers = providers;
|
||||
}
|
||||
|
||||
|
||||
public static class MemoryInfo implements Serializable {
|
||||
|
||||
protected long total;
|
||||
protected long used;
|
||||
|
||||
public MemoryInfo(){
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill object fwith info.
|
||||
* @param runtime used to get memory info from.
|
||||
* @return itself for chaining
|
||||
*/
|
||||
public MemoryInfo init(Runtime runtime){
|
||||
total = runtime.maxMemory();
|
||||
used = runtime.totalMemory() - runtime.freeMemory();
|
||||
return this;
|
||||
}
|
||||
|
||||
public long getTotal(){
|
||||
return total;
|
||||
}
|
||||
|
||||
public String getTotalFormated(){
|
||||
return formatMemory(getTotal());
|
||||
}
|
||||
|
||||
public long getFree(){
|
||||
return getTotal() - getUsed();
|
||||
}
|
||||
|
||||
public String getFreeFormated(){
|
||||
return formatMemory(getFree());
|
||||
}
|
||||
|
||||
public long getUsed(){
|
||||
return used;
|
||||
}
|
||||
|
||||
public String getUsedFormated(){
|
||||
return formatMemory(getUsed());
|
||||
}
|
||||
|
||||
public long getFreePercentage(){
|
||||
return getFree() * 100 / getTotal();
|
||||
}
|
||||
|
||||
private String formatMemory(long bytes){
|
||||
if(bytes > 1024L*1024L){
|
||||
return bytes/(1024L *1024L) + " MB";
|
||||
} else if(bytes > 1024L){
|
||||
return bytes/(1024L) + " kB";
|
||||
} else {
|
||||
return bytes + " B";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class SystemInfo implements Serializable {
|
||||
|
||||
protected String javaVersion;
|
||||
protected String javaVendor;
|
||||
protected String javaVm;
|
||||
protected String javaVmVersion;
|
||||
protected String javaRuntime;
|
||||
protected String javaHome;
|
||||
protected String osName;
|
||||
protected String osArchitecture;
|
||||
protected String osVersion;
|
||||
protected String fileEncoding;
|
||||
protected String userName;
|
||||
protected String userDir;
|
||||
protected String userTimezone;
|
||||
protected String userLocale;
|
||||
|
||||
public SystemInfo() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill object with info about current system loaded from {@link System} properties.
|
||||
* @return object itself for chaining
|
||||
*/
|
||||
protected SystemInfo init(){
|
||||
javaVersion = System.getProperty("java.version");
|
||||
javaVendor = System.getProperty("java.vendor");
|
||||
javaVm = System.getProperty("java.vm.name");
|
||||
javaVmVersion = System.getProperty("java.vm.version");
|
||||
javaRuntime = System.getProperty("java.runtime.name");
|
||||
javaHome = System.getProperty("java.home");
|
||||
osName = System.getProperty("os.name");
|
||||
osArchitecture = System.getProperty("os.arch");
|
||||
osVersion = System.getProperty("os.version");
|
||||
fileEncoding = System.getProperty("file.encoding");
|
||||
userName = System.getProperty("user.name");
|
||||
userDir = System.getProperty("user.dir");
|
||||
userTimezone = System.getProperty("user.timezone");
|
||||
userLocale = (new Locale(System.getProperty("user.country"),System.getProperty("user.language")).toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getJavaVersion(){
|
||||
return javaVersion;
|
||||
}
|
||||
|
||||
public String getJavaVendor(){
|
||||
return javaVendor;
|
||||
}
|
||||
|
||||
public String getJavaVm(){
|
||||
return javaVm;
|
||||
}
|
||||
|
||||
public String getJavaVmVersion(){
|
||||
return javaVmVersion;
|
||||
}
|
||||
|
||||
public String getJavaRuntime(){
|
||||
return javaRuntime;
|
||||
}
|
||||
|
||||
public String getJavaHome(){
|
||||
return javaHome;
|
||||
}
|
||||
|
||||
public String getOsName(){
|
||||
return osName;
|
||||
}
|
||||
|
||||
public String getOsArchitecture(){
|
||||
return osArchitecture;
|
||||
}
|
||||
|
||||
public String getOsVersion(){
|
||||
return osVersion;
|
||||
}
|
||||
|
||||
public String getFileEncoding(){
|
||||
return fileEncoding;
|
||||
}
|
||||
|
||||
public String getUserName(){
|
||||
return userName;
|
||||
}
|
||||
|
||||
public String getUserDir(){
|
||||
return userDir;
|
||||
}
|
||||
|
||||
public String getUserTimezone(){
|
||||
return userTimezone;
|
||||
}
|
||||
|
||||
public String getUserLocale(){
|
||||
return userLocale;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ServerInfoRepresentation implements Serializable {
|
||||
|
||||
private String version;
|
||||
private String serverTime;
|
||||
private long serverStartupTime;
|
||||
|
||||
|
||||
private List<SpiInfoRepresentation> providers;
|
||||
|
||||
private MemoryInfo memoryInfo;
|
||||
private SystemInfo systemInfo;
|
||||
|
||||
public ServerInfoRepresentation() {
|
||||
}
|
||||
|
||||
public SystemInfo getSystemInfo(){
|
||||
return systemInfo;
|
||||
}
|
||||
|
||||
public MemoryInfo getMemoryInfo(){
|
||||
return memoryInfo;
|
||||
}
|
||||
|
||||
public String getServerTime() {
|
||||
return serverTime;
|
||||
}
|
||||
|
||||
public long getServerStartupTime() {
|
||||
return serverStartupTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return server startup time formatted
|
||||
*/
|
||||
public String getServerStartupTimeFormatted() {
|
||||
return (new Date(serverStartupTime)).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return server uptime in millis
|
||||
*/
|
||||
public long getServerUptimeMillis(){
|
||||
return System.currentTimeMillis() - serverStartupTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return server uptime formatted like "0 days, 10 hours, 24 minutes, 55 seconds"
|
||||
*/
|
||||
public String getServerUptime(){
|
||||
long diffInSeconds = getServerUptimeMillis()/1000;
|
||||
long diff[] = new long[] { 0, 0, 0, 0 };
|
||||
/* sec */diff[3] = (diffInSeconds >= 60 ? diffInSeconds % 60 : diffInSeconds);
|
||||
/* min */diff[2] = (diffInSeconds = (diffInSeconds / 60)) >= 60 ? diffInSeconds % 60 : diffInSeconds;
|
||||
/* hours */diff[1] = (diffInSeconds = (diffInSeconds / 60)) >= 24 ? diffInSeconds % 24 : diffInSeconds;
|
||||
/* days */diff[0] = (diffInSeconds = (diffInSeconds / 24));
|
||||
|
||||
return String.format(
|
||||
"%d day%s, %d hour%s, %d minute%s, %d second%s",
|
||||
diff[0],
|
||||
diff[0] != 1 ? "s" : "",
|
||||
diff[1],
|
||||
diff[1] != 1 ? "s" : "",
|
||||
diff[2],
|
||||
diff[2] != 1 ? "s" : "",
|
||||
diff[3],
|
||||
diff[3] != 1 ? "s" : "");
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
|
||||
public List<SpiInfoRepresentation> getProviders() {
|
||||
return providers;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SpiInfoRepresentation implements Serializable {
|
||||
private String name;
|
||||
private boolean internal;
|
||||
private boolean systemInfo;
|
||||
private Set<SpiImplementationRepresentation> implementations;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean isInternal() {
|
||||
return internal;
|
||||
}
|
||||
|
||||
public void setInternal(boolean internal) {
|
||||
this.internal = internal;
|
||||
}
|
||||
|
||||
public Set<SpiImplementationRepresentation> getImplementations() {
|
||||
return implementations;
|
||||
}
|
||||
|
||||
public boolean isSystemInfo() {
|
||||
return systemInfo;
|
||||
}
|
||||
|
||||
public void setSystemInfo(boolean systemInfo) {
|
||||
this.systemInfo = systemInfo;
|
||||
}
|
||||
|
||||
public void setImplementations(Set<SpiImplementationRepresentation> implementations) {
|
||||
this.implementations = implementations;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SpiImplementationRepresentation implements Serializable {
|
||||
|
||||
private String name;
|
||||
private Map<String, String> operationalInfo;
|
||||
|
||||
public SpiImplementationRepresentation(String name) {
|
||||
super();
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Map<String, String> getOperationalInfo() {
|
||||
return operationalInfo;
|
||||
}
|
||||
|
||||
public void setOperationalInfo(Map<String, String> operationalInfo) {
|
||||
this.operationalInfo = operationalInfo;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package org.keycloak.services.resources.admin.info;
|
||||
|
||||
public class MemoryInfoRepresentation {
|
||||
|
||||
protected long total;
|
||||
protected long used;
|
||||
|
||||
public static MemoryInfoRepresentation create() {
|
||||
MemoryInfoRepresentation rep = new MemoryInfoRepresentation();
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
rep.total = runtime.maxMemory();
|
||||
rep.used = runtime.totalMemory() - runtime.freeMemory();
|
||||
return rep;
|
||||
}
|
||||
|
||||
public long getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public String getTotalFormated() {
|
||||
return formatMemory(getTotal());
|
||||
}
|
||||
|
||||
public long getFree() {
|
||||
return getTotal() - getUsed();
|
||||
}
|
||||
|
||||
public String getFreeFormated() {
|
||||
return formatMemory(getFree());
|
||||
}
|
||||
|
||||
public long getUsed() {
|
||||
return used;
|
||||
}
|
||||
|
||||
public String getUsedFormated() {
|
||||
return formatMemory(getUsed());
|
||||
}
|
||||
|
||||
public long getFreePercentage() {
|
||||
return getFree() * 100 / getTotal();
|
||||
}
|
||||
|
||||
private String formatMemory(long bytes) {
|
||||
if (bytes > 1024L * 1024L) {
|
||||
return bytes / (1024L * 1024L) + " MB";
|
||||
} else if (bytes > 1024L) {
|
||||
return bytes / (1024L) + " kB";
|
||||
} else {
|
||||
return bytes + " B";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package org.keycloak.services.resources.admin.info;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ProviderRepresentation {
|
||||
|
||||
private Map<String, String> operationalInfo;
|
||||
|
||||
public Map<String, String> getOperationalInfo() {
|
||||
return operationalInfo;
|
||||
}
|
||||
|
||||
public void setOperationalInfo(Map<String, String> operationalInfo) {
|
||||
this.operationalInfo = operationalInfo;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +1,7 @@
|
|||
package org.keycloak.services.resources.admin;
|
||||
package org.keycloak.services.resources.admin.info;
|
||||
|
||||
import org.keycloak.Version;
|
||||
import org.keycloak.broker.provider.IdentityProvider;
|
||||
import org.keycloak.broker.provider.IdentityProviderFactory;
|
||||
import org.keycloak.events.EventListenerProvider;
|
||||
import org.keycloak.events.EventType;
|
||||
import org.keycloak.events.admin.OperationType;
|
||||
import org.keycloak.exportimport.ClientImporter;
|
||||
|
@ -18,6 +16,7 @@ import org.keycloak.protocol.LoginProtocolFactory;
|
|||
import org.keycloak.protocol.ProtocolMapper;
|
||||
import org.keycloak.provider.ProviderConfigProperty;
|
||||
import org.keycloak.provider.ProviderFactory;
|
||||
import org.keycloak.provider.ServerInfoAwareProviderFactory;
|
||||
import org.keycloak.provider.Spi;
|
||||
import org.keycloak.representations.idm.ConfigPropertyRepresentation;
|
||||
import org.keycloak.representations.idm.ProtocolMapperRepresentation;
|
||||
|
@ -26,14 +25,7 @@ import org.keycloak.social.SocialIdentityProvider;
|
|||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.core.Context;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||
|
@ -53,13 +45,12 @@ public class ServerInfoAdminResource {
|
|||
@GET
|
||||
public ServerInfoRepresentation getInfo() {
|
||||
ServerInfoRepresentation info = new ServerInfoRepresentation();
|
||||
info.version = Version.VERSION;
|
||||
info.serverTime = new Date().toString();
|
||||
info.setSystemInfo(SystemInfoRepresentation.create(session));
|
||||
info.setMemoryInfo(MemoryInfoRepresentation.create());
|
||||
|
||||
setSocialProviders(info);
|
||||
setIdentityProviders(info);
|
||||
setThemes(info);
|
||||
setEventListeners(info);
|
||||
setProtocols(info);
|
||||
setClientImporters(info);
|
||||
setProviders(info);
|
||||
setProtocolMapperTypes(info);
|
||||
|
@ -69,42 +60,55 @@ public class ServerInfoAdminResource {
|
|||
}
|
||||
|
||||
private void setProviders(ServerInfoRepresentation info) {
|
||||
List<SpiInfoRepresentation> providers = new LinkedList<>();
|
||||
Map<String, SpiInfoRepresentation> spis = new HashMap<>();
|
||||
for (Spi spi : ServiceLoader.load(Spi.class)) {
|
||||
SpiInfoRepresentation spiRep = new SpiInfoRepresentation();
|
||||
spiRep.setName(spi.getName());
|
||||
spiRep.setInternal(spi.isInternal());
|
||||
spiRep.setImplementations(session.listProviderIds(spi.getProviderClass()));
|
||||
providers.add(spiRep);
|
||||
spiRep.setSystemInfo(ServerInfoAwareProviderFactory.class.isAssignableFrom(spi.getProviderFactoryClass()));
|
||||
Set<String> providerIds = session.listProviderIds(spi.getProviderClass());
|
||||
Map<String, ProviderRepresentation> providers = new HashMap<>();
|
||||
|
||||
if (providerIds != null) {
|
||||
for (String name : providerIds) {
|
||||
ProviderRepresentation provider = new ProviderRepresentation();
|
||||
if (spiRep.isSystemInfo()) {
|
||||
provider.setOperationalInfo(((ServerInfoAwareProviderFactory) session.getKeycloakSessionFactory().getProviderFactory(spi.getProviderClass(), name)).getOperationalInfo());
|
||||
}
|
||||
providers.put(name, provider);
|
||||
}
|
||||
}
|
||||
spiRep.setProviders(providers);
|
||||
|
||||
spis.put(spi.getName(), spiRep);
|
||||
}
|
||||
info.providers = providers;
|
||||
info.setProviders(spis);
|
||||
}
|
||||
|
||||
private void setThemes(ServerInfoRepresentation info) {
|
||||
ThemeProvider themeProvider = session.getProvider(ThemeProvider.class, "extending");
|
||||
info.themes = new HashMap<String, List<String>>();
|
||||
info.setThemes(new HashMap<String, List<String>>());
|
||||
|
||||
for (Theme.Type type : Theme.Type.values()) {
|
||||
List<String> themes = new LinkedList<String>(themeProvider.nameSet(type));
|
||||
Collections.sort(themes);
|
||||
|
||||
info.themes.put(type.toString().toLowerCase(), themes);
|
||||
info.getThemes().put(type.toString().toLowerCase(), themes);
|
||||
}
|
||||
}
|
||||
|
||||
private void setSocialProviders(ServerInfoRepresentation info) {
|
||||
info.socialProviders = new LinkedList<>();
|
||||
info.setSocialProviders(new LinkedList<Map<String, String>>());
|
||||
List<ProviderFactory> providerFactories = session.getKeycloakSessionFactory().getProviderFactories(SocialIdentityProvider.class);
|
||||
setIdentityProviders(providerFactories, info.socialProviders, "Social");
|
||||
setIdentityProviders(providerFactories, info.getSocialProviders(), "Social");
|
||||
}
|
||||
|
||||
private void setIdentityProviders(ServerInfoRepresentation info) {
|
||||
info.identityProviders = new LinkedList<>();
|
||||
info.setIdentityProviders(new LinkedList<Map<String, String>>());
|
||||
List<ProviderFactory> providerFactories = session.getKeycloakSessionFactory().getProviderFactories(IdentityProvider.class);
|
||||
setIdentityProviders(providerFactories, info.identityProviders, "User-defined");
|
||||
setIdentityProviders(providerFactories, info.getIdentityProviders(), "User-defined");
|
||||
|
||||
providerFactories = session.getKeycloakSessionFactory().getProviderFactories(SocialIdentityProvider.class);
|
||||
setIdentityProviders(providerFactories, info.identityProviders, "Social");
|
||||
setIdentityProviders(providerFactories, info.getIdentityProviders(), "Social");
|
||||
}
|
||||
|
||||
public void setIdentityProviders(List<ProviderFactory> factories, List<Map<String, String>> providers, String groupName) {
|
||||
|
@ -119,31 +123,14 @@ public class ServerInfoAdminResource {
|
|||
}
|
||||
}
|
||||
|
||||
private void setEventListeners(ServerInfoRepresentation info) {
|
||||
info.eventListeners = new LinkedList<String>();
|
||||
|
||||
Set<String> providers = session.listProviderIds(EventListenerProvider.class);
|
||||
if (providers != null) {
|
||||
info.eventListeners.addAll(providers);
|
||||
}
|
||||
}
|
||||
|
||||
private void setProtocols(ServerInfoRepresentation info) {
|
||||
info.protocols = new LinkedList<String>();
|
||||
for (ProviderFactory p : session.getKeycloakSessionFactory().getProviderFactories(LoginProtocol.class)) {
|
||||
info.protocols.add(p.getId());
|
||||
}
|
||||
Collections.sort(info.protocols);
|
||||
}
|
||||
|
||||
private void setProtocolMapperTypes(ServerInfoRepresentation info) {
|
||||
info.protocolMapperTypes = new HashMap<String, List<ProtocolMapperTypeRepresentation>>();
|
||||
info.setProtocolMapperTypes(new HashMap<String, List<ProtocolMapperTypeRepresentation>>());
|
||||
for (ProviderFactory p : session.getKeycloakSessionFactory().getProviderFactories(ProtocolMapper.class)) {
|
||||
ProtocolMapper mapper = (ProtocolMapper)p;
|
||||
List<ProtocolMapperTypeRepresentation> types = info.protocolMapperTypes.get(mapper.getProtocol());
|
||||
List<ProtocolMapperTypeRepresentation> types = info.getProtocolMapperTypes().get(mapper.getProtocol());
|
||||
if (types == null) {
|
||||
types = new LinkedList<ProtocolMapperTypeRepresentation>();
|
||||
info.protocolMapperTypes.put(mapper.getProtocol(), types);
|
||||
info.getProtocolMapperTypes().put(mapper.getProtocol(), types);
|
||||
}
|
||||
ProtocolMapperTypeRepresentation rep = new ProtocolMapperTypeRepresentation();
|
||||
rep.setId(mapper.getId());
|
||||
|
@ -166,136 +153,25 @@ public class ServerInfoAdminResource {
|
|||
}
|
||||
|
||||
private void setBuiltinProtocolMappers(ServerInfoRepresentation info) {
|
||||
info.builtinProtocolMappers = new HashMap<>();
|
||||
info.setBuiltinProtocolMappers(new HashMap<String, List<ProtocolMapperRepresentation>>());
|
||||
for (ProviderFactory p : session.getKeycloakSessionFactory().getProviderFactories(LoginProtocol.class)) {
|
||||
LoginProtocolFactory factory = (LoginProtocolFactory)p;
|
||||
List<ProtocolMapperRepresentation> mappers = new LinkedList<>();
|
||||
for (ProtocolMapperModel mapper : factory.getBuiltinMappers()) {
|
||||
mappers.add(ModelToRepresentation.toRepresentation(mapper));
|
||||
}
|
||||
info.builtinProtocolMappers.put(p.getId(), mappers);
|
||||
info.getBuiltinProtocolMappers().put(p.getId(), mappers);
|
||||
}
|
||||
}
|
||||
|
||||
private void setClientImporters(ServerInfoRepresentation info) {
|
||||
info.clientImporters = new LinkedList<Map<String, String>>();
|
||||
info.setClientImporters(new LinkedList<Map<String, String>>());
|
||||
for (ProviderFactory p : session.getKeycloakSessionFactory().getProviderFactories(ClientImporter.class)) {
|
||||
ClientImporterFactory factory = (ClientImporterFactory)p;
|
||||
Map<String, String> data = new HashMap<String, String>();
|
||||
data.put("id", factory.getId());
|
||||
data.put("name", factory.getDisplayName());
|
||||
info.clientImporters.add(data);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ServerInfoRepresentation {
|
||||
|
||||
private String version;
|
||||
|
||||
private String serverTime;
|
||||
|
||||
private Map<String, List<String>> themes;
|
||||
|
||||
private List<Map<String, String>> socialProviders;
|
||||
public List<Map<String, String>> identityProviders;
|
||||
private List<String> protocols;
|
||||
private List<Map<String, String>> clientImporters;
|
||||
|
||||
private List<SpiInfoRepresentation> providers;
|
||||
|
||||
private List<String> eventListeners;
|
||||
private Map<String, List<ProtocolMapperTypeRepresentation>> protocolMapperTypes;
|
||||
private Map<String, List<ProtocolMapperRepresentation>> builtinProtocolMappers;
|
||||
|
||||
private Map<String, List<String>> enums;
|
||||
|
||||
public ServerInfoRepresentation() {
|
||||
}
|
||||
|
||||
public String getServerTime() {
|
||||
return serverTime;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public Map<String, List<String>> getThemes() {
|
||||
return themes;
|
||||
}
|
||||
|
||||
public List<Map<String, String>> getSocialProviders() {
|
||||
return socialProviders;
|
||||
}
|
||||
|
||||
public List<Map<String, String>> getIdentityProviders() {
|
||||
return this.identityProviders;
|
||||
}
|
||||
|
||||
public List<String> getEventListeners() {
|
||||
return eventListeners;
|
||||
}
|
||||
|
||||
public List<String> getProtocols() {
|
||||
return protocols;
|
||||
}
|
||||
|
||||
public List<Map<String, String>> getClientImporters() {
|
||||
return clientImporters;
|
||||
}
|
||||
|
||||
public List<SpiInfoRepresentation> getProviders() {
|
||||
return providers;
|
||||
}
|
||||
|
||||
public Map<String, List<ProtocolMapperTypeRepresentation>> getProtocolMapperTypes() {
|
||||
return protocolMapperTypes;
|
||||
}
|
||||
|
||||
public Map<String, List<ProtocolMapperRepresentation>> getBuiltinProtocolMappers() {
|
||||
return builtinProtocolMappers;
|
||||
}
|
||||
|
||||
public void setBuiltinProtocolMappers(Map<String, List<ProtocolMapperRepresentation>> builtinProtocolMappers) {
|
||||
this.builtinProtocolMappers = builtinProtocolMappers;
|
||||
}
|
||||
|
||||
public Map<String, List<String>> getEnums() {
|
||||
return enums;
|
||||
}
|
||||
|
||||
public void setEnums(Map<String, List<String>> enums) {
|
||||
this.enums = enums;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SpiInfoRepresentation {
|
||||
private String name;
|
||||
private boolean internal;
|
||||
private Set<String> implementations;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean isInternal() {
|
||||
return internal;
|
||||
}
|
||||
|
||||
public void setInternal(boolean internal) {
|
||||
this.internal = internal;
|
||||
}
|
||||
|
||||
public Set<String> getImplementations() {
|
||||
return implementations;
|
||||
}
|
||||
|
||||
public void setImplementations(Set<String> implementations) {
|
||||
this.implementations = implementations;
|
||||
info.getClientImporters().add(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
package org.keycloak.services.resources.admin.info;
|
||||
|
||||
import org.keycloak.representations.idm.ProtocolMapperRepresentation;
|
||||
import org.keycloak.representations.idm.ProtocolMapperTypeRepresentation;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||
*/
|
||||
public class ServerInfoRepresentation {
|
||||
|
||||
private SystemInfoRepresentation systemInfo;
|
||||
private MemoryInfoRepresentation memoryInfo;
|
||||
|
||||
private Map<String, List<String>> themes;
|
||||
|
||||
private List<Map<String, String>> socialProviders;
|
||||
private List<Map<String, String>> identityProviders;
|
||||
private List<Map<String, String>> clientImporters;
|
||||
|
||||
private Map<String, SpiInfoRepresentation> providers;
|
||||
|
||||
private Map<String, List<ProtocolMapperTypeRepresentation>> protocolMapperTypes;
|
||||
private Map<String, List<ProtocolMapperRepresentation>> builtinProtocolMappers;
|
||||
|
||||
private Map<String, List<String>> enums;
|
||||
|
||||
public SystemInfoRepresentation getSystemInfo() {
|
||||
return systemInfo;
|
||||
}
|
||||
|
||||
public void setSystemInfo(SystemInfoRepresentation systemInfo) {
|
||||
this.systemInfo = systemInfo;
|
||||
}
|
||||
|
||||
public MemoryInfoRepresentation getMemoryInfo() {
|
||||
return memoryInfo;
|
||||
}
|
||||
|
||||
public void setMemoryInfo(MemoryInfoRepresentation memoryInfo) {
|
||||
this.memoryInfo = memoryInfo;
|
||||
}
|
||||
public Map<String, List<String>> getThemes() {
|
||||
return themes;
|
||||
}
|
||||
|
||||
public void setThemes(Map<String, List<String>> themes) {
|
||||
this.themes = themes;
|
||||
}
|
||||
|
||||
public List<Map<String, String>> getSocialProviders() {
|
||||
return socialProviders;
|
||||
}
|
||||
|
||||
public void setSocialProviders(List<Map<String, String>> socialProviders) {
|
||||
this.socialProviders = socialProviders;
|
||||
}
|
||||
|
||||
public List<Map<String, String>> getIdentityProviders() {
|
||||
return identityProviders;
|
||||
}
|
||||
|
||||
public void setIdentityProviders(List<Map<String, String>> identityProviders) {
|
||||
this.identityProviders = identityProviders;
|
||||
}
|
||||
|
||||
public List<Map<String, String>> getClientImporters() {
|
||||
return clientImporters;
|
||||
}
|
||||
|
||||
public void setClientImporters(List<Map<String, String>> clientImporters) {
|
||||
this.clientImporters = clientImporters;
|
||||
}
|
||||
|
||||
public Map<String, SpiInfoRepresentation> getProviders() {
|
||||
return providers;
|
||||
}
|
||||
|
||||
public void setProviders(Map<String, SpiInfoRepresentation> providers) {
|
||||
this.providers = providers;
|
||||
}
|
||||
|
||||
public Map<String, List<ProtocolMapperTypeRepresentation>> getProtocolMapperTypes() {
|
||||
return protocolMapperTypes;
|
||||
}
|
||||
|
||||
public void setProtocolMapperTypes(Map<String, List<ProtocolMapperTypeRepresentation>> protocolMapperTypes) {
|
||||
this.protocolMapperTypes = protocolMapperTypes;
|
||||
}
|
||||
|
||||
public Map<String, List<ProtocolMapperRepresentation>> getBuiltinProtocolMappers() {
|
||||
return builtinProtocolMappers;
|
||||
}
|
||||
|
||||
public void setBuiltinProtocolMappers(Map<String, List<ProtocolMapperRepresentation>> builtinProtocolMappers) {
|
||||
this.builtinProtocolMappers = builtinProtocolMappers;
|
||||
}
|
||||
|
||||
public Map<String, List<String>> getEnums() {
|
||||
return enums;
|
||||
}
|
||||
|
||||
public void setEnums(Map<String, List<String>> enums) {
|
||||
this.enums = enums;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package org.keycloak.services.resources.admin.info;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||
*/
|
||||
public class SpiInfoRepresentation {
|
||||
|
||||
private boolean internal;
|
||||
private boolean systemInfo;
|
||||
|
||||
private Map<String, ProviderRepresentation> providers;
|
||||
|
||||
public boolean isInternal() {
|
||||
return internal;
|
||||
}
|
||||
|
||||
public void setInternal(boolean internal) {
|
||||
this.internal = internal;
|
||||
}
|
||||
|
||||
public boolean isSystemInfo() {
|
||||
return systemInfo;
|
||||
}
|
||||
|
||||
public void setSystemInfo(boolean systemInfo) {
|
||||
this.systemInfo = systemInfo;
|
||||
}
|
||||
|
||||
public Map<String, ProviderRepresentation> getProviders() {
|
||||
return providers;
|
||||
}
|
||||
|
||||
public void setProviders(Map<String, ProviderRepresentation> providers) {
|
||||
this.providers = providers;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,217 @@
|
|||
package org.keycloak.services.resources.admin.info;
|
||||
|
||||
import org.keycloak.Version;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
public class SystemInfoRepresentation {
|
||||
|
||||
private String version;
|
||||
private String serverTime;
|
||||
private String uptime;
|
||||
private long uptimeMillis;
|
||||
private String javaVersion;
|
||||
private String javaVendor;
|
||||
private String javaVm;
|
||||
private String javaVmVersion;
|
||||
private String javaRuntime;
|
||||
private String javaHome;
|
||||
private String osName;
|
||||
private String osArchitecture;
|
||||
private String osVersion;
|
||||
private String fileEncoding;
|
||||
private String userName;
|
||||
private String userDir;
|
||||
private String userTimezone;
|
||||
private String userLocale;
|
||||
|
||||
public static SystemInfoRepresentation create(KeycloakSession session) {
|
||||
SystemInfoRepresentation rep = new SystemInfoRepresentation();
|
||||
rep.version = Version.VERSION;
|
||||
rep.serverTime = new Date().toString();
|
||||
rep.uptimeMillis = System.currentTimeMillis() - session.getKeycloakSessionFactory().getServerStartupTimestamp();
|
||||
rep.uptime = formatUptime(rep.uptimeMillis);
|
||||
rep.javaVersion = System.getProperty("java.version");
|
||||
rep.javaVendor = System.getProperty("java.vendor");
|
||||
rep.javaVm = System.getProperty("java.vm.name");
|
||||
rep.javaVmVersion = System.getProperty("java.vm.version");
|
||||
rep.javaRuntime = System.getProperty("java.runtime.name");
|
||||
rep.javaHome = System.getProperty("java.home");
|
||||
rep.osName = System.getProperty("os.name");
|
||||
rep.osArchitecture = System.getProperty("os.arch");
|
||||
rep.osVersion = System.getProperty("os.version");
|
||||
rep.fileEncoding = System.getProperty("file.encoding");
|
||||
rep.userName = System.getProperty("user.name");
|
||||
rep.userDir = System.getProperty("user.dir");
|
||||
rep.userTimezone = System.getProperty("user.timezone");
|
||||
rep.userLocale = (new Locale(System.getProperty("user.country"), System.getProperty("user.language")).toString());
|
||||
return rep;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getServerTime() {
|
||||
return serverTime;
|
||||
}
|
||||
|
||||
public void setServerTime(String serverTime) {
|
||||
this.serverTime = serverTime;
|
||||
}
|
||||
|
||||
public String getUptime() {
|
||||
return uptime;
|
||||
}
|
||||
|
||||
public void setUptime(String uptime) {
|
||||
this.uptime = uptime;
|
||||
}
|
||||
|
||||
public long getUptimeMillis() {
|
||||
return uptimeMillis;
|
||||
}
|
||||
|
||||
public void setUptimeMillis(long uptimeMillis) {
|
||||
this.uptimeMillis = uptimeMillis;
|
||||
}
|
||||
|
||||
public String getJavaVersion() {
|
||||
return javaVersion;
|
||||
}
|
||||
|
||||
public void setJavaVersion(String javaVersion) {
|
||||
this.javaVersion = javaVersion;
|
||||
}
|
||||
|
||||
public String getJavaVendor() {
|
||||
return javaVendor;
|
||||
}
|
||||
|
||||
public void setJavaVendor(String javaVendor) {
|
||||
this.javaVendor = javaVendor;
|
||||
}
|
||||
|
||||
public String getJavaVm() {
|
||||
return javaVm;
|
||||
}
|
||||
|
||||
public void setJavaVm(String javaVm) {
|
||||
this.javaVm = javaVm;
|
||||
}
|
||||
|
||||
public String getJavaVmVersion() {
|
||||
return javaVmVersion;
|
||||
}
|
||||
|
||||
public void setJavaVmVersion(String javaVmVersion) {
|
||||
this.javaVmVersion = javaVmVersion;
|
||||
}
|
||||
|
||||
public String getJavaRuntime() {
|
||||
return javaRuntime;
|
||||
}
|
||||
|
||||
public void setJavaRuntime(String javaRuntime) {
|
||||
this.javaRuntime = javaRuntime;
|
||||
}
|
||||
|
||||
public String getJavaHome() {
|
||||
return javaHome;
|
||||
}
|
||||
|
||||
public void setJavaHome(String javaHome) {
|
||||
this.javaHome = javaHome;
|
||||
}
|
||||
|
||||
public String getOsName() {
|
||||
return osName;
|
||||
}
|
||||
|
||||
public void setOsName(String osName) {
|
||||
this.osName = osName;
|
||||
}
|
||||
|
||||
public String getOsArchitecture() {
|
||||
return osArchitecture;
|
||||
}
|
||||
|
||||
public void setOsArchitecture(String osArchitecture) {
|
||||
this.osArchitecture = osArchitecture;
|
||||
}
|
||||
|
||||
public String getOsVersion() {
|
||||
return osVersion;
|
||||
}
|
||||
|
||||
public void setOsVersion(String osVersion) {
|
||||
this.osVersion = osVersion;
|
||||
}
|
||||
|
||||
public String getFileEncoding() {
|
||||
return fileEncoding;
|
||||
}
|
||||
|
||||
public void setFileEncoding(String fileEncoding) {
|
||||
this.fileEncoding = fileEncoding;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getUserDir() {
|
||||
return userDir;
|
||||
}
|
||||
|
||||
public void setUserDir(String userDir) {
|
||||
this.userDir = userDir;
|
||||
}
|
||||
|
||||
public String getUserTimezone() {
|
||||
return userTimezone;
|
||||
}
|
||||
|
||||
public void setUserTimezone(String userTimezone) {
|
||||
this.userTimezone = userTimezone;
|
||||
}
|
||||
|
||||
public String getUserLocale() {
|
||||
return userLocale;
|
||||
}
|
||||
|
||||
public void setUserLocale(String userLocale) {
|
||||
this.userLocale = userLocale;
|
||||
}
|
||||
|
||||
private static String formatUptime(long uptime) {
|
||||
long diffInSeconds = uptime / 1000;
|
||||
long diff[] = new long[]{0, 0, 0, 0}; // sec
|
||||
diff[3] = (diffInSeconds >= 60 ? diffInSeconds % 60 : diffInSeconds); // min
|
||||
diff[2] = (diffInSeconds = (diffInSeconds / 60)) >= 60 ? diffInSeconds % 60 : diffInSeconds; // hours
|
||||
diff[1] = (diffInSeconds = (diffInSeconds / 60)) >= 24 ? diffInSeconds % 24 : diffInSeconds; // days
|
||||
diff[0] = (diffInSeconds = (diffInSeconds / 24));
|
||||
|
||||
return String.format(
|
||||
"%d day%s, %d hour%s, %d minute%s, %d second%s",
|
||||
diff[0],
|
||||
diff[0] != 1 ? "s" : "",
|
||||
diff[1],
|
||||
diff[1] != 1 ? "s" : "",
|
||||
diff[2],
|
||||
diff[2] != 1 ? "s" : "",
|
||||
diff[3],
|
||||
diff[3] != 1 ? "s" : "");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue