-
Notifications
You must be signed in to change notification settings - Fork 6
NFC-47 NFC support for web-eid example #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: web-eid-mobile
Are you sure you want to change the base?
Conversation
102c405
to
5108d00
Compare
1da9ec5
to
d3edcb7
Compare
b519373
to
81dea4d
Compare
323499f
to
b18fa03
Compare
81dea4d
to
44ebf84
Compare
44ebf84
to
123e619
Compare
example/src/main/java/eu/webeid/example/security/WebEidAjaxLoginProcessingFilter.java
Outdated
Show resolved
Hide resolved
example/src/main/java/eu/webeid/example/security/WebEidAjaxLoginProcessingFilter.java
Outdated
Show resolved
Hide resolved
example/src/main/java/eu/webeid/example/security/WebEidAjaxLoginProcessingFilter.java
Outdated
Show resolved
Hide resolved
example/src/main/java/eu/webeid/example/security/WebEidAjaxLoginProcessingFilter.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Sander Kondratjev <[email protected]>
123e619
to
379d320
Compare
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me now apart from the suggested changes, thanks for your great work!
As discussed, also consider making mobile code configurable both to make it easier to discern and possibly serve a real business need not to use it in certain circumstances.
import java.io.IOException; | ||
|
||
public final class WebEidLoginPageGeneratingFilter extends OncePerRequestFilter { | ||
private static final String LOGIN_PAGE_HTML = """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, let's use Thymeleaf to avoid the somewhat fragile String.format()
and keep HTML out of Java files. The HTML should be moved to resources/templates/webeid-login.html
.
public WebEidLoginPageGeneratingFilter(String path, String loginProcessingPath) { | ||
this.requestMatcher = PathPatternRequestMatcher.withDefaults().matcher(HttpMethod.GET, path); | ||
this.loginProcessingPath = loginProcessingPath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For Thymeleaf support:
public WebEidLoginPageGeneratingFilter(String path, String loginProcessingPath) { | |
this.requestMatcher = PathPatternRequestMatcher.withDefaults().matcher(HttpMethod.GET, path); | |
this.loginProcessingPath = loginProcessingPath; | |
public WebEidLoginPageGeneratingFilter(String path, String loginProcessingPath, ITemplateEngine templateEngine, JakartaServletWebApplication webApp) { | |
this.requestMatcher = PathPatternRequestMatcher.withDefaults().matcher(HttpMethod.GET, path); | |
this.loginProcessingPath = loginProcessingPath; | |
this.templateEngine = templateEngine; | |
this.webApp = webApp; |
And add fields above:
private final ITemplateEngine templateEngine;
private final JakartaServletWebApplication webApp;
private String generateHtml(CsrfToken csrf) { | ||
return String.format( | ||
LOGIN_PAGE_HTML, | ||
loginProcessingPath, | ||
csrf != null ? csrf.getHeaderName() : "X-CSRF-TOKEN", | ||
csrf != null ? csrf.getToken() : "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private String generateHtml(CsrfToken csrf) { | |
return String.format( | |
LOGIN_PAGE_HTML, | |
loginProcessingPath, | |
csrf != null ? csrf.getHeaderName() : "X-CSRF-TOKEN", | |
csrf != null ? csrf.getToken() : "" | |
private String renderTemplate(HttpServletRequest request, HttpServletResponse response, CsrfToken csrf) { | |
IWebExchange exchange = webApp.buildExchange(request, response); | |
var locale = RequestContextUtils.getLocale(request); | |
var ctx = new WebContext(exchange, locale); | |
ctx.setVariable("loginProcessingPath", loginProcessingPath); | |
ctx.setVariable("csrfHeaderName", csrf != null ? csrf.getHeaderName() : "X-CSRF-TOKEN"); | |
ctx.setVariable("csrfToken", csrf != null ? csrf.getToken() : ""); | |
return templateEngine.process("webeid-login", ctx); |
and add import org.springframework.web.servlet.support.RequestContextUtils
.
String html = generateHtml(csrf); | ||
|
||
response.setContentType(MediaType.TEXT_HTML_VALUE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String html = generateHtml(csrf); | |
response.setContentType(MediaType.TEXT_HTML_VALUE); | |
String html = renderTemplate(request, response, csrf); | |
response.setCharacterEncoding(StandardCharsets.UTF_8.name()); | |
response.setContentType(MediaType.TEXT_HTML_VALUE); |
Signed-off-by: Sander Kondratjev [email protected]