@Override
  public void authorize(UserGroupInformation user,
      InetAddress remoteAddress) throws AuthorizationException {
    
    if (user == null) {
      throw new IllegalArgumentException("user is null.");
    }

    UserGroupInformation realUser = user.getRealUser();
    if (realUser == null) {
      return;
    }
    
    AccessControlList acl = proxyUserAcl.get(configPrefix +
        realUser.getShortUserName());
    if (acl == null || !acl.isUserAllowed(user)) {
      throw new AuthorizationException("User: " + realUser.getUserName()
          + " is not allowed to impersonate " + user.getUserName());
    }

    MachineList MachineList = proxyHosts.get(
        getProxySuperuserIpConfKey(realUser.getShortUserName()));

    if(MachineList == null || !MachineList.includes(remoteAddress)) {
      throw new AuthorizationException("Unauthorized connection for super-user: "
          + realUser.getUserName() + " from IP " + remoteAddress);
    }
  }
@Test
  public void testAuthorizationSuccess() throws AuthorizationException {
    proxyUser = "fakeuser";
    user = "dummyUser";
    when(realUserUGI.getShortUserName()).thenReturn(proxyUser);
    when(userGroupInformation.getRealUser()).thenReturn(realUserUGI);
    provider.authorize(userGroupInformation, "2.2.2.2");

    user = "somerandomuser";
    proxyUser = "test.user";
    when(realUserUGI.getShortUserName()).thenReturn(proxyUser);
    when(userGroupInformation.getRealUser()).thenReturn(realUserUGI);
    provider.authorize(userGroupInformation, "2.2.2.2");
  }