gluu
公開メンバ関数 | 公開変数類 | 全メンバ一覧
UafExternalAuthenticator.PersonAuthentication クラス
UafExternalAuthenticator.PersonAuthentication の継承関係図
Inheritance graph
UafExternalAuthenticator.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 logout (self, configurationAttributes, requestParameters)
 
def setRequestScopedParameters (self, identity)
 
def processBasicAuthentication (self, credentials)
 
def findEnrollments (self, credentials)
 
def executePost (self, request_uri, request_data)
 

公開変数類

 currentTimeMillis
 
 uaf_server_uri
 
 uaf_policy_name
 
 send_push_notifaction
 
 registration_uri
 
 customQrOptions
 
 http_client
 

詳解

構築子と解体子

◆ __init__()

def UafExternalAuthenticator.PersonAuthentication.__init__ (   self,
  currentTimeMillis 
)
33  def __init__(self, currentTimeMillis):
34  self.currentTimeMillis = currentTimeMillis
35 

関数詳解

◆ authenticate()

def UafExternalAuthenticator.PersonAuthentication.authenticate (   self,
  configurationAttributes,
  requestParameters,
  step 
)
86  def authenticate(self, configurationAttributes, requestParameters, step):
87  identity = CdiUtil.bean(Identity)
88  credentials = identity.getCredentials()
89 
90  session_attributes = identity.getSessionId().getSessionAttributes()
91 
92  self.setRequestScopedParameters(identity)
93 
94  if (step == 1):
95  print "UAF. Authenticate for step 1"
96 
97  user_name = credentials.getUsername()
98 
99  authenticated_user = self.processBasicAuthentication(credentials)
100  if authenticated_user == None:
101  return False
102 
103  uaf_auth_method = "authenticate"
104  # Uncomment this block if you need to allow user second device registration
105  #enrollment_mode = ServerUtil.getFirstValue(requestParameters, "loginForm:registerButton")
106  #if StringHelper.isNotEmpty(enrollment_mode):
107  # uaf_auth_method = "enroll"
108 
109  if uaf_auth_method == "authenticate":
110  user_enrollments = self.findEnrollments(credentials)
111  if len(user_enrollments) == 0:
112  uaf_auth_method = "enroll"
113  print "UAF. Authenticate for step 1. There is no UAF enrollment for user '%s'. Changing uaf_auth_method to '%s'" % (user_name, uaf_auth_method)
114 
115  print "UAF. Authenticate for step 1. uaf_auth_method: '%s'" % uaf_auth_method
116 
117  identity.setWorkingParameter("uaf_auth_method", uaf_auth_method)
118 
119  return True
120  elif (step == 2):
121  print "UAF. Authenticate for step 2"
122 
123  session_id = CdiUtil.bean(SessionIdService).getSessionIdFromCookie()
124  if StringHelper.isEmpty(session_id):
125  print "UAF. Prepare for step 2. Failed to determine session_id"
126  return False
127 
128  user = authenticationService.getAuthenticatedUser()
129  if (user == None):
130  print "UAF. Authenticate for step 2. Failed to determine user name"
131  return False
132  user_name = user.getUserId()
133 
134  uaf_auth_result = ServerUtil.getFirstValue(requestParameters, "auth_result")
135  if uaf_auth_result != "success":
136  print "UAF. Authenticate for step 2. auth_result is '%s'" % uaf_auth_result
137  return False
138 
139  # Restore state from session
140  uaf_auth_method = session_attributes.get("uaf_auth_method")
141 
142  if not uaf_auth_method in ['enroll', 'authenticate']:
143  print "UAF. Authenticate for step 2. Failed to authenticate user. uaf_auth_method: '%s'" % uaf_auth_method
144  return False
145 
146  # Request STATUS_OBB
147  if True:
148  #TODO: Remove this condition
149  # It's workaround becuase it's not possible to call STATUS_OBB 2 times. First time on browser and second ime on server
150  uaf_user_device_handle = ServerUtil.getFirstValue(requestParameters, "auth_handle")
151  else:
152  uaf_obb_auth_method = session_attributes.get("uaf_obb_auth_method")
153  uaf_obb_server_uri = session_attributes.get("uaf_obb_server_uri")
154  uaf_obb_start_response = session_attributes.get("uaf_obb_start_response")
155 
156  # Prepare STATUS_OBB
157  uaf_obb_start_response_json = json.loads(uaf_obb_start_response)
158  uaf_obb_status_request_dictionary = { "operation": "STATUS_%s" % uaf_obb_auth_method,
159  "userName": user_name,
160  "needDetails": 1,
161  "oobStatusHandle": uaf_obb_start_response_json["oobStatusHandle"],
162  }
163 
164  uaf_obb_status_request = json.dumps(uaf_obb_status_request_dictionary, separators=(',',':'))
165  print "UAF. Authenticate for step 2. Prepared STATUS request: '%s' to send to '%s'" % (uaf_obb_status_request, uaf_obb_server_uri)
166 
167  uaf_status_obb_response = self.executePost(uaf_obb_server_uri, uaf_obb_status_request)
168  if uaf_status_obb_response == None:
169  return False
170 
171  print "UAF. Authenticate for step 2. Get STATUS response: '%s'" % uaf_status_obb_response
172  uaf_status_obb_response_json = json.loads(uaf_status_obb_response)
173 
174  if uaf_status_obb_response_json["statusCode"] != 4000:
175  print "UAF. Authenticate for step 2. UAF operation status is invalid. statusCode: '%s'" % uaf_status_obb_response_json["statusCode"]
176  return False
177 
178  uaf_user_device_handle = uaf_status_obb_response_json["additionalInfo"]["authenticatorsResult"]["handle"]
179 
180  if StringHelper.isEmpty(uaf_user_device_handle):
181  print "UAF. Prepare for step 2. Failed to get UAF handle"
182  return False
183 
184  uaf_user_external_uid = "uaf:%s" % uaf_user_device_handle
185  print "UAF. Authenticate for step 2. UAF handle: '%s'" % uaf_user_external_uid
186 
187  if uaf_auth_method == "authenticate":
188  # Validate if user used device with same keYHandle
189  user_enrollments = self.findEnrollments(credentials)
190  if len(user_enrollments) == 0:
191  uaf_auth_method = "enroll"
192  print "UAF. Authenticate for step 2. There is no UAF enrollment for user '%s'." % user_name
193  return False
194 
195  for user_enrollment in user_enrollments:
196  if StringHelper.equalsIgnoreCase(user_enrollment, uaf_user_device_handle):
197  print "UAF. Authenticate for step 2. There is UAF enrollment for user '%s'. User authenticated successfully" % user_name
198  return True
199  else:
200  userService = CdiUtil.bean(UserService)
201 
202  # Double check just to make sure. We did checking in previous step
203  # Check if there is user which has uaf_user_external_uid
204  # Avoid mapping user cert to more than one IDP account
205  find_user_by_external_uid = userService.getUserByAttribute("oxExternalUid", uaf_user_external_uid)
206  if find_user_by_external_uid == None:
207  # Add uaf_user_external_uid to user's external GUID list
208  find_user_by_external_uid = userService.addUserAttribute(user_name, "oxExternalUid", uaf_user_external_uid)
209  if find_user_by_external_uid == None:
210  print "UAF. Authenticate for step 2. Failed to update current user"
211  return False
212 
213  return True
214 
215  return False
216  else:
217  return False
218 

◆ destroy()

def UafExternalAuthenticator.PersonAuthentication.destroy (   self,
  configurationAttributes 
)
72  def destroy(self, configurationAttributes):
73  print "UAF. Destroy"
74  print "UAF. Destroyed successfully"
75  return True
76 

◆ executePost()

def UafExternalAuthenticator.PersonAuthentication.executePost (   self,
  request_uri,
  request_data 
)
362  def executePost(self, request_uri, request_data):
363  httpService = CdiUtil.bean(HttpService)
364 
365  request_headers = { "Content-type" : "application/json; charset=UTF-8", "Accept" : "application/json" }
366 
367  try:
368  http_service_response = httpService.executePost(self.http_client, request_uri, None, request_headers, request_data)
369  http_response = http_service_response.getHttpResponse()
370  except:
371  print "UAF. Validate POST response. Exception: ", sys.exc_info()[1]
372  return None
373 
374  try:
375  if not httpService.isResponseStastusCodeOk(http_response):
376  print "UAF. Validate POST response. Get invalid response from server: %s" % str(http_response.getStatusLine().getStatusCode())
377  httpService.consume(http_response)
378  return None
379 
380  response_bytes = httpService.getResponseContent(http_response)
381  response_string = httpService.convertEntityToString(response_bytes)
382  httpService.consume(http_response)
383 
384  return response_string
385  finally:
386  http_service_response.closeConnection()
387  return None
388 

◆ findEnrollments()

def UafExternalAuthenticator.PersonAuthentication.findEnrollments (   self,
  credentials 
)
338  def findEnrollments(self, credentials):
339  result = []
340 
341  userService = CdiUtil.bean(UserService)
342  user_name = credentials.getUsername()
343  user = userService.getUser(user_name, "oxExternalUid")
344  if user == None:
345  print "UAF. Find enrollments. Failed to find user"
346  return result
347 
348  user_custom_ext_attribute = userService.getCustomAttribute(user, "oxExternalUid")
349  if user_custom_ext_attribute == None:
350  return result
351 
352  uaf_prefix = "uaf:"
353  uaf_prefix_length = len(uaf_prefix)
354  for user_external_uid in user_custom_ext_attribute.getValues():
355  index = user_external_uid.find(uaf_prefix)
356  if index != -1:
357  enrollment_uid = user_external_uid[uaf_prefix_length:]
358  result.append(enrollment_uid)
359 
360  return result
361 

◆ getAlternativeAuthenticationMethod()

def UafExternalAuthenticator.PersonAuthentication.getAlternativeAuthenticationMethod (   self,
  usageType,
  configurationAttributes 
)
83  def getAlternativeAuthenticationMethod(self, usageType, configurationAttributes):
84  return None
85 

◆ getApiVersion()

def UafExternalAuthenticator.PersonAuthentication.getApiVersion (   self)
77  def getApiVersion(self):
78  return 1
79 

◆ getCountAuthenticationSteps()

def UafExternalAuthenticator.PersonAuthentication.getCountAuthenticationSteps (   self,
  configurationAttributes 
)
300  def getCountAuthenticationSteps(self, configurationAttributes):
301  return 2
302 

◆ getExtraParametersForStep()

def UafExternalAuthenticator.PersonAuthentication.getExtraParametersForStep (   self,
  configurationAttributes,
  step 
)
297  def getExtraParametersForStep(self, configurationAttributes, step):
298  return Arrays.asList("uaf_auth_method", "uaf_obb_auth_method", "uaf_obb_server_uri", "uaf_obb_start_response")
299 

◆ getPageForStep()

def UafExternalAuthenticator.PersonAuthentication.getPageForStep (   self,
  configurationAttributes,
  step 
)
303  def getPageForStep(self, configurationAttributes, step):
304  if (step == 2):
305  return "/auth/uaf/login.xhtml"
306 
307  return ""
308 

◆ init()

def UafExternalAuthenticator.PersonAuthentication.init (   self,
  configurationAttributes 
)
36  def init(self, configurationAttributes):
37  print "UAF. Initialization"
38 
39  if not configurationAttributes.containsKey("uaf_server_uri"):
40  print "UAF. Initialization. Property uaf_server_uri is mandatory"
41  return False
42 
43  self.uaf_server_uri = configurationAttributes.get("uaf_server_uri").getValue2()
44 
45  self.uaf_policy_name = "default"
46  if configurationAttributes.containsKey("uaf_policy_name"):
47  self.uaf_policy_name = configurationAttributes.get("uaf_policy_name").getValue2()
48 
49  self.send_push_notifaction = False
50  if configurationAttributes.containsKey("send_push_notifaction"):
51  self.send_push_notifaction = StringHelper.toBoolean(configurationAttributes.get("send_push_notifaction").getValue2(), False)
52 
53  self.registration_uri = None
54  if configurationAttributes.containsKey("registration_uri"):
55  self.registration_uri = configurationAttributes.get("registration_uri").getValue2()
56 
57  self.customQrOptions = {}
58  if configurationAttributes.containsKey("qr_options"):
59  self.customQrOptions = configurationAttributes.get("qr_options").getValue2()
60 
61  print "UAF. Initializing HTTP client"
62  httpService = CdiUtil.bean(HttpService)
63  self.http_client = httpService.getHttpsClient()
64  http_client_params = self.http_client.getParams()
65  http_client_params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 15 * 1000)
66 
67  print "UAF. Initialized successfully. uaf_server_uri: '%s', uaf_policy_name: '%s', send_push_notifaction: '%s', registration_uri: '%s', qr_options: '%s'" % (self.uaf_server_uri, self.uaf_policy_name, self.send_push_notifaction, self.registration_uri, self.customQrOptions)
68 
69  print "UAF. Initialized successfully"
70  return True
71 

◆ isValidAuthenticationMethod()

def UafExternalAuthenticator.PersonAuthentication.isValidAuthenticationMethod (   self,
  usageType,
  configurationAttributes 
)
80  def isValidAuthenticationMethod(self, usageType, configurationAttributes):
81  return True
82 

◆ logout()

def UafExternalAuthenticator.PersonAuthentication.logout (   self,
  configurationAttributes,
  requestParameters 
)
309  def logout(self, configurationAttributes, requestParameters):
310  return True
311 

◆ prepareForStep()

def UafExternalAuthenticator.PersonAuthentication.prepareForStep (   self,
  configurationAttributes,
  requestParameters,
  step 
)
219  def prepareForStep(self, configurationAttributes, requestParameters, step):
220  authenticationService = CdiUtil.bean(AuthenticationService)
221 
222  identity = CdiUtil.bean(Identity)
223  credentials = identity.getCredentials()
224 
225  session_attributes = identity.getSessionId().getSessionAttributes()
226 
227  self.setRequestScopedParameters(identity)
228 
229  if (step == 1):
230  return True
231  elif (step == 2):
232  print "UAF. Prepare for step 2"
233 
234  session_id = CdiUtil.bean(SessionIdService).getSessionIdFromCookie()
235  if StringHelper.isEmpty(session_id):
236  print "UAF. Prepare for step 2. Failed to determine session_id"
237  return False
238 
239  user = authenticationService.getAuthenticatedUser()
240  if (user == None):
241  print "UAF. Prepare for step 2. Failed to determine user name"
242  return False
243 
244  uaf_auth_method = session_attributes.get("uaf_auth_method")
245  if StringHelper.isEmpty(uaf_auth_method):
246  print "UAF. Prepare for step 2. Failed to determine auth_method"
247  return False
248 
249  print "UAF. Prepare for step 2. uaf_auth_method: '%s'" % uaf_auth_method
250 
251  uaf_obb_auth_method = "OOB_REG"
252  uaf_obb_server_uri = self.uaf_server_uri + "/nnl/v2/reg"
253  if StringHelper.equalsIgnoreCase(uaf_auth_method, "authenticate"):
254  uaf_obb_auth_method = "OOB_AUTH"
255  uaf_obb_server_uri = self.uaf_server_uri + "/nnl/v2/auth"
256 
257  # Prepare START_OBB
258  uaf_obb_start_request_dictionary = { "operation": "START_%s" % uaf_obb_auth_method,
259  "userName": user.getUserId(),
260  "policyName": "default",
261  "oobMode":
262  { "qr": "true", "rawData": "false", "push": "false" }
263  }
264 
265  uaf_obb_start_request = json.dumps(uaf_obb_start_request_dictionary, separators=(',',':'))
266  print "UAF. Prepare for step 2. Prepared START request: '%s' to send to '%s'" % (uaf_obb_start_request, uaf_obb_server_uri)
267 
268  # Request START_OBB
269  uaf_obb_start_response = self.executePost(uaf_obb_server_uri, uaf_obb_start_request)
270  if uaf_obb_start_response == None:
271  return False
272 
273  print "UAF. Prepare for step 2. Get START response: '%s'" % uaf_obb_start_response
274  uaf_obb_start_response_json = json.loads(uaf_obb_start_response)
275 
276  # Prepare STATUS_OBB
277  #TODO: Remove needDetails parameter
278  uaf_obb_status_request_dictionary = { "operation": "STATUS_%s" % uaf_obb_auth_method,
279  "userName": user.getUserId(),
280  "needDetails": 1,
281  "oobStatusHandle": uaf_obb_start_response_json["oobStatusHandle"],
282  }
283 
284  uaf_obb_status_request = json.dumps(uaf_obb_status_request_dictionary, separators=(',',':'))
285  print "UAF. Prepare for step 2. Prepared STATUS request: '%s' to send to '%s'" % (uaf_obb_status_request, uaf_obb_server_uri)
286 
287  identity.setWorkingParameter("uaf_obb_auth_method", uaf_obb_auth_method)
288  identity.setWorkingParameter("uaf_obb_server_uri", uaf_obb_server_uri)
289  identity.setWorkingParameter("uaf_obb_start_response", uaf_obb_start_response)
290  identity.setWorkingParameter("qr_image", uaf_obb_start_response_json["modeResult"]["qrCode"]["qrImage"])
291  identity.setWorkingParameter("uaf_obb_status_request", uaf_obb_status_request)
292 
293  return True
294  else:
295  return False
296 

◆ processBasicAuthentication()

def UafExternalAuthenticator.PersonAuthentication.processBasicAuthentication (   self,
  credentials 
)
317  def processBasicAuthentication(self, credentials):
318  userService = CdiUtil.bean(UserService)
319  authenticationService = CdiUtil.bean(AuthenticationService)
320 
321  user_name = credentials.getUsername()
322  user_password = credentials.getPassword()
323 
324  logged_in = False
325  if StringHelper.isNotEmptyString(user_name) and StringHelper.isNotEmptyString(user_password):
326  logged_in = authenticationService.authenticate(user_name, user_password)
327 
328  if not logged_in:
329  return None
330 
331  find_user_by_uid = authenticationService.getAuthenticatedUser()
332  if find_user_by_uid == None:
333  print "UAF. Process basic authentication. Failed to find user '%s'" % user_name
334  return None
335 
336  return find_user_by_uid
337 

◆ setRequestScopedParameters()

def UafExternalAuthenticator.PersonAuthentication.setRequestScopedParameters (   self,
  identity 
)
312  def setRequestScopedParameters(self, identity):
313  if self.registration_uri != None:
314  identity.setWorkingParameter("external_registration_uri", self.registration_uri)
315  identity.setWorkingParameter("qr_options", self.customQrOptions)
316 

メンバ詳解

◆ currentTimeMillis

UafExternalAuthenticator.PersonAuthentication.currentTimeMillis

◆ customQrOptions

UafExternalAuthenticator.PersonAuthentication.customQrOptions

◆ http_client

UafExternalAuthenticator.PersonAuthentication.http_client

◆ registration_uri

UafExternalAuthenticator.PersonAuthentication.registration_uri

◆ send_push_notifaction

UafExternalAuthenticator.PersonAuthentication.send_push_notifaction

◆ uaf_policy_name

UafExternalAuthenticator.PersonAuthentication.uaf_policy_name

◆ uaf_server_uri

UafExternalAuthenticator.PersonAuthentication.uaf_server_uri

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