@Test public void testWrongCookieName() throws Exception { final String jwt = "my-jwt"; final Cookie knoxCookie = mock(Cookie.class); when(knoxCookie.getName()).thenReturn("not-hadoop-jwt"); when(knoxCookie.getValue()).thenReturn(jwt); final HttpServletRequest request = mock(HttpServletRequest.class); when(request.isSecure()).thenReturn(true); when(request.getCookies()).thenReturn(new Cookie[] {knoxCookie}); final KnoxAuthenticationRequestToken authRequest = (KnoxAuthenticationRequestToken) knoxAuthenticationFilter.attemptAuthentication(request); assertNull(authRequest); }
@Override public Authentication attemptAuthentication(final HttpServletRequest request) { if (!request.isSecure()) { return null; } final NiFiProperties properties = getProperties(); if (!properties.isKnoxSsoEnabled()) { return null; } final String knoxJwt = getJwtFromCookie(request, properties.getKnoxCookieName()); if (knoxJwt == null) { return null; } else { return new KnoxAuthenticationRequestToken(knoxJwt, request.getRemoteAddr()); } }
KnoxAuthenticationFilter extends NiFiAuthenticationFilter { @Override public Authentication attemptAuthentication(final HttpServletRequest request) { if (!request.isSecure()) { return null; } final NiFiProperties properties = getProperties(); if (!properties.isKnoxSsoEnabled()) { return null; } final String knoxJwt = getJwtFromCookie(request, properties.getKnoxCookieName()); if (knoxJwt == null) { return null; } else { return new KnoxAuthenticationRequestToken(knoxJwt, request.getRemoteAddr()); } } }
KnoxAuthenticationFilter extends NiFiAuthenticationFilter { @Override public Authentication attemptAuthentication(final HttpServletRequest request) { if (!request.isSecure()) { return null; } final NiFiProperties properties = getProperties(); if (!properties.isKnoxSsoEnabled()) { return null; } final String knoxJwt = getJwtFromCookie(request, properties.getKnoxCookieName()); if (knoxJwt == null) { return null; } else { return new KnoxAuthenticationRequestToken(knoxJwt, request.getRemoteAddr()); } }  }
KnoxAuthenticationFilter extends NiFiAuthenticationFilter { @Override public Authentication attemptAuthentication(final HttpServletRequest request) { if (!request.isSecure()) { return null; } final NiFiProperties properties = getProperties(); if (!properties.isKnoxSsoEnabled()) { return null; } final String knoxJwt = getJwtFromCookie(request, properties.getKnoxCookieName()); if (knoxJwt == null) { return null; } else { return new KnoxAuthenticationRequestToken(knoxJwt, request.getRemoteAddr()); } }  @Override Authentication attemptAuthentication(final HttpServletRequest request); String getJwtFromCookie(final HttpServletRequest request, final String cookieName); }
KnoxAuthenticationFilter extends NiFiAuthenticationFilter { @Override public Authentication attemptAuthentication(final HttpServletRequest request) { if (!request.isSecure()) { return null; } final NiFiProperties properties = getProperties(); if (!properties.isKnoxSsoEnabled()) { return null; } final String knoxJwt = getJwtFromCookie(request, properties.getKnoxCookieName()); if (knoxJwt == null) { return null; } else { return new KnoxAuthenticationRequestToken(knoxJwt, request.getRemoteAddr()); } }  @Override Authentication attemptAuthentication(final HttpServletRequest request); String getJwtFromCookie(final HttpServletRequest request, final String cookieName);  }