gluu
公開メンバ関数 | 公開変数類 | 全メンバ一覧
ToopherExternalAuthenticator.PersonAuthentication クラス
ToopherExternalAuthenticator.PersonAuthentication の継承関係図
Inheritance graph
ToopherExternalAuthenticator.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 checkPairingStatus (self, pairing_id, timeout)
 
def checkRequestStatus (self, request_id, timeout)
 
def logout (self, configurationAttributes, requestParameters)
 

公開変数類

 currentTimeMillis
 
 tapi
 

詳解

構築子と解体子

◆ __init__()

def ToopherExternalAuthenticator.PersonAuthentication.__init__ (   self,
  currentTimeMillis 
)
22  def __init__(self, currentTimeMillis):
23  self.currentTimeMillis = currentTimeMillis
24 

関数詳解

◆ authenticate()

def ToopherExternalAuthenticator.PersonAuthentication.authenticate (   self,
  configurationAttributes,
  requestParameters,
  step 
)
65  def authenticate(self, configurationAttributes, requestParameters, step):
66  userService = CdiUtil.bean(UserService)
67  authenticationService = CdiUtil.bean(AuthenticationService)
68 
69  identity = CdiUtil.bean(Identity)
70  credentials = identity.getCredentials()
71 
72  toopher_user_timeout = int(configurationAttributes.get("toopher_user_timeout").getValue2())
73 
74  user_name = credentials.getUsername()
75 
76  if (step == 1):
77  print "Toopher. Authenticate for step 1"
78 
79  user_password = credentials.getPassword()
80  logged_in = False
81  if (StringHelper.isNotEmptyString(user_name) and StringHelper.isNotEmptyString(user_password)):
82  userService = CdiUtil.bean(UserService)
83  logged_in = authenticationService.authenticate(user_name, user_password)
84 
85  if (not logged_in):
86  return False
87 
88  # Get user entry
89  userService = CdiUtil.bean(UserService)
90  find_user_by_uid = authenticationService.getAuthenticatedUser()
91  if (find_user_by_uid == None):
92  print "Toopher. Authenticate for step 1. Failed to find user"
93  return False
94 
95  # Check if the user paired account to phone
96  user_external_uid_attr = userService.getCustomAttribute(find_user_by_uid, "oxExternalUid")
97  if ((user_external_uid_attr == None) or (user_external_uid_attr.getValues() == None)):
98  print "Toopher. Authenticate for step 1. There is no external UIDs for user: ", user_name
99  else:
100  topher_user_uid = None
101  for ext_uid in user_external_uid_attr.getValues():
102  if (ext_uid.startswith('toopher:')):
103  topher_user_uid = ext_uid[8:len(ext_uid)]
104  break
105 
106  if (topher_user_uid == None):
107  print "Toopher. Authenticate for step 1. There is no Topher UID for user: ", user_name
108  else:
109  identity.setWorkingParameter("toopher_user_uid", topher_user_uid)
110 
111  return True
112  elif (step == 2):
113  print "Toopher. Authenticate for step 2"
114 
115  passed_step1 = self.isPassedDefaultAuthentication
116  if (not passed_step1):
117  return False
118 
119  sessionAttributes = identity.getSessionId().getSessionAttributes()
120  if (sessionAttributes == None) or not sessionAttributes.containsKey("toopher_user_uid"):
121  print "Toopher. Authenticate for step 2. toopher_user_uid is empty"
122 
123  # Pair with phone
124  pairing_phrase_array = requestParameters.get("pairing_phrase")
125  if ArrayHelper.isEmpty(pairing_phrase_array):
126  print "Toopher. Authenticate for step 2. pairing_phrase is empty"
127  return False
128 
129  pairing_phrase = pairing_phrase_array[0]
130  try:
131  pairing_status = self.tapi.pair(pairing_phrase, user_name)
132  toopher_user_uid = pairing_status.id
133  except RequestError, err:
134  print "Toopher. Authenticate for step 2. Failed pair with phone: ", err
135  return False
136 
137  pairing_result = self.checkPairingStatus(toopher_user_uid, toopher_user_timeout)
138 
139  if (not pairing_result):
140  print "Toopher. Authenticate for step 2. The pairing has not been authorized by the phone yet"
141  return False
142 
143  print "Toopher. Authenticate for step 2. Storing toopher_user_uid in user entry", toopher_user_uid
144 
145  # Store toopher_user_uid in user entry
146  find_user_by_uid = userService.addUserAttribute(user_name, "oxExternalUid", "toopher:" + toopher_user_uid)
147  if (find_user_by_uid == None):
148  print "Toopher. Authenticate for step 2. Failed to update current user"
149  return False
150 
151  identity.setWorkingParameter("toopher_user_uid", toopher_user_uid)
152  else:
153  toopher_user_uid = sessionAttributes.get("toopher_user_uid")
154 
155  # Check pairing stastus
156  print "Toopher. Authenticate for step 2. toopher_user_uid: ", toopher_user_uid
157  pairing_result = self.checkPairingStatus(toopher_user_uid, 0)
158  if (not pairing_result):
159  print "Toopher. Authenticate for step 2. The pairing has not been authorized by the phone yet"
160  return False
161 
162  return True
163  elif (step == 3):
164  print "Toopher. Authenticate for step 3"
165 
166  passed_step1 = self.isPassedDefaultAuthentication
167  if (not passed_step1):
168  return False
169 
170  sessionAttributes = identity.getSessionId().getSessionAttributes()
171  if (sessionAttributes == None) or not sessionAttributes.containsKey("toopher_user_uid"):
172  print "Toopher. Authenticate for step 3. toopher_user_uid is empty"
173  return False
174 
175  toopher_user_uid = sessionAttributes.get("toopher_user_uid")
176  passed_step1 = StringHelper.isNotEmptyString(toopher_user_uid)
177  if (not passed_step1):
178  return False
179 
180  toopher_terminal_name = configurationAttributes.get("toopher_terminal_name").getValue2()
181 
182  try:
183  request_status = self.tapi.authenticate(toopher_user_uid, toopher_terminal_name)
184  request_id = request_status.id
185  except RequestError, err:
186  print "Toopher. Authenticate for step 3. Failed to send authentication request to phone: ", err
187  return False
188 
189  print "Toopher. Authenticate for step 3. request_id: ", request_id
190  request_result = self.checkRequestStatus(request_id, toopher_user_timeout)
191 
192  if (not request_result):
193  print "Toopher. Authenticate for step 3. The authentication request has not received a response from the phone yet"
194  return False
195 
196  print "Toopher. Authenticate for step 3. The request was granted"
197 
198  return True
199  else:
200  return False
201 

◆ checkPairingStatus()

def ToopherExternalAuthenticator.PersonAuthentication.checkPairingStatus (   self,
  pairing_id,
  timeout 
)
230  def checkPairingStatus(self, pairing_id, timeout):
231  try:
232  curTime = java.lang.System.currentTimeMillis()
233  endTime = curTime + timeout * 1000
234  while (endTime >= curTime):
235  pairing_status = self.tapi.getPairingStatus(pairing_id)
236  if (pairing_status.enabled):
237  print "Toopher. Pairing complete"
238  return True
239 
240  java.lang.Thread.sleep(2000)
241  curTime = java.lang.System.currentTimeMillis()
242  except java.lang.Exception, err:
243  print "Toopher. Could not check pairing status: ", err
244  return False
245 
246  print "Toopher. The pairing has not been authorized by the phone yet"
247 
248  return False
249 

◆ checkRequestStatus()

def ToopherExternalAuthenticator.PersonAuthentication.checkRequestStatus (   self,
  request_id,
  timeout 
)
250  def checkRequestStatus(self, request_id, timeout):
251  try:
252  curTime = java.lang.System.currentTimeMillis()
253  endTime = curTime + timeout * 1000
254  while (endTime >= curTime):
255  request_status = self.tapi.getAuthenticationStatus(request_id)
256  if (request_status.cancelled):
257  print "Toopher. The authentication request has been cancelled"
258  return False
259 
260  if (not request_status.pending):
261  if (request_status.granted):
262  print "Toopher. The request was granted"
263  return True
264 
265  java.lang.Thread.sleep(2000)
266  curTime = java.lang.System.currentTimeMillis()
267  except java.lang.Exception, err:
268  print "Toopher. Could not check authentication status: ", err
269  return False
270 
271  print "Toopher. The authentication request has not received a response from the phone yet"
272 
273  return False
274 

◆ destroy()

def ToopherExternalAuthenticator.PersonAuthentication.destroy (   self,
  configurationAttributes 
)
51  def destroy(self, configurationAttributes):
52  print "Toopher. Destroy"
53  print "Toopher. Destroyed successfully"
54  return True
55 

◆ getAlternativeAuthenticationMethod()

def ToopherExternalAuthenticator.PersonAuthentication.getAlternativeAuthenticationMethod (   self,
  usageType,
  configurationAttributes 
)
62  def getAlternativeAuthenticationMethod(self, usageType, configurationAttributes):
63  return None
64 

◆ getApiVersion()

def ToopherExternalAuthenticator.PersonAuthentication.getApiVersion (   self)
56  def getApiVersion(self):
57  return 1
58 

◆ getCountAuthenticationSteps()

def ToopherExternalAuthenticator.PersonAuthentication.getCountAuthenticationSteps (   self,
  configurationAttributes 
)
211  def getCountAuthenticationSteps(self, configurationAttributes):
212  return 3
213 

◆ getExtraParametersForStep()

def ToopherExternalAuthenticator.PersonAuthentication.getExtraParametersForStep (   self,
  configurationAttributes,
  step 
)
205  def getExtraParametersForStep(self, configurationAttributes, step):
206  if (step in [2, 3]):
207  return Arrays.asList("toopher_user_uid")
208 
209  return None
210 

◆ getPageForStep()

def ToopherExternalAuthenticator.PersonAuthentication.getPageForStep (   self,
  configurationAttributes,
  step 
)
214  def getPageForStep(self, configurationAttributes, step):
215  if (step == 2):
216  return "/auth/toopher/tppair.xhtml"
217  elif (step == 3):
218  return "/auth/toopher/tpauthenticate.xhtml"
219  return ""
220 

◆ init()

def ToopherExternalAuthenticator.PersonAuthentication.init (   self,
  configurationAttributes 
)
25  def init(self, configurationAttributes):
26  print "Toopher. Initialization"
27  toopher_creds_file = configurationAttributes.get("toopher_creds_file").getValue2()
28 
29  # Load credentials from file
30  f = open(toopher_creds_file, 'r')
31  try:
32  creds = json.loads(f.read())
33  except:
34  return False
35  finally:
36  f.close()
37 
38  consumer_key = creds["CONSUMER_KEY"]
39  consumer_secret = creds["CONSUMER_SECRET"]
40  try:
41  encryptionService = CdiUtil.bean(EncryptionService)
42  consumer_secret = encryptionService.decrypt(consumer_secret)
43  except:
44  return False
45 
46  self.tapi = ToopherAPI(consumer_key, consumer_secret)
47  print "Toopher. Initialized successfully"
48 
49  return True
50 

◆ isPassedDefaultAuthentication()

def ToopherExternalAuthenticator.PersonAuthentication.isPassedDefaultAuthentication ( )
221  def isPassedDefaultAuthentication():
222  identity = CdiUtil.bean(Identity)
223  credentials = identity.getCredentials()
224 
225  user_name = credentials.getUsername()
226  passed_step1 = StringHelper.isNotEmptyString(user_name)
227 
228  return passed_step1
229 

◆ isValidAuthenticationMethod()

def ToopherExternalAuthenticator.PersonAuthentication.isValidAuthenticationMethod (   self,
  usageType,
  configurationAttributes 
)
59  def isValidAuthenticationMethod(self, usageType, configurationAttributes):
60  return True
61 

◆ logout()

def ToopherExternalAuthenticator.PersonAuthentication.logout (   self,
  configurationAttributes,
  requestParameters 
)
275  def logout(self, configurationAttributes, requestParameters):
276  return True
277 

◆ prepareForStep()

def ToopherExternalAuthenticator.PersonAuthentication.prepareForStep (   self,
  configurationAttributes,
  requestParameters,
  step 
)
202  def prepareForStep(self, configurationAttributes, requestParameters, step):
203  return True
204 

メンバ詳解

◆ currentTimeMillis

ToopherExternalAuthenticator.PersonAuthentication.currentTimeMillis

◆ tapi

ToopherExternalAuthenticator.PersonAuthentication.tapi

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