gluu
公開メンバ関数 | 公開変数類 | 全メンバ一覧
cred-manager-external_twilio_sms.PersonAuthentication クラス
cred-manager-external_twilio_sms.PersonAuthentication の継承関係図
Inheritance graph
cred-manager-external_twilio_sms.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 hasEnrollments (self, configurationAttributes, user)
 
def sendMessage (self, code, numb)
 

公開変数類

 currentTimeMillis
 

詳解

構築子と解体子

◆ __init__()

def cred-manager-external_twilio_sms.PersonAuthentication.__init__ (   self,
  currentTimeMillis 
)
29  def __init__(self, currentTimeMillis):
30  self.currentTimeMillis = currentTimeMillis
31 

関数詳解

◆ authenticate()

def cred-manager-external_twilio_sms.PersonAuthentication.authenticate (   self,
  configurationAttributes,
  requestParameters,
  step 
)
49  def authenticate(self, configurationAttributes, requestParameters, step):
50 
51  print "TwilioSMS. Authenticate for Step %s" % str(step)
52  identity = CdiUtil.bean(Identity)
53  authenticationService = CdiUtil.bean(AuthenticationService)
54  user = authenticationService.getAuthenticatedUser()
55 
56  if step == 1:
57 
58  if user == None:
59  credentials = identity.getCredentials()
60  user_name = credentials.getUsername()
61  user_password = credentials.getPassword()
62 
63  if StringHelper.isNotEmptyString(user_name) and StringHelper.isNotEmptyString(user_password):
64  authenticationService.authenticate(user_name, user_password)
65  user = authenticationService.getAuthenticatedUser()
66 
67  if user == None:
68  return False
69 
70  #Attempt to send message now if user has only one mobile number
71  mobiles = user.getAttributeValues("mobile")
72 
73  if mobiles == None:
74  return False
75  else:
76  code = random.randint(100000, 999999)
77  identity.setWorkingParameter("randCode", code)
78 
79  sid = configurationAttributes.get("twilio_sid").getValue2()
80  token = configurationAttributes.get("twilio_token").getValue2()
81  from_no = configurationAttributes.get("from_number").getValue2()
82  Twilio.init(sid, token)
83 
84  if mobiles.size() == 1:
85  self.sendMessage(code, mobiles.get(0))
86  else:
87  chopped = ""
88  for numb in mobiles:
89  l = len(numb)
90  chopped += "," + numb[max(0, l-4) : l]
91 
92  #converting to comma-separated list (identity does not remember lists in 3.1.3)
93  identity.setWorkingParameter("numbers", Joiner.on(",").join(mobiles.toArray()))
94  identity.setWorkingParameter("choppedNos", chopped[1:])
95 
96  return True
97  else:
98  if user == None:
99  return False
100 
101  session_attributes = identity.getSessionId().getSessionAttributes()
102  code = session_attributes.get("randCode")
103  numbers = session_attributes.get("numbers")
104 
105  if step == 2 and numbers != None:
106  #Means the selection number page was used
107  idx = ServerUtil.getFirstValue(requestParameters, "TwilioSmsloginForm:indexOfNumber")
108  if idx != None and code != None:
109  sendToNumber = numbers.split(",")[int(idx)]
110  self.sendMessage(code, sendToNumber)
111  return True
112  else:
113  return False
114 
115  success = False
116  form_passcode = ServerUtil.getFirstValue(requestParameters, "passcode")
117 
118  if form_passcode != None and code == form_passcode:
119  print "TwilioSMS. authenticate. 6-digit code matches with code sent via SMS"
120  success = True
121  else:
122  facesMessages = CdiUtil.bean(FacesMessages)
123  facesMessages.setKeepMessages()
124  facesMessages.clear()
125  facesMessages.add(FacesMessage.SEVERITY_ERROR, "Wrong code entered")
126 
127  return success
128 

◆ destroy()

def cred-manager-external_twilio_sms.PersonAuthentication.destroy (   self,
  configurationAttributes 
)
36  def destroy(self, configurationAttributes):
37  print "Twilio SMS. Destroyed successfully"
38  return True
39 

◆ getAlternativeAuthenticationMethod()

def cred-manager-external_twilio_sms.PersonAuthentication.getAlternativeAuthenticationMethod (   self,
  usageType,
  configurationAttributes 
)
46  def getAlternativeAuthenticationMethod(self, usageType, configurationAttributes):
47  return None
48 

◆ getApiVersion()

def cred-manager-external_twilio_sms.PersonAuthentication.getApiVersion (   self)
40  def getApiVersion(self):
41  return 1
42 

◆ getCountAuthenticationSteps()

def cred-manager-external_twilio_sms.PersonAuthentication.getCountAuthenticationSteps (   self,
  configurationAttributes 
)
138  def getCountAuthenticationSteps(self, configurationAttributes):
139  print "TwilioSMS. getCountAuthenticationSteps called"
140 
141  if CdiUtil.bean(Identity).getWorkingParameter("numbers") == None:
142  return 2
143  else:
144  return 3
145 

◆ getExtraParametersForStep()

def cred-manager-external_twilio_sms.PersonAuthentication.getExtraParametersForStep (   self,
  configurationAttributes,
  step 
)
133  def getExtraParametersForStep(self, configurationAttributes, step):
134  if step > 1:
135  return Arrays.asList("randCode", "numbers", "choppedNos")
136  return None
137 

◆ getPageForStep()

def cred-manager-external_twilio_sms.PersonAuthentication.getPageForStep (   self,
  configurationAttributes,
  step 
)
146  def getPageForStep(self, configurationAttributes, step):
147  print "TwilioSMS. getPageForStep called %s" % step
148  print "numbers are %s" % CdiUtil.bean(Identity).getWorkingParameter("numbers")
149 
150  defPage = "/cm/twiliosms.xhtml"
151  if step == 2:
152  if CdiUtil.bean(Identity).getWorkingParameter("numbers") == None:
153  return defPage
154  else:
155  return "/cm/twiliosms_prompt.xhtml"
156  elif step == 3:
157  return defPage
158  return ""
159 

◆ hasEnrollments()

def cred-manager-external_twilio_sms.PersonAuthentication.hasEnrollments (   self,
  configurationAttributes,
  user 
)
163  def hasEnrollments(self, configurationAttributes, user):
164  return user.getAttribute("mobile") != None
165 

◆ init()

def cred-manager-external_twilio_sms.PersonAuthentication.init (   self,
  configurationAttributes 
)
32  def init(self, configurationAttributes):
33  print "Twilio SMS. Initialized"
34  return True
35 

◆ isValidAuthenticationMethod()

def cred-manager-external_twilio_sms.PersonAuthentication.isValidAuthenticationMethod (   self,
  usageType,
  configurationAttributes 
)
43  def isValidAuthenticationMethod(self, usageType, configurationAttributes):
44  return True
45 

◆ logout()

def cred-manager-external_twilio_sms.PersonAuthentication.logout (   self,
  configurationAttributes,
  requestParameters 
)
160  def logout(self, configurationAttributes, requestParameters):
161  return True
162 

◆ prepareForStep()

def cred-manager-external_twilio_sms.PersonAuthentication.prepareForStep (   self,
  configurationAttributes,
  requestParameters,
  step 
)
129  def prepareForStep(self, configurationAttributes, requestParameters, step):
130  print "TwilioSMS. Prepare for Step %s" % str(step)
131  return True
132 

◆ sendMessage()

def cred-manager-external_twilio_sms.PersonAuthentication.sendMessage (   self,
  code,
  numb 
)
166  def sendMessage(self, code, numb):
167  try:
168  print "TwilioSMS. prepareForStep. Sending SMS message (%s) to %s" % (code, numb)
169  msg = "%s is your passcode to access your account" % code
170  #message = TwMessage.creator(PhoneNumber(numb), PhoneNumber(from_no), msg).create()
171  #print "TwilioSMS. prepareForStep. Message Sid: %s" % message.getSid()
172  except:
173  print "TwilioSMS. prepareForStep. Error sending message", sys.exc_info()[1]
174 

メンバ詳解

◆ currentTimeMillis

cred-manager-external_twilio_sms.PersonAuthentication.currentTimeMillis

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