def parse_incoming(sh,url,headers,data): if url.find('logout.php?step=2')>-1: return LOGOUT_PROCESS_SUCCESS c=re.compile(u'\S*mv_login_id=(?P<mv_login_id>([0-9a-zA-Z]+))') m=c.match(url) if m: try: #server_error_logger.warning('') mv_login_id = m.groupdict().get('mv_login_id') sw = SessionWrapper(sh) # Fetch webservice ## UserService cli_user = JSONWSPClient('http://mv-login.valhalla.local/ws-2/UserService/jsonwsp/description') cli_user.parse_url('http://mv-login.valhalla.local/ws-2/UserService/jsonwsp') res = cli_user.whoami(session_id=mv_login_id, lookup_primary_group = True, extract_usergroups = False, extract_userroles = True, extract_generated_passwords = False) if not res.response_dict['result']['method_result']['res_code']==0: raise AuthProcessFailed(MVLoginCompanyAuthHandler,details="Failed to communicate with MV-Login webservice",system_code=400) user_info = res.response_dict['result']['user_info'] ## DomainService cli_domain = JSONWSPClient('http://mv-login.valhalla.local/ws-2/DomainService/jsonwsp/description') cli_domain.parse_url('http://mv-login.valhalla.local/ws-2/DomainService/jsonwsp') res = cli_domain.listDomains(session_id=mv_login_id, parent_domain=user_info['domain']) if not res.response_dict['result']['method_result']['res_code']==0: raise AuthProcessFailed(MVLoginCompanyAuthHandler,details="Failed to communicate with MV-Login webservice",system_code=400) domain_info = res.response_dict['result']['domains'][0] # Institution #sw.set_institution_id(user_info['org_code']) sw.set_institution_id(domain_info['institutionCode']) sw.set_institution_name(domain_info['o']) sw.set_institution_type(domain_info.get('domainType','company')) # Domain sw.set_domain(user_info['domain']) # IdP sw.set_identity_provider('mvlogin-company') # User sw.set_username(user_info['uid']) sw.set_uid(user_info['uid']) sw.set_given_name(user_info.get('givenName','Unknown')) sw.set_surname(user_info.get('sn','Unknown')) roles = user_info.get('roles',['employee']) if not len(roles): raise AuthProcessFailed(MVLoginCompanyAuthHandler,details='Problem occurred while fetching roles',system_code=401) sw.set_role(roles) # User - optional if user_info.get('mail'): sw.set_mail(user_info.get('mail')) if user_info.get('sex'): sw.set_sex(str(user_info.get('sex')) ) if user_info.get('mobile'): sw.set_mobile(str(user_info.get('mobile')) ) if user_info.get('telephoneNumber'): sw.set_telephone_number(str(user_info.get('telephoneNumber')) ) if user_info.get('street'): sw.set_street(user_info.get('street')) if user_info.get('postalCode'): sw.set_postal_code(str(user_info.get('postalCode')) ) if user_info.get('l'): sw.set_city(user_info.get('l')) if user_info.get('st'): sw.set_state(user_info.get('st')) if user_info.get('birthday'): sw.set_date_of_birth(user_info.get('birthday')) return AUTH_PROCESS_SUCCESS except Exception, e: logger.warning('Error: %s' % e) logger.warning(get_traceback()) raise e
def parse_incoming(sh,url,headers,data): if url.find('logout.php?step=2')>-1: return LOGOUT_PROCESS_SUCCESS c=re.compile(u'\S*mv_login_id=(?P<mv_login_id>([0-9a-zA-Z]+))') m=c.match(url) if m: try: mv_login_id = m.groupdict().get('mv_login_id') sw = SessionWrapper(sh) # Fetch webservice ## UserService cli_user = JSONWSPClient('http://mv-login.valhalla.local/ws-2/UserService/jsonwsp/description') cli_user.parse_url('http://mv-login.valhalla.local/ws-2/UserService/jsonwsp') res = cli_user.whoami(session_id=mv_login_id, lookup_primary_group = True, extract_usergroups = False, extract_userroles = True, extract_generated_passwords = False) if not res.response_dict['result']['method_result']['res_code']==0: raise AuthProcessFailed(MVLoginAuthHandler,details="Failed to communicate with MV-Login webservice",system_code=400) user_info = res.response_dict['result']['user_info'] ## DomainService cli_domain = JSONWSPClient('http://mv-login.valhalla.local/ws-2/DomainService/jsonwsp/description') cli_domain.parse_url('http://mv-login.valhalla.local/ws-2/DomainService/jsonwsp') res = cli_domain.listDomains(session_id=mv_login_id, parent_domain=user_info['domain']) if not res.response_dict['result']['method_result']['res_code']==0: raise AuthProcessFailed(MVLoginAuthHandler,details="Failed to communicate with MV-Login webservice",system_code=400) domain_info = res.response_dict['result']['domains'][0] # Institution #sw.set_institution_id(user_info['org_code']) sw.set_institution_id(domain_info['institutionCode']) sw.set_institution_name(domain_info['o']) sw.set_institution_type(domain_info.get('domainType','school')) # Domain sw.set_domain(user_info['domain']) # IdP sw.set_identity_provider('mvlogin') # User sw.set_username(user_info['uid']) sw.set_uid(user_info['uid']) sw.set_given_name(user_info.get('givenName','Unknown')) sw.set_surname(user_info.get('sn','Unknown')) roles = user_info.get('roles',['pupil']) if not len(roles): raise AuthProcessFailed(MVLoginAuthHandler,details='Problem occurred while fetching roles',system_code=401) sw.set_role(roles) # User - optional if user_info.get('mail'): sw.set_mail(user_info.get('mail')) if user_info.get('sex'): sw.set_sex(str(user_info.get('sex')) ) if user_info.get('mobile'): sw.set_mobile(str(user_info.get('mobile')) ) if user_info.get('telephoneNumber'): sw.set_telephone_number(str(user_info.get('telephoneNumber')) ) if user_info.get('street'): sw.set_street(user_info.get('street')) if user_info.get('postalCode'): sw.set_postal_code(str(user_info.get('postalCode')) ) if user_info.get('l'): sw.set_city(user_info.get('l')) if user_info.get('st'): sw.set_state(user_info.get('st')) if user_info.get('birthday'): sw.set_date_of_birth(user_info.get('birthday')) # User - class res = cli_user.listOwnGroups(session_id=mv_login_id,domain=user_info['domain'],uid=user_info['uid'],group_types=['classtype']) if not res.response_dict['result']['method_result']['res_code']==0: raise AuthProcessFailed(MVLoginAuthHandler,details="Failed to communicate with MV-Login webservice",system_code=400) groups = res.response_dict['result']['groups'] if len(groups): first_school_year = groups[0].get(u'firstSchoolYear',None) grade_ok = False if str(first_school_year).strip().isdigit(): grade = datetools.first_school_year_to_grade(int(first_school_year)) sw.set_grade(str(grade)) grade_ok = True track_name = groups[0].get(u'calculatedName',None) if not grade_ok and track_name: m = re.search('\d+', track_name) if m: sw.set_grade(m.group()) if track_name: # Remove any digits, dots and excessive spacings from the track_name: tn = re.sub('\s+', ' ', re.sub('[\d,\.]+', '', track_name)).strip() sw.set_track_name(tn) return AUTH_PROCESS_SUCCESS except Exception as e: logger.warning('Error: %s' % e) logger.warning(get_traceback()) raise e return AUTH_PROCESS_IDLE