How to use the crossbar._util.hlid function in crossbar

To help you get started, we’ve selected a few crossbar examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github crossbario / crossbar / crossbar / node / node.py View on Github external
def set_service_session(self, session, realm, authrole=None):
        self.log.info('{func}(session={session}, realm="{realm}", authrole="{authrole}")',
                      func=hltype(self.set_service_session), session=session,
                      realm=hlid(realm), authrole=hlid(authrole))
        if realm not in self._service_sessions:
            self._service_sessions[realm] = {}
        self._service_sessions[realm][authrole] = session
github crossbario / crossbar / crossbar / router / dealer.py View on Github external
def on_authorize_success(authorization):
            # the call to authorize the action _itself_ succeeded. now go on depending on whether
            # the action was actually authorized or not ..
            if not call.procedure.endswith('.on_log'):
                self.log.debug(
                    '{func}::on_authorize_success() - permission {result} for CALL of procedure "{procedure}" [realm="{realm}", session_id={session_id}, authid="{authid}", authrole="{authrole}"]',
                    func=hltype(self.processCall),
                    result=hlflag(authorization['allow'], 'GRANTED', 'DENIED'),
                    procedure=hlid(call.procedure),
                    realm=hlid(session._realm),
                    session_id=hlid(session._session_id),
                    authid=hlid(session._authid),
                    authrole=hlid(session._authrole))

            if not authorization['allow']:
                reply = message.Error(
                    message.Call.MESSAGE_TYPE,
                    call.request,
                    ApplicationError.NOT_AUTHORIZED,
                    ['session (session_id={}, authid="{}", authrole="{}") is not authorized to call procedure "{}" on realm "{}"'.format(
                        session._session_id, session._authid, session._authrole, call.procedure, session._realm)]
                )
                reply.correlation_id = call.correlation_id
                reply.correlation_uri = call.procedure
                reply.correlation_is_anchor = False
                reply.correlation_is_last = True
                self._router.send(session, reply)

            else:
github crossbario / crossbar / crossbar / node / node.py View on Github external
"register": True,
                        "publish": True,
                        "subscribe": True
                    },
                    "disclose": {
                        "caller": True,
                        "publisher": True
                    },
                    "cache": True
                }
            ]
        }
        self._router_factory.add_role(self._realm, controller_role_config)
        self.log.info('{func} node-wide role "{authrole}" added on node management router realm "{realm}"',
                      func=hltype(self._add_global_roles), authrole=hlid(controller_role_config['name']),
                      realm=hlid(self._realm))
github crossbario / crossbar / crossbar / worker / container.py View on Github external
def _ready(s):
                    # this is different from "self.config.controller._realm" !!
                    self.log.info('Container component ready: component_id="{component_id}", realm="{realm}", authrole="{authrole}", authid="{authid}", session={session} {func}',
                                  func=hltype(self.onJoin), component_id=hlid(component_id), realm=hlid(session._realm),
                                  authid=hlid(session._authid), authrole=hlid(session._authrole), session=hlid(session._session_id))
                    if not joined_d.called:
                        joined_d.callback(None)
                session.on('ready', _ready)
github crossbario / crossbar / crossbar / router / session.py View on Github external
:param authid: The fixed/trusted authentication ID under which the session will run.
        :type authid: str

        :param authrole: The fixed/trusted authentication role under which the session will run.
        :type authrole: str
        """
        assert isinstance(session, ApplicationSession), 'session must be of class ApplicationSession, not {}'.format(session.__class__.__name__ if session else type(session))
        assert isinstance(router, Router), 'router must be of class Router, not {}'.format(router.__class__.__name__ if router else type(router))
        assert(authid is None or isinstance(authid, str))
        assert(authrole is None or isinstance(authrole, str))
        assert(authextra is None or type(authextra) == dict)

        self.log.debug('{func}(session={session}, router={router}, authid="{authid}", authrole="{authrole}", authextra={authextra}, store={store})',
                       func=hltype(RouterApplicationSession.__init__), session=session, router=router,
                       authid=hlid(authid), authrole=hlid(authrole), authextra=authextra, store=store)

        # remember router we are wrapping the app session for
        #
        self._router = router

        # remember wrapped app session
        #
        self._session = session

        # remember "trusted" authentication information
        #
        self._trusted_authid = authid
        self._trusted_authrole = authrole
        self._trusted_authextra = authextra

        # FIXME: do we need / should we do this?
github crossbario / crossbar / crossbar / router / router.py View on Github external
detached_session_ids = []
        if session is None:
            # detach all sessions from router
            for session in list(self._session_id_to_session.values()):
                self._detach(session)
                detached_session_ids.append(session._session_id)
        else:
            # detach single session from router
            self._detach(session)
            detached_session_ids.append(session._session_id)

        self.log.info('detached session {session} from realm "{realm}" (authid="{authid}", authrole="{authrole}", detached {detached_session_ids} sessions total) {func}',
                      func=hltype(self.detach),
                      session=hlid(session._session_id) if session else '',
                      authid=hlid(session._authid),
                      authrole=hlid(session._authrole),
                      detached_session_ids=hlval(len(detached_session_ids)),
                      realm=hlid(session._realm))

        return detached_session_ids
github crossbario / crossbar / crossbar / node / node.py View on Github external
# get controller config/options
        controller_config = self._config.get('controller', {})
        controller_options = controller_config.get('options', {})

        # the node ID: CLI takes precedence over config over hostname
        if node_id:
            self._node_id = node_id
            _node_id_source = 'explicit run-time argument'
        elif 'id' in controller_config:
            self._node_id = controller_config['id']
            _node_id_source = 'explicit configuration'
        else:
            self._node_id = '{}-{}'.format(socket.gethostname(), os.getpid()).lower()
            _node_id_source = 'hostname/pid'
        self.log.info('Node ID {node_id} set from {node_id_source}',
                      node_id=hlid(self._node_id),
                      node_id_source=_node_id_source)

        # set controller process title
        try:
            import setproctitle
        except ImportError:
            self.log.warn("Warning, could not set process title (setproctitle not installed)")
        else:
            setproctitle.setproctitle(controller_options.get('title', 'crossbar-controller'))

        # add the node controller singleton component
        self._controller = self.NODE_CONTROLLER(self)

        # local node management router
        self._router_factory = RouterFactory(self._node_id, None, None)
        self._router_session_factory = RouterSessionFactory(self._router_factory)
github crossbario / crossbar / crossbar / router / auth / anonymous.py View on Github external
def hello(self, realm: str, details: types.SessionDetails):
        self.log.info('{func}(realm={realm}, details.realm={authrealm}, details.authid={authid}, details.authrole={authrole}) [config={config}]',
                      func=hltype(self.hello), realm=hlid(realm), authrealm=hlid(details.realm),
                      authid=hlid(details.authid), authrole=hlid(details.authrole), config=self._config)

        # remember the realm the client requested to join (if any)
        self._realm = realm

        self._authid = self._config.get('authid', util.generate_serial_number())

        self._session_details['authmethod'] = 'anonymous'
        self._session_details['authextra'] = details.authextra

        # WAMP-anonymous "static"
        if self._config['type'] == 'static':

            self._authprovider = 'static'

            # FIXME: if cookie tracking is enabled, set authid to cookie value
            # self._authid = self._transport._cbtid
github crossbario / crossbar / crossbar / worker / proxy.py View on Github external
def _on_backend_joined(session, details):
                    self.log.info('Proxy backend session JOINED: session_id={backend_session_id} session={backend_session}, details={details}',
                                  backend_session_id=hlid(details.session), backend_session=session,
                                  pending_session_id=self._pending_session_id, details=details)
                    # we're ready now! store and return the backend session
                    self._backend_session = session

                    # we set the frontend session ID to that of the backend session mapped for our frontend session ..
                    self._session_id = details.session
                    # .. NOT our (fake) pending session ID (generated in the proxy worker)
                    # self._session_id = self._pending_session_id

                    # credentials of the backend session mapped for our frontend session
                    self._realm = details.realm
                    self._authid = details.authid
                    self._authrole = details.authrole

                    # this is the authextra returned for the backend session mapped for our frontend session
                    self._authextra = details.authextra
github crossbario / crossbar / crossbar / router / router.py View on Github external
self.log.debug('{func}(session={session})', func=hltype(self.detach), session=session)

        detached_session_ids = []
        if session is None:
            # detach all sessions from router
            for session in list(self._session_id_to_session.values()):
                self._detach(session)
                detached_session_ids.append(session._session_id)
        else:
            # detach single session from router
            self._detach(session)
            detached_session_ids.append(session._session_id)

        self.log.info('detached session {session} from realm "{realm}" (authid="{authid}", authrole="{authrole}", detached {detached_session_ids} sessions total) {func}',
                      func=hltype(self.detach),
                      session=hlid(session._session_id) if session else '',
                      authid=hlid(session._authid),
                      authrole=hlid(session._authrole),
                      detached_session_ids=hlval(len(detached_session_ids)),
                      realm=hlid(session._realm))

        return detached_session_ids