File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed
spring-security-login-and-registration/src/main/java/org/baeldung/security Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ public MyUserDetailsService() {
4545
4646 @ Override
4747 public UserDetails loadUserByUsername (final String email ) throws UsernameNotFoundException {
48- final String ip = request . getRemoteAddr ();
48+ final String ip = getClientIP ();
4949 if (loginAttemptService .isBlocked (ip )) {
5050 throw new RuntimeException ("blocked" );
5151 }
@@ -88,4 +88,10 @@ private final List<GrantedAuthority> getGrantedAuthorities(final List<String> pr
8888 return authorities ;
8989 }
9090
91+ private String getClientIP () {
92+ final String xfHeader = request .getHeader ("X-Forwarded-For" );
93+ if (xfHeader == null )
94+ return request .getRemoteAddr ();
95+ return xfHeader .split ("," )[0 ];
96+ }
9197}
You can’t perform that action at this time.
0 commit comments