Пример #1
0
    def __init__(self, db, user_model, role_model):
        """Init new datastore given user and role models."""
        SQLAlchemyUserDatastore.__init__(self, db, user_model, role_model)

        log = current_app.artemis_logger

        self.role_mapping = config_value("RADIUS_ROLE_MAPPING", default=None)
        self.role_attribute_code = config_value("RADIUS_ROLE_ATTRIBUTE_CODE",
                                                default=None)
        try:
            self.role_attribute_code = (int(self.role_attribute_code)
                                        if self.role_attribute_code is not None
                                        else None)
        except ValueError:
            raise Exception(
                "RADIUS_ROLE_ATTRIBUTE_CODE must be a number (was %s)" %
                self.role_attribute_code)

        self.default_role = config_value("RADIUS_DEFAULT_ROLE", default="user")
        servers = self._create_radius_clients(
            config_value("RADIUS_SERVERS", default=[]))
        self.client_iterator = cycle(servers)
        self.client_attempts = len(servers)
        try:
            self.current_client = next(self.client_iterator)
            log.info(
                "Radius servers configured. First server to try is %s:%s" %
                (self.current_client.server, self.current_client.authport))
        except StopIteration:
            raise Exception(
                "No radius servers defined but RADIUS auth is enabled!")
Пример #2
0
 def __init__(self, db, user_model, role_model):
     """Init new datastore given user and role models."""
     SQLAlchemyUserDatastore.__init__(self, db, user_model, role_model)