-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
58cbe20
commit 8aea2ee
Showing
11 changed files
with
269 additions
and
7 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
File renamed without changes
16 changes: 16 additions & 0 deletions
16
docs/admin/developer/agama/basic/io.jans.flow.sample.basic
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,16 @@ | ||
Flow io.jans.flow.sample.basic | ||
Basepath "samples/basic" | ||
|
||
asrv = Call io.jans.as.server.service.AuthenticationService#class | ||
asrv = Call io.jans.service.cdi.util.CdiUtil#bean asrv | ||
obj = {} | ||
|
||
Repeat 3 times max | ||
creds = RRF "login.ftlh" obj | ||
obj.success = Call asrv authenticate creds.username creds.password | ||
obj.uid = creds.username | ||
|
||
When obj.success is true | ||
Finish obj.uid | ||
|
||
Finish false |
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,59 @@ | ||
<!doctype html> | ||
<html xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="icon" href="${webCtx.contextPath}/servlet/favicon" type="image/x-icon"> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" | ||
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous"> | ||
<style> | ||
#logo { | ||
max-height: 3.25rem; | ||
margin: 0.5rem; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
|
||
<div class="d-flex flex-column align-items-center justify-content-between min-vh-100 w-100"> | ||
<header class="d-flex w-100 justify-content-between border-bottom"> | ||
<img id="logo" src="https://gluu.org/wp-content/uploads/2021/02/janssen-project-transparent-630px-182px-300x86.png" /> | ||
</header> | ||
|
||
<div class="row col-sm-10 col-md-5 mb-5 pb-5"> | ||
|
||
<div class="border border-1 rounded mb-5 p-5"> | ||
<p class="fs-4 mb-5">Welcome</p> | ||
|
||
<#if !(success!true)> | ||
<p class="fs-6 text-danger mb-3">${msgs["login.errorMessage"]}</p> | ||
</#if> | ||
|
||
<form method="post" enctype="application/x-www-form-urlencoded"> | ||
<div class="mb-3 row"> | ||
<label for="username" class="col-md-3 col-form-label">${msgs["login.username"]}</label> | ||
<div class="col-md-9"> | ||
<input type="text" class="form-control" name="username" id="username" value="${uid!}" required> | ||
</div> | ||
</div> | ||
<div class="mb-4 row"> | ||
<label for="password" class="col-md-3 col-form-label">${msgs["login.password"]}</label> | ||
<div class="col-md-9"> | ||
<input type="password" class="form-control" id="password" name="password"> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col-md-12 d-flex justify-content-end"> | ||
<input type="submit" class="btn btn-success px-4" value="${msgs["login.login"]}"> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
|
||
</div> | ||
<footer class="d-flex flex-column align-items-center w-100 pb-2"> | ||
<hr class="w-75"> | ||
</footer> | ||
</div> | ||
|
||
</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
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,34 @@ | ||
package io.jans.agama.samples; | ||
|
||
import io.jans.as.common.service.common.UserService; | ||
import io.jans.service.cdi.util.CdiUtil; | ||
import io.jans.service.MailService; | ||
|
||
import java.security.SecureRandom; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
public class EmailOTPUtil { | ||
|
||
private static final int OTP_LENGTH = 6; | ||
private static final String SUBJECT = "Your passcode to get access"; | ||
private static final String BODY_TEMPLATE = "Hi, the code to complete your authentication is %s"; | ||
private static final SecureRandom RAND = new SecureRandom(); | ||
|
||
public static String send(String to) { | ||
|
||
IntStream digits = RAND.ints(OTP_LENGTH, 0, 10); | ||
String otp = digits.mapToObj(i -> "" + i).collect(Collectors.joining()); | ||
|
||
String body = String.format(BODY_TEMPLATE, otp); | ||
MailService mailService = CdiUtil.bean(MailService.class); | ||
return mailService.sendMail(to, SUBJECT, body) ? otp : null; | ||
|
||
} | ||
|
||
public static String emailOf(String username) { | ||
UserService userService = CdiUtil.bean(UserService.class); | ||
return userService.getUser(username).getAttribute("mail"); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
docs/admin/developer/agama/otp-email/io.jans.flow.sample.otp.email
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,38 @@ | ||
Flow io.jans.flow.sample.otp.email | ||
Basepath "samples/otp-email" | ||
|
||
//Launch usr/pwd authentication | ||
obj = Trigger io.jans.flow.sample.basic | ||
When obj.success is false | ||
Finish obj | ||
|
||
userId = obj.data.userId | ||
email = Call io.jans.agama.samples.EmailOTPUtil#emailOf userId | ||
|
||
When email is null //stop if no e-mail was found | ||
obj = { success: false, error: "Unable to proceed. No e-mail registered for this account" } | ||
Finish obj | ||
|
||
sendMail = true | ||
obj = {} | ||
Repeat 3 times max | ||
|
||
When sendMail is true | ||
sendMail = false | ||
otpCode = Call io.jans.agama.samples.EmailOTPUtil#send email | ||
|
||
When otpCode is null | ||
obj = { success: false, error: "Unable to deliver e-mail message" } | ||
Finish obj | ||
|
||
obj = RRF "otp.ftlh" obj | ||
|
||
When obj.resend is "" //user clicked on "resend code" | ||
sendMail = true | ||
Otherwise | ||
When obj.passcode is otpCode | ||
Finish userId | ||
obj.matches = false //wrong code entered | ||
|
||
obj = { success: false, error: "You have exceeded the number of attempts allowed" } | ||
Finish obj |
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,60 @@ | ||
<!doctype html> | ||
<html xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="icon" href="${webCtx.contextPath}/servlet/favicon" type="image/x-icon"> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" | ||
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous"> | ||
<style> | ||
#logo { | ||
max-height: 3.25rem; | ||
margin: 0.5rem; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
|
||
<div class="d-flex flex-column align-items-center justify-content-between min-vh-100 w-100"> | ||
<header class="d-flex w-100 justify-content-between border-bottom"> | ||
<img id="logo" src="https://gluu.org/wp-content/uploads/2021/02/janssen-project-transparent-630px-182px-300x86.png" /> | ||
</header> | ||
|
||
<div class="row col-sm-10 col-md-5 mb-5 pb-5"> | ||
|
||
<div class="border border-1 rounded mb-5 p-5"> | ||
<p class="fs-4 mb-5">Check your e-mail</p> | ||
|
||
<#if !(matches!true)> | ||
<p class="fs-6 text-danger mb-3">Wrong code entered</p> | ||
</#if> | ||
|
||
<form method="post" enctype="application/x-www-form-urlencoded"> | ||
<div class="mb-1 row"> | ||
<label for="passcode" class="col-md-5 col-form-label">Enter the passcode code sent</label> | ||
<div class="col-md-7"> | ||
<input type="text" class="form-control" id="passcode" name="passcode"> | ||
<#-- Pressing the enter key on this field triggers submission via the FIRST submit button found in the page --> | ||
</div> | ||
</div> | ||
<div class="mb-4 row"> | ||
<div class="col-md-12 d-flex justify-content-end"> | ||
<input type="submit" class="btn btn-success px-4" value="Continue"> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="d-flex justify-content-center"> | ||
Didn't get a message? | ||
<button type="submit" class="btn btn-link p-0 ps-1" id="resend" name="resend" value="">resend code</button> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
|
||
</div> | ||
<footer class="d-flex flex-column align-items-center w-100 pb-2"> | ||
<hr class="w-75"> | ||
</footer> | ||
</div> | ||
|
||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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