def create( self, trans, payload, **kwd ): """ POST /api/users Creates a new Galaxy user. """ if not trans.app.config.allow_user_creation: raise HTTPNotImplemented( detail='User creation is not allowed in this Galaxy instance' ) if trans.app.config.use_remote_user and trans.user_is_admin(): user = trans.get_or_create_remote_user(remote_user_email=payload['remote_user_email']) elif trans.user_is_admin(): username = payload[ 'username' ] email = payload[ 'email' ] password = payload[ 'password' ] message = "\n".join( [ validate_email( trans, email ), validate_password( trans, password, password ), validate_publicname( trans, username ) ] ).rstrip() if message: raise exceptions.RequestParameterInvalidException( message ) else: user = self.create_user( trans=trans, email=email, username=username, password=password ) else: raise HTTPNotImplemented() item = user.to_dict( view='element', value_mapper={ 'id': trans.security.encode_id, 'total_disk_usage': float } ) return item
def create(self, trans, payload, **kwd): """ POST /api/users Creates a new Galaxy user. """ if not trans.app.config.allow_user_creation: raise HTTPNotImplemented( detail='User creation is not allowed in this Galaxy instance') if trans.app.config.use_remote_user and trans.user_is_admin(): user = trans.get_or_create_remote_user( remote_user_email=payload['remote_user_email']) item = user.get_api_value(view='element', value_mapper={ 'id': trans.security.encode_id, 'total_disk_usage': float }) else: raise HTTPNotImplemented() return item
def validate_form(self): values = variable_decode(self.request.params) schema_id = values.get('type') if not schema_id: raise HTTPNotImplemented() try: resp = self.validate_values(values) except Invalid, error: log.error(error.error_dict) self.result['values'][schema_id] = error.value or {} self.result['errors'][schema_id] = error.error_dict or {} self.request.response.status_int = 401
def validate_values(self, values, renderTemplates = {}): req = self.request if values.get('token') != req.session.get_csrf_token(): raise InvalidCSRFToken() try: ### determine actual form used in this submission schema_id = values['type'] schema = self.schemas[schema_id] form = schema.getSchema(req) except KeyError, e: raise HTTPNotImplemented("Unexpected submission type!")
def _pick_idp(self, environ, came_from): """ If more than one idp and if none is selected, I have to do wayf or disco """ # check headers to see if it's an ECP request # headers = { # 'Accept' : 'text/html; application/vnd.paos+xml', # 'PAOS' : 'ver="%s";"%s"' % (paos.NAMESPACE, # SERVICE) # } _cli = self.saml_client logger.info("[_pick_idp] %s" % environ) if "HTTP_PAOS" in environ: if environ["HTTP_PAOS"] == PAOS_HEADER_INFO: if 'application/vnd.paos+xml' in environ["HTTP_ACCEPT"]: # Where should I redirect the user to # entityid -> the IdP to use # relay_state -> when back from authentication logger.info("- ECP client detected -") _relay_state = construct_came_from(environ) _entityid = _cli.config.ecp_endpoint(environ["REMOTE_ADDR"]) if not _entityid: return -1, HTTPInternalServerError( detail="No IdP to talk to") logger.info("IdP to talk to: %s" % _entityid) return ecp.ecp_auth_request(_cli, _entityid, _relay_state) else: return -1, HTTPInternalServerError( detail='Faulty Accept header') else: return -1, HTTPInternalServerError( detail='unknown ECP version') idps = self.metadata.with_descriptor("idpsso") logger.info("IdP URL: %s" % idps) idp_entity_id = query = None for key in ['s2repoze.body', "QUERY_STRING"]: query = environ.get(key) if query: try: _idp_entity_id = dict(parse_qs(query))[ self.idp_query_param][0] if _idp_entity_id in idps: idp_entity_id = _idp_entity_id break except KeyError: logger.debug("No IdP entity ID in query: %s" % query) pass if idp_entity_id is None: if len(idps) == 1: # idps is a dictionary idp_entity_id = idps.keys()[0] elif not len(idps): return -1, HTTPInternalServerError(detail='Misconfiguration') else: idp_entity_id = "" logger.info("ENVIRON: %s" % environ) if self.wayf: if query: try: wayf_selected = dict(parse_qs(query))[ "wayf_selected"][0] except KeyError: return self._wayf_redirect(came_from) idp_entity_id = wayf_selected else: return self._wayf_redirect(came_from) elif self.discosrv: if query: idp_entity_id = _cli.parse_discovery_service_response( query=environ.get("QUERY_STRING")) else: sid_ = sid() self.outstanding_queries[sid_] = came_from logger.debug("Redirect to Discovery Service function") eid = _cli.config.entityid ret = _cli.config.getattr( "endpoints", "sp")["discovery_response"][0][0] ret += "?sid=%s" % sid_ loc = _cli.create_discovery_service_request( self.discosrv, eid, **{"return": ret}) return -1, SeeOther(loc) else: return -1, HTTPNotImplemented( detail='No WAYF or DJ present!') logger.info("Chosen IdP: '%s'" % idp_entity_id) return 0, idp_entity_id
def undelete( self, trans, **kwd ): raise HTTPNotImplemented()
def update( self, trans, **kwd ): raise HTTPNotImplemented()
def create(self, trans, tag_name, payload=None, **kwd): payload = payload or {} raise HTTPNotImplemented()
def _pick_idp(self, environ, came_from): """ If more than one idp and if none is selected, I have to do wayf or disco """ # check headers to see if it's an ECP request # headers = { # 'Accept' : 'text/html; application/vnd.paos+xml', # 'PAOS' : 'ver="%s";"%s"' % (paos.NAMESPACE, SERVICE) # } logger.info("[_pick_idp] %s" % environ) if "HTTP_PAOS" in environ: if environ["HTTP_PAOS"] == PAOS_HEADER_INFO: if 'application/vnd.paos+xml' in environ["HTTP_ACCEPT"]: # Where should I redirect the user to # entityid -> the IdP to use # relay_state -> when back from authentication logger.info("- ECP client detected -") _relay_state = construct_came_from(environ) _entityid = self.saml_client.config.ecp_endpoint( environ["REMOTE_ADDR"]) if not _entityid: return -1, HTTPInternalServerError( detail="No IdP to talk to") logger.info("IdP to talk to: %s" % _entityid) return ecp.ecp_auth_request(self.saml_client, _entityid, _relay_state) else: return -1, HTTPInternalServerError( detail='Faulty Accept header') else: return -1, HTTPInternalServerError( detail='unknown ECP version') idps = self.conf.idps() logger.info("IdP URL: %s" % idps) if len(idps) == 1: # idps is a dictionary idp_entity_id = idps.keys()[0] elif not len(idps): return -1, HTTPInternalServerError(detail='Misconfiguration') else: idp_entity_id = "" logger.info("ENVIRON: %s" % environ) query = environ.get('s2repoze.body', '') if not query: query = environ.get("QUERY_STRING", "") logger.info("<_pick_idp> query: %s" % query) if self.wayf: if query: try: wayf_selected = dict( parse_qs(query))["wayf_selected"][0] except KeyError: return self._wayf_redirect(came_from) idp_entity_id = wayf_selected else: return self._wayf_redirect(came_from) elif self.discovery: if query: idp_entity_id = self.saml_client.get_idp_from_discovery_service( query=environ.get("QUERY_STRING")) else: sid_ = sid() self.outstanding_queries[sid_] = came_from logger.info("Redirect to Discovery Service function") loc = self.saml_client.request_to_discovery_service( self.discovery) return -1, HTTPSeeOther(headers=[('Location', loc)]) else: return -1, HTTPNotImplemented(detail='No WAYF or DJ present!') logger.info("Choosen IdP: '%s'" % idp_entity_id) return 0, idp_entity_id