gluu
公開メンバ関数 | 公開変数類 | 全メンバ一覧
OneIdExternalAuthenticator.PersonAuthentication クラス
OneIdExternalAuthenticator.PersonAuthentication の継承関係図
Inheritance graph
OneIdExternalAuthenticator.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)
 

公開変数類

 currentTimeMillis
 

詳解

構築子と解体子

◆ __init__()

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

関数詳解

◆ authenticate()

def OneIdExternalAuthenticator.PersonAuthentication.authenticate (   self,
  configurationAttributes,
  requestParameters,
  step 
)
43  def authenticate(self, configurationAttributes, requestParameters, step):
44  identity = CdiUtil.bean(Identity)
45 
46  userService = CdiUtil.bean(UserService)
47  authenticationService = CdiUtil.bean(AuthenticationService)
48  httpService = CdiUtil.bean(HttpService)
49 
50  server_flag = configurationAttributes.get("oneid_server_flag").getValue2()
51  callback_attrs = configurationAttributes.get("oneid_callback_attrs").getValue2()
52  creds_file = configurationAttributes.get("oneid_creds_file").getValue2()
53 
54  # Create OneID
55  authn = OneID(server_flag)
56 
57  # Set path to credentials file
58  authn.creds_file = creds_file
59 
60  if (step == 1):
61  print "OneId. Authenticate for step 1"
62 
63  # Find OneID request
64  json_data_array = requestParameters.get("json_data")
65  if ArrayHelper.isEmpty(json_data_array):
66  print "OneId. Authenticate for step 1. json_data is empty"
67  return False
68 
69  request = json_data_array[0]
70  print "OneId. Authenticate for step 1. request: " + request
71 
72  if (StringHelper.isEmptyString(request)):
73  return False
74 
75  authn.set_credentials()
76 
77  # Validate request
78  http_client = httpService.getHttpsClientDefaulTrustStore()
79  auth_data = httpService.encodeBase64(authn.api_id + ":" + authn.api_key)
80  http_response = httpService.executePost(http_client, authn.helper_server + "/validate", auth_data, request, ContentType.APPLICATION_JSON)
81  validation_content = httpService.convertEntityToString(httpService.getResponseContent(http_response))
82  print "OneId. Authenticate for step 1. validation_content: " + validation_content
83 
84  if (StringHelper.isEmptyString(validation_content)):
85  return False
86 
87  validation_resp = json.loads(validation_content)
88  print "OneId. Authenticate for step 1. validation_resp: " + str(validation_resp)
89 
90  if (not authn.success(validation_resp)):
91  return False
92 
93  response = json.loads(request)
94  for x in validation_resp:
95  response[x] = validation_resp[x]
96 
97  oneid_user_uid = response['uid']
98  print "OneId. Authenticate for step 1. oneid_user_uid: " + oneid_user_uid
99 
100  # Check if the is user with specified oneid_user_uid
101  find_user_by_uid = userService.getUserByAttribute("oxExternalUid", "oneid:" + oneid_user_uid)
102 
103  if (find_user_by_uid == None):
104  print "OneId. Authenticate for step 1. Failed to find user"
105  print "OneId. Authenticate for step 1. Setting count steps to 2"
106  identity.setWorkingParameter("oneid_count_login_steps", 2)
107  identity.setWorkingParameter("oneid_user_uid", oneid_user_uid)
108  return True
109 
110  found_user_name = find_user_by_uid.getUserId()
111  print "OneId. Authenticate for step 1. found_user_name: " + found_user_name
112 
113  identity = CdiUtil.bean(Identity)
114  credentials = identity.getCredentials()
115 
116  credentials.setUsername(found_user_name)
117  credentials.setUser(find_user_by_uid)
118 
119  print "OneId. Authenticate for step 1. Setting count steps to 1"
120  identity.setWorkingParameter("oneid_count_login_steps", 1)
121 
122  return True
123  elif (step == 2):
124  print "OneId. Authenticate for step 2"
125 
126  sessionAttributes = identity.getSessionId().getSessionAttributes()
127  if (sessionAttributes == None) or not sessionAttributes.containsKey("oneid_user_uid"):
128  print "OneId. Authenticate for step 2. oneid_user_uid is empty"
129  return False
130 
131  oneid_user_uid = sessionAttributes.get("oneid_user_uid")
132  passed_step1 = StringHelper.isNotEmptyString(oneid_user_uid)
133  if (not passed_step1):
134  return False
135 
136  identity = CdiUtil.bean(Identity)
137  credentials = identity.getCredentials()
138 
139  user_name = credentials.getUsername()
140  passed_step1 = StringHelper.isNotEmptyString(user_name)
141 
142  if (not passed_step1):
143  return False
144 
145  identity = CdiUtil.bean(Identity)
146  credentials = identity.getCredentials()
147 
148  user_name = credentials.getUsername()
149  user_password = credentials.getPassword()
150  logged_in = False
151  if (StringHelper.isNotEmptyString(user_name) and StringHelper.isNotEmptyString(user_password)):
152  logged_in = authenticationService.authenticate(user_name, user_password)
153 
154  if (not logged_in):
155  return False
156 
157  # Check if there is user which has oneid_user_uid
158  # Avoid mapping OneID account to more than one IDP account
159  find_user_by_uid = userService.getUserByAttribute("oxExternalUid", "oneid:" + oneid_user_uid)
160 
161  if (find_user_by_uid == None):
162  # Add oneid_user_uid to user one id UIDs
163  find_user_by_uid = userService.addUserAttribute(user_name, "oxExternalUid", "oneid:" + oneid_user_uid)
164  if (find_user_by_uid == None):
165  print "OneId. Authenticate for step 2. Failed to update current user"
166  return False
167 
168  return True
169  else:
170  found_user_name = find_user_by_uid.getUserId()
171  print "OneId. Authenticate for step 2. found_user_name: " + found_user_name
172 
173  if StringHelper.equals(user_name, found_user_name):
174  return True
175 
176  return False
177  else:
178  return False
179 

◆ destroy()

def OneIdExternalAuthenticator.PersonAuthentication.destroy (   self,
  configurationAttributes 
)
29  def destroy(self, configurationAttributes):
30  print "OneId. Destroy"
31  print "OneId. Destroyed successfully"
32  return True
33 

◆ getAlternativeAuthenticationMethod()

def OneIdExternalAuthenticator.PersonAuthentication.getAlternativeAuthenticationMethod (   self,
  usageType,
  configurationAttributes 
)
40  def getAlternativeAuthenticationMethod(self, usageType, configurationAttributes):
41  return None
42 

◆ getApiVersion()

def OneIdExternalAuthenticator.PersonAuthentication.getApiVersion (   self)
34  def getApiVersion(self):
35  return 1
36 

◆ getCountAuthenticationSteps()

def OneIdExternalAuthenticator.PersonAuthentication.getCountAuthenticationSteps (   self,
  configurationAttributes 
)
223  def getCountAuthenticationSteps(self, configurationAttributes):
224  identity = CdiUtil.bean(Identity)
225  if (identity.isSetWorkingParameter("oneid_count_login_steps")):
226  return identity.getWorkingParameter("oneid_count_login_steps")
227 
228  return 2
229 

◆ getExtraParametersForStep()

def OneIdExternalAuthenticator.PersonAuthentication.getExtraParametersForStep (   self,
  configurationAttributes,
  step 
)
217  def getExtraParametersForStep(self, configurationAttributes, step):
218  if (step == 2):
219  return Arrays.asList("oneid_user_uid")
220 
221  return None
222 

◆ getPageForStep()

def OneIdExternalAuthenticator.PersonAuthentication.getPageForStep (   self,
  configurationAttributes,
  step 
)
230  def getPageForStep(self, configurationAttributes, step):
231  if (step == 1):
232  return "/auth/oneid/oneidlogin.xhtml"
233  return "/auth/oneid/oneidpostlogin.xhtml"
234 

◆ init()

def OneIdExternalAuthenticator.PersonAuthentication.init (   self,
  configurationAttributes 
)
24  def init(self, configurationAttributes):
25  print "OneId. Initialization"
26  print "OneId. Initialized successfully"
27  return True
28 

◆ isValidAuthenticationMethod()

def OneIdExternalAuthenticator.PersonAuthentication.isValidAuthenticationMethod (   self,
  usageType,
  configurationAttributes 
)
37  def isValidAuthenticationMethod(self, usageType, configurationAttributes):
38  return True
39 

◆ logout()

def OneIdExternalAuthenticator.PersonAuthentication.logout (   self,
  configurationAttributes,
  requestParameters 
)
235  def logout(self, configurationAttributes, requestParameters):
236  return True
237 

◆ prepareForStep()

def OneIdExternalAuthenticator.PersonAuthentication.prepareForStep (   self,
  configurationAttributes,
  requestParameters,
  step 
)
180  def prepareForStep(self, configurationAttributes, requestParameters, step):
181  identity = CdiUtil.bean(Identity)
182  authenticationService = CdiUtil.bean(AuthenticationService)
183 
184  server_flag = configurationAttributes.get("oneid_server_flag").getValue2()
185  callback_attrs = configurationAttributes.get("oneid_callback_attrs").getValue2()
186  creds_file = configurationAttributes.get("oneid_creds_file").getValue2()
187 
188  # Create OneID
189  authn = OneID(server_flag)
190 
191  # Set path to credentials file
192  authn.creds_file = creds_file
193 
194  if (step == 1):
195  print "OneId. Prepare for step 1"
196 
197  facesContext = CdiUtil.bean(FacesContext)
198  request = facesContext.getExternalContext().getRequest()
199  validation_page = request.getContextPath() + "/postlogin.htm?" + "request_uri=&" + authenticationService.parametersAsString()
200  print "OneId. Prepare for step 1. validation_page: " + validation_page
201 
202  oneid_login_button = authn.draw_signin_button(validation_page, callback_attrs, True)
203  print "OneId. Prepare for step 1. oneid_login_button: " + oneid_login_button
204 
205  identity.setWorkingParameter("oneid_login_button", oneid_login_button)
206  identity.setWorkingParameter("oneid_script_header", authn.script_header)
207  identity.setWorkingParameter("oneid_form_script", authn.oneid_form_script)
208 
209  return True
210  elif (step == 2):
211  print "OneId. Prepare for step 2"
212 
213  return True
214  else:
215  return False
216 

メンバ詳解

◆ currentTimeMillis

OneIdExternalAuthenticator.PersonAuthentication.currentTimeMillis

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