Skip to content

Commit

Permalink
feat: add login x509 info page (#52)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Lukin <anthony@lukin.dev>
  • Loading branch information
dorianim and lukin committed Oct 22, 2023
1 parent a7d7a66 commit b1c4767
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Keywind is a component-based Keycloak Login Theme built with [Tailwind CSS](http
- Login Update Password
- Login Update Profile
- Login Username
- Login X.509 Info
- Logout Confirm
- Register
- Select Authenticator
Expand Down
65 changes: 65 additions & 0 deletions html/login/login-x509-info.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<html lang="en">
<head>
<title>Sign in to </title>
<meta charset="utf-8">
<meta name="robots" content="noindex, nofollow">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="../../theme/keywind/login/resources/dist/index.css" rel="stylesheet">
<script defer src="../../theme/keywind/login/resources/dist/index.js" type="module"></script>
</head>
<body class="bg-secondary-100 flex flex-col items-center justify-center min-h-screen sm:py-16">
<div class="max-w-md space-y-6 w-full">
<div class="bg-white p-8 rounded-lg space-y-6">
<div class="space-y-4">
<div class="font-bold text-center text-2xl">
Keywind
</div>
<h1 class="text-center text-xl">Sign In</h1>
</div>
<div class="space-y-4">
<div class="bg-red-100 text-red-600 p-4 rounded-lg text-sm" role="alert">
Example of an error message
</div>
<div>
<div>
X509 client certificate:
</div>
<div class="text-secondary-600">
CN=User, C=US, O=Keywind
</div>
</div>
<div>
<span>You will be logged in as:</span> <b>Username</b>
</div>
<form class="m-0 space-y-4" method="post" action="loginAction">
<div class="flex flex-col pt-4 space-y-2">
<button class="bg-primary-600 text-white focus:ring-primary-600 hover:bg-primary-700 px-4 py-2 text-sm flex justify-center relative rounded-lg w-full focus:outline-none focus:ring-2 focus:ring-offset-2" name="login" type="submit"> Continue </button> <button class="bg-secondary-100 text-secondary-600 focus:ring-secondary-600 hover:bg-secondary-200 hover:text-secondary-900 px-4 py-2 text-sm flex justify-center relative rounded-lg w-full focus:outline-none focus:ring-2 focus:ring-offset-2" name="cancel" type="submit"> Ignore </button>
</div>
</form>
<form action="loginAction" method="post">
<input name="tryAnotherWay" type="hidden" value="on"> <button class="bg-secondary-100 text-secondary-600 focus:ring-secondary-600 hover:bg-secondary-200 hover:text-secondary-900 px-4 py-2 text-sm flex justify-center relative rounded-lg w-full focus:outline-none focus:ring-2 focus:ring-offset-2" type="submit"> Try Another Way </button>
</form>
</div>
</div>
<div class="flex justify-around">
<div class="relative" x-data="{ open: false }">
<button class="text-secondary-600 hover:text-secondary-900 inline-flex" @click="open = true" type="button">
<div class="flex items-center">
<span class="mr-1 text-sm">English</span>
<svg class="h-5 w-5" fill="currentColor" viewbox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
<path clip-rule="evenodd" d="M5.23017 7.20938C5.52875 6.92228 6.00353 6.93159 6.29063 7.23017L10 11.1679L13.7094 7.23017C13.9965 6.93159 14.4713 6.92228 14.7698 7.20938C15.0684 7.49647 15.0777 7.97125 14.7906 8.26983L10.5406 12.7698C10.3992 12.9169 10.204 13 10 13C9.79599 13 9.60078 12.9169 9.45938 12.7698L5.20938 8.26983C4.92228 7.97125 4.93159 7.49647 5.23017 7.20938Z" fill-rule="evenodd" />
</svg>
</div></button>
<div @click.away="open = false" class="absolute bg-white bottom-0 -left-4 max-h-80 mb-6 overflow-y-scroll rounded-lg shadow-lg" x-cloak x-show="open">
<div class="px-4 py-2">
<a class="text-secondary-600 hover:text-secondary-900 text-sm inline-flex" href="url"> Deutsch </a>
</div>
<div class="px-4 py-2">
<a class="text-secondary-600 hover:text-secondary-900 text-sm inline-flex" href="url"> Français </a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
13 changes: 13 additions & 0 deletions src/test/java/org/keywind/theme/LoginDataModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static Map<String, Object> createDataModel() {
dataModel.put("url", createUrlModel());
dataModel.put("user", createUserModel());
dataModel.put("username", "Username");
dataModel.put("x509", createX509Model());
dataModel.putAll(createWebAuthnModel());

return dataModel;
Expand Down Expand Up @@ -249,4 +250,16 @@ private static Map<String, Object> createWebAuthnModel() {

return webAuthn;
}

private static Map<String, Object> createX509Model() {
Map<String, Object> formData = new HashMap<>();
formData.put("isUserEnabled", "true");
formData.put("subjectDN", "CN=User, C=US, O=Keywind");
formData.put("username", "Username");

Map<String, Object> x509 = new HashMap<>();
x509.put("formData", formData);

return x509;
}
}
40 changes: 40 additions & 0 deletions theme/keywind/login/login-x509-info.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<#import "template.ftl" as layout>
<#import "components/atoms/button.ftl" as button>
<#import "components/atoms/button-group.ftl" as buttonGroup>
<#import "components/atoms/form.ftl" as form>
<#import "components/atoms/link.ftl" as link>

<@layout.registrationLayout; section>
<#if section = "header">
${msg("doLogIn")}
<#elseif section = "form">
<div>
<div>${msg("clientCertificate")}</div>
<div class="text-secondary-600">
<#if x509.formData.subjectDN??>
${(x509.formData.subjectDN!"")}
<#else>
${msg("noCertificate")}
</#if>
</div>
</div>
<#if x509.formData.isUserEnabled??>
<div>
<span>${msg("doX509Login")}</span>
<b>${(x509.formData.username!'')}</b>
</div>
</#if>
<@form.kw action=url.loginAction method="post">
<@buttonGroup.kw>
<@button.kw color="primary" name="login" type="submit">
${msg("doContinue")}
</@button.kw>
<#if x509.formData.isUserEnabled??>
<@button.kw color="secondary" name="cancel" type="submit">
${msg("doIgnore")}
</@button.kw>
</#if>
</@buttonGroup.kw>
</@form.kw>
</#if>
</@layout.registrationLayout>

0 comments on commit b1c4767

Please sign in to comment.