@Test public void testUnsuccessfulLoginWithIpFiltering() throws Exception { TrustedProxyAuthorizationService srv = new TrustedProxyAuthorizationService(Collections.singletonList(AUTH_SERVICE_NAME), IP_FILTER); HttpServletRequest mockRequest = mock(HttpServletRequest.class); expect(mockRequest.getRemoteAddr()).andReturn("192.167.0.1"); replay(mockRequest); srv.start(); try { UserIdentity result = srv.getUserIdentity(mockRequest, AUTH_SERVICE_NAME); assertNull(result); } finally { srv.stop(); } }
@Override public UserIdentity getUserIdentity(HttpServletRequest request, String name) { int nameHostSeparatorIndex = name.indexOf('/'); String serviceName = nameHostSeparatorIndex > 0 ? name.substring(0, nameHostSeparatorIndex) : name; UserIdentity serviceIdentity = _adminUserStore.getUserIdentity(serviceName); if (_trustedProxyIpPattern != null) { return _trustedProxyIpPattern.matcher(request.getRemoteAddr()).matches() ? serviceIdentity : null; } else { return serviceIdentity; } }
TrustedProxyAuthorizationService extends AbstractLifeCycle implements AuthorizationService { @Override public UserIdentity getUserIdentity(HttpServletRequest request, String name) { int nameHostSeparatorIndex = name.indexOf('/'); String serviceName = nameHostSeparatorIndex > 0 ? name.substring(0, nameHostSeparatorIndex) : name; UserIdentity serviceIdentity = _adminUserStore.getUserIdentity(serviceName); if (_trustedProxyIpPattern != null) { return _trustedProxyIpPattern.matcher(request.getRemoteAddr()).matches() ? serviceIdentity : null; } else { return serviceIdentity; } } }
TrustedProxyAuthorizationService extends AbstractLifeCycle implements AuthorizationService { @Override public UserIdentity getUserIdentity(HttpServletRequest request, String name) { int nameHostSeparatorIndex = name.indexOf('/'); String serviceName = nameHostSeparatorIndex > 0 ? name.substring(0, nameHostSeparatorIndex) : name; UserIdentity serviceIdentity = _adminUserStore.getUserIdentity(serviceName); if (_trustedProxyIpPattern != null) { return _trustedProxyIpPattern.matcher(request.getRemoteAddr()).matches() ? serviceIdentity : null; } else { return serviceIdentity; } } TrustedProxyAuthorizationService(List<String> userNames, String trustedProxyIpPattern); }
TrustedProxyAuthorizationService extends AbstractLifeCycle implements AuthorizationService { @Override public UserIdentity getUserIdentity(HttpServletRequest request, String name) { int nameHostSeparatorIndex = name.indexOf('/'); String serviceName = nameHostSeparatorIndex > 0 ? name.substring(0, nameHostSeparatorIndex) : name; UserIdentity serviceIdentity = _adminUserStore.getUserIdentity(serviceName); if (_trustedProxyIpPattern != null) { return _trustedProxyIpPattern.matcher(request.getRemoteAddr()).matches() ? serviceIdentity : null; } else { return serviceIdentity; } } TrustedProxyAuthorizationService(List<String> userNames, String trustedProxyIpPattern); @Override UserIdentity getUserIdentity(HttpServletRequest request, String name); }
TrustedProxyAuthorizationService extends AbstractLifeCycle implements AuthorizationService { @Override public UserIdentity getUserIdentity(HttpServletRequest request, String name) { int nameHostSeparatorIndex = name.indexOf('/'); String serviceName = nameHostSeparatorIndex > 0 ? name.substring(0, nameHostSeparatorIndex) : name; UserIdentity serviceIdentity = _adminUserStore.getUserIdentity(serviceName); if (_trustedProxyIpPattern != null) { return _trustedProxyIpPattern.matcher(request.getRemoteAddr()).matches() ? serviceIdentity : null; } else { return serviceIdentity; } } TrustedProxyAuthorizationService(List<String> userNames, String trustedProxyIpPattern); @Override UserIdentity getUserIdentity(HttpServletRequest request, String name);  }