def init(self, configurationAttributes): print "oxPush. Initialization" oxpush_server_base_uri = configurationAttributes.get("oxpush_server_base_uri").getValue2() self.oxPushClient = OxPushClient(oxpush_server_base_uri) print "oxPush. Initialized successfully" return True
class PersonAuthentication(PersonAuthenticationType): def __init__(self, currentTimeMillis): self.currentTimeMillis = currentTimeMillis def init(self, configurationAttributes): print "oxPush. Initialization" oxpush_server_base_uri = configurationAttributes.get("oxpush_server_base_uri").getValue2() self.oxPushClient = OxPushClient(oxpush_server_base_uri) print "oxPush. Initialized successfully" return True def destroy(self, configurationAttributes): print "oxPush. Destroy" print "oxPush. Destroyed successfully" return True def getApiVersion(self): return 1 def isValidAuthenticationMethod(self, usageType, configurationAttributes): return True def getAlternativeAuthenticationMethod(self, usageType, configurationAttributes): return None def authenticate(self, configurationAttributes, requestParameters, step): userService = CdiUtil.bean(UserService) authenticationService = CdiUtil.bean(AuthenticationService) identity = CdiUtil.bean(Identity) credentials = identity.getCredentials() oxpush_user_timeout = int(configurationAttributes.get("oxpush_user_timeout").getValue2()) oxpush_application_name = configurationAttributes.get("oxpush_application_name").getValue2() user_name = credentials.getUsername() if (step == 1): print "oxPush. Authenticate for step 1" user_password = credentials.getPassword() logged_in = False if (StringHelper.isNotEmptyString(user_name) and StringHelper.isNotEmptyString(user_password)): userService = CdiUtil.bean(UserService) logged_in = authenticationService.authenticate(user_name, user_password) if (not logged_in): return False # Find user by uid userService = CdiUtil.bean(UserService) find_user_by_uid = userService.getUser(user_name) if (find_user_by_uid == None): print "oxPush. Authenticate for step 1. Failed to find user" return False # Check if the user paired account to phone user_external_uid_attr = userService.getCustomAttribute(find_user_by_uid, "oxExternalUid") if ((user_external_uid_attr == None) or (user_external_uid_attr.getValues() == None)): print "oxPush. Authenticate for step 1. There is no external UIDs for user: "******"oxPush. Authenticate for step 1. There is no oxPush UID for user: "******"oxPush. Authenticate for step 1. oxpush_user_uid: ", oxpush_user_uid deployment_status = self.oxPushClient.getDeploymentStatus(oxpush_user_uid) if (deployment_status.result): print "oxPush. Authenticate for step 1. Deployment status is valid" if ("enabled" == deployment_status.status): print "oxPush. Authenticate for step 1. Deployment is enabled" identity.setWorkingParameter("oxpush_user_uid", oxpush_user_uid) else: print "oxPush. Authenticate for step 1. Deployment is disabled" return False else: print "oxPush. Authenticate for step 1. Deployment status is invalid. Force user to pair again" # Remove oxpush_user_uid from user entry find_user_by_uid = userService.removeUserAttribute(user_name, "oxExternalUid", "oxpush:" + oxpush_user_uid) if (find_user_by_uid == None): print "oxPush. Authenticate for step 1. Failed to update current user" return False return True elif (step == 2): print "oxPush. Authenticate for step 2" passed_step1 = self.isPassedDefaultAuthentication if (not passed_step1): return False sessionAttributes = identity.getSessionId().getSessionAttributes() if (sessionAttributes == None) or not sessionAttributes.containsKey("oxpush_user_uid"): print "oxPush. Authenticate for step 2. oxpush_user_uid is empty" if (not sessionAttributes.containsKey("oxpush_pairing_uid")): print "oxPush. Authenticate for step 2. oxpush_pairing_uid is empty" return False oxpush_pairing_uid = sessionAttributes.get("oxpush_pairing_uid") # Check pairing status pairing_status = self.checkStatus("pair", oxpush_pairing_uid, oxpush_user_timeout) if (pairing_status == None): print "oxPush. Authenticate for step 2. The pairing has not been authorized by user" return False oxpush_user_uid = pairing_status.deploymentId print "oxPush. Authenticate for step 2. Storing oxpush_user_uid in user entry", oxpush_user_uid # Store oxpush_user_uid in user entry find_user_by_uid = userService.addUserAttribute(user_name, "oxExternalUid", "oxpush:" + oxpush_user_uid) if (find_user_by_uid == None): print "oxPush. Authenticate for step 2. Failed to update current user" return False identity.setWorkingParameter("oxpush_count_login_steps", 2) identity.setWorkingParameter("oxpush_user_uid", oxpush_user_uid) else: print "oxPush. Authenticate for step 2. Deployment status is valid" return True elif (step == 3): print "oxPush. Authenticate for step 3" passed_step1 = self.isPassedDefaultAuthentication if (not passed_step1): return False sessionAttributes = identity.getWorkingParameter("oxpush_user_uid") if (sessionAttributes == None) or not sessionAttributes.containsKey("oxpush_user_uid"): print "oxPush. Authenticate for step 3. oxpush_user_uid is empty" return False oxpush_user_uid = sessionAttributes.get("oxpush_user_uid") passed_step1 = StringHelper.isNotEmptyString(oxpush_user_uid) if (not passed_step1): return False # Initialize authentication process authentication_request = None try: authentication_request = self.oxPushClient.authenticate(oxpush_user_uid, user_name) except java.lang.Exception, err: print "oxPush. Authenticate for step 3. Failed to initialize authentication process: ", err return False if (not authentication_request.result): print "oxPush. Authenticate for step 3. Failed to initialize authentication process" return False # Check authentication status authentication_status = self.checkStatus("authenticate", authentication_request.authenticationId, oxpush_user_timeout) if (authentication_status == None): print "oxPush. Authenticate for step 3. The authentication has not been authorized by user" return False print "oxPush. Authenticate for step 3. The request was granted" return True else:
class PersonAuthentication(PersonAuthenticationType): def __init__(self, currentTimeMillis): self.currentTimeMillis = currentTimeMillis def init(self, configurationAttributes): print "oxPush. Initialization" oxpush_server_base_uri = configurationAttributes.get("oxpush_server_base_uri").getValue2() self.oxPushClient = OxPushClient(oxpush_server_base_uri) print "oxPush. Initialized successfully" return True def destroy(self, configurationAttributes): print "oxPush. Destroy" print "oxPush. Destroyed successfully" return True def getApiVersion(self): return 1 def isValidAuthenticationMethod(self, usageType, configurationAttributes): return True def getAlternativeAuthenticationMethod(self, usageType, configurationAttributes): return None def authenticate(self, configurationAttributes, requestParameters, step): context = Contexts.getEventContext() userService = UserService.instance() oxpush_user_timeout = int(configurationAttributes.get("oxpush_user_timeout").getValue2()) oxpush_application_name = configurationAttributes.get("oxpush_application_name").getValue2() credentials = Identity.instance().getCredentials() user_name = credentials.getUsername() if (step == 1): print "oxPush. Authenticate for step 1" user_password = credentials.getPassword() logged_in = False if (StringHelper.isNotEmptyString(user_name) and StringHelper.isNotEmptyString(user_password)): userService = UserService.instance() logged_in = userService.authenticate(user_name, user_password) if (not logged_in): return False # Find user by uid userService = UserService.instance() find_user_by_uid = userService.getUser(user_name) if (find_user_by_uid == None): print "oxPush. Authenticate for step 1. Failed to find user" return False # Check if the user paired account to phone user_external_uid_attr = userService.getCustomAttribute(find_user_by_uid, "oxExternalUid") if ((user_external_uid_attr == None) or (user_external_uid_attr.getValues() == None)): print "oxPush. Authenticate for step 1. There is no external UIDs for user: "******"oxPush. Authenticate for step 1. There is no oxPush UID for user: "******"oxPush. Authenticate for step 1. oxpush_user_uid: ", oxpush_user_uid deployment_status = self.oxPushClient.getDeploymentStatus(oxpush_user_uid); if (deployment_status.result): print "oxPush. Authenticate for step 1. Deployment status is valid" if ("enabled" == deployment_status.status): print "oxPush. Authenticate for step 1. Deployment is enabled" context.set("oxpush_user_uid", oxpush_user_uid) else: print "oxPush. Authenticate for step 1. Deployment is disabled" return False else: print "oxPush. Authenticate for step 1. Deployment status is invalid. Force user to pair again" # Remove oxpush_user_uid from user entry find_user_by_uid = userService.removeUserAttribute(user_name, "oxExternalUid", "oxpush:" + oxpush_user_uid) if (find_user_by_uid == None): print "oxPush. Authenticate for step 1. Failed to update current user" return False return True elif (step == 2): print "oxPush. Authenticate for step 2" passed_step1 = self.isPassedDefaultAuthentication if (not passed_step1): return False sessionAttributes = context.get("sessionAttributes") if (sessionAttributes == None) or not sessionAttributes.containsKey("oxpush_user_uid"): print "oxPush. Authenticate for step 2. oxpush_user_uid is empty" if (not sessionAttributes.containsKey("oxpush_pairing_uid")): print "oxPush. Authenticate for step 2. oxpush_pairing_uid is empty" return False oxpush_pairing_uid = sessionAttributes.get("oxpush_pairing_uid") # Check pairing status pairing_status = self.checkStatus("pair", oxpush_pairing_uid, oxpush_user_timeout) if (pairing_status == None): print "oxPush. Authenticate for step 2. The pairing has not been authorized by user" return False oxpush_user_uid = pairing_status.deploymentId print "oxPush. Authenticate for step 2. Storing oxpush_user_uid in user entry", oxpush_user_uid # Store oxpush_user_uid in user entry find_user_by_uid = userService.addUserAttribute(user_name, "oxExternalUid", "oxpush:" + oxpush_user_uid) if (find_user_by_uid == None): print "oxPush. Authenticate for step 2. Failed to update current user" return False context.set("oxpush_count_login_steps", 2) context.set("oxpush_user_uid", oxpush_user_uid) else: print "oxPush. Authenticate for step 2. Deployment status is valid" return True elif (step == 3): print "oxPush. Authenticate for step 3" passed_step1 = self.isPassedDefaultAuthentication if (not passed_step1): return False sessionAttributes = context.get("oxpush_user_uid") if (sessionAttributes == None) or not sessionAttributes.containsKey("oxpush_user_uid"): print "oxPush. Authenticate for step 3. oxpush_user_uid is empty" return False oxpush_user_uid = sessionAttributes.get("oxpush_user_uid") passed_step1 = StringHelper.isNotEmptyString(oxpush_user_uid) if (not passed_step1): return False # Initialize authentication process authentication_request = None try: authentication_request = self.oxPushClient.authenticate(oxpush_user_uid, user_name); except java.lang.Exception, err: print "oxPush. Authenticate for step 3. Failed to initialize authentication process: ", err return False if (not authentication_request.result): print "oxPush. Authenticate for step 3. Failed to initialize authentication process" return False # Check authentication status authentication_status = self.checkStatus("authenticate", authentication_request.authenticationId, oxpush_user_timeout) if (authentication_status == None): print "oxPush. Authenticate for step 3. The authentication has not been authorized by user" return False print "oxPush. Authenticate for step 3. The request was granted" return True else: