@Test public void testIsAccessAllowed_ValidCsrfToken() { when(httpServletRequest.getMethod()).thenReturn(HttpMethod.POST); when(httpServletRequest.getHeader(HttpHeaders.USER_AGENT)).thenReturn(BROWSER_UA); when(httpServletRequest.getHeader("NX-ANTI-CSRF-TOKEN")).thenReturn("avalue"); when(httpServletRequest.getCookies()).thenReturn(new Cookie[] { new Cookie("NX-ANTI-CSRF-TOKEN", "avalue") }); assertThat(underTest.isAccessAllowed(httpServletRequest), is(true)); verify(httpServletRequest, times(1)).getCookies(); }
public boolean isAccessAllowed(final HttpServletRequest httpRequest) { if (!enabled) { return true; } return isSafeHttpMethod(httpRequest) || isMultiPartFormDataPost(httpRequest) || isNotBrowserRequest(httpRequest) || isAntiCsrfTokenValid(httpRequest, Optional.ofNullable(httpRequest.getHeader(ANTI_CSRF_TOKEN_NAME))); }
AntiCsrfHelper extends ComponentSupport { public boolean isAccessAllowed(final HttpServletRequest httpRequest) { if (!enabled) { return true; } return isSafeHttpMethod(httpRequest) || isMultiPartFormDataPost(httpRequest) || isNotBrowserRequest(httpRequest) || isAntiCsrfTokenValid(httpRequest, Optional.ofNullable(httpRequest.getHeader(ANTI_CSRF_TOKEN_NAME))); } }
AntiCsrfHelper extends ComponentSupport { public boolean isAccessAllowed(final HttpServletRequest httpRequest) { if (!enabled) { return true; } return isSafeHttpMethod(httpRequest) || isMultiPartFormDataPost(httpRequest) || isNotBrowserRequest(httpRequest) || isAntiCsrfTokenValid(httpRequest, Optional.ofNullable(httpRequest.getHeader(ANTI_CSRF_TOKEN_NAME))); } @Inject  AntiCsrfHelper(
      @Named("${nexus.security.anticsrftoken.enabled:-true}") final boolean enabled,
      @Named("${nexus.security.anticsrftoken.whitelist}") @Nullable final String whitelist); }
AntiCsrfHelper extends ComponentSupport { public boolean isAccessAllowed(final HttpServletRequest httpRequest) { if (!enabled) { return true; } return isSafeHttpMethod(httpRequest) || isMultiPartFormDataPost(httpRequest) || isNotBrowserRequest(httpRequest) || isAntiCsrfTokenValid(httpRequest, Optional.ofNullable(httpRequest.getHeader(ANTI_CSRF_TOKEN_NAME))); } @Inject  AntiCsrfHelper(
      @Named("${nexus.security.anticsrftoken.enabled:-true}") final boolean enabled,
      @Named("${nexus.security.anticsrftoken.whitelist}") @Nullable final String whitelist); boolean isAccessAllowed(final HttpServletRequest httpRequest); void requireValidToken(final HttpServletRequest httpRequest, @Nullable final String token); boolean isEnabled(); }
AntiCsrfHelper extends ComponentSupport { public boolean isAccessAllowed(final HttpServletRequest httpRequest) { if (!enabled) { return true; } return isSafeHttpMethod(httpRequest) || isMultiPartFormDataPost(httpRequest) || isNotBrowserRequest(httpRequest) || isAntiCsrfTokenValid(httpRequest, Optional.ofNullable(httpRequest.getHeader(ANTI_CSRF_TOKEN_NAME))); } @Inject  AntiCsrfHelper(
      @Named("${nexus.security.anticsrftoken.enabled:-true}") final boolean enabled,
      @Named("${nexus.security.anticsrftoken.whitelist}") @Nullable final String whitelist); boolean isAccessAllowed(final HttpServletRequest httpRequest); void requireValidToken(final HttpServletRequest httpRequest, @Nullable final String token); boolean isEnabled(); static final String ENABLED; static final String ERROR_MESSAGE_TOKEN_MISMATCH; static final String ANTI_CSRF_TOKEN_NAME; }