Skip to content

Commit

Permalink
Complete extension development
Browse files Browse the repository at this point in the history
  • Loading branch information
cevheri committed Sep 10, 2021
1 parent 6a87046 commit 195ddeb
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 27 deletions.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Keycloak Extension - Custom Event Listener

"User create" and "register" events, listen and Call Rest API with Java

### Generate JAR:
```shell
mvn clean package
```

### Attach keycloak dockerVolume
```yaml
volumes:
- ../../../target/custom-event-listener.jar://opt/jboss/keycloak/standalone/deployments/custom-event-listener.jar
```
### Run on Docker:
```shell
docker-compose -f src/main/docker/docker-compose.yml up -d
```

### Test :
#### First
![](files/event-configuration.png)


#### Then
![](files/create-new-user.png)

### Test Result on MockAPI:
#### Setup Mock API
![](files/mockapi-view-api.png)

#### View api result
![](files/mockapi-view-user.png)

### Stop Docker:
```shell
docker-compose -f src/main/docker/docker-compose.yml down
```
Binary file added files/create-new-user.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added files/event-configuration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added files/mockapi-view-api.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added files/mockapi-view-user.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 0 additions & 5 deletions src/main/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,3 @@ services:
POSTGRES_PASSWORD: password
ports:
- 5432:5432

# mailhog:
# image: mailhog/mailhog
# ports:
# - 8025:8025
30 changes: 8 additions & 22 deletions src/main/java/com/cevher/keycloak/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

public class Client {


public static void postService(String data) {
System.out.println("Hi, its Client class");
try {

URL url = new URL("https://613933731fcce10017e78a68.mockapi.io/api/v1/users");
Expand All @@ -21,36 +19,24 @@ public static void postService(String data) {
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json; utf-8");

String input = data;

OutputStream os = conn.getOutputStream();
os.write(input.getBytes());
os.write(data.getBytes());
os.flush();

if (conn.getResponseCode() != HttpURLConnection.HTTP_CREATED) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}

BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));

String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
}

// just development
// BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
// String output;
// System.out.println("Output from Server .... \n");
// while ((output = br.readLine()) != null) {
// System.out.println(output);
// }
conn.disconnect();

} catch (MalformedURLException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}
Expand Down

0 comments on commit 195ddeb

Please sign in to comment.