@Override protected Authentication createAuthentication(HttpServletRequest request) { return new NiFiAuthenticationToken(new NiFiUserDetails(StandardNiFiUser.ANONYMOUS)); }
/** * Returns the current NiFiUser or null if the current user is not a NiFiUser. * * @return user */ public static NiFiUser getNiFiUser() { NiFiUser user = null; // obtain the principal in the current authentication final SecurityContext context = SecurityContextHolder.getContext(); final Authentication authentication = context.getAuthentication(); if (authentication != null) { Object principal = authentication.getPrincipal(); if (principal instanceof NiFiUserDetails) { user = ((NiFiUserDetails) principal).getNiFiUser(); } } return user; }
@Override public void run() { try { // set the user authentication token final Authentication authentication = new NiFiAuthenticationToken(new NiFiUserDetails(request.getUser())); SecurityContextHolder.getContext().setAuthentication(authentication); task.accept(request); } catch (final Exception e) { logger.error("Failed to perform asynchronous task", e); request.setFailureReason("Encountered unexpected error when performing asynchronous task: " + e); } finally { // clear the authentication token SecurityContextHolder.getContext().setAuthentication(null); } } });
final NiFiUser nifiUser = ((NiFiUserDetails) authenticationResponse.getDetails()).getNiFiUser(); final NiFiUser nifiUser = ((NiFiUserDetails) authenticationResponse.getDetails()).getNiFiUser();
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { final KnoxAuthenticationRequestToken request = (KnoxAuthenticationRequestToken) authentication; try { final String jwtPrincipal = knoxService.getAuthenticationFromToken(request.getToken()); final String mappedIdentity = mapIdentity(jwtPrincipal); final NiFiUser user = new Builder().identity(mappedIdentity).groups(getUserGroups(mappedIdentity)).clientAddress(request.getClientAddress()).build(); return new NiFiAuthenticationToken(new NiFiUserDetails(user)); } catch (ParseException | JOSEException e) { logger.info("Unable to validate the access token: " + e.getMessage(), e); throw new InvalidAuthenticationException("Unable to validate the access token.", e); } }
try { final Authentication authentication = new NiFiAuthenticationToken(new NiFiUserDetails(user)); SecurityContextHolder.getContext().setAuthentication(authentication);
return new NiFiAuthenticationToken(new NiFiUserDetails(new Builder().identity(mappedIdentity).groups(getUserGroups(mappedIdentity)).clientAddress(request.getClientAddress()).build())); } else { return new NiFiAuthenticationToken(new NiFiUserDetails(proxy));
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { final JwtAuthenticationRequestToken request = (JwtAuthenticationRequestToken) authentication; try { final String jwtPrincipal = jwtService.getAuthenticationFromToken(request.getToken()); final String mappedIdentity = mapIdentity(jwtPrincipal); final NiFiUser user = new Builder().identity(mappedIdentity).groups(getUserGroups(mappedIdentity)).clientAddress(request.getClientAddress()).build(); return new NiFiAuthenticationToken(new NiFiUserDetails(user)); } catch (JwtException e) { throw new InvalidAuthenticationException(e.getMessage(), e); } }
try { final Authentication authentication = new NiFiAuthenticationToken(new NiFiUserDetails(user)); SecurityContextHolder.getContext().setAuthentication(authentication);
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { final OtpAuthenticationRequestToken request = (OtpAuthenticationRequestToken) authentication; try { final String otpPrincipal; if (request.isDownloadToken()) { otpPrincipal = otpService.getAuthenticationFromDownloadToken(request.getToken()); } else { otpPrincipal = otpService.getAuthenticationFromUiExtensionToken(request.getToken()); } final String mappedIdentity = mapIdentity(otpPrincipal); final NiFiUser user = new Builder().identity(mappedIdentity).groups(getUserGroups(mappedIdentity)).clientAddress(request.getClientAddress()).build(); return new NiFiAuthenticationToken(new NiFiUserDetails(user)); } catch (OtpAuthenticationException e) { throw new InvalidAuthenticationException(e.getMessage(), e); } }
try { final Authentication authentication = new NiFiAuthenticationToken(new NiFiUserDetails(user)); SecurityContextHolder.getContext().setAuthentication(authentication);
@Override protected Authentication createAuthentication(HttpServletRequest request) { return new NiFiAuthenticationToken(new NiFiUserDetails(StandardNiFiUser.ANONYMOUS)); }
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { final KnoxAuthenticationRequestToken request = (KnoxAuthenticationRequestToken) authentication; try { final String jwtPrincipal = knoxService.getAuthenticationFromToken(request.getToken()); final String mappedIdentity = mapIdentity(jwtPrincipal); final NiFiUser user = new Builder().identity(mappedIdentity).groups(getUserGroups(mappedIdentity)).clientAddress(request.getClientAddress()).build(); return new NiFiAuthenticationToken(new NiFiUserDetails(user)); } catch (ParseException | JOSEException e) { logger.info("Unable to validate the access token: " + e.getMessage(), e); throw new InvalidAuthenticationException("Unable to validate the access token.", e); } }
return new NiFiAuthenticationToken(new NiFiUserDetails(new Builder().identity(mappedIdentity).groups(getUserGroups(mappedIdentity)).clientAddress(request.getClientAddress()).build())); } else { return new NiFiAuthenticationToken(new NiFiUserDetails(proxy));
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { final JwtAuthenticationRequestToken request = (JwtAuthenticationRequestToken) authentication; try { final String jwtPrincipal = jwtService.getAuthenticationFromToken(request.getToken()); final String mappedIdentity = mapIdentity(jwtPrincipal); final NiFiUser user = new Builder().identity(mappedIdentity).groups(getUserGroups(mappedIdentity)).clientAddress(request.getClientAddress()).build(); return new NiFiAuthenticationToken(new NiFiUserDetails(user)); } catch (JwtException e) { throw new InvalidAuthenticationException(e.getMessage(), e); } }
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { final OtpAuthenticationRequestToken request = (OtpAuthenticationRequestToken) authentication; try { final String otpPrincipal; if (request.isDownloadToken()) { otpPrincipal = otpService.getAuthenticationFromDownloadToken(request.getToken()); } else { otpPrincipal = otpService.getAuthenticationFromUiExtensionToken(request.getToken()); } final String mappedIdentity = mapIdentity(otpPrincipal); final NiFiUser user = new Builder().identity(mappedIdentity).groups(getUserGroups(mappedIdentity)).clientAddress(request.getClientAddress()).build(); return new NiFiAuthenticationToken(new NiFiUserDetails(user)); } catch (OtpAuthenticationException e) { throw new InvalidAuthenticationException(e.getMessage(), e); } }