keycloak-aplcache

KEYCLOAK-814 Admin Client Example

11/4/2014 7:32:25 AM

Details

diff --git a/distribution/examples-docs-zip/build.xml b/distribution/examples-docs-zip/build.xml
index a33d88d..16f93f5 100755
--- a/distribution/examples-docs-zip/build.xml
+++ b/distribution/examples-docs-zip/build.xml
@@ -50,6 +50,14 @@
                 <exclude name="**/subsystem-config.xml"/>
             </fileset>
         </copy>
+        <copy todir="target/examples/admin-client" overwrite="true">
+            <fileset dir="../../examples/admin-client">
+                <exclude name="**/target/**"/>
+                <exclude name="**/*.iml"/>
+                <exclude name="**/*.unconfigured"/>
+                <exclude name="**/subsystem-config.xml"/>
+            </fileset>
+        </copy>
         <copy todir="target/examples/themes" overwrite="true">
             <fileset dir="../../examples/themes">
                 <exclude name="**/target/**"/>
diff --git a/examples/admin-client/example-realm.json b/examples/admin-client/example-realm.json
new file mode 100755
index 0000000..2615e56
--- /dev/null
+++ b/examples/admin-client/example-realm.json
@@ -0,0 +1,37 @@
+{
+    "realm": "example",
+    "enabled": true,
+    "sslRequired": "external",
+    "registrationAllowed": true,
+    "passwordCredentialGrantAllowed": true,
+    "privateKey": "MIICXAIBAAKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQABAoGAfmO8gVhyBxdqlxmIuglbz8bcjQbhXJLR2EoS8ngTXmN1bo2L90M0mUKSdc7qF10LgETBzqL8jYlQIbt+e6TH8fcEpKCjUlyq0Mf/vVbfZSNaVycY13nTzo27iPyWQHK5NLuJzn1xvxxrUeXI6A2WFpGEBLbHjwpx5WQG9A+2scECQQDvdn9NE75HPTVPxBqsEd2z10TKkl9CZxu10Qby3iQQmWLEJ9LNmy3acvKrE3gMiYNWb6xHPKiIqOR1as7L24aTAkEAtyvQOlCvr5kAjVqrEKXalj0Tzewjweuxc0pskvArTI2Oo070h65GpoIKLc9jf+UA69cRtquwP93aZKtW06U8dQJAF2Y44ks/mK5+eyDqik3koCI08qaC8HYq2wVl7G2QkJ6sbAaILtcvD92ToOvyGyeE0flvmDZxMYlvaZnaQ0lcSQJBAKZU6umJi3/xeEbkJqMfeLclD27XGEFoPeNrmdx0q10Azp4NfJAY+Z8KRyQCR2BEG+oNitBOZ+YXF9KCpH3cdmECQHEigJhYg+ykOvr1aiZUMFT72HU0jnmQe2FVekuG+LJUt2Tm7GtMjTFoGpf0JwrVuZN39fOYAlo+nTixgeW7X8Y=",
+    "publicKey": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB",
+    "requiredCredentials": [ "password" ],
+    "users": [
+        {
+            "username": "examples-admin-client",
+            "enabled": true,
+            "credentials": [
+                {
+                    "type": "password",
+                    "value": "password"
+                }
+            ],
+            "applicationRoles": {
+                "realm-management": [ "realm-admin" ]
+            }
+        }
+    ],
+    "applications": [
+        {
+            "name": "examples-admin-client",
+            "enabled": true,
+            "fullScopeAllowed": true,
+            "baseUrl": "/examples-admin-client",
+            "redirectUris": [
+                "/examples-admin-client/*"
+            ],
+            "secret": "password"
+        }
+    ]
+}
diff --git a/examples/admin-client/pom.xml b/examples/admin-client/pom.xml
new file mode 100644
index 0000000..256089f
--- /dev/null
+++ b/examples/admin-client/pom.xml
@@ -0,0 +1,33 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <artifactId>keycloak-parent</artifactId>
+        <groupId>org.keycloak</groupId>
+        <version>1.1.0-Alpha1-SNAPSHOT</version>
+        <relativePath>../../pom.xml</relativePath>
+    </parent>
+
+    <name>Keycloak Examples - Admin Client</name>
+    <artifactId>examples-admin-client</artifactId>
+    <packaging>war</packaging>
+
+    <description>
+        Keycloak Admin Client Example
+    </description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.keycloak</groupId>
+            <artifactId>keycloak-admin-client</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <finalName>${project.artifactId}</finalName>
+    </build>
+
+</project>
+
diff --git a/examples/admin-client/src/main/webapp/index.jsp b/examples/admin-client/src/main/webapp/index.jsp
new file mode 100644
index 0000000..13b6eee
--- /dev/null
+++ b/examples/admin-client/src/main/webapp/index.jsp
@@ -0,0 +1,33 @@
+<%@ page import="org.keycloak.admin.client.Keycloak" %>
+<%@ page import="org.keycloak.admin.client.resource.ApplicationsResource" %>
+<%@ page import="org.keycloak.representations.idm.ApplicationRepresentation" %>
+<%@ page import="org.keycloak.util.UriUtils" %>
+<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
+<%@ page session="false" %>
+<html>
+<head>
+    <title>Applications</title>
+</head>
+<body>
+<%
+    String authServer = UriUtils.getOrigin(request.getRequestURL().toString()) + "/auth";
+
+    Keycloak keycloak = Keycloak.getInstance(authServer, "example", "examples-admin-client", "password", "examples-admin-client", "password");
+    ApplicationsResource applications = keycloak.realm("example").applications();
+
+    out.println("<h1>Applications</h1>");
+    out.println("<ul>");
+    for (ApplicationRepresentation app : applications.findAll()) {
+        out.println("\t<li>");
+        if (app.getBaseUrl() != null) {
+            out.println("\t\t<a href=\"" + app.getBaseUrl() + "\">" + app.getName() + "</a>");
+        } else {
+            out.println("\t\t" + app.getName());
+        }
+        out.println("</li>");
+    }
+    out.println("</ul>");
+%>
+<br><br>
+</body>
+</html>
diff --git a/examples/admin-client/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/examples/admin-client/src/main/webapp/WEB-INF/jboss-deployment-structure.xml
new file mode 100755
index 0000000..1ef0bb4
--- /dev/null
+++ b/examples/admin-client/src/main/webapp/WEB-INF/jboss-deployment-structure.xml
@@ -0,0 +1,10 @@
+<jboss-deployment-structure>
+    <deployment>
+        <dependencies>
+            <module name="org.jboss.resteasy.resteasy-jackson-provider" services="import"/>
+        </dependencies>
+        <exclusions>
+            <module name="org.jboss.resteasy.resteasy-jackson2-provider"/>
+        </exclusions>
+    </deployment>
+</jboss-deployment-structure>
\ No newline at end of file
diff --git a/examples/admin-client/src/main/webapp/WEB-INF/web.xml b/examples/admin-client/src/main/webapp/WEB-INF/web.xml
new file mode 100755
index 0000000..c8dab29
--- /dev/null
+++ b/examples/admin-client/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+         version="3.0">
+
+    <module-name>examples-admin-client</module-name>
+
+</web-app>

examples/pom.xml 1(+1 -0)

diff --git a/examples/pom.xml b/examples/pom.xml
index 7ec8a31..67f53e8 100755
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -25,6 +25,7 @@
         </plugins>
     </build>
     <modules>
+        <module>admin-client</module>
         <module>cors</module>
         <module>demo-template</module>
         <module>providers</module>
diff --git a/integration/admin-client/pom.xml b/integration/admin-client/pom.xml
index 7419d8f..4f65c7c 100755
--- a/integration/admin-client/pom.xml
+++ b/integration/admin-client/pom.xml
@@ -23,31 +23,37 @@
         <dependency>
             <groupId>org.codehaus.jackson</groupId>
             <artifactId>jackson-mapper-asl</artifactId>
+            <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.httpcomponents</groupId>
             <artifactId>httpclient</artifactId>
             <version>${keycloak.apache.httpcomponents.version}</version>
+            <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>org.jboss.resteasy</groupId>
             <artifactId>jaxrs-api</artifactId>
             <version>${resteasy.version.latest}</version>
+            <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>org.jboss.resteasy</groupId>
             <artifactId>resteasy-jaxrs</artifactId>
             <version>${resteasy.version.latest}</version>
+            <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>org.jboss.resteasy</groupId>
             <artifactId>resteasy-client</artifactId>
             <version>${resteasy.version.latest}</version>
+            <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>org.jboss.resteasy</groupId>
             <artifactId>resteasy-jackson-provider</artifactId>
             <version>${resteasy.version.latest}</version>
+            <scope>provided</scope>
         </dependency>
     </dependencies>