64 def authenticate(self, configurationAttributes, requestParameters, step):
65 authenticationService = CdiUtil.bean(AuthenticationService)
68 print "Basic (lock account). Authenticate for step 1" 69 facesMessages = CdiUtil.bean(FacesMessages)
70 facesMessages.setKeepMessages()
71 identity = CdiUtil.bean(Identity)
72 credentials = identity.getCredentials()
73 user_name = credentials.getUsername()
74 user_password = credentials.getPassword()
75 cacheService= CdiUtil.bean(CacheService)
76 userService = CdiUtil.bean(UserService)
80 if (StringHelper.isNotEmptyString(user_name)
and StringHelper.isNotEmptyString(user_password)):
82 logged_in = authenticationService.authenticate(user_name, user_password)
83 except AuthenticationException:
84 print "Basic (lock account). Authenticate. Failed to authenticate user '%s'" % user_name
87 countInvalidLoginArributeValue = self.getUserAttributeValue(user_name, self.invalidLoginCountAttribute)
88 userSatus = self.getUserAttributeValue(user_name,
"gluuStatus")
89 print "Current user status %s" %userSatus
90 countInvalidLogin = StringHelper.toInteger(countInvalidLoginArributeValue, 0)
92 if countInvalidLogin < self.maximumInvalidLoginAttemps:
93 countInvalidLogin = countInvalidLogin + 1
94 remainingAttempts=self.maximumInvalidLoginAttemps-countInvalidLogin
95 print "Remainings counts %s" %remainingAttempts
96 self.setUserAttributeValue(user_name, self.invalidLoginCountAttribute, StringHelper.toString(countInvalidLogin))
97 if remainingAttempts > 0
and userSatus ==
"active":
98 facesMessages.add(FacesMessage.SEVERITY_INFO, StringHelper.toString(remainingAttempts)+
" more attempt(s) before account is LOCKED!")
101 if countInvalidLogin >= self.maximumInvalidLoginAttemps:
102 self.lockUser(user_name, self.maximumInvalidLoginAttemps)
104 object_from_store = cacheService.get(
None,
"lock_user_" + user_name);
105 if object_from_store ==
None and countInvalidLogin >= self.maximumInvalidLoginAttemps:
106 print "Basic (lock account).Lock Expired for '%s'" % user_name
107 find_user_by_uid = userService.getUser(user_name)
108 self.setUserAttributeValue(user_name,
"gluuStatus",
"active")
109 self.setUserAttributeValue(user_name, self.invalidLoginCountAttribute,
"0")
110 logged_in = authenticationService.authenticate(user_name, user_password)
112 elif object_from_store !=
None:
113 print "Basic (lock account). Lock Expiration time is ACTIVE for user '%s'" % user_name
117 self.setUserAttributeValue(user_name, self.invalidLoginCountAttribute, StringHelper.toString(0))