コード例 #1
0
ファイル: jwt_auth.py プロジェクト: JCF13/proyecto
def make_header(user):
    valido = False
    usuario = find_user_by_username(user['username'])
    if bcrypt.check_password_hash(usuario.password, user['passwd']):
        valido = True

    if valido is True:
        respuesta = {}
        respuesta['result'] = 0

        tok = {
            "access_token": create_access_token(identity=usuario.user_id),
            "refresh_token": create_refresh_token(identity=usuario.user_id)
        }
        respuesta['your_auth'] = marshal(tok, auth_token, skip_none=True)

        return marshal(respuesta, loginResp, skip_none=True)
    else:
        respuesta = {}
        fallo = {
            'error_type': 24,
            'error_desc': 'Credenciales Autorización incorrectas',
        }
        respuesta['result'] = -1

        respuesta['error'] = marshal(fallo, errorSchema, skip_none=True)

        return marshal(respuesta, loginResp, skip_none=True)
コード例 #2
0
 def format(self, value):
     try:
         if value.get("track_id"):
             return marshal(value, track_full)
         if value.get("playlist_id"):
             return marshal(value, full_playlist_model)
     except Exception as e:
         raise MarshallingError("Unable to marshal as activity item") from e
コード例 #3
0
 def format(self, value):
     try:
         if value.get("track_id"):
             return marshal(value, track)
         if value.get("playlist_id"):
             return marshal(value, playlist_model)
     except:
         raise MarshallingError("Unable to marshal as activity item")
コード例 #4
0
 def format(self, value):
     try:
         if value.get("type") == "playlist":
             return marshal(value, playlist_identifier)
         if value.get("type") == "explore_playlist":
             return marshal(value, explore_playlist_identifier)
         if value.get("type") == "folder":
             return marshal(value, playlist_library_folder)
     except Exception as e:
         raise MarshallingError(
             f"Unable to marshal as playlist library identifier: {str(value)}"
         ) from e
コード例 #5
0
def handler_invalid_header(error):
    resultado = {}
    resultado['result'] = -1
    resultado['request'] = ' _ '
    fallo = {}
    fallo['error_type'] = 26
    fallo['error_desc'] = error
    errorDoc = marshal(fallo, errorSchema)
    resultado['error'] = errorDoc

    respuesta = marshal(resultado, loginResp)
    elLog = gen_log(respuesta, _LEVELLOG_)
    authorization.logger.log(_LEVELLOG_, elLog)
    return respuesta
コード例 #6
0
def handler_signature_expired(error):
    resultado = {}
    resultado['result'] = -1
    resultado['request'] = ' _ '
    fallo = {}
    fallo['error_type'] = 28
    fallo['error_desc'] = error
    errorDoc = marshal(fallo, errorSchema)
    resultado['error'] = errorDoc
    respuesta = marshal(resultado, loginResp)

    elLog = gen_log(respuesta, _LEVELLOG_)
    authorization.logger.log(_LEVELLOG_, str(elLog))

    return respuesta
コード例 #7
0
    def post(self):

        load_user = request.get_json()
        # request.get_data()

        user_dict = marshal(load_user, loginReq)

        header = make_header(user_dict)
        elLog = gen_log(header, _LEVELLOG_)
        authorization.logger.log(_LEVELLOG_, elLog)

        return header
コード例 #8
0
def handler_invalid_username_login(error):

    load_user = request.get_json()
    print(load_user)
    resultado = {}
    resultado['result'] = -1
    resultado['request'] = ' _ '
    auth = {}
    if load_user.get('username'):
        auth['username'] = load_user['username']
        auth[
            'access_token'] = 'inicio de sesion fallido, el usuario o la contraseña están mal'
    authDoc = marshal(auth, auth_token)
    fallo = {}
    fallo['error_type'] = 26
    fallo['error_desc'] = error
    errorDoc = marshal(fallo, errorSchema)
    resultado['your_auth'] = authDoc
    resultado['error'] = errorDoc

    respuesta = marshal(resultado, loginResp)
    elLog = gen_log(respuesta, _LEVELLOG_)
    authorization.logger.log(_LEVELLOG_, elLog)
    return respuesta
コード例 #9
0
 def __expand_json(js):
     res = {}
     for entry in js:
         # /!\ after marshalling, 'fullname' will be 'key'
         res[entry["fullname"]] = marshal(entry, node_fields)
     return res
コード例 #10
0
    def get(self, server=None, name=None, backup=None):
        """Returns a list of 'nodes' under a given path

        **GET** method provided by the webservice.

        The *JSON* returned is:
        ::

            [
              {
                "date": "2015-05-21 14:54:49",
                "gid": "0",
                "inodes": "173",
                "selected": false,
                "expanded": false,
                "children": [],
                "mode": "drwxr-xr-x",
                "name": "/",
                "key": "/",
                "title": "/",
                "fullname": "/",
                "parent": "",
                "size": "12.0KiB",
                "type": "d",
                "uid": "0"
              }
            ]


        The output is filtered by the :mod:`burpui.misc.acl` module so that you
        only see stats about the clients you are authorized to.

        :param server: Which server to collect data from when in multi-agent
                       mode
        :type server: str

        :param name: The client we are working on
        :type name: str

        :param backup: The backup we are working on
        :type backup: int

        :returns: The *JSON* described above.
        """
        args = self.parser.parse_args()
        server = server or args["serverName"]
        json = []
        if not name or not backup:
            return json

        root_list = sorted(args["root"]) if args["root"] else []
        root_loaded = False
        paths_loaded = []
        to_select_list = []

        if (
            not current_user.is_anonymous
            and not current_user.acl.is_admin()
            and not current_user.acl.is_client_allowed(name, server)
        ):
            self.abort(403, "Sorry, you are not allowed to view this client")

        from_cookie = None
        if args["init"] and not root_list:
            from_cookie = request.cookies.get("fancytree-1-expanded", "")
            if from_cookie:
                args["recursive"] = True
                _root = bui.client.get_tree(name, backup, agent=server)
                root_list = [x["name"] for x in _root]
                for path in from_cookie.split("~"):
                    if not path.endswith("/"):
                        path += "/"
                    if path not in root_list:
                        root_list.append(path)
                root_list = sorted(root_list)

        try:
            root_list_clean = []

            for root in root_list:
                if args["recursive"]:
                    path = ""
                    # fetch the root first if not already loaded
                    if not root_loaded:
                        part = bui.client.get_tree(name, backup, level=0, agent=server)
                        root_loaded = True
                    else:
                        part = []
                    root = root.rstrip("/")
                    to_select = root.rsplit("/", 1)
                    if not to_select[0]:
                        to_select[0] = "/"
                    if len(to_select) == 1:
                        # special case we want to select '/'
                        to_select = ("", "/")
                    if not root:
                        root = "/"
                    to_select_list.append(to_select)
                    root_list_clean.append(root)
                    paths = root.split("/")
                    for level, sub in enumerate(paths, start=1):
                        path = os.path.join(path, sub)
                        if not path:
                            path = "/"
                        if path in paths_loaded:
                            continue
                        temp = bui.client.get_tree(
                            name, backup, path, level, agent=server
                        )
                        paths_loaded.append(path)
                        part += temp
                else:
                    part = bui.client.get_tree(name, backup, root, agent=server)
                json += part

            if args["selected"]:
                for entry in json:
                    for parent, fold in to_select_list:
                        if entry["parent"] == parent and entry["name"] == fold:
                            entry["selected"] = True
                            break
                    if entry["parent"] in root_list_clean:
                        entry["selected"] = True

            if not root_list:
                json = bui.client.get_tree(name, backup, agent=server)
                if args["selected"]:
                    for entry in json:
                        if not entry["parent"]:
                            entry["selected"] = True

            if args["recursive"]:
                tree = {}
                rjson = []
                roots = []
                for entry in json:
                    # /!\ after marshalling, 'fullname' will be 'key'
                    tree[entry["fullname"]] = marshal(entry, node_fields)

                for key, entry in tree.items():
                    parent = entry["parent"]
                    if not entry["children"]:
                        entry["children"] = None
                    if parent:
                        node = tree[parent]
                        if not node["children"]:
                            node["children"] = []
                        node["children"].append(entry)
                        if node["folder"]:
                            node["lazy"] = False
                            node["expanded"] = True
                    else:
                        roots.append(entry["key"])

                for fullname in roots:
                    rjson.append(tree[fullname])

                json = rjson
            else:
                for entry in json:
                    entry["children"] = None
                    if not entry["folder"]:
                        entry["lazy"] = False

        except BUIserverException as e:
            self.abort(500, str(e))
        return json
コード例 #11
0
    def post(self):
        to_register = request.get_json()
        marshalled = marshal(to_register, userRegister)

        return create_user(marshalled)