gluu
公開メンバ関数 | 公開変数類 | 全メンバ一覧
oxPushExternalAuthenticator.PersonAuthentication クラス
oxPushExternalAuthenticator.PersonAuthentication の継承関係図
Inheritance graph
oxPushExternalAuthenticator.PersonAuthentication 連携図
Collaboration graph

公開メンバ関数

def __init__ (self, currentTimeMillis)
 
def init (self, configurationAttributes)
 
def destroy (self, configurationAttributes)
 
def getApiVersion (self)
 
def isValidAuthenticationMethod (self, usageType, configurationAttributes)
 
def getAlternativeAuthenticationMethod (self, usageType, configurationAttributes)
 
def authenticate (self, configurationAttributes, requestParameters, step)
 
def prepareForStep (self, configurationAttributes, requestParameters, step)
 
def getExtraParametersForStep (self, configurationAttributes, step)
 
def getCountAuthenticationSteps (self, configurationAttributes)
 
def getPageForStep (self, configurationAttributes, step)
 
def isPassedDefaultAuthentication ()
 
def checkStatus (self, mode, request_id, timeout)
 
def logout (self, configurationAttributes, requestParameters)
 

公開変数類

 currentTimeMillis
 
 oxPushClient
 

詳解

構築子と解体子

◆ __init__()

def oxPushExternalAuthenticator.PersonAuthentication.__init__ (   self,
  currentTimeMillis 
)
19  def __init__(self, currentTimeMillis):
20  self.currentTimeMillis = currentTimeMillis
21 

関数詳解

◆ authenticate()

def oxPushExternalAuthenticator.PersonAuthentication.authenticate (   self,
  configurationAttributes,
  requestParameters,
  step 
)
45  def authenticate(self, configurationAttributes, requestParameters, step):
46  userService = CdiUtil.bean(UserService)
47  authenticationService = CdiUtil.bean(AuthenticationService)
48 
49  identity = CdiUtil.bean(Identity)
50  credentials = identity.getCredentials()
51 
52  oxpush_user_timeout = int(configurationAttributes.get("oxpush_user_timeout").getValue2())
53  oxpush_application_name = configurationAttributes.get("oxpush_application_name").getValue2()
54 
55  user_name = credentials.getUsername()
56 
57  if (step == 1):
58  print "oxPush. Authenticate for step 1"
59 
60  user_password = credentials.getPassword()
61  logged_in = False
62  if (StringHelper.isNotEmptyString(user_name) and StringHelper.isNotEmptyString(user_password)):
63  userService = CdiUtil.bean(UserService)
64  logged_in = authenticationService.authenticate(user_name, user_password)
65 
66  if (not logged_in):
67  return False
68 
69  # Get user entry
70  userService = CdiUtil.bean(UserService)
71  find_user_by_uid = authenticationService.getAuthenticatedUser()
72  if (find_user_by_uid == None):
73  print "oxPush. Authenticate for step 1. Failed to find user"
74  return False
75 
76  # Check if the user paired account to phone
77  user_external_uid_attr = userService.getCustomAttribute(find_user_by_uid, "oxExternalUid")
78  if ((user_external_uid_attr == None) or (user_external_uid_attr.getValues() == None)):
79  print "oxPush. Authenticate for step 1. There is no external UIDs for user: ", user_name
80  else:
81  oxpush_user_uid = None
82  for ext_uid in user_external_uid_attr.getValues():
83  if (ext_uid.startswith('oxpush:')):
84  oxpush_user_uid = ext_uid[7:len(ext_uid)]
85  break
86 
87  if (oxpush_user_uid == None):
88  print "oxPush. Authenticate for step 1. There is no oxPush UID for user: ", user_name
89  else:
90  # Check deployment status
91  print "oxPush. Authenticate for step 1. oxpush_user_uid: ", oxpush_user_uid
92  deployment_status = self.oxPushClient.getDeploymentStatus(oxpush_user_uid)
93  if (deployment_status.result):
94  print "oxPush. Authenticate for step 1. Deployment status is valid"
95  if ("enabled" == deployment_status.status):
96  print "oxPush. Authenticate for step 1. Deployment is enabled"
97  identity.setWorkingParameter("oxpush_user_uid", oxpush_user_uid)
98  else:
99  print "oxPush. Authenticate for step 1. Deployment is disabled"
100  return False
101  else:
102  print "oxPush. Authenticate for step 1. Deployment status is invalid. Force user to pair again"
103  # Remove oxpush_user_uid from user entry
104  find_user_by_uid = userService.removeUserAttribute(user_name, "oxExternalUid", "oxpush:" + oxpush_user_uid)
105  if (find_user_by_uid == None):
106  print "oxPush. Authenticate for step 1. Failed to update current user"
107  return False
108 
109  return True
110  elif (step == 2):
111  print "oxPush. Authenticate for step 2"
112 
113  passed_step1 = self.isPassedDefaultAuthentication
114  if (not passed_step1):
115  return False
116 
117  sessionAttributes = identity.getSessionId().getSessionAttributes()
118  if (sessionAttributes == None) or not sessionAttributes.containsKey("oxpush_user_uid"):
119  print "oxPush. Authenticate for step 2. oxpush_user_uid is empty"
120 
121  if (not sessionAttributes.containsKey("oxpush_pairing_uid")):
122  print "oxPush. Authenticate for step 2. oxpush_pairing_uid is empty"
123  return False
124 
125  oxpush_pairing_uid = sessionAttributes.get("oxpush_pairing_uid")
126 
127  # Check pairing status
128  pairing_status = self.checkStatus("pair", oxpush_pairing_uid, oxpush_user_timeout)
129  if (pairing_status == None):
130  print "oxPush. Authenticate for step 2. The pairing has not been authorized by user"
131  return False
132 
133  oxpush_user_uid = pairing_status.deploymentId
134 
135  print "oxPush. Authenticate for step 2. Storing oxpush_user_uid in user entry", oxpush_user_uid
136 
137  # Store oxpush_user_uid in user entry
138  find_user_by_uid = userService.addUserAttribute(user_name, "oxExternalUid", "oxpush:" + oxpush_user_uid)
139  if (find_user_by_uid == None):
140  print "oxPush. Authenticate for step 2. Failed to update current user"
141  return False
142 
143  identity.setWorkingParameter("oxpush_count_login_steps", 2)
144  identity.setWorkingParameter("oxpush_user_uid", oxpush_user_uid)
145  else:
146  print "oxPush. Authenticate for step 2. Deployment status is valid"
147 
148  return True
149  elif (step == 3):
150  print "oxPush. Authenticate for step 3"
151 
152  passed_step1 = self.isPassedDefaultAuthentication
153  if (not passed_step1):
154  return False
155 
156  sessionAttributes = identity.getWorkingParameter("oxpush_user_uid")
157  if (sessionAttributes == None) or not sessionAttributes.containsKey("oxpush_user_uid"):
158  print "oxPush. Authenticate for step 3. oxpush_user_uid is empty"
159  return False
160 
161  oxpush_user_uid = sessionAttributes.get("oxpush_user_uid")
162  passed_step1 = StringHelper.isNotEmptyString(oxpush_user_uid)
163  if (not passed_step1):
164  return False
165 
166  # Initialize authentication process
167  authentication_request = None
168  try:
169  authentication_request = self.oxPushClient.authenticate(oxpush_user_uid, user_name)
170  except java.lang.Exception, err:
171  print "oxPush. Authenticate for step 3. Failed to initialize authentication process: ", err
172  return False
173 
174  if (not authentication_request.result):
175  print "oxPush. Authenticate for step 3. Failed to initialize authentication process"
176  return False
177 
178  # Check authentication status
179  authentication_status = self.checkStatus("authenticate", authentication_request.authenticationId, oxpush_user_timeout)
180  if (authentication_status == None):
181  print "oxPush. Authenticate for step 3. The authentication has not been authorized by user"
182  return False
183 
184  print "oxPush. Authenticate for step 3. The request was granted"
185 
186  return True
187  else:
188  return False
189 

◆ checkStatus()

def oxPushExternalAuthenticator.PersonAuthentication.checkStatus (   self,
  mode,
  request_id,
  timeout 
)
267  def checkStatus(self, mode, request_id, timeout):
268  try:
269  curTime = java.lang.System.currentTimeMillis()
270  endTime = curTime + timeout * 1000
271  while (endTime >= curTime):
272  response_status = None
273  if (StringHelper.equals("pair", mode)):
274  response_status = self.oxPushClient.getPairingStatus(request_id)
275  else:
276  response_status = self.oxPushClient.getAuthenticationStatus(request_id)
277 
278  if (not response_status.result):
279  print "oxPush. CheckStatus. Get false result from oxPushServer"
280  return None
281 
282  status = response_status.status
283 
284  if ("declined" == status):
285  print "oxPush. CheckStatus. The process has been cancelled"
286  return None
287 
288  if ("expired" == status):
289  print "oxPush. CheckStatus. The process has been expired"
290  return None
291 
292  if ("approved" == status):
293  print "oxPush. CheckStatus. The process was approved"
294  return response_status
295 
296  java.lang.Thread.sleep(2000)
297  curTime = java.lang.System.currentTimeMillis()
298  except java.lang.Exception, err:
299  print "oxPush. CheckStatus. Could not check process status: ", err
300  return None
301 
302  print "oxPush. CheckStatus. The process has not received a response from the phone yet"
303 
304  return None
305 

◆ destroy()

def oxPushExternalAuthenticator.PersonAuthentication.destroy (   self,
  configurationAttributes 
)
31  def destroy(self, configurationAttributes):
32  print "oxPush. Destroy"
33  print "oxPush. Destroyed successfully"
34  return True
35 

◆ getAlternativeAuthenticationMethod()

def oxPushExternalAuthenticator.PersonAuthentication.getAlternativeAuthenticationMethod (   self,
  usageType,
  configurationAttributes 
)
42  def getAlternativeAuthenticationMethod(self, usageType, configurationAttributes):
43  return None
44 

◆ getApiVersion()

def oxPushExternalAuthenticator.PersonAuthentication.getApiVersion (   self)
36  def getApiVersion(self):
37  return 1
38 

◆ getCountAuthenticationSteps()

def oxPushExternalAuthenticator.PersonAuthentication.getCountAuthenticationSteps (   self,
  configurationAttributes 
)
242  def getCountAuthenticationSteps(self, configurationAttributes):
243  identity = CdiUtil.bean(Identity)
244  if (identity.isSetWorkingParameter("oxpush_count_login_steps")):
245  return identity.getWorkingParameter("oxpush_count_login_steps")
246 
247  return 3
248 

◆ getExtraParametersForStep()

def oxPushExternalAuthenticator.PersonAuthentication.getExtraParametersForStep (   self,
  configurationAttributes,
  step 
)
236  def getExtraParametersForStep(self, configurationAttributes, step):
237  if (step in [2, 3]):
238  return Arrays.asList("oxpush_user_uid", "oxpush_pairing_uid")
239 
240  return None
241 

◆ getPageForStep()

def oxPushExternalAuthenticator.PersonAuthentication.getPageForStep (   self,
  configurationAttributes,
  step 
)
249  def getPageForStep(self, configurationAttributes, step):
250  if (step == 1):
251  return "/auth/oxpush/oxlogin.xhtml"
252  elif (step == 2):
253  return "/auth/oxpush/oxpair.xhtml"
254  elif (step == 3):
255  return "/auth/oxpush/oxauthenticate.xhtml"
256  return ""
257 

◆ init()

def oxPushExternalAuthenticator.PersonAuthentication.init (   self,
  configurationAttributes 
)
22  def init(self, configurationAttributes):
23  print "oxPush. Initialization"
24 
25  oxpush_server_base_uri = configurationAttributes.get("oxpush_server_base_uri").getValue2()
26  self.oxPushClient = OxPushClient(oxpush_server_base_uri)
27  print "oxPush. Initialized successfully"
28 
29  return True
30 

◆ isPassedDefaultAuthentication()

def oxPushExternalAuthenticator.PersonAuthentication.isPassedDefaultAuthentication ( )
258  def isPassedDefaultAuthentication():
259  identity = CdiUtil.bean(Identity)
260  credentials = identity.getCredentials()
261 
262  user_name = credentials.getUsername()
263  passed_step1 = StringHelper.isNotEmptyString(user_name)
264 
265  return passed_step1
266 

◆ isValidAuthenticationMethod()

def oxPushExternalAuthenticator.PersonAuthentication.isValidAuthenticationMethod (   self,
  usageType,
  configurationAttributes 
)
39  def isValidAuthenticationMethod(self, usageType, configurationAttributes):
40  return True
41 

◆ logout()

def oxPushExternalAuthenticator.PersonAuthentication.logout (   self,
  configurationAttributes,
  requestParameters 
)
306  def logout(self, configurationAttributes, requestParameters):
307  return True
308 

◆ prepareForStep()

def oxPushExternalAuthenticator.PersonAuthentication.prepareForStep (   self,
  configurationAttributes,
  requestParameters,
  step 
)
190  def prepareForStep(self, configurationAttributes, requestParameters, step):
191  identity = CdiUtil.bean(Identity)
192 
193  oxpush_application_name = configurationAttributes.get("oxpush_application_name").getValue2()
194 
195  if (step == 1):
196  print "oxPush. Prepare for step 1"
197  oxpush_android_download_url = configurationAttributes.get("oxpush_android_download_url").getValue2()
198  identity.setWorkingParameter("oxpush_android_download_url", oxpush_android_download_url)
199  elif (step == 2):
200  print "oxPush. Prepare for step 2"
201 
202  passed_step1 = self.isPassedDefaultAuthentication
203  if (not passed_step1):
204  return False
205 
206  identity = CdiUtil.bean(Identity)
207  credentials = identity.getCredentials()
208 
209  user_name = credentials.getUsername()
210 
211  sessionAttributes = identity.getSessionId().getSessionAttributes()
212  if (sessionAttributes == None) or not sessionAttributes.containsKey("oxpush_user_uid"):
213  print "oxPush. Prepare for step 2. oxpush_user_uid is empty"
214 
215  # Initialize pairing process
216  pairing_process = None
217  try:
218  pairing_process = self.oxPushClient.pair(oxpush_application_name, user_name)
219  except java.lang.Exception, err:
220  print "oxPush. Prepare for step 2. Failed to initialize pairing process: ", err
221  return False
222 
223  if (not pairing_process.result):
224  print "oxPush. Prepare for step 2. Failed to initialize pairing process"
225  return False
226 
227  pairing_id = pairing_process.pairingId
228  print "oxPush. Prepare for step 2. Pairing Id: ", pairing_id
229 
230  identity.setWorkingParameter("oxpush_pairing_uid", pairing_id)
231  identity.setWorkingParameter("oxpush_pairing_code", pairing_process.pairingCode)
232  identity.setWorkingParameter("oxpush_pairing_qr_image", pairing_process.pairingQrImage)
233 
234  return True
235 

メンバ詳解

◆ currentTimeMillis

oxPushExternalAuthenticator.PersonAuthentication.currentTimeMillis

◆ oxPushClient

oxPushExternalAuthenticator.PersonAuthentication.oxPushClient

このクラス詳解は次のファイルから抽出されました: