Repository: nifi Updated Branches: refs/heads/NIFI-655 ed27ed044 -> 7799deeaa
NIFI-655: - Starting to style the login page. - Added simple 'login' support by identifying username/password. Issuing JWT token coming... - Added logout support - Rendering the username when appropriate. Project: http://git-wip-us.apache.org/repos/asf/nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/7799deea Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/7799deea Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/7799deea Branch: refs/heads/NIFI-655 Commit: 7799deeaa1543d3ba0a6b70cdc0611c968d38b90 Parents: ed27ed0 Author: Matt Gilman <matt.c.gil...@gmail.com> Authored: Tue Nov 3 17:08:37 2015 -0500 Committer: Matt Gilman <matt.c.gil...@gmail.com> Committed: Tue Nov 3 17:08:37 2015 -0500 ---------------------------------------------------------------------- .../service/action/AuthorizeUserAction.java | 4 +- .../form/LoginAuthenticationFilter.java | 2 +- .../nifi/web/security/jwt/JwtService.java | 18 +- .../src/main/webapp/WEB-INF/pages/login.jsp | 14 +- .../WEB-INF/partials/canvas/canvas-header.jsp | 4 +- .../WEB-INF/partials/login/login-form.jsp | 19 +- .../WEB-INF/partials/login/login-message.jsp | 1 + .../WEB-INF/partials/login/login-submission.jsp | 2 +- .../partials/login/nifi-registration-form.jsp | 19 +- .../partials/login/user-registration-form.jsp | 14 ++ .../nifi-web-ui/src/main/webapp/css/canvas.css | 1 - .../nifi-web-ui/src/main/webapp/css/header.css | 1 + .../nifi-web-ui/src/main/webapp/css/login.css | 64 +++++- .../nifi-web-ui/src/main/webapp/css/main.css | 2 +- .../webapp/js/nf/canvas/nf-canvas-header.js | 10 +- .../src/main/webapp/js/nf/canvas/nf-canvas.js | 5 +- .../src/main/webapp/js/nf/login/nf-login.js | 222 +++++++++++-------- 17 files changed, 271 insertions(+), 131 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/nifi/blob/7799deea/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/main/java/org/apache/nifi/admin/service/action/AuthorizeUserAction.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/main/java/org/apache/nifi/admin/service/action/AuthorizeUserAction.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/main/java/org/apache/nifi/admin/service/action/AuthorizeUserAction.java index fe32772..f83dc4d 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/main/java/org/apache/nifi/admin/service/action/AuthorizeUserAction.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-administration/src/main/java/org/apache/nifi/admin/service/action/AuthorizeUserAction.java @@ -165,9 +165,9 @@ public class AuthorizeUserAction extends AbstractUserAction<NiFiUser> { */ private void checkAccountStatus(NiFiUser user) { if (AccountStatus.DISABLED.equals(user.getStatus())) { - throw new AccountDisabledException(String.format("Account for %s is disabled.", user.getDn())); + throw new AccountDisabledException(String.format("The account for %s has been disabled.", user.getDn())); } else if (AccountStatus.PENDING.equals(user.getStatus())) { - throw new AccountPendingException(String.format("Account for %s is pending.", user.getDn())); + throw new AccountPendingException(String.format("The account for %s is currently pending approval.", user.getDn())); } } } http://git-wip-us.apache.org/repos/asf/nifi/blob/7799deea/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-security/src/main/java/org/apache/nifi/web/security/form/LoginAuthenticationFilter.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-security/src/main/java/org/apache/nifi/web/security/form/LoginAuthenticationFilter.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-security/src/main/java/org/apache/nifi/web/security/form/LoginAuthenticationFilter.java index fcff545..c2ceb49 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-security/src/main/java/org/apache/nifi/web/security/form/LoginAuthenticationFilter.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-security/src/main/java/org/apache/nifi/web/security/form/LoginAuthenticationFilter.java @@ -155,7 +155,7 @@ public class LoginAuthenticationFilter extends AbstractAuthenticationProcessingF jwtService.addToken(response, authentication); // mark as successful - response.setStatus(HttpServletResponse.SC_OK); + response.setStatus(HttpServletResponse.SC_CREATED); response.setContentType("text/plain"); response.setContentLength(0); } http://git-wip-us.apache.org/repos/asf/nifi/blob/7799deea/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-security/src/main/java/org/apache/nifi/web/security/jwt/JwtService.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-security/src/main/java/org/apache/nifi/web/security/jwt/JwtService.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-security/src/main/java/org/apache/nifi/web/security/jwt/JwtService.java index cfe7073..1ff67df 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-security/src/main/java/org/apache/nifi/web/security/jwt/JwtService.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-security/src/main/java/org/apache/nifi/web/security/jwt/JwtService.java @@ -18,13 +18,16 @@ package org.apache.nifi.web.security.jwt; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.commons.lang3.StringUtils; import org.springframework.security.core.Authentication; /** * */ public class JwtService { - + + private final static String AUTHORIZATION = "Authorization"; + /** * Gets the Authentication by extracting a JWT token from the specified request. * @@ -32,10 +35,12 @@ public class JwtService { * @return The user identifier from the token */ public String getAuthentication(final HttpServletRequest request) { + // TODO : actually extract/verify token + // extract/verify token from incoming request - // load user details with identifier from token - // create authentication using user details - return null; + final String authorization = request.getHeader(AUTHORIZATION); + final String username = StringUtils.substringAfterLast(authorization, " "); + return username; } /** @@ -45,7 +50,12 @@ public class JwtService { * @param authentication The authentication to generate a token for */ public void addToken(final HttpServletResponse response, final Authentication authentication) { + // TODO : actually create real token + // create a token the specified authentication + String token = authentication.getName(); + // add the token as a response header + response.setHeader(AUTHORIZATION, "Bearer " + token); } } http://git-wip-us.apache.org/repos/asf/nifi/blob/7799deea/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/pages/login.jsp ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/pages/login.jsp b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/pages/login.jsp index 58bdaad..2c52032 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/pages/login.jsp +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/pages/login.jsp @@ -34,11 +34,13 @@ <script type="text/javascript" src="js/nf/nf-namespace.js?${project.version}"></script> ${nf.login.script.tags} </head> - <body> - <jsp:include page="/WEB-INF/partials/login/login-message.jsp"/> - <jsp:include page="/WEB-INF/partials/login/login-form.jsp"/> - <jsp:include page="/WEB-INF/partials/login/user-registration-form.jsp"/> - <jsp:include page="/WEB-INF/partials/login/nifi-registration-form.jsp"/> - <jsp:include page="/WEB-INF/partials/login/login-submission.jsp"/> + <body class="login-body"> + <div id="login-contents-container"> + <jsp:include page="/WEB-INF/partials/login/login-message.jsp"/> + <jsp:include page="/WEB-INF/partials/login/login-form.jsp"/> + <jsp:include page="/WEB-INF/partials/login/user-registration-form.jsp"/> + <jsp:include page="/WEB-INF/partials/login/nifi-registration-form.jsp"/> + <jsp:include page="/WEB-INF/partials/login/login-submission.jsp"/> + </div> </body> </html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi/blob/7799deea/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/canvas/canvas-header.jsp ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/canvas/canvas-header.jsp b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/canvas/canvas-header.jsp index 43e306e..81296d2 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/canvas/canvas-header.jsp +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/canvas/canvas-header.jsp @@ -44,8 +44,10 @@ </div> <div id="header-links-container"> <ul> + <li id="current-user-container"> + <span id="current-user"></span> + </li> <li id="login-link-container"> - <span id="current-user" class="hidden"></span> <span id="login-link" class="link">login</span> </li> <li id="logout-link-container" style="display: none;"> http://git-wip-us.apache.org/repos/asf/nifi/blob/7799deea/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/login/login-form.jsp ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/login/login-form.jsp b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/login/login-form.jsp index 2ee0a17..f8f06f3 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/login/login-form.jsp +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/login/login-form.jsp @@ -16,10 +16,17 @@ --%> <%@ page contentType="text/html" pageEncoding="UTF-8" session="false" %> <div id="login-container" class="hidden"> - <legend>Please Login</legend> - <label for="username">Username</label> - <input type="text" id="username" name="username" value="${username}"/> - <br> - <label for="password">Password</label> - <input type="password" id="password" name="password"/> + <div class="login-title">Log In</div> + <div class="setting"> + <div class="setting-name">Username</div> + <div class="setting-field"> + <input type="text" id="username"/> + </div> + </div> + <div class="setting"> + <div class="setting-name">Password</div> + <div class="setting-field"> + <input type="password" id="password"/> + </div> + </div> </div> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi/blob/7799deea/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/login/login-message.jsp ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/login/login-message.jsp b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/login/login-message.jsp index 5284c23..053af81 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/login/login-message.jsp +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/login/login-message.jsp @@ -16,5 +16,6 @@ --%> <%@ page contentType="text/html" pageEncoding="UTF-8" session="false" %> <div id="login-message-container" class="hidden"> + <div id="login-message-title"></div> <div id="login-message"></div> </div> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi/blob/7799deea/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/login/login-submission.jsp ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/login/login-submission.jsp b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/login/login-submission.jsp index 5749ab9..65c6077 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/login/login-submission.jsp +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/login/login-submission.jsp @@ -16,5 +16,5 @@ --%> <%@ page contentType="text/html" pageEncoding="UTF-8" session="false" %> <div id="login-submission-container" class="hidden"> - <button id="login-submission-button" type="submit" class="btn">Log in</button> + <div id="login-submission-button" class="button">Log in</div> </div> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi/blob/7799deea/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/login/nifi-registration-form.jsp ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/login/nifi-registration-form.jsp b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/login/nifi-registration-form.jsp index 3d5f864..afa7687 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/login/nifi-registration-form.jsp +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/login/nifi-registration-form.jsp @@ -16,16 +16,15 @@ --%> <%@ page contentType="text/html" pageEncoding="UTF-8" session="false" %> <div id="nifi-registration-container" class="hidden"> - <div id="nifi-registration-form" class="settings"> - <div class="setting"> - <div class="setting-name">Justification</div> - <div class="setting-field"> - <textarea cols="30" rows="4" id="nifi-registration-justification" maxlength="500" class="setting-input"></textarea> - </div> - <div style="text-align: right; color: #666; margin-top: 2px;"> - <span id="remaining-characters"></span> characters remaining - </div> - <div class="clear"></div> + <div id="nifi-registration-title" class="login-title">Submit Justification</div> + <div class="setting"> + <div class="setting-name">Justification</div> + <div class="setting-field"> + <textarea cols="30" rows="4" id="nifi-registration-justification" maxlength="500" class="setting-input"></textarea> </div> + <div style="text-align: right; color: #666; margin-top: 2px;"> + <span id="remaining-characters"></span> characters remaining + </div> + <div class="clear"></div> </div> </div> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi/blob/7799deea/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/login/user-registration-form.jsp ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/login/user-registration-form.jsp b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/login/user-registration-form.jsp index 92382b3..89517e4 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/login/user-registration-form.jsp +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/WEB-INF/partials/login/user-registration-form.jsp @@ -16,4 +16,18 @@ --%> <%@ page contentType="text/html" pageEncoding="UTF-8" session="false" %> <div id="user-registration-container" class="hidden"> + <div class="login-title">Log In</div> + <div class="setting"> + <div class="setting-name">Username</div> + <div class="setting-field"> + <input type="text" id="username"/> + </div> + </div> + <div class="setting"> + <div class="setting-name">Password</div> + <div class="setting-field"> + <input type="password" id="password"/><br/> + <input type="password" id="password-confirmation" placeholder="Confirm password"/> + </div> + </div> </div> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi/blob/7799deea/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/css/canvas.css ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/css/canvas.css b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/css/canvas.css index e4cf89a..abb5ebd 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/css/canvas.css +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/css/canvas.css @@ -41,5 +41,4 @@ @import url(settings.css); @import url(about.css); @import url(message-pane.css); -@import url(login.css); @import url(status-history.css); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi/blob/7799deea/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/css/header.css ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/css/header.css b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/css/header.css index 7161a8c..3f0b299 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/css/header.css +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/css/header.css @@ -508,6 +508,7 @@ div.search-glass-pane { #current-user { margin-right: 8px; + font-weight: bold; } #utilities-container { http://git-wip-us.apache.org/repos/asf/nifi/blob/7799deea/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/css/login.css ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/css/login.css b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/css/login.css index 72f15f4..e8466df 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/css/login.css +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/css/login.css @@ -19,19 +19,73 @@ Login Styles */ +body.login-body { + position: absolute; + top: 0px; + left: 0px; + bottom: 0px; + right: 0px; + background: #fff url(../images/bg-error.png) left top no-repeat; + font-family: Verdana, Geneva, sans-serif; + color: #191919; + z-index: 999999; +} + +#login-contents-container { + margin-top: 100px; + margin-left: 100px; +} + +#login-message-title { + font-size: 18px; + color: #294c58; + margin-bottom: 16px; +} + +#login-message { + font-size: 11px; +} + +.login-title { + font-size: 12px; + font-weight: bold; + margin-bottom: 10px; + color: #000; +} + /* - NiFi Registration + Login */ -#nifi-registration-container { +body.login-body input, body.login-body textarea { + width: 400px; } -#nifi-registration-form { +/* + User Registration +*/ + +/* + NiFi Registration +*/ + +#nifi-registration-container { margin-top: 10px; - width: 610px; + width: 412px; } #nifi-registration-justification { - width: 600px; height: 200px; +} + +/* + Submission +*/ + +#login-submission-container { + width: 412px; +} + +#login-submission-button { + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi/blob/7799deea/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/css/main.css ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/css/main.css b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/css/main.css index 95ee641..2e43a8b 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/css/main.css +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/css/main.css @@ -153,7 +153,7 @@ input.filter-list { background: transparent url(../images/iconTwistArrow.png) no-repeat scroll top right; } -input[type=text], textarea { +input[type=text], input[type=password], textarea { background: white url(../images/bgInputText.png) repeat-x scroll top; border: 1px solid #ccc; font-family: Verdana; http://git-wip-us.apache.org/repos/asf/nifi/blob/7799deea/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-canvas-header.js ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-canvas-header.js b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-canvas-header.js index 9ae3f4e..9e7bce1 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-canvas-header.js +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-canvas-header.js @@ -31,6 +31,8 @@ nf.CanvasHeader = (function () { return { /** * Initialize the canvas header. + * + * @argument {boolean} supportsLogin Whether login is supported */ init: function (supportsLogin) { // mouse over for the reporting link @@ -140,7 +142,7 @@ nf.CanvasHeader = (function () { }); // show the login link if supported and user is currently anonymous - var isAnonymous = $('#current-user').text() === 'anonymous'; + var isAnonymous = $('#current-user').text() === nf.Canvas.ANONYMOUS_USER_TEXT; if (supportsLogin === true && isAnonymous) { // login link $('#login-link').click(function () { @@ -150,9 +152,15 @@ nf.CanvasHeader = (function () { $('#login-link-container').css('display', 'none'); } + // if login is not supported, don't show the current user + if (supportsLogin !== true) { + $('#current-user-container').css('display', 'none'); + } + // logout link $('#logout-link').click(function () { nf.Storage.removeItem("jwt"); + window.location = '/nifi'; }); // initialize the new template dialog http://git-wip-us.apache.org/repos/asf/nifi/blob/7799deea/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-canvas.js ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-canvas.js b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-canvas.js index 1906620..b714c46 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-canvas.js +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-canvas.js @@ -938,6 +938,7 @@ nf.Canvas = (function () { return { + ANONYMOUS_USER_TEXT: 'Anonymous user', CANVAS_OFFSET: 0, /** @@ -1054,10 +1055,11 @@ nf.Canvas = (function () { nf.Common.setAuthorities(authoritiesResponse.authorities); // at this point the user may be themselves or anonymous - $('#current-user').text(identityResponse.identity).show(); // if the user is logged, we want to determine if they were logged in using a certificate if (identityResponse.identity !== 'anonymous') { + $('#current-user').text(identityResponse.identity).show(); + // attempt to get a token for the current user without passing login credentials $.ajax({ type: 'GET', @@ -1070,6 +1072,7 @@ nf.Canvas = (function () { deferred.resolve(); }); } else { + $('#current-user').text(nf.Canvas.ANONYMOUS_USER_TEXT).show(); deferred.resolve(); } }).fail(function (xhr, status, error) { http://git-wip-us.apache.org/repos/asf/nifi/blob/7799deea/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/login/nf-login.js ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/login/nf-login.js b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/login/nf-login.js index 9bc3264..b844cba 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/login/nf-login.js +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/login/nf-login.js @@ -22,7 +22,9 @@ $(document).ready(function () { }); nf.Login = (function () { - + + var isAnonymous = false; + var config = { urls: { registrationStatus: '../nifi-api/registration/status', @@ -38,109 +40,124 @@ nf.Login = (function () { $('#login-message-container').show(); }; - var initializeLogin = function () { - return $.ajax({ - type: 'GET', - url: config.urls.loginConfig, - dataType: 'json' - }).done(function (response) { - var config = response.config; - - // if this nifi supports login, render the login form - if (config.supportsLogin === true) { - - // handle login click - $('#login-button').on('click', function () { - login().done(function (response, status, xhr) { - var authorization = xhr.getResponseHeader('Authorization'); - var badToken = false; - - // ensure there was a token in the response - if (authorization) { - var tokens = authorization.split(/ /); - - // ensure the token is the appropriate length - if (tokens.length === 2) { - // store the jwt and reload the page - nf.Storage.setItem('jwt', tokens[1]); - window.location = '/nifi'; - } else { - badToken = true; - } - } else { - badToken = true; - } - - if (badToken === true) { - // TODO - show unable to parse response token - } - }); - }); - - // show the login form - $('#login-container').show(); - } - - // if this nifi supports registration, render the registration form - if (config.supportsRegistration === true) { - initializeUserRegistration(); - - // automatically include support for nifi registration - initializeNiFiRegistration(); - } - }); + var initializeLogin = function (supportsRegistration) { + // if this nifi supports registration, render the registration form + if (supportsRegistration === true) { + initializeUserRegistration(); + + // automatically include support for nifi registration + initializeNiFiRegistration(); + + // hide the submit justification title + $('#nifi-registration-title').hide(); + + // update the submit button text + $('#login-submission-button').text('Create'); + } + + // show the login form + $('#login-container').show(); }; - + var initializeUserRegistration = function () { - + // show the user registration form $('#user-registration-container').show(); }; - - var login = function () { - var username = $('#username').val(); - var password = $('#password').val(); - - return $.ajax({ - type: 'POST', - url: '../nifi-api/token', - data: { - 'username': username, - 'password': password - }, - dataType: 'json' - }); - }; - + var initializeNiFiRegistration = function () { $('#nifi-registration-justification').count({ charCountField: '#remaining-characters' }); + // update the button text + $('#login-submission-button').text('Submit'); + // show the nifi registration container $('#nifi-registration-container').show(); }; - + var initializeSubmission = function () { $('#login-submission-button').one('click', function () { if ($('#login-container').is(':visible')) { + var username = $('#username').val(); + var password = $('#password').val(); + // login submit + $.ajax({ + type: 'POST', + url: '../nifi-api/token', + data: { + 'username': username, + 'password': password + } + }).done(function (response, status, xhr) { + var authorization = xhr.getResponseHeader('Authorization'); + var badToken = false; + + // ensure there was a token in the response + if (authorization) { + var tokens = authorization.split(/ /); + + // ensure the token is the appropriate length + if (tokens.length === 2) { + // store the jwt and reload the page + nf.Storage.setItem('jwt', tokens[1]); + + // reload as appropriate + if (top !== window) { + parent.window.location = '/nifi'; + } else { + window.location = '/nifi'; + } + return; + } else { + badToken = true; + } + } else { + badToken = true; + } + + if (badToken === true) { + $('#login-message-title').text('An unexpected error has occurred'); + $('#login-message').text('The id token could not be parsed.'); + + // update visibility + $('#login-container').hide(); + $('#login-submission-container').hide(); + $('#login-message-container').show(); + } + }).fail(function (xhr, status, error) { + $('#login-message-title').text('An unexpected error has occurred'); + $('#login-message').text(xhr.responseText); + + // update visibility + $('#login-container').hide(); + $('#login-submission-container').hide(); + $('#login-message-container').show(); + }); } else if ($('#user-registration-container').is(':visible')) { + var justification = $('#registration-justification').val(); + // new user account submit } else if ($('#nifi-registration-container').is(':visible')) { - // new nifi account submit - var justification = $('#registration-justification').val(); - // attempt to create the user account registration $.ajax({ type: 'POST', url: config.urls.users, data: { - 'justification': justification + 'justification': $('#registration-justification').val() } }).done(function (response) { - $('#login-message').text('Thanks! Your request will be processed shortly.'); + var markup = 'An administrator will process your request shortly.'; + if (isAnonymous === true) { + markup += '<br/><br/>In the meantime you can continue accessing anonymously.'; + } + + $('#login-message-title').text('Thanks!'); + $('#login-message').html(markup); }).fail(function (xhr, status, error) { + $('#login-message-title').text('An unexpected error has occurred'); $('#login-message').text(xhr.responseText); }).always(function () { // update form visibility @@ -150,7 +167,7 @@ nf.Login = (function () { }); } }); - + $('#login-submission-container').show(); }; @@ -160,27 +177,29 @@ nf.Login = (function () { */ init: function () { nf.Storage.init(); - + var showMessage = false; var needsLogin = false; var needsNiFiRegistration = false; - + var token = $.ajax({ type: 'GET', url: config.urls.token }); - + var identity = $.ajax({ type: 'GET', url: config.urls.identity, dataType: 'json' }); - - var pageStateInit = $.Deferred(function(deferred) { + + var pageStateInit = $.Deferred(function (deferred) { // get the current user's identity identity.done(function (response) { // if the user is anonymous see if they need to login or if they are working with a certificate if (response.identity === 'anonymous') { + isAnonymous = true; + // request a token without including credentials, if successful then the user is using a certificate token.done(function () { // the user is using a certificate, see if their account is active/pending/revoked/etc @@ -189,8 +208,9 @@ nf.Login = (function () { url: config.urls.registrationStatus }).done(function () { showMessage = true; - + // account is active and good + $('#login-message-title').text('Success'); $('#login-message').text('Your account is active and you are already logged in.'); deferred.resolve(); }).fail(function (xhr, status, error) { @@ -199,8 +219,9 @@ nf.Login = (function () { needsNiFiRegistration = true; } else { showMessage = true; - - // anonymous user and non-401 means they already have an account and it's pending/revoked + + // anonymous user and non-401 means they already have an account and it's pending/revoked + $('#login-message-title').text('Access Denied'); if ($.trim(xhr.responseText) === '') { $('#login-message').text('Unable to check registration status.'); } else { @@ -216,8 +237,9 @@ nf.Login = (function () { }); } else { showMessage = true; - + // the user is not anonymous and has an active account (though maybe role-less) + $('#login-message-title').text('Success'); $('#login-message').text('Your account is active and you are already logged in.'); deferred.resolve(); } @@ -236,29 +258,47 @@ nf.Login = (function () { }); } else { showMessage = true; - + // the user is logged in with certificate or credentials but their account is pending/revoked. error message should indicate + $('#login-message-title').text('Access Denied'); if ($.trim(xhr.responseText) === '') { $('#login-message').text('Unable to authorize you to use this NiFi and anonymous access is disabled.'); } else { $('#login-message').text(xhr.responseText); } - + deferred.resolve(); } }); }).promise(); + var loginConfigXhr = $.ajax({ + type: 'GET', + url: config.urls.loginConfig, + dataType: 'json' + }); + // render the page accordingly - pageStateInit.done(function () { + $.when(loginConfigXhr, pageStateInit).done(function (loginResult) { + var loginResponse = loginResult[0]; + var loginConfig = loginResponse.config; + + // if login is required, verify its supported + if (loginConfig.supportsLogin === false && needsLogin === true) { + $('#login-message-title').text('Access Denied'); + $('#login-message').text('This NiFi is not configured to support login.'); + showMessage = true; + needsLogin = false; + } + if (showMessage === true) { initializeMessage(); } else if (needsLogin === true) { - initializeLogin(); + initializeLogin(loginConfig.supportsRegistration); } else if (needsNiFiRegistration === true) { initializeNiFiRegistration(); } - + if (needsLogin === true || needsNiFiRegistration === true) { initializeSubmission(); }