NIFI-655:

- Fixing typo when loading the ldap connect timeout.
- Providing a better experience for session expiration.
- Using ellipsis for lengthly user name.
- Adding an issuer to the authentication response so the LIP can specify the appropriate value.
This commit is contained in:
Matt Gilman 2015-11-18 15:44:47 -05:00
parent 0fa68a5bac
commit 3da198135e
7 changed files with 33 additions and 22 deletions

View File

@ -24,6 +24,7 @@ public class AuthenticationResponse {
private final String identity; private final String identity;
private final String username; private final String username;
private final long expiration; private final long expiration;
private final String issuer;
/** /**
* Creates an authentication response. The username and how long the authentication is valid in milliseconds * Creates an authentication response. The username and how long the authentication is valid in milliseconds
@ -31,11 +32,13 @@ public class AuthenticationResponse {
* @param identity The user identity * @param identity The user identity
* @param username The username * @param username The username
* @param expiration The expiration in milliseconds * @param expiration The expiration in milliseconds
* @param issuer The issuer of the token
*/ */
public AuthenticationResponse(final String identity, final String username, final long expiration) { public AuthenticationResponse(final String identity, final String username, final long expiration, final String issuer) {
this.identity = identity; this.identity = identity;
this.username = username; this.username = username;
this.expiration = expiration; this.expiration = expiration;
this.issuer = issuer;
} }
public String getIdentity() { public String getIdentity() {
@ -46,6 +49,10 @@ public class AuthenticationResponse {
return username; return username;
} }
public String getIssuer() {
return issuer;
}
/** /**
* Returns the expiration of a given authentication in milliseconds. * Returns the expiration of a given authentication in milliseconds.
* *

View File

@ -336,8 +336,7 @@ public class AccessResource extends ApplicationResource {
} }
// create the authentication token // create the authentication token
// TODO: Some Spring beans return "" for getClass().getSimpleName(). Using getName() temporarily, the way that NAR loader works, this value will always be an anonymous inner class loginAuthenticationToken = new LoginAuthenticationToken(authenticationResponse.getIdentity(), expiration, authenticationResponse.getIssuer());
loginAuthenticationToken = new LoginAuthenticationToken(authenticationResponse.getIdentity(), expiration, loginIdentityProvider.getClass().getName());
} catch (final InvalidLoginCredentialsException ilce) { } catch (final InvalidLoginCredentialsException ilce) {
throw new IllegalArgumentException("The supplied username and password are not valid.", ilce); throw new IllegalArgumentException("The supplied username and password are not valid.", ilce);
} catch (final IdentityAccessException iae) { } catch (final IdentityAccessException iae) {
@ -358,8 +357,7 @@ public class AccessResource extends ApplicationResource {
authorizeProxyIfNecessary(proxyChain); authorizeProxyIfNecessary(proxyChain);
// create the authentication token // create the authentication token
// TODO: Some Spring beans return "" for getClass().getSimpleName(). Using getName() temporarilyy, the way that NAR loader works, this value will always be an anonymous inner class loginAuthenticationToken = new LoginAuthenticationToken(proxyChain.get(0), authenticationResponse.getExpiration(), authenticationResponse.getIssuer());
loginAuthenticationToken = new LoginAuthenticationToken(proxyChain.get(0), authenticationResponse.getExpiration(), certificateIdentityProvider.getClass().getName());
} }
// generate JWT for response // generate JWT for response

View File

@ -57,7 +57,7 @@ public class NiFiTestLoginIdentityProvider implements LoginIdentityProvider {
@Override @Override
public AuthenticationResponse authenticate(LoginCredentials credentials) throws InvalidLoginCredentialsException, IdentityAccessException { public AuthenticationResponse authenticate(LoginCredentials credentials) throws InvalidLoginCredentialsException, IdentityAccessException {
checkUser(credentials.getUsername(), credentials.getPassword()); checkUser(credentials.getUsername(), credentials.getPassword());
return new AuthenticationResponse(credentials.getUsername(), credentials.getUsername(), TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS)); return new AuthenticationResponse(credentials.getUsername(), credentials.getUsername(), TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS), getClass().getSimpleName());
} }
@Override @Override

View File

@ -32,6 +32,8 @@ public class X509IdentityProvider {
private static final Logger logger = LoggerFactory.getLogger(X509IdentityProvider.class); private static final Logger logger = LoggerFactory.getLogger(X509IdentityProvider.class);
private final String issuer = getClass().getSimpleName();
private X509CertificateValidator certificateValidator; private X509CertificateValidator certificateValidator;
private X509PrincipalExtractor principalExtractor; private X509PrincipalExtractor principalExtractor;
@ -77,7 +79,7 @@ public class X509IdentityProvider {
} }
// build the authentication response // build the authentication response
return new AuthenticationResponse(principal, principal, TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS)); return new AuthenticationResponse(principal, principal, TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS), issuer);
} }
/* setters */ /* setters */

View File

@ -519,6 +519,9 @@ div.search-glass-pane {
float: left; float: left;
margin-right: 8px; margin-right: 8px;
font-weight: bold; font-weight: bold;
max-width: 250px;
text-overflow: ellipsis;
overflow: hidden;
} }
#utilities-container { #utilities-container {

View File

@ -155,7 +155,7 @@ nf.Common = (function () {
} }
// set the interval to one hour // set the interval to one hour
var interval = 10 * nf.Common.MILLIS_PER_MINUTE; var interval = nf.Common.MILLIS_PER_MINUTE;
var checkExpiration = function () { var checkExpiration = function () {
var expiration = nf.Storage.getItemExpiration('jwt'); var expiration = nf.Storage.getItemExpiration('jwt');
@ -166,7 +166,7 @@ nf.Common = (function () {
var now = new Date(); var now = new Date();
// get the time remainging plus a little bonus time to reload the token // get the time remainging plus a little bonus time to reload the token
var timeRemaining = expirationDate.valueOf() - now.valueOf() - nf.Common.MILLIS_PER_MINUTE; var timeRemaining = expirationDate.valueOf() - now.valueOf() - (30 * nf.Common.MILLIS_PER_SECOND);
if (timeRemaining < interval) { if (timeRemaining < interval) {
if ($('#current-user').text() !== nf.Common.ANONYMOUS_USER_TEXT && !$('#anonymous-user-alert').is(':visible')) { if ($('#current-user').text() !== nf.Common.ANONYMOUS_USER_TEXT && !$('#anonymous-user-alert').is(':visible')) {
// if the token will expire before the next interval minus some bonus time, notify the user to re-login // if the token will expire before the next interval minus some bonus time, notify the user to re-login
@ -320,9 +320,6 @@ nf.Common = (function () {
// show the error pane // show the error pane
$('#message-pane').show(); $('#message-pane').show();
// close the canvas
nf.Common.closeCanvas();
} else { } else {
nf.Dialog.showOkDialog({ nf.Dialog.showOkDialog({
dialogContent: 'Your session has expired. Please press Ok to log in again.', dialogContent: 'Your session has expired. Please press Ok to log in again.',
@ -332,6 +329,9 @@ nf.Common = (function () {
} }
}); });
} }
// close the canvas
nf.Common.closeCanvas();
return; return;
} }
@ -424,6 +424,12 @@ nf.Common = (function () {
* Closes the canvas by removing the splash screen and stats poller. * Closes the canvas by removing the splash screen and stats poller.
*/ */
closeCanvas: function () { closeCanvas: function () {
if (nf.Storage.getItem('jwt') === null) {
$('#user-logout-container').hide();
} else {
$('#user-logout-container').show();
}
// ensure this javascript has been loaded in the nf canvas page // ensure this javascript has been loaded in the nf canvas page
if (nf.Common.isDefinedAndNotNull(nf.Canvas)) { if (nf.Common.isDefinedAndNotNull(nf.Canvas)) {
// hide the splash screen if required // hide the splash screen if required
@ -431,13 +437,6 @@ nf.Common = (function () {
nf.Canvas.hideSplash(); nf.Canvas.hideSplash();
} }
// update the log out link accordingly
if (nf.Storage.getItem('jwt') === null) {
$('#user-logout-container').hide();
} else {
$('#user-logout-container').show();
}
// hide the context menu // hide the context menu
nf.ContextMenu.hide(); nf.ContextMenu.hide();

View File

@ -66,10 +66,12 @@ public class LdapProvider implements LoginIdentityProvider {
private static final String TLS = "TLS"; private static final String TLS = "TLS";
private AbstractLdapAuthenticationProvider provider; private AbstractLdapAuthenticationProvider provider;
private String issuer;
private long expiration; private long expiration;
@Override @Override
public final void initialize(final LoginIdentityProviderInitializationContext initializationContext) throws ProviderCreationException { public final void initialize(final LoginIdentityProviderInitializationContext initializationContext) throws ProviderCreationException {
this.issuer = getClass().getSimpleName();
} }
@Override @Override
@ -251,9 +253,9 @@ public class LdapProvider implements LoginIdentityProvider {
// attempt to get the ldap user details to get the DN // attempt to get the ldap user details to get the DN
if (authentication.getPrincipal() instanceof LdapUserDetails) { if (authentication.getPrincipal() instanceof LdapUserDetails) {
final LdapUserDetails userDetails = (LdapUserDetails) authentication.getPrincipal(); final LdapUserDetails userDetails = (LdapUserDetails) authentication.getPrincipal();
return new AuthenticationResponse(userDetails.getDn(), credentials.getUsername(), expiration); return new AuthenticationResponse(userDetails.getDn(), credentials.getUsername(), expiration, issuer);
} else { } else {
return new AuthenticationResponse(authentication.getName(), credentials.getUsername(), expiration); return new AuthenticationResponse(authentication.getName(), credentials.getUsername(), expiration, issuer);
} }
} catch (final CommunicationException | AuthenticationServiceException e) { } catch (final CommunicationException | AuthenticationServiceException e) {
logger.error(e.getMessage()); logger.error(e.getMessage());