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

公開変数類

 currentTimeMillis
 
 cas_host
 
 cas_extra_opts
 
 cas_renew_opt
 
 cas_map_user
 
 cas_enable_server_validation
 
 cas_validation_uri
 
 cas_validation_pattern
 
 http_client
 
 http_client_params
 
 cas_alt_auth_mode
 

詳解

構築子と解体子

◆ __init__()

def Cas2ExternalAuthenticator.PersonAuthentication.__init__ (   self,
  currentTimeMillis 
)
21  def __init__(self, currentTimeMillis):
22  self.currentTimeMillis = currentTimeMillis
23 

関数詳解

◆ authenticate()

def Cas2ExternalAuthenticator.PersonAuthentication.authenticate (   self,
  configurationAttributes,
  requestParameters,
  step 
)
120  def authenticate(self, configurationAttributes, requestParameters, step):
121  identity = CdiUtil.bean(Identity)
122  credentials = identity.getCredentials()
123 
124  userService = CdiUtil.bean(UserService)
125  requestParameterService = CdiUtil.bean(RequestParameterService)
126  authenticationService = CdiUtil.bean(AuthenticationService)
127  httpService = CdiUtil.bean(HttpService)
128 
129  if step == 1:
130  print "CAS2. Authenticate for step 1"
131  ticket_array = requestParameters.get("ticket")
132  if ArrayHelper.isEmpty(ticket_array):
133  print "CAS2. Authenticate for step 1. ticket is empty"
134  return False
135 
136  ticket = ticket_array[0]
137  print "CAS2. Authenticate for step 1. ticket: " + ticket
138 
139  if StringHelper.isEmptyString(ticket):
140  print "CAS2. Authenticate for step 1. ticket is invalid"
141  return False
142 
143  # Validate ticket
144  facesContext = CdiUtil.bean(FacesContext)
145  request = facesContext.getExternalContext().getRequest()
146 
147  parametersMap = HashMap()
148  parametersMap.put("service", httpService.constructServerUrl(request) + "/postlogin.htm")
149  if self.cas_renew_opt:
150  parametersMap.put("renew", "true")
151  parametersMap.put("ticket", ticket)
152  cas_service_request_uri = requestParameterService.parametersAsString(parametersMap)
153  cas_service_request_uri = self.cas_host + "/serviceValidate?" + cas_service_request_uri
154  if self.cas_extra_opts != None:
155  cas_service_request_uri = cas_service_request_uri + "&" + self.cas_extra_opts
156 
157  print "CAS2. Authenticate for step 1. cas_service_request_uri: " + cas_service_request_uri
158 
159  http_client = httpService.getHttpsClient()
160  http_service_response = httpService.executeGet(http_client, cas_service_request_uri)
161  try:
162  validation_content = httpService.convertEntityToString(httpService.getResponseContent(http_service_response.getHttpResponse()))
163  finally:
164  http_service_response.closeConnection()
165 
166  print "CAS2. Authenticate for step 1. validation_content: " + validation_content
167  if StringHelper.isEmpty(validation_content):
168  print "CAS2. Authenticate for step 1. Ticket validation response is invalid"
169  return False
170 
171  cas2_auth_failure = self.parse_tag(validation_content, "cas:authenticationFailure")
172  print "CAS2. Authenticate for step 1. cas2_auth_failure: ", cas2_auth_failure
173 
174  cas2_user_uid = self.parse_tag(validation_content, "cas:user")
175  print "CAS2. Authenticate for step 1. cas2_user_uid: ", cas2_user_uid
176 
177  if (cas2_auth_failure != None) or (cas2_user_uid == None):
178  print "CAS2. Authenticate for step 1. Ticket is invalid"
179  return False
180 
181  if self.cas_map_user:
182  print "CAS2. Authenticate for step 1. Attempting to find user by oxExternalUid: cas2:" + cas2_user_uid
183 
184  # Check if the is user with specified cas2_user_uid
185  find_user_by_uid = userService.getUserByAttribute("oxExternalUid", "cas2:" + cas2_user_uid)
186 
187  if find_user_by_uid == None:
188  print "CAS2. Authenticate for step 1. Failed to find user"
189  print "CAS2. Authenticate for step 1. Setting count steps to 2"
190  identity.setWorkingParameter("cas2_count_login_steps", 2)
191  identity.setWorkingParameter("cas2_user_uid", cas2_user_uid)
192  return True
193 
194  found_user_name = find_user_by_uid.getUserId()
195  print "CAS2. Authenticate for step 1. found_user_name: " + found_user_name
196 
197  authenticationService.authenticate(found_user_name)
198 
199  print "CAS2. Authenticate for step 1. Setting count steps to 1"
200  identity.setWorkingParameter("cas2_count_login_steps", 1)
201 
202  return True
203  else:
204  print "CAS2. Authenticate for step 1. Attempting to find user by uid:" + cas2_user_uid
205 
206  # Check if there is user with specified cas2_user_uid
207  find_user_by_uid = userService.getUser(cas2_user_uid)
208  if find_user_by_uid == None:
209  print "CAS2. Authenticate for step 1. Failed to find user"
210  return False
211 
212  found_user_name = find_user_by_uid.getUserId()
213  print "CAS2. Authenticate for step 1. found_user_name: " + found_user_name
214 
215  authenticationService.authenticate(found_user_name)
216 
217  print "CAS2. Authenticate for step 1. Setting count steps to 1"
218  identity.setWorkingParameter("cas2_count_login_steps", 1)
219 
220  return True
221  elif step == 2:
222  print "CAS2. Authenticate for step 2"
223 
224  if identity.isSetWorkingParameter("cas2_user_uid"):
225  print "CAS2. Authenticate for step 2. cas2_user_uid is empty"
226  return False
227 
228  cas2_user_uid = identity.getWorkingParameter("cas2_user_uid")
229  passed_step1 = StringHelper.isNotEmptyString(cas2_user_uid)
230  if not passed_step1:
231  return False
232 
233  user_name = credentials.getUsername()
234  user_password = credentials.getPassword()
235 
236  logged_in = False
237  if StringHelper.isNotEmptyString(user_name) and StringHelper.isNotEmptyString(user_password):
238  logged_in = authenticationService.authenticate(user_name, user_password)
239 
240  if not logged_in:
241  return False
242 
243  # Check if there is user which has cas2_user_uid
244  # Avoid mapping CAS2 account to more than one IDP account
245  find_user_by_uid = userService.getUserByAttribute("oxExternalUid", "cas2:" + cas2_user_uid)
246 
247  if find_user_by_uid == None:
248  # Add cas2_user_uid to user one id UIDs
249  find_user_by_uid = userService.addUserAttribute(user_name, "oxExternalUid", "cas2:" + cas2_user_uid)
250  if find_user_by_uid == None:
251  print "CAS2. Authenticate for step 2. Failed to update current user"
252  return False
253 
254  return True
255  else:
256  found_user_name = find_user_by_uid.getUserId()
257  print "CAS2. Authenticate for step 2. found_user_name: " + found_user_name
258 
259  if StringHelper.equals(user_name, found_user_name):
260  return True
261 
262  return False
263  else:
264  return False
265 

◆ destroy()

def Cas2ExternalAuthenticator.PersonAuthentication.destroy (   self,
  configurationAttributes 
)
72  def destroy(self, configurationAttributes):
73  print "CAS2. Destroy"
74  if self.cas_enable_server_validation:
75  print "CAS2. CDestory. Destorying checker client"
76  self.http_client = None
77 
78  print "CAS2. Destroyed successfully"
79  return True
80 

◆ getAlternativeAuthenticationMethod()

def Cas2ExternalAuthenticator.PersonAuthentication.getAlternativeAuthenticationMethod (   self,
  usageType,
  configurationAttributes 
)
117  def getAlternativeAuthenticationMethod(self, usageType, configurationAttributes):
118  return self.cas_alt_auth_mode
119 

◆ getApiVersion()

def Cas2ExternalAuthenticator.PersonAuthentication.getApiVersion (   self)
81  def getApiVersion(self):
82  return 1
83 

◆ getCountAuthenticationSteps()

def Cas2ExternalAuthenticator.PersonAuthentication.getCountAuthenticationSteps (   self,
  configurationAttributes 
)
303  def getCountAuthenticationSteps(self, configurationAttributes):
304  identity = CdiUtil.bean(Identity)
305  if identity.isSetWorkingParameter("cas2_count_login_steps"):
306  return int(identity.getWorkingParameter("cas2_count_login_steps"))
307 
308  return 2
309 

◆ getExtraParametersForStep()

def Cas2ExternalAuthenticator.PersonAuthentication.getExtraParametersForStep (   self,
  configurationAttributes,
  step 
)
297  def getExtraParametersForStep(self, configurationAttributes, step):
298  if step == 2:
299  return Arrays.asList("cas2_count_login_steps", "cas2_user_uid")
300 
301  return None
302 

◆ getPageForStep()

def Cas2ExternalAuthenticator.PersonAuthentication.getPageForStep (   self,
  configurationAttributes,
  step 
)
310  def getPageForStep(self, configurationAttributes, step):
311  identity = CdiUtil.bean(Identity)
312  if step == 1:
313  return "/auth/cas2/cas2login.xhtml"
314  return "/auth/cas2/cas2postlogin.xhtml"
315 

◆ init()

def Cas2ExternalAuthenticator.PersonAuthentication.init (   self,
  configurationAttributes 
)
24  def init(self, configurationAttributes):
25  print "CAS2. Initialization"
26 
27  if not configurationAttributes.containsKey("cas_host"):
28  print "CAS2. Initialization. Parameter 'cas_host' is missing"
29  return False
30 
31  self.cas_host = configurationAttributes.get("cas_host").getValue2()
32 
33  self.cas_extra_opts = None
34  if configurationAttributes.containsKey("cas_extra_opts"):
35  self.cas_extra_opts = configurationAttributes.get("cas_extra_opts").getValue2()
36 
37 
38  self.cas_renew_opt = False
39  if configurationAttributes.containsKey("cas_renew_opt"):
40  self.cas_renew_opt = StringHelper.toBoolean(configurationAttributes.get("cas_renew_opt").getValue2(), False)
41 
42  self.cas_map_user = False
43  if configurationAttributes.containsKey("cas_map_user"):
44  self.cas_map_user = StringHelper.toBoolean(configurationAttributes.get("cas_map_user").getValue2(), False)
45 
46  self.cas_enable_server_validation = False
47  if (configurationAttributes.containsKey("cas_validation_uri") and
48  configurationAttributes.containsKey("cas_validation_pattern") and
49  configurationAttributes.containsKey("cas_validation_timeout")):
50 
51  print "CAS2. Initialization. Configuring checker client"
52  self.cas_enable_server_validation = True
53 
54  self.cas_validation_uri = configurationAttributes.get("cas_validation_uri").getValue2()
55  self.cas_validation_pattern = configurationAttributes.get("cas_validation_pattern").getValue2()
56  cas_validation_timeout = int(configurationAttributes.get("cas_validation_timeout").getValue2()) * 1000
57 
58  httpService = CdiUtil.bean(HttpService)
59 
60  self.http_client = httpService.getHttpsClient()
61  self.http_client_params = self.http_client.getParams()
62  self.http_client_params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, cas_validation_timeout)
63 
64  self.cas_alt_auth_mode = None
65  if configurationAttributes.containsKey("cas_alt_auth_mode"):
66  self.cas_alt_auth_mode = configurationAttributes.get("cas_alt_auth_mode").getValue2()
67 
68  print "CAS2. Initialized successfully"
69 
70  return True
71 

◆ isValidAuthenticationMethod()

def Cas2ExternalAuthenticator.PersonAuthentication.isValidAuthenticationMethod (   self,
  usageType,
  configurationAttributes 
)
84  def isValidAuthenticationMethod(self, usageType, configurationAttributes):
85  if not self.cas_enable_server_validation:
86  return True
87 
88  print "CAS2. isValidAuthenticationMethod"
89 
90  httpService = CdiUtil.bean(HttpService)
91 
92  try:
93  http_service_response = httpService.executeGet(self.http_client, self.cas_validation_uri)
94  except:
95  print "CAS2. isValidAuthenticationMethod. Exception: ", sys.exc_info()[1]
96  return False
97 
98  try:
99  http_response = http_service_response.getHttpResponse()
100  if http_response.getStatusLine().getStatusCode() != 200:
101  print "CAS2. isValidAuthenticationMethod. Get invalid response from CAS2 server: ", str(http_response.getStatusLine().getStatusCode())
102  httpService.consume(http_response)
103  return False
104 
105  validation_response_bytes = httpService.getResponseContent(http_response)
106  validation_response_string = httpService.convertEntityToString(validation_response_bytes)
107  httpService.consume(http_response)
108  finally:
109  http_service_response.closeConnection()
110 
111  if (validation_response_string == None) or (validation_response_string.find(self.cas_validation_pattern) == -1):
112  print "CAS2. isValidAuthenticationMethod. Get invalid login page from CAS2 server:"
113  return False
114 
115  return True
116 

◆ logout()

def Cas2ExternalAuthenticator.PersonAuthentication.logout (   self,
  configurationAttributes,
  requestParameters 
)
327  def logout(self, configurationAttributes, requestParameters):
328  return True
329 

◆ parse_tag()

def Cas2ExternalAuthenticator.PersonAuthentication.parse_tag (   self,
  str,
  tag 
)
316  def parse_tag(self, str, tag):
317  tag1_pos1 = str.find("<" + tag)
318  # No tag found, return empty string.
319  if tag1_pos1 == -1: return None
320  tag1_pos2 = str.find(">", tag1_pos1)
321  if tag1_pos2 == -1: return None
322  tag2_pos1 = str.find("</" + tag, tag1_pos2)
323  if tag2_pos1 == -1: return None
324 
325  return str[tag1_pos2+1:tag2_pos1].strip()
326 

◆ prepareForStep()

def Cas2ExternalAuthenticator.PersonAuthentication.prepareForStep (   self,
  configurationAttributes,
  requestParameters,
  step 
)
266  def prepareForStep(self, configurationAttributes, requestParameters, step):
267  if step == 1:
268  print "CAS2. Prepare for step 1"
269 
270  requestParameterService = CdiUtil.bean(RequestParameterService)
271  httpService = CdiUtil.bean(HttpService)
272 
273  facesContext = CdiUtil.bean(FacesContext)
274  request = facesContext.getExternalContext().getRequest()
275 
276  parametersMap = HashMap()
277  parametersMap.put("service", httpService.constructServerUrl(request) + "/postlogin.htm")
278  if self.cas_renew_opt:
279  parametersMap.put("renew", "true")
280  cas_service_request_uri = requestParameterService.parametersAsString(parametersMap)
281  cas_service_request_uri = self.cas_host + "/login?" + cas_service_request_uri
282  if self.cas_extra_opts != None:
283  cas_service_request_uri = cas_service_request_uri + "&" + self.cas_extra_opts
284 
285  print "CAS2. Prepare for step 1. cas_service_request_uri: " + cas_service_request_uri
286  facesService = CdiUtil.bean(FacesService)
287  facesService.redirectToExternalURL(cas_service_request_uri)
288 
289  return True
290  elif step == 2:
291  print "CAS2. Prepare for step 2"
292 
293  return True
294  else:
295  return False
296 

メンバ詳解

◆ cas_alt_auth_mode

Cas2ExternalAuthenticator.PersonAuthentication.cas_alt_auth_mode

◆ cas_enable_server_validation

Cas2ExternalAuthenticator.PersonAuthentication.cas_enable_server_validation

◆ cas_extra_opts

Cas2ExternalAuthenticator.PersonAuthentication.cas_extra_opts

◆ cas_host

Cas2ExternalAuthenticator.PersonAuthentication.cas_host

◆ cas_map_user

Cas2ExternalAuthenticator.PersonAuthentication.cas_map_user

◆ cas_renew_opt

Cas2ExternalAuthenticator.PersonAuthentication.cas_renew_opt

◆ cas_validation_pattern

Cas2ExternalAuthenticator.PersonAuthentication.cas_validation_pattern

◆ cas_validation_uri

Cas2ExternalAuthenticator.PersonAuthentication.cas_validation_uri

◆ currentTimeMillis

Cas2ExternalAuthenticator.PersonAuthentication.currentTimeMillis

◆ http_client

Cas2ExternalAuthenticator.PersonAuthentication.http_client

◆ http_client_params

Cas2ExternalAuthenticator.PersonAuthentication.http_client_params

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