-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
and UI improvements for login page Signed-off-by: Kai Helbig <[email protected]>
- Loading branch information
Showing
9 changed files
with
287 additions
and
54 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
69 changes: 69 additions & 0 deletions
69
mock/src/main/java/com/tngtech/keycloakmock/impl/handler/DocumentationRoute.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,69 @@ | ||
package com.tngtech.keycloakmock.impl.handler; | ||
|
||
import dagger.Lazy; | ||
import io.vertx.core.Handler; | ||
import io.vertx.core.http.HttpHeaders; | ||
import io.vertx.core.http.HttpMethod; | ||
import io.vertx.core.json.JsonObject; | ||
import io.vertx.ext.web.Route; | ||
import io.vertx.ext.web.Router; | ||
import io.vertx.ext.web.RoutingContext; | ||
import io.vertx.ext.web.common.template.TemplateEngine; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
import javax.annotation.Nonnull; | ||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@Singleton | ||
public class DocumentationRoute implements Handler<RoutingContext> { | ||
private static final Logger LOG = LoggerFactory.getLogger(DocumentationRoute.class); | ||
|
||
@Nonnull private final Lazy<Router> lazyRouter; | ||
@Nonnull private final TemplateEngine engine; | ||
|
||
@Inject | ||
public DocumentationRoute(@Nonnull Lazy<Router> lazyRouter, @Nonnull TemplateEngine engine) { | ||
this.lazyRouter = lazyRouter; | ||
this.engine = engine; | ||
} | ||
|
||
@Override | ||
public void handle(RoutingContext routingContext) { | ||
List<Route> descriptions = | ||
lazyRouter.get().getRoutes().stream() | ||
// annoyingly, if a path is set but the name is null, the path is returned instead | ||
.filter(r -> r.getName() != null && !Objects.equals(r.getName(), r.getPath())) | ||
.sorted(Comparator.comparing(Route::getPath)) | ||
.collect(Collectors.toList()); | ||
if ("application/json".equals(routingContext.getAcceptableContentType())) { | ||
JsonObject result = new JsonObject(); | ||
descriptions.forEach( | ||
r -> { | ||
JsonObject routeDescription = new JsonObject(); | ||
routeDescription.put( | ||
"methods", | ||
r.methods().stream().map(HttpMethod::name).sorted().collect(Collectors.toList())); | ||
routeDescription.put("description", r.getName()); | ||
result.put(r.getPath(), routeDescription); | ||
}); | ||
routingContext.response().putHeader("content-type", "application/json").end(result.encode()); | ||
} else { | ||
routingContext.put("descriptions", descriptions); | ||
engine | ||
.render(routingContext.data(), "documentation.ftl") | ||
.onSuccess( | ||
b -> | ||
routingContext.response().putHeader(HttpHeaders.CONTENT_TYPE, "text/html").end(b)) | ||
.onFailure( | ||
t -> { | ||
LOG.error("Unable to render documentation page", t); | ||
routingContext.fail(t); | ||
}); | ||
} | ||
} | ||
} |
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,27 @@ | ||
<!DOCTYPE html> | ||
<html lang="de"> | ||
<head> | ||
<meta charset="utf-8"/> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> | ||
<title>Documentation</title> | ||
<link rel="stylesheet" href="/style.css"> | ||
</head> | ||
<body> | ||
<h1>Keycloak Mock API</h1> | ||
<p>These are the endpoints that are currently supported by Keycloak Mock.</p> | ||
<table> | ||
<tr> | ||
<th>Methods</th> | ||
<th>Path</th> | ||
<th>Description</th> | ||
</tr> | ||
<#list descriptions as description> | ||
<tr> | ||
<td>${description.methods()?join(", ")}</td> | ||
<td>${description.getPath()}</td> | ||
<td>${description.getName()}</td> | ||
</tr> | ||
</#list> | ||
</table> | ||
</body> | ||
</html> |
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 |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
<meta charset="utf-8"/> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> | ||
<title>Login</title> | ||
<link rel="stylesheet" href="/style.css"> | ||
<style>body { text-align: center; }</style> | ||
</head> | ||
<body> | ||
<h1>Keycloak Mock</h1> | ||
|
@@ -12,14 +14,12 @@ | |
<form action="${authentication_uri}" id="authenticate" method="post"> | ||
<p> | ||
<label for="username">User</label> | ||
<br> | ||
<input type="text" name="username" id="username"> | ||
<input type="text" name="username" id="username" placeholder="[email protected]" required> | ||
</p> | ||
|
||
<p> | ||
<label for="password">Roles</label> | ||
<br> | ||
<input type="text" name="password" id="password"> | ||
<input type="text" name="password" id="password" placeholder="role1,role2,..."> | ||
</p> | ||
|
||
<button type="submit">Login</button> | ||
|
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,72 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
margin: 1em; | ||
background-color: #f0f0f0; | ||
} | ||
|
||
h1 { | ||
color: #00698f; | ||
} | ||
|
||
form { | ||
width: 20em; | ||
margin: 1em auto; | ||
padding: 1em; | ||
background-color: #fff; | ||
border: 0.1em solid #ddd; | ||
border-radius: 1em; | ||
box-shadow: 0 0 1em rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
label { | ||
display: block; | ||
margin-bottom: 0.5em; | ||
} | ||
|
||
input[type="text"] { | ||
width: calc(100% - 2em); | ||
height: 2.5em; | ||
margin-bottom: 1em; | ||
padding: 0 0.5em; | ||
border: 0.1em solid #ccc; | ||
border-radius: 0.25em; | ||
} | ||
|
||
button[type="submit"] { | ||
width: 100%; | ||
height: 2.5em; | ||
background-color: #00698f; | ||
color: #fff; | ||
padding: 0.5em; | ||
border: none; | ||
border-radius: 0.25em; | ||
cursor: pointer; | ||
} | ||
|
||
button[type="submit"]:hover { | ||
background-color: #004d6f; | ||
} | ||
|
||
table { | ||
border-collapse: collapse; | ||
width: 100%; | ||
margin-top: 1em; | ||
} | ||
|
||
th, td { | ||
border: 0.1em solid #ddd; | ||
padding: 0.5em; | ||
text-align: left; | ||
} | ||
|
||
th { | ||
background-color: #f2f2f2; | ||
} | ||
|
||
tr:nth-child(even) { | ||
background-color: #fff; | ||
} | ||
|
||
tr:hover { | ||
background-color: #ddd; | ||
} |
Oops, something went wrong.