@Override
  public Response postDelegationTokenExpiration(HttpServletRequest hsr)
      throws AuthorizationException, IOException, InterruptedException, Exception {

    if (hsr == null) {
      RouterAuditLogger.logFailure(getUser().getShortUserName(), POST_DELEGATION_TOKEN_EXPIRATION,
          UNKNOWN, TARGET_WEB_SERVICE, "Parameter error, the hsr is null.");
      throw new IllegalArgumentException("Parameter error, the hsr is null.");
    }

    try {
      // get Caller UserGroupInformation
      Configuration conf = federationFacade.getConf();
      UserGroupInformation callerUGI = getKerberosUserGroupInformation(conf, hsr);
      return renewDelegationToken(hsr, callerUGI);
    } catch (YarnException e) {
      LOG.error("Renew delegation token request failed.", e);
      RouterAuditLogger.logFailure(getUser().getShortUserName(), POST_DELEGATION_TOKEN_EXPIRATION,
          UNKNOWN, TARGET_WEB_SERVICE, e.getLocalizedMessage());
      return Response.status(Status.FORBIDDEN).entity(e.getMessage()).build();
    }
  }
@Test
  public void testPostDelegationTokenExpirationError() throws Exception {

    // If we don't set hsr
    LambdaTestUtils.intercept(IllegalArgumentException.class,
        "Parameter error, the hsr is null.",
        () -> interceptor.postDelegationTokenExpiration(null));

    Principal principal = mock(Principal.class);
    when(principal.getName()).thenReturn(TEST_RENEWER);

    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getRemoteUser()).thenReturn(TEST_RENEWER);
    when(request.getUserPrincipal()).thenReturn(principal);
    when(request.getAuthType()).thenReturn("kerberos");

    // If we don't set the header.
    String errorMsg = "Header 'Hadoop-YARN-RM-Delegation-Token' containing encoded token not found";
    LambdaTestUtils.intercept(BadRequestException.class, errorMsg,
        () -> interceptor.postDelegationTokenExpiration(request));
  }