archimed: use new mandaye backend

This commit is contained in:
Jérôme Schneider 2014-10-30 10:06:21 +01:00
parent f25e030c80
commit 294da17ba8
1 changed files with 15 additions and 13 deletions

View File

@ -5,10 +5,11 @@ import json
import re
import urllib
from importlib import import_module
from urlparse import parse_qs
from mandaye import config
from mandaye.backends.default import ManagerServiceProvider, ManagerIDPUser, ManagerSPUser
from mandaye.backends.default import Association
from mandaye.http import HTTPResponse, HTTPHeader, HTTPRequest
from mandaye.log import logger
from mandaye.response import _500, _302, template_response
@ -80,10 +81,16 @@ def associate_confirm(env, values, request, response):
return template_response(values.get('template'), values)
def json_response(env, values, request, response):
from cam.configs.archimed_saml import auth
site_name = env["mandaye.config"]["site_name"]
headers = HTTPHeader({'Content-Type': ['application/json']})
target = '%s/EXPLOITATION/DEFAULT/Ermes/Services/ILSClient.svc/RetrieveAccount' % \
env['target'].geturl()
auth_type = env['mandaye.config']['auth_type']
mapper_name = env['mandaye.config']['mapper']
Auth = import_module(config.authentifications[auth_type])
mapper = import_module(config.mappers[mapper_name])
auth = Auth(env, mapper)
qs = parse_qs(env['QUERY_STRING'])
if qs.has_key('nameid'):
unique_id = qs['nameid'][-1]
@ -91,26 +98,21 @@ def json_response(env, values, request, response):
logger.warning('archimed json: no nameid id into get')
return HTTPResponse(401, 'Unauthorized', headers,
"{'error': 'bad parameter no nameid'}")
service_provider = ManagerServiceProvider.get_or_create(auth.site_name)
idp_user = ManagerIDPUser.get(unique_id)
if not idp_user:
logger.warning('archimed json: NameID %s not found' % unique_id)
return HTTPResponse(401, 'Unauthorized', headers,
"{'error': 'archimed json: NameID %s not found'}" % unique_id)
sp_user = ManagerSPUser.get_last_connected(idp_user, service_provider)
if not sp_user:
associations = Association.get(site_name, unique_id)
if not associations:
return HTTPResponse(401, 'Unauthorized', headers,
"{'error': '%s is not associate with %s'}" %\
(unique_id, auth.site_name))
(unique_id, site_name))
association = associations[0]
post_values = copy.copy(sp_user.post_values)
post_values = copy.copy(association['sp_post_values'])
if config.encrypt_sp_password:
password = auth.decrypt_pwd(post_values[auth.form_values['password_field']])
post_values[auth.form_values['password_field']] = password
response = auth.replay(env, post_values)
cookies = response.cookies
content = '{"codeConfig":"", "xslPath":"Services/LectorShortAccount.xslt"}'
request = HTTPRequest(cookies, headers, "POST", content)
request = HTTPRequest(cookies, headers, "POST", content)
request.msg = content
return get_response(env, request, target)