|
@@ -50,6 +50,12 @@ public class LoginPageGeneratingWebFilter implements WebFilter {
|
|
|
|
|
|
private Map<String, String> oauth2AuthenticationUrlToClientName = new HashMap<>();
|
|
|
|
|
|
+ private boolean formLoginEnabled;
|
|
|
+
|
|
|
+ public void setFormLoginEnabled(boolean enabled) {
|
|
|
+ this.formLoginEnabled = enabled;
|
|
|
+ }
|
|
|
+
|
|
|
public void setOauth2AuthenticationUrlToClientName(
|
|
|
Map<String, String> oauth2AuthenticationUrlToClientName) {
|
|
|
Assert.notNull(oauth2AuthenticationUrlToClientName, "oauth2AuthenticationUrlToClientName cannot be null");
|
|
@@ -87,45 +93,47 @@ public class LoginPageGeneratingWebFilter implements WebFilter {
|
|
|
private byte[] createPage(ServerWebExchange exchange, String csrfTokenHtmlInput) {
|
|
|
MultiValueMap<String, String> queryParams = exchange.getRequest()
|
|
|
.getQueryParams();
|
|
|
- boolean isError = queryParams.containsKey("error");
|
|
|
- boolean isLogoutSuccess = queryParams.containsKey("logout");
|
|
|
String contextPath = exchange.getRequest().getPath().contextPath().value();
|
|
|
- String page = "<!DOCTYPE html>\n"
|
|
|
- + "<html lang=\"en\">\n"
|
|
|
- + " <head>\n"
|
|
|
- + " <meta charset=\"utf-8\">\n"
|
|
|
- + " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">\n"
|
|
|
- + " <meta name=\"description\" content=\"\">\n"
|
|
|
- + " <meta name=\"author\" content=\"\">\n"
|
|
|
- + " <title>Please sign in</title>\n"
|
|
|
- + " <link href=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css\" rel=\"stylesheet\" integrity=\"sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M\" crossorigin=\"anonymous\">\n"
|
|
|
- + " <link href=\"http://getbootstrap.com/docs/4.0/examples/signin/signin.css\" rel=\"stylesheet\" crossorigin=\"anonymous\"/>\n"
|
|
|
- + " </head>\n"
|
|
|
- + " <body>\n"
|
|
|
- + " <div class=\"container\">\n"
|
|
|
- + " <form class=\"form-signin\" method=\"post\" action=\"/login\">\n"
|
|
|
- + " <h2 class=\"form-signin-heading\">Please sign in</h2>\n"
|
|
|
- + createError(isError)
|
|
|
- + createLogoutSuccess(isLogoutSuccess)
|
|
|
- + " <p>\n"
|
|
|
- + " <label for=\"username\" class=\"sr-only\">Username</label>\n"
|
|
|
- + " <input type=\"text\" id=\"username\" name=\"username\" class=\"form-control\" placeholder=\"Username\" required autofocus>\n"
|
|
|
- + " </p>\n"
|
|
|
- + " <p>\n"
|
|
|
- + " <label for=\"password\" class=\"sr-only\">Password</label>\n"
|
|
|
- + " <input type=\"password\" id=\"password\" name=\"password\" class=\"form-control\" placeholder=\"Password\" required>\n"
|
|
|
- + " </p>\n"
|
|
|
- + csrfTokenHtmlInput
|
|
|
- + " <button class=\"btn btn-lg btn-primary btn-block\" type=\"submit\">Sign in</button>\n"
|
|
|
- + " </form>\n"
|
|
|
- + oauth2LoginLinks(contextPath, this.oauth2AuthenticationUrlToClientName)
|
|
|
- + " </div>\n"
|
|
|
- + " </body>\n"
|
|
|
- + "</html>";
|
|
|
+ String page = "<!DOCTYPE html>\n" + "<html lang=\"en\">\n" + " <head>\n"
|
|
|
+ + " <meta charset=\"utf-8\">\n"
|
|
|
+ + " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">\n"
|
|
|
+ + " <meta name=\"description\" content=\"\">\n"
|
|
|
+ + " <meta name=\"author\" content=\"\">\n"
|
|
|
+ + " <title>Please sign in</title>\n"
|
|
|
+ + " <link href=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css\" rel=\"stylesheet\" integrity=\"sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M\" crossorigin=\"anonymous\">\n"
|
|
|
+ + " <link href=\"http://getbootstrap.com/docs/4.0/examples/signin/signin.css\" rel=\"stylesheet\" crossorigin=\"anonymous\"/>\n"
|
|
|
+ + " </head>\n"
|
|
|
+ + " <body>\n"
|
|
|
+ + " <div class=\"container\">\n"
|
|
|
+ + formLogin(queryParams, csrfTokenHtmlInput)
|
|
|
+ + oauth2LoginLinks(contextPath, this.oauth2AuthenticationUrlToClientName)
|
|
|
+ + " </div>\n"
|
|
|
+ + " </body>\n"
|
|
|
+ + "</html>";
|
|
|
|
|
|
return page.getBytes(Charset.defaultCharset());
|
|
|
}
|
|
|
|
|
|
+ private String formLogin(MultiValueMap<String, String> queryParams, String csrfTokenHtmlInput) {
|
|
|
+ if (!this.formLoginEnabled) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ boolean isError = queryParams.containsKey("error");
|
|
|
+ boolean isLogoutSuccess = queryParams.containsKey("logout");
|
|
|
+ return " <form class=\"form-signin\" method=\"post\" action=\"/login\">\n"
|
|
|
+ + " <h2 class=\"form-signin-heading\">Please sign in</h2>\n"
|
|
|
+ + createError(isError) + createLogoutSuccess(isLogoutSuccess)
|
|
|
+ + " <p>\n"
|
|
|
+ + " <label for=\"username\" class=\"sr-only\">Username</label>\n"
|
|
|
+ + " <input type=\"text\" id=\"username\" name=\"username\" class=\"form-control\" placeholder=\"Username\" required autofocus>\n"
|
|
|
+ + " </p>\n" + " <p>\n"
|
|
|
+ + " <label for=\"password\" class=\"sr-only\">Password</label>\n"
|
|
|
+ + " <input type=\"password\" id=\"password\" name=\"password\" class=\"form-control\" placeholder=\"Password\" required>\n"
|
|
|
+ + " </p>\n" + csrfTokenHtmlInput
|
|
|
+ + " <button class=\"btn btn-lg btn-primary btn-block\" type=\"submit\">Sign in</button>\n"
|
|
|
+ + " </form>\n";
|
|
|
+ }
|
|
|
+
|
|
|
private static String oauth2LoginLinks(String contextPath, Map<String, String> oauth2AuthenticationUrlToClientName) {
|
|
|
if (oauth2AuthenticationUrlToClientName.isEmpty()) {
|
|
|
return "";
|