diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiWebApiSecurityConfiguration.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiWebApiSecurityConfiguration.java index 3d7544e29f..7d1b02bdfd 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiWebApiSecurityConfiguration.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiWebApiSecurityConfiguration.java @@ -88,16 +88,15 @@ public class NiFiWebApiSecurityConfiguration extends WebSecurityConfigurerAdapte .sessionManagement() .sessionCreationPolicy(SessionCreationPolicy.STATELESS); - // verify that login authentication is enabled if (loginIdentityProvider != null) { - // login authentication for /token - exchanges for JWT for subsequent API usage - http.addFilterBefore(buildLoginFilter("/token"), UsernamePasswordAuthenticationFilter.class); - // verify the configured login authenticator supports user login registration if (loginIdentityProvider.supportsRegistration()) { http.addFilterBefore(buildRegistrationFilter("/registration"), UsernamePasswordAuthenticationFilter.class); } } + + // login authentication for /token - exchanges for JWT for subsequent API usage + http.addFilterBefore(buildLoginFilter("/token"), UsernamePasswordAuthenticationFilter.class); // registration status - will check the status of a user's account registration (regardless if its based on login or not) http.addFilterBefore(buildRegistrationStatusFilter("/registration/status"), UsernamePasswordAuthenticationFilter.class); @@ -111,8 +110,10 @@ public class NiFiWebApiSecurityConfiguration extends WebSecurityConfigurerAdapte // x509 http.addFilterAfter(buildX509Filter(), AnonymousAuthenticationFilter.class); - // jwt - http.addFilterAfter(buildJwtFilter(), AnonymousAuthenticationFilter.class); + // jwt - consider when configured for log in + if (loginIdentityProvider != null) { + http.addFilterAfter(buildJwtFilter(), AnonymousAuthenticationFilter.class); + } } @Bean 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 456a2b2f65..2c10863b2c 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 @@ -86,6 +86,11 @@ public class LoginAuthenticationFilter extends AbstractAuthenticationProcessingF // if there is no certificate, look for an existing token if (certificate == null) { + // if not configured for login, don't consider existing tokens + if (loginIdentityProvider == null) { + throw new BadCredentialsException("Login not supported."); + } + final String principal = jwtService.getAuthentication(request); if (principal == null) { @@ -129,6 +134,11 @@ public class LoginAuthenticationFilter extends AbstractAuthenticationProcessingF return new LoginAuthenticationToken(preAuthenticatedCredentials); } } else { + // if not configuration for login, don't consider credentials + if (loginIdentityProvider == null) { + throw new BadCredentialsException("Login not supported."); + } + if (loginIdentityProvider.authenticate(credentials)) { return new LoginAuthenticationToken(credentials); } else { 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/RegistrationFilter.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-security/src/main/java/org/apache/nifi/web/security/form/RegistrationFilter.java index 39adb6892e..68d738371a 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-security/src/main/java/org/apache/nifi/web/security/form/RegistrationFilter.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-security/src/main/java/org/apache/nifi/web/security/form/RegistrationFilter.java @@ -120,11 +120,6 @@ public class RegistrationFilter extends AbstractAuthenticationProcessingFilter { // generate JWT for response jwtService.addToken(response, authentication); - - // mark as successful - response.setStatus(HttpServletResponse.SC_CREATED); - response.setContentType("text/plain"); - response.setContentLength(0); } @Override 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 e2b7b9b127..a4967b1f3e 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 @@ -37,6 +37,9 @@ ${nf.login.script.tags}
+