def get(self): logging.warning("cas return") ticket = self.get_query_argument('ticket') logging.warning("ticket:%s", ticket) client = CASClient(version='2', renew=False, extra_login_params=False, server_url=CONF.lfid_url, service_url='http://{0}/{1}'.format( self.request.host, CONF.lfid_return_url)) user, attrs, _ = client.verify_ticket(ticket) logging.debug("user:%s", user) logging.debug("attr:%s", attrs) openid = user role = const.DEFAULT_ROLE new_user_info = { 'openid': openid, 'email': attrs['mail'], 'fullname': attrs['profile_name_full'], const.ROLE: role } user = yield dbapi.db_find_one(self.table, {'openid': openid}) if not user: dbapi.db_save(self.table, new_user_info) else: role = user.get(const.ROLE) self.clear_cookie(const.OPENID) self.clear_cookie(const.ROLE) self.clear_cookie('ticket') self.set_secure_cookie(const.OPENID, openid) self.set_secure_cookie(const.ROLE, role) self.set_secure_cookie('ticket', ticket) self.redirect('http://{0}'.format(self.request.host))
def get(self): logging.warning("jira return") # Step 1. Use the request token in the session to build a new client. consumer = oauth.Consumer(CONF.jira_oauth_consumer_key, CONF.jira_oauth_consumer_secret) token = oauth.Token(self.get_secure_cookie('oauth_token'), self.get_secure_cookie('oauth_token_secret')) client = oauth.Client(consumer, token) client.set_signature_method(SignatureMethod_RSA_SHA1()) # Step 2. Request the authorized access token from Jira. try: resp, content = client.request(CONF.jira_oauth_access_token_url, "POST") except Exception as e: logging.error("Connect jira exception:%s", e) self._auth_failure('Error: Connection to Jira failed. \ Please contact an Administrator') if resp['status'] != '200': logging.error("Connect jira error:%s", resp) self._auth_failure('Error: Connection to Jira failed. \ Please contact an Administrator') access_token = dict(parse.parse_qsl(content.decode())) logging.warning("access_token: %s", access_token) # jira = JIRA(server=CONF.jira_jira_url, oauth=oauth_dict) jira = get_jira(access_token) lf_id = jira.current_user() logging.warning("lf_id: %s", lf_id) user = jira.myself() logging.warning("user: %s", user) # Step 3. Lookup the user or create them if they don't exist. role = const.DEFAULT_ROLE new_user_info = { 'openid': lf_id, 'email': user['emailAddress'], 'fullname': user['displayName'], const.ROLE: role } user = yield dbapi.db_find_one(self.table, {'openid': lf_id}) if not user: dbapi.db_save(self.table, new_user_info) else: role = user.get(const.ROLE) self.clear_cookie(const.OPENID) self.clear_cookie(const.ROLE) self.set_secure_cookie(const.OPENID, lf_id) self.set_secure_cookie(const.ROLE, role) self.redirect(url=CONF.ui_url)
def _inner_create(self, **kwargs): data = self.table_cls.from_dict(self.json_args) for k, v in kwargs.iteritems(): if k != 'query': data.__setattr__(k, v) if self.table != 'results': data.creation_date = datetime.now() _id = yield dbapi.db_save(self.table, data.format()) logging.warning("_id:%s", _id) raise gen.Return(_id)
def get(self): ticket = self.get_query_argument('ticket', default=None) if ticket: (user, attrs, _) = self.cas_client.verify_ticket(ticket=ticket) login_user = { 'user': user, 'email': attrs.get('mail'), 'fullname': attrs.get('field_lf_full_name'), 'groups': constants.TESTAPI_USERS + attrs.get('group', []) } q_user = {'user': user} db_user = yield dbapi.db_find_one(self.table, q_user) if not db_user: dbapi.db_save(self.table, login_user) else: dbapi.db_update(self.table, q_user, login_user) self.clear_cookie(constants.TESTAPI_ID) self.set_secure_cookie(constants.TESTAPI_ID, user) self.redirect(url=CONF.ui_url)
def get(self): if self.get_query_argument(const.OPENID_MODE) == 'cancel': self._auth_failure('Authentication canceled.') openid = self.get_query_argument(const.OPENID_CLAIMED_ID) role = const.DEFAULT_ROLE new_user_info = { 'openid': openid, 'email': self.get_query_argument(const.OPENID_NS_SREG_EMAIL), 'fullname': self.get_query_argument(const.OPENID_NS_SREG_FULLNAME), const.ROLE: role } user = yield dbapi.db_find_one(self.table, {'openid': openid}) if not user: dbapi.db_save(self.table, new_user_info) else: role = user.get(const.ROLE) self.clear_cookie(const.OPENID) self.clear_cookie(const.ROLE) self.set_secure_cookie(const.OPENID, openid) self.set_secure_cookie(const.ROLE, role) self.redirect(url=CONF.ui_url)
def _create(self, **kwargs): # resource = self._inner_create(**kwargs) data = self.table_cls.from_dict(self.json_args) for k, v in kwargs.iteritems(): if k != 'query': data.__setattr__(k, v) if self.table != 'results': data.creation_date = datetime.now() _id = yield dbapi.db_save(self.table, data.format()) if 'name' in self.json_args: resource = data.name else: resource = _id self.finish_request(self._create_response(resource))
def _create(self, **kwargs): """ :param miss_checks: [miss1, miss2] :param db_checks: [(table, exist, query, error)] """ data = self.table_cls.from_dict(self.json_args) for k, v in kwargs.iteritems(): if k != 'query': data.__setattr__(k, v) if self.table != 'results': data.creation_date = datetime.now() _id = yield dbapi.db_save(self.table, data.format()) if 'name' in self.json_args: resource = data.name else: resource = _id self.finish_request(self._create_response(resource))