@Override
  public UserIdentity getUserIdentity(HttpServletRequest request, String name) {
    // ConfigurableSpnegoAuthenticator may pass names in servicename/host format but we only store the servicename
    int nameHostSeparatorIndex = name.indexOf('/');
    String serviceName = nameHostSeparatorIndex > 0 ? name.substring(0, nameHostSeparatorIndex) : name;
    UserIdentity serviceIdentity = _serviceUserStore.getUserIdentity(serviceName);
    if (_trustedProxyIpPattern != null) {
      return _trustedProxyIpPattern.matcher(request.getRemoteAddr()).matches() ? serviceIdentity : null;
    } else {
      return serviceIdentity;
    }
  }
@Test
  public void testSuccessfulLoginWithIpFiltering() throws Exception {
    TrustedProxyAuthorizationService srv = new TrustedProxyAuthorizationService(Collections.singletonList(AUTH_SERVICE_NAME), IP_FILTER);
    HttpServletRequest mockRequest = mock(HttpServletRequest.class);

    expect(mockRequest.getRemoteAddr()).andReturn("192.168.0.1");
    replay(mockRequest);
    srv.start();
    try {
      UserIdentity result = srv.getUserIdentity(mockRequest, AUTH_SERVICE_NAME);
      assertNotNull(result);
      assertEquals(AUTH_SERVICE_NAME, result.getUserPrincipal().getName());
      verify(mockRequest);
    } finally {
      srv.stop();
    }
  }