@@ -32,9 +32,8 @@ class UserService {
32
32
33
33
public static final String USER_ROLE = " USER"
34
34
35
- def grailsApplication
36
35
def permissionService
37
-
36
+ def grailsApplication
38
37
def events = [:]
39
38
40
39
/**
@@ -284,6 +283,7 @@ class UserService {
284
283
user. addToPasswdHistory(crypt)
285
284
286
285
user. save()
286
+
287
287
if (user. hasErrors()) {
288
288
log. error(" Unable to assign random password to user [$user . id ]$user . username " )
289
289
user. errors. each { log. error(it) }
@@ -305,13 +305,10 @@ class UserService {
305
305
}
306
306
307
307
log. debug(" Creating new record for user [$user . id ]$user . username login" )
308
-
308
+
309
309
def record = new LoginRecord ()
310
-
311
- String ip = request. getRemoteAddr()
312
- // it will be different then ip if request was forwarded by a proxy
313
- String resolvedIp = getClientIpAddress(request)
314
-
310
+ String resolvedIp = getClientIpAddress(request)
311
+
315
312
record. remoteAddr = resolvedIp
316
313
record. remoteHost = request. getRemoteHost()
317
314
record. userAgent = request. getHeader(" User-Agent" )
@@ -329,7 +326,7 @@ class UserService {
329
326
330
327
user. save()
331
328
332
- if (record . hasErrors()) {
329
+ if (user . hasErrors()) {
333
330
log. error(" Unable to update user [$user . id ]$user . username with new login record" )
334
331
user. errors. each { log. error(it) }
335
332
@@ -384,15 +381,14 @@ class UserService {
384
381
boolean validatePass (UserBase user , boolean checkOnly ) {
385
382
log. debug(" Validating user entered password" )
386
383
387
- if (user. pass == null || user. pass. length() < grailsApplication . config . nimble . passwords. minlength) {
384
+ if (user. pass == null || user. pass. length() < nimbleConfig . passwords. minlength) {
388
385
log. debug(" Password to short" )
389
386
user. errors. rejectValue(' pass' , ' nimble.user.password.required' )
390
387
return false
391
388
}
392
389
393
- if (user. passConfirm == null || user. passConfirm. length() < grailsApplication . config . nimble . passwords. minlength) {
390
+ if (user. passConfirm == null || user. passConfirm. length() < nimbleConfig . passwords. minlength) {
394
391
log. debug(" Confirmation password to short" )
395
-
396
392
user. errors. rejectValue(' passConfirm' , ' nimble.user.passconfirm.required' )
397
393
return false
398
394
}
@@ -403,25 +399,25 @@ class UserService {
403
399
return false
404
400
}
405
401
406
- if (grailsApplication . config . nimble . passwords. mustcontain. lowercase && ! (user. pass =~ / ^.*[a-z].*$/ )) {
402
+ if (nimbleConfig . passwords. mustcontain. lowercase && ! (user. pass =~ / ^.*[a-z].*$/ )) {
407
403
log. debug(" Password does not contain lower case letters" )
408
404
user. errors. rejectValue(' pass' , ' nimble.user.password.no.lowercase' )
409
405
return false
410
406
}
411
407
412
- if (grailsApplication . config . nimble . passwords. mustcontain. uppercase && ! (user. pass =~ / ^.*[A-Z].*$/ )) {
408
+ if (nimbleConfig . passwords. mustcontain. uppercase && ! (user. pass =~ / ^.*[A-Z].*$/ )) {
413
409
log. debug(" Password does not contain uppercase letters" )
414
410
user. errors. rejectValue(' pass' , ' nimble.user.password.no.uppercase' )
415
411
return false
416
412
}
417
413
418
- if (grailsApplication . config . nimble . passwords. mustcontain. numbers && ! (user. pass =~ / ^.*[0-9].*$/ )) {
414
+ if (nimbleConfig . passwords. mustcontain. numbers && ! (user. pass =~ / ^.*[0-9].*$/ )) {
419
415
log. debug(" Password does not contain numbers" )
420
416
user. errors. rejectValue(' pass' , ' nimble.user.password.no.numbers' )
421
417
return false
422
418
}
423
419
424
- if (grailsApplication . config . nimble . passwords. mustcontain. symbols && ! (user. pass =~ / ^.*\W .*$/ )) {
420
+ if (nimbleConfig . passwords. mustcontain. symbols && ! (user. pass =~ / ^.*\W .*$/ )) {
425
421
log. debug(" Password does not contain symbols" )
426
422
user. errors. rejectValue(' pass' , ' nimble.user.password.no.symbols' )
427
423
return false
@@ -430,10 +426,12 @@ class UserService {
430
426
def pwEnc = new Sha256Hash (user. pass)
431
427
def crypt = pwEnc. toHex()
432
428
433
- if (user. passwdHistory != null && user. passwdHistory. contains(crypt)) {
434
- log. debug(" Password was previously utilized" )
435
- user. errors. rejectValue(' pass' , ' nimble.user.password.duplicate' )
436
- return false
429
+ if (! nimbleConfig. passwords. allowreuse) {
430
+ if (user. passwdHistory != null && user. passwdHistory. contains(crypt)) {
431
+ log. debug(" Password was previously utilized" )
432
+ user. errors. rejectValue(' pass' , ' nimble.user.password.duplicate' )
433
+ return false
434
+ }
437
435
}
438
436
439
437
if (! user. hasErrors() && ! checkOnly) {
@@ -443,4 +441,9 @@ class UserService {
443
441
444
442
return true
445
443
}
444
+
445
+ private getNimbleConfig () {
446
+ grailsApplication. config. nimble
447
+ }
448
+
446
449
}
0 commit comments