@Test public void testRequireValidToken_Disabled() { underTest = new AntiCsrfHelper(false, ""); underTest.requireValidToken(httpServletRequest, "a-token"); verifyZeroInteractions(httpServletRequest); }
public void requireValidToken(final HttpServletRequest httpRequest, @Nullable final String token) { Optional<String> optToken = token == null ? Optional.ofNullable(httpRequest.getHeader(ANTI_CSRF_TOKEN_NAME)) : Optional.of(token); if (!enabled || isNotBrowserRequest(httpRequest) || isAntiCsrfTokenValid(httpRequest, optToken)) { return; } throw new UnauthorizedException(ERROR_MESSAGE_TOKEN_MISMATCH); }
AntiCsrfHelper extends ComponentSupport { public void requireValidToken(final HttpServletRequest httpRequest, @Nullable final String token) { Optional<String> optToken = token == null ? Optional.ofNullable(httpRequest.getHeader(ANTI_CSRF_TOKEN_NAME)) : Optional.of(token); if (!enabled || isNotBrowserRequest(httpRequest) || isAntiCsrfTokenValid(httpRequest, optToken)) { return; } throw new UnauthorizedException(ERROR_MESSAGE_TOKEN_MISMATCH); } }
AntiCsrfHelper extends ComponentSupport { public void requireValidToken(final HttpServletRequest httpRequest, @Nullable final String token) { Optional<String> optToken = token == null ? Optional.ofNullable(httpRequest.getHeader(ANTI_CSRF_TOKEN_NAME)) : Optional.of(token); if (!enabled || isNotBrowserRequest(httpRequest) || isAntiCsrfTokenValid(httpRequest, optToken)) { return; } throw new UnauthorizedException(ERROR_MESSAGE_TOKEN_MISMATCH); } @Inject  AntiCsrfHelper(
      @Named("${nexus.security.anticsrftoken.enabled:-true}") final boolean enabled,
      @Named("${nexus.security.anticsrftoken.whitelist}") @Nullable final String whitelist); }
AntiCsrfHelper extends ComponentSupport { public void requireValidToken(final HttpServletRequest httpRequest, @Nullable final String token) { Optional<String> optToken = token == null ? Optional.ofNullable(httpRequest.getHeader(ANTI_CSRF_TOKEN_NAME)) : Optional.of(token); if (!enabled || isNotBrowserRequest(httpRequest) || isAntiCsrfTokenValid(httpRequest, optToken)) { return; } throw new UnauthorizedException(ERROR_MESSAGE_TOKEN_MISMATCH); } @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 void requireValidToken(final HttpServletRequest httpRequest, @Nullable final String token) { Optional<String> optToken = token == null ? Optional.ofNullable(httpRequest.getHeader(ANTI_CSRF_TOKEN_NAME)) : Optional.of(token); if (!enabled || isNotBrowserRequest(httpRequest) || isAntiCsrfTokenValid(httpRequest, optToken)) { return; } throw new UnauthorizedException(ERROR_MESSAGE_TOKEN_MISMATCH); } @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; }