@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 testPostDelegationTokenExpiration() throws Exception {

    DelegationToken token = new DelegationToken();
    token.setRenewer(TEST_RENEWER);

    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");

    Response response = interceptor.postDelegationToken(token, request);
    Assert.assertNotNull(response);
    Object entity = response.getEntity();
    Assert.assertNotNull(entity);
    Assert.assertTrue(entity instanceof DelegationToken);
    DelegationToken dtoken = (DelegationToken) entity;

    final String yarnTokenHeader = "Hadoop-YARN-RM-Delegation-Token";
    when(request.getHeader(yarnTokenHeader)).thenReturn(dtoken.getToken());

    Response renewResponse = interceptor.postDelegationTokenExpiration(request);
    Assert.assertNotNull(renewResponse);

    Object renewEntity = renewResponse.getEntity();
    Assert.assertNotNull(renewEntity);
    Assert.assertTrue(renewEntity instanceof DelegationToken);

    // renewDelegation, we only return renewDate, other values are NULL.
    DelegationToken renewDToken = (DelegationToken) renewEntity;
    Assert.assertNull(renewDToken.getRenewer());
    Assert.assertNull(renewDToken.getOwner());
    Assert.assertNull(renewDToken.getKind());
    Assert.assertTrue(renewDToken.getNextExpirationTime() > dtoken.getNextExpirationTime());
  }