commit
53ac88ca26
8 changed files with 119 additions and 1 deletions
10
core/pom.xml
10
core/pom.xml
|
@ -13,6 +13,10 @@
|
||||||
<name>Keycloak Core</name>
|
<name>Keycloak Core</name>
|
||||||
<description/>
|
<description/>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<timestamp>${maven.build.timestamp}</timestamp>
|
||||||
|
<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
|
||||||
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bouncycastle</groupId>
|
<groupId>org.bouncycastle</groupId>
|
||||||
|
@ -41,6 +45,12 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
|
44
core/src/main/java/org/keycloak/Version.java
Executable file
44
core/src/main/java/org/keycloak/Version.java
Executable file
|
@ -0,0 +1,44 @@
|
||||||
|
package org.keycloak;
|
||||||
|
|
||||||
|
import org.codehaus.jackson.annotate.JsonProperty;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||||
|
* @version $Revision: 1 $
|
||||||
|
*/
|
||||||
|
public class Version {
|
||||||
|
public static String VERSION;
|
||||||
|
public static String BUILD_TIME;
|
||||||
|
public static final String UNKNOWN = "UNKNOWN";
|
||||||
|
public static final Version SINGLETON = new Version();
|
||||||
|
|
||||||
|
private final String version = VERSION;
|
||||||
|
private final String buildTime = BUILD_TIME;
|
||||||
|
|
||||||
|
static {
|
||||||
|
Properties props = new Properties();
|
||||||
|
InputStream is = Version.class.getResourceAsStream("/keycloak-version.properties");
|
||||||
|
try {
|
||||||
|
props.load(is);
|
||||||
|
VERSION = props.getProperty("version");
|
||||||
|
BUILD_TIME = props.getProperty("build-time");
|
||||||
|
} catch (IOException e) {
|
||||||
|
VERSION=UNKNOWN;
|
||||||
|
BUILD_TIME=UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("version")
|
||||||
|
public String getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("build-time")
|
||||||
|
public String getBuildTime() {
|
||||||
|
return buildTime;
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ public interface AdapterConstants {
|
||||||
|
|
||||||
// URL endpoints
|
// URL endpoints
|
||||||
public static final String K_LOGOUT = "k_logout";
|
public static final String K_LOGOUT = "k_logout";
|
||||||
|
public static final String K_VERSION = "k_version";
|
||||||
public static final String K_PUSH_NOT_BEFORE = "k_push_not_before";
|
public static final String K_PUSH_NOT_BEFORE = "k_push_not_before";
|
||||||
public static final String K_GET_USER_STATS = "k_get_user_stats";
|
public static final String K_GET_USER_STATS = "k_get_user_stats";
|
||||||
public static final String K_GET_SESSION_STATS = "k_get_session_stats";
|
public static final String K_GET_SESSION_STATS = "k_get_session_stats";
|
||||||
|
|
2
core/src/main/resources/keycloak-version.properties
Executable file
2
core/src/main/resources/keycloak-version.properties
Executable file
|
@ -0,0 +1,2 @@
|
||||||
|
version=${project.version}
|
||||||
|
build-time=${timestamp}
|
|
@ -1,6 +1,7 @@
|
||||||
package org.keycloak.adapters;
|
package org.keycloak.adapters;
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
import org.keycloak.Version;
|
||||||
import org.keycloak.jose.jws.JWSInput;
|
import org.keycloak.jose.jws.JWSInput;
|
||||||
import org.keycloak.jose.jws.crypto.RSAProvider;
|
import org.keycloak.jose.jws.crypto.RSAProvider;
|
||||||
import org.keycloak.representations.adapters.action.AdminAction;
|
import org.keycloak.representations.adapters.action.AdminAction;
|
||||||
|
@ -63,10 +64,13 @@ public class PreAuthActionsHandler {
|
||||||
if (!resolveDeployment()) return true;
|
if (!resolveDeployment()) return true;
|
||||||
handleGetSessionStats();
|
handleGetSessionStats();
|
||||||
return true;
|
return true;
|
||||||
}else if (requestUri.endsWith(AdapterConstants.K_GET_USER_STATS)) {
|
} else if (requestUri.endsWith(AdapterConstants.K_GET_USER_STATS)) {
|
||||||
if (!resolveDeployment()) return true;
|
if (!resolveDeployment()) return true;
|
||||||
handleGetUserStats();
|
handleGetUserStats();
|
||||||
return true;
|
return true;
|
||||||
|
} else if (requestUri.endsWith(AdapterConstants.K_VERSION)) {
|
||||||
|
handleVersion();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -240,6 +244,15 @@ public class PreAuthActionsHandler {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
protected void handleVersion() {
|
||||||
|
try {
|
||||||
|
facade.getResponse().setStatus(200);
|
||||||
|
facade.getResponse().setHeader("Content-Type", "application/json");
|
||||||
|
JsonSerialization.writeValueToStream(facade.getResponse().getOutputStream(), Version.SINGLETON);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected UserStats getUserStats(String user) {
|
protected UserStats getUserStats(String user) {
|
||||||
UserStats stats = new UserStats();
|
UserStats stats = new UserStats();
|
||||||
|
|
|
@ -70,6 +70,7 @@ public class KeycloakApplication extends Application {
|
||||||
|
|
||||||
TokenManager tokenManager = new TokenManager();
|
TokenManager tokenManager = new TokenManager();
|
||||||
|
|
||||||
|
singletons.add(new ServerVersionResource());
|
||||||
singletons.add(new RealmsResource(tokenManager));
|
singletons.add(new RealmsResource(tokenManager));
|
||||||
singletons.add(new SocialResource(tokenManager));
|
singletons.add(new SocialResource(tokenManager));
|
||||||
singletons.add(new AdminRoot(tokenManager));
|
singletons.add(new AdminRoot(tokenManager));
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package org.keycloak.services.resources;
|
||||||
|
|
||||||
|
import org.keycloak.Version;
|
||||||
|
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||||
|
* @version $Revision: 1 $
|
||||||
|
*/
|
||||||
|
@Path("/version")
|
||||||
|
public class ServerVersionResource {
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Version getVersion() {
|
||||||
|
return Version.SINGLETON;
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,6 +21,8 @@
|
||||||
*/
|
*/
|
||||||
package org.keycloak.testsuite.adapter;
|
package org.keycloak.testsuite.adapter;
|
||||||
|
|
||||||
|
import org.keycloak.Version;
|
||||||
|
import org.keycloak.adapters.AdapterConstants;
|
||||||
import org.keycloak.util.BasicAuthHelper;
|
import org.keycloak.util.BasicAuthHelper;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.ClassRule;
|
import org.junit.ClassRule;
|
||||||
|
@ -367,6 +369,29 @@ public class AdapterTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testVersion() throws Exception {
|
||||||
|
Client client = ClientBuilder.newClient();
|
||||||
|
WebTarget target = client.target(org.keycloak.testsuite.Constants.AUTH_SERVER_ROOT).path("version");
|
||||||
|
Version version = target.request().get(Version.class);
|
||||||
|
Assert.assertNotNull(version);
|
||||||
|
Assert.assertNotNull(version.getVersion());
|
||||||
|
Assert.assertNotNull(version.getBuildTime());
|
||||||
|
Assert.assertNotEquals(version.getVersion(), Version.UNKNOWN);
|
||||||
|
Assert.assertNotEquals(version.getBuildTime(), Version.UNKNOWN);
|
||||||
|
|
||||||
|
Version version2 = client.target("http://localhost:8081/secure-portal").path(AdapterConstants.K_VERSION).request().get(Version.class);
|
||||||
|
Assert.assertNotNull(version2);
|
||||||
|
Assert.assertNotNull(version2.getVersion());
|
||||||
|
Assert.assertNotNull(version2.getBuildTime());
|
||||||
|
Assert.assertEquals(version.getVersion(), version2.getVersion());
|
||||||
|
Assert.assertEquals(version.getBuildTime(), version2.getBuildTime());
|
||||||
|
client.close();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAuthenticated() throws Exception {
|
public void testAuthenticated() throws Exception {
|
||||||
// test login to customer-portal which does a bearer request to customer-db
|
// test login to customer-portal which does a bearer request to customer-db
|
||||||
|
|
Loading…
Reference in a new issue