KEYCLOAK-974 ServerVersionResource doesn't handle cors requests
This commit is contained in:
parent
a5b348dfba
commit
e4a8ced8b0
3 changed files with 42 additions and 0 deletions
|
@ -81,6 +81,16 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr />
|
<hr />
|
||||||
|
<div>
|
||||||
|
<h2><span>Server version</span></h2>
|
||||||
|
<button type="submit" data-ng-click="loadVersion()">Load version</button>
|
||||||
|
|
||||||
|
<div data-ng-show="version">
|
||||||
|
Keycloak version: {{version.version}} <br/>
|
||||||
|
Keycloak build time: {{version['build-time'] | date:'yyyy-MM-dd HH:mm:ss'}} <br/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<hr />
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -32,6 +32,9 @@ angular.element(document).ready(function ($http) {
|
||||||
module.controller('GlobalCtrl', function($scope, $http) {
|
module.controller('GlobalCtrl', function($scope, $http) {
|
||||||
$scope.products = [];
|
$scope.products = [];
|
||||||
$scope.roles = [];
|
$scope.roles = [];
|
||||||
|
$scope.serverInfo = [];
|
||||||
|
$scope.realm = [];
|
||||||
|
$scope.version = [];
|
||||||
$scope.reloadData = function() {
|
$scope.reloadData = function() {
|
||||||
$http.get("http://localhost-db:8080/cors-database/products").success(function(data) {
|
$http.get("http://localhost-db:8080/cors-database/products").success(function(data) {
|
||||||
$scope.products = angular.fromJson(data);
|
$scope.products = angular.fromJson(data);
|
||||||
|
@ -72,6 +75,12 @@ module.controller('GlobalCtrl', function($scope, $http) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.loadVersion = function() {
|
||||||
|
$http.get("http://localhost-auth:8080/auth/version").success(function(data) {
|
||||||
|
$scope.version = angular.fromJson(data);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
$scope.logout = logout;
|
$scope.logout = logout;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,19 @@
|
||||||
package org.keycloak.services.resources;
|
package org.keycloak.services.resources;
|
||||||
|
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
import org.jboss.resteasy.annotations.cache.NoCache;
|
import org.jboss.resteasy.annotations.cache.NoCache;
|
||||||
|
import org.jboss.resteasy.spi.HttpRequest;
|
||||||
|
import org.jboss.resteasy.spi.HttpResponse;
|
||||||
import org.keycloak.Version;
|
import org.keycloak.Version;
|
||||||
|
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.OPTIONS;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.Context;
|
||||||
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||||
|
@ -15,10 +22,26 @@ import javax.ws.rs.core.MediaType;
|
||||||
@Path("/version")
|
@Path("/version")
|
||||||
public class ServerVersionResource {
|
public class ServerVersionResource {
|
||||||
|
|
||||||
|
protected static final Logger logger = Logger.getLogger(ServerVersionResource.class);
|
||||||
|
|
||||||
|
@Context
|
||||||
|
protected HttpRequest request;
|
||||||
|
|
||||||
|
@Context
|
||||||
|
protected HttpResponse response;
|
||||||
|
|
||||||
|
@OPTIONS
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Response getVersionPreflight() {
|
||||||
|
logger.debugv("cors request from: {0}", request.getHttpHeaders().getRequestHeaders().getFirst("Origin"));
|
||||||
|
return Cors.add(request, Response.ok()).allowedMethods("GET").auth().preflight().build();
|
||||||
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@NoCache
|
@NoCache
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public Version getVersion() {
|
public Version getVersion() {
|
||||||
|
Cors.add(request).allowedOrigins("*").allowedMethods("GET").auth().build(response);
|
||||||
return Version.SINGLETON;
|
return Version.SINGLETON;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue