forked from keycloak/keycloak
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
filter examples, subsystem dependencies
- Loading branch information
1 parent
84bc19f
commit ec9b987
Showing
41 changed files
with
755 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...les/demo-template/admin-access-app/src/main/webapp/WEB-INF/jboss-deployment-structure.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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/maven-v4_0_0.xsd"> | ||
<parent> | ||
<artifactId>keycloak-examples-demo-parent</artifactId> | ||
<groupId>org.keycloak</groupId> | ||
<version>1.9.0.CR1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.keycloak.example.demo</groupId> | ||
<artifactId>customer-portal-filter-example</artifactId> | ||
<packaging>war</packaging> | ||
<name>Customer Portal - Secured via Servlet Filter</name> | ||
<description/> | ||
|
||
<repositories> | ||
<repository> | ||
<id>jboss</id> | ||
<name>jboss repo</name> | ||
<url>http://repository.jboss.org/nexus/content/groups/public/</url> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jboss.spec.javax.servlet</groupId> | ||
<artifactId>jboss-servlet-api_3.0_spec</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.keycloak</groupId> | ||
<artifactId>keycloak-servlet-filter-adapter</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<finalName>customer-portal-filter</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.jboss.as.plugins</groupId> | ||
<artifactId>jboss-as-maven-plugin</artifactId> | ||
<configuration> | ||
<skip>false</skip> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.wildfly.plugins</groupId> | ||
<artifactId>wildfly-maven-plugin</artifactId> | ||
<configuration> | ||
<skip>false</skip> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
81 changes: 81 additions & 0 deletions
81
...mplate/customer-app-filter/src/main/java/org/keycloak/example/CustomerDatabaseClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.keycloak.example; | ||
|
||
import org.apache.http.HttpEntity; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.impl.client.DefaultHttpClient; | ||
import org.keycloak.KeycloakSecurityContext; | ||
import org.keycloak.adapters.AdapterUtils; | ||
import org.keycloak.representations.IDToken; | ||
import org.keycloak.util.JsonSerialization; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpSession; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> | ||
* @version $Revision: 1 $ | ||
*/ | ||
public class CustomerDatabaseClient { | ||
|
||
static class TypedList extends ArrayList<String> { | ||
} | ||
|
||
public static class Failure extends Exception { | ||
private int status; | ||
|
||
public Failure(int status) { | ||
this.status = status; | ||
} | ||
|
||
public int getStatus() { | ||
return status; | ||
} | ||
} | ||
|
||
public static IDToken getIDToken(HttpServletRequest req) { | ||
KeycloakSecurityContext session = (KeycloakSecurityContext) req.getAttribute(KeycloakSecurityContext.class.getName()); | ||
return session.getIdToken(); | ||
|
||
} | ||
|
||
public static List<String> getCustomers(HttpServletRequest req) throws Failure { | ||
KeycloakSecurityContext session = (KeycloakSecurityContext) req.getAttribute(KeycloakSecurityContext.class.getName()); | ||
|
||
HttpClient client = new DefaultHttpClient(); | ||
try { | ||
HttpGet get = new HttpGet(AdapterUtils.getOriginForRestCalls(req.getRequestURL().toString(), session) + "/database/customers"); | ||
get.addHeader("Authorization", "Bearer " + session.getTokenString()); | ||
try { | ||
HttpResponse response = client.execute(get); | ||
if (response.getStatusLine().getStatusCode() != 200) { | ||
throw new Failure(response.getStatusLine().getStatusCode()); | ||
} | ||
HttpEntity entity = response.getEntity(); | ||
InputStream is = entity.getContent(); | ||
try { | ||
return JsonSerialization.readValue(is, TypedList.class); | ||
} finally { | ||
is.close(); | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} finally { | ||
client.getConnectionManager().shutdown(); | ||
} | ||
} | ||
|
||
public static String increaseAndGetCounter(HttpServletRequest req) { | ||
HttpSession session = req.getSession(); | ||
Integer counter = (Integer)session.getAttribute("counter"); | ||
counter = (counter == null) ? 1 : counter + 1; | ||
session.setAttribute("counter", counter); | ||
return String.valueOf(counter); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
examples/demo-template/customer-app-filter/src/main/webapp/WEB-INF/keycloak.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"realm": "demo", | ||
"resource": "customer-portal-filter", | ||
"realm-public-key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB", | ||
"auth-server-url": "/auth", | ||
"ssl-required" : "external", | ||
"expose-token": true, | ||
"credentials": { | ||
"secret": "password" | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
examples/demo-template/customer-app-filter/src/main/webapp/WEB-INF/web.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?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>customer-portal-filter</module-name> | ||
|
||
<filter> | ||
<filter-name>Keycloak Filter</filter-name> | ||
<filter-class>org.keycloak.adapters.servlet.KeycloakOIDCFilter</filter-class> | ||
</filter> | ||
<filter-mapping> | ||
<filter-name>Keycloak Filter</filter-name> | ||
<url-pattern>/customers/*</url-pattern> | ||
</filter-mapping> | ||
|
||
</web-app> |
8 changes: 8 additions & 0 deletions
8
examples/demo-template/customer-app-filter/src/main/webapp/WEB-INF/web.xml.unconfigured
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?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>customer-portal-filter</module-name> | ||
</web-app> |
Oops, something went wrong.