4040import org .springframework .validation .BindException ;
4141import org .springframework .web .bind .annotation .*;
4242
43- import jakarta .servlet .http .HttpServletRequest ;
4443import jakarta .servlet .http .HttpServletResponse ;
4544
4645import java .util .Arrays ;
@@ -80,13 +79,11 @@ public class UserController {
8079 private String domainBanExclusion ;
8180
8281 private static final Logger logger = LoggerFactory .getLogger (UserController .class );
83- private static final String REAL_IP_ADDRESS_HEADER = "X-Real-IP" ;
84-
8582 @ RequestMapping (method = RequestMethod .POST , value = "/" , produces = {"application/json" })
8683 @ ResponseStatus (value = HttpStatus .CREATED )
87- public void registerUser (@ RequestBody RestUserRegistration registration , @ NotNull HttpServletRequest request ,
84+ public void registerUser (@ RequestBody RestUserRegistration registration ,
8885 @ NotNull HttpServletResponse response ) throws WiseMappingException , BindException {
89- logger .debug ("Register new user:" + registration . getEmail () );
86+ logger .debug ("Register new user." );
9087 if (!registrationEnabled ) {
9188 throw new WiseMappingException ("Registration is disabled. You can enable it using app.registration.enabled" );
9289 }
@@ -103,13 +100,7 @@ public void registerUser(@RequestBody RestUserRegistration registration, @NotNul
103100 throw new PasswordTooLongException ();
104101 }
105102
106- // If tomcat is behind a reverse proxy, ip needs to be found in other header.
107- String remoteIp = request .getHeader (REAL_IP_ADDRESS_HEADER );
108- if (remoteIp == null || remoteIp .isEmpty ()) {
109- remoteIp = request .getRemoteAddr ();
110- }
111- logger .debug ("Remote address" + remoteIp );
112- verify (registration , remoteIp );
103+ verify (registration );
113104
114105 final Account user = new Account ();
115106 user .setEmail (registration .getEmail ().trim ());
@@ -150,7 +141,7 @@ public void activateAccount(@RequestParam long code) throws WiseMappingException
150141 userService .activateAccount (code );
151142 }
152143
153- private void verify (@ NotNull final RestUserRegistration registration , @ NotNull String remoteAddress )
144+ private void verify (@ NotNull final RestUserRegistration registration )
154145 throws BindException {
155146
156147 final BindException errors = new RegistrationException (registration , "registration" );
@@ -163,7 +154,7 @@ private void verify(@NotNull final RestUserRegistration registration, @NotNull S
163154 if (registrationCaptchaEnabled ) {
164155 final String recaptcha = registration .getRecaptcha ();
165156 if (recaptcha != null ) {
166- final String reCaptchaResponse = captchaService .verifyRecaptcha (remoteAddress , recaptcha );
157+ final String reCaptchaResponse = captchaService .verifyRecaptcha (recaptcha );
167158 if (reCaptchaResponse != null && !reCaptchaResponse .isEmpty ()) {
168159 errors .rejectValue ("recaptcha" , reCaptchaResponse );
169160 }
0 commit comments