gluu
公開メンバ関数 | 公開変数類 | 全メンバ一覧
DuoExternalAuthenticator.PersonAuthentication クラス
DuoExternalAuthenticator.PersonAuthentication の継承関係図
Inheritance graph
DuoExternalAuthenticator.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 isUserMemberOfGroup (self, user, attribute, group)
 
def processAuditGroup (self, user)
 

公開変数類

 currentTimeMillis
 
 ikey
 
 skey
 
 akey
 
 use_duo_group
 
 duo_group
 
 use_audit_group
 
 audit_group
 
 audit_email
 
 audit_attribute
 

詳解

構築子と解体子

◆ __init__()

def DuoExternalAuthenticator.PersonAuthentication.__init__ (   self,
  currentTimeMillis 
)
20  def __init__(self, currentTimeMillis):
21  self.currentTimeMillis = currentTimeMillis
22 

関数詳解

◆ authenticate()

def DuoExternalAuthenticator.PersonAuthentication.authenticate (   self,
  configurationAttributes,
  requestParameters,
  step 
)
84  def authenticate(self, configurationAttributes, requestParameters, step):
85  duo_host = configurationAttributes.get("duo_host").getValue2()
86 
87  authenticationService = CdiUtil.bean(AuthenticationService)
88 
89  identity = CdiUtil.bean(Identity)
90 
91  if (step == 1):
92  print "Duo. Authenticate for step 1"
93 
94  # Check if user authenticated alreadyin another custom script
95  user = authenticationService.getAuthenticatedUser()
96  if user == None:
97  credentials = identity.getCredentials()
98  user_name = credentials.getUsername()
99  user_password = credentials.getPassword()
100 
101  logged_in = False
102  if (StringHelper.isNotEmptyString(user_name) and StringHelper.isNotEmptyString(user_password)):
103  userService = CdiUtil.bean(UserService)
104  logged_in = authenticationService.authenticate(user_name, user_password)
105 
106  if (not logged_in):
107  return False
108 
109  user = authenticationService.getAuthenticatedUser()
110 
111  if (self.use_duo_group):
112  print "Duo. Authenticate for step 1. Checking if user belong to Duo group"
113  is_member_duo_group = self.isUserMemberOfGroup(user, self.audit_attribute, self.duo_group)
114  if (is_member_duo_group):
115  print "Duo. Authenticate for step 1. User '" + user.getUserId() + "' member of Duo group"
116  duo_count_login_steps = 2
117  else:
118  self.processAuditGroup(user)
119  duo_count_login_steps = 1
120 
121  identity.setWorkingParameter("duo_count_login_steps", duo_count_login_steps)
122 
123  return True
124  elif (step == 2):
125  print "Duo. Authenticate for step 2"
126  user = authenticationService.getAuthenticatedUser()
127  if user == None:
128  print "Duo. Authenticate for step 2. Failed to determine user name"
129  return False
130 
131  user_name = user.getUserId()
132 
133  sig_response_array = requestParameters.get("sig_response")
134  if ArrayHelper.isEmpty(sig_response_array):
135  print "Duo. Authenticate for step 2. sig_response is empty"
136  return False
137 
138  duo_sig_response = sig_response_array[0]
139 
140  print "Duo. Authenticate for step 2. duo_sig_response: " + duo_sig_response
141 
142  authenticated_username = duo_web.verify_response(self.ikey, self.skey, self.akey, duo_sig_response)
143 
144  print "Duo. Authenticate for step 2. authenticated_username: " + authenticated_username + ", expected user_name: " + user_name
145 
146  if (not StringHelper.equals(user_name, authenticated_username)):
147  return False
148 
149  self.processAuditGroup(user)
150 
151  return True
152  else:
153  return False
154 
def verify_response(ikey, skey, akey, sig_response)
Definition: duo_web.py:154

◆ destroy()

def DuoExternalAuthenticator.PersonAuthentication.destroy (   self,
  configurationAttributes 
)
70  def destroy(self, configurationAttributes):
71  print "Duo. Destroy"
72  print "Duo. Destroyed successfully"
73  return True
74 

◆ getAlternativeAuthenticationMethod()

def DuoExternalAuthenticator.PersonAuthentication.getAlternativeAuthenticationMethod (   self,
  usageType,
  configurationAttributes 
)
81  def getAlternativeAuthenticationMethod(self, usageType, configurationAttributes):
82  return None
83 

◆ getApiVersion()

def DuoExternalAuthenticator.PersonAuthentication.getApiVersion (   self)
75  def getApiVersion(self):
76  return 1
77 

◆ getCountAuthenticationSteps()

def DuoExternalAuthenticator.PersonAuthentication.getCountAuthenticationSteps (   self,
  configurationAttributes 
)
190  def getCountAuthenticationSteps(self, configurationAttributes):
191  identity = CdiUtil.bean(Identity)
192  if (identity.isSetWorkingParameter("duo_count_login_steps")):
193  return int(identity.getWorkingParameter("duo_count_login_steps"))
194 
195  return 2
196 

◆ getExtraParametersForStep()

def DuoExternalAuthenticator.PersonAuthentication.getExtraParametersForStep (   self,
  configurationAttributes,
  step 
)
184  def getExtraParametersForStep(self, configurationAttributes, step):
185  if step == 2:
186  return Arrays.asList("duo_count_login_steps", "cas2_user_uid")
187 
188  return None
189 

◆ getPageForStep()

def DuoExternalAuthenticator.PersonAuthentication.getPageForStep (   self,
  configurationAttributes,
  step 
)
197  def getPageForStep(self, configurationAttributes, step):
198  if (step == 2):
199  return "/auth/duo/duologin.xhtml"
200  return ""
201 

◆ init()

def DuoExternalAuthenticator.PersonAuthentication.init (   self,
  configurationAttributes 
)
23  def init(self, configurationAttributes):
24  print "Duo. Initialization"
25 
26  duo_creds_file = configurationAttributes.get("duo_creds_file").getValue2()
27  # Load credentials from file
28  f = open(duo_creds_file, 'r')
29  try:
30  creds = json.loads(f.read())
31  except:
32  print "Duo. Initialization. Failed to load creds from file:", duo_creds_file
33  return False
34  finally:
35  f.close()
36 
37  self.ikey = str(creds["ikey"])
38  self.skey = str(creds["skey"])
39  self.akey = str(creds["akey"])
40 
41  self.use_duo_group = False
42  if (configurationAttributes.containsKey("duo_group")):
43  self.duo_group = configurationAttributes.get("duo_group").getValue2()
44  self.use_duo_group = True
45  print "Duo. Initialization. Using Duo only if user belong to group:", self.duo_group
46 
47  self.use_audit_group = False
48  if (configurationAttributes.containsKey("audit_group")):
49  self.audit_group = configurationAttributes.get("audit_group").getValue2()
50 
51  if (not configurationAttributes.containsKey("audit_group_email")):
52  print "Duo. Initialization. Property audit_group_email is not specified"
53  return False
54 
55  self.audit_email = configurationAttributes.get("audit_group_email").getValue2()
56  self.use_audit_group = True
57 
58  print "Duo. Initialization. Using audito group:", self.audit_group
59 
60  if (self.use_duo_group or self.use_audit_group):
61  if (not configurationAttributes.containsKey("audit_attribute")):
62  print "Duo. Initialization. Property audit_attribute is not specified"
63  return False
64  else:
65  self.audit_attribute = configurationAttributes.get("audit_attribute").getValue2()
66 
67  print "Duo. Initialized successfully"
68  return True
69 

◆ isUserMemberOfGroup()

def DuoExternalAuthenticator.PersonAuthentication.isUserMemberOfGroup (   self,
  user,
  attribute,
  group 
)
205  def isUserMemberOfGroup(self, user, attribute, group):
206  is_member = False
207  member_of_list = user.getAttributeValues(attribute)
208  if (member_of_list != None):
209  for member_of in member_of_list:
210  if StringHelper.equalsIgnoreCase(group, member_of) or member_of.endswith(group):
211  is_member = True
212  break
213 
214  return is_member
215 

◆ isValidAuthenticationMethod()

def DuoExternalAuthenticator.PersonAuthentication.isValidAuthenticationMethod (   self,
  usageType,
  configurationAttributes 
)
78  def isValidAuthenticationMethod(self, usageType, configurationAttributes):
79  return True
80 

◆ logout()

def DuoExternalAuthenticator.PersonAuthentication.logout (   self,
  configurationAttributes,
  requestParameters 
)
202  def logout(self, configurationAttributes, requestParameters):
203  return True
204 

◆ prepareForStep()

def DuoExternalAuthenticator.PersonAuthentication.prepareForStep (   self,
  configurationAttributes,
  requestParameters,
  step 
)
155  def prepareForStep(self, configurationAttributes, requestParameters, step):
156  identity = CdiUtil.bean(Identity)
157  authenticationService = CdiUtil.bean(AuthenticationService)
158 
159  duo_host = configurationAttributes.get("duo_host").getValue2()
160 
161  if (step == 1):
162  print "Duo. Prepare for step 1"
163 
164  return True
165  elif (step == 2):
166  print "Duo. Prepare for step 2"
167 
168  user = authenticationService.getAuthenticatedUser()
169  if (user == None):
170  print "Duo. Prepare for step 2. Failed to determine user name"
171  return False
172  user_name = user.getUserId()
173 
174  duo_sig_request = duo_web.sign_request(self.ikey, self.skey, self.akey, user_name)
175  print "Duo. Prepare for step 2. duo_sig_request: " + duo_sig_request
176 
177  identity.setWorkingParameter("duo_host", duo_host)
178  identity.setWorkingParameter("duo_sig_request", duo_sig_request)
179 
180  return True
181  else:
182  return False
183 
def sign_request(ikey, skey, akey, username)
Definition: duo_web.py:104

◆ processAuditGroup()

def DuoExternalAuthenticator.PersonAuthentication.processAuditGroup (   self,
  user 
)
216  def processAuditGroup(self, user):
217  if (self.use_audit_group):
218  is_member = self.isUserMemberOfGroup(user, self.audit_attribute, self.audit_group)
219  if (is_member):
220  print "Duo. Authenticate for processAuditGroup. User '" + user.getUserId() + "' member of audit group"
221  print "Duo. Authenticate for processAuditGroup. Sending e-mail about user '" + user.getUserId() + "' login to", self.audit_email
222 
223  # Send e-mail to administrator
224  user_id = user.getUserId()
225  mailService = CdiUtil.bean(MailService)
226  subject = "User log in: " + user_id
227  body = "User log in: " + user_id
228  mailService.sendMail(self.audit_email, subject, body)
229 

メンバ詳解

◆ akey

DuoExternalAuthenticator.PersonAuthentication.akey

◆ audit_attribute

DuoExternalAuthenticator.PersonAuthentication.audit_attribute

◆ audit_email

DuoExternalAuthenticator.PersonAuthentication.audit_email

◆ audit_group

DuoExternalAuthenticator.PersonAuthentication.audit_group

◆ currentTimeMillis

DuoExternalAuthenticator.PersonAuthentication.currentTimeMillis

◆ duo_group

DuoExternalAuthenticator.PersonAuthentication.duo_group

◆ ikey

DuoExternalAuthenticator.PersonAuthentication.ikey

◆ skey

DuoExternalAuthenticator.PersonAuthentication.skey

◆ use_audit_group

DuoExternalAuthenticator.PersonAuthentication.use_audit_group

◆ use_duo_group

DuoExternalAuthenticator.PersonAuthentication.use_duo_group

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