Exemple #1
0
class SSOLogin(Referenceable, SignalBroadcaster):
    """Login thru the Single Sign On service."""

    __metaclass__ = RemoteMeta

    # calls that will be accessible remotely
    remote_calls = [
        'generate_captcha',
        'register_user',
        'login',
        'validate_email',
        'request_password_reset_token',
        'set_new_password']

    def __init__(self, bus_name, object_path=None,
                 sso_login_processor_class=Account,
                 sso_service_class=None):
        """Initiate the Login object."""
        super(SSOLogin, self).__init__()
        # ignore bus_name and object path so that we do not break the current
        # API. Shall we change this???
        self.root = SSOLoginRoot(sso_login_processor_class, sso_service_class)

    # generate_capcha signals
    def emit_captcha_generated(self, app_name, result):
        """Signal thrown after the captcha is generated."""
        logger.debug('SSOLogin: emitting CaptchaGenerated with app_name "%s" '
                     'and result %r', app_name, result)
        self.emit_signal('on_captcha_generated', app_name, result)

    def emit_captcha_generation_error(self, app_name, raised_error):
        """Signal thrown when there's a problem generating the captcha."""
        logger.debug('SSOLogin: emitting CaptchaGenerationError with '
                     'app_name "%s" and error %r', app_name, raised_error)
        self.emit_signal('on_captcha_generation_error', app_name,
                         except_to_errdict(raised_error.value))

    def generate_captcha(self, app_name, filename):
        """Call the matching method in the processor."""
        self.root.generate_captcha(app_name, filename,
                                   self.emit_captcha_generated,
                                   self.emit_captcha_generation_error)

    # register_user signals
    def emit_user_registered(self, app_name, result):
        """Signal thrown when the user is registered."""
        logger.debug('SSOLogin: emitting UserRegistered with app_name "%s" '
                     'and result %r', app_name, result)
        self.emit_signal('on_user_registered', app_name, result)

    def emit_user_registration_error(self, app_name, raised_error):
        """Signal thrown when there's a problem registering the user."""
        logger.debug('SSOLogin: emitting UserRegistrationError with '
                     'app_name "%s" and error %r', app_name, raised_error)
        self.emit_signal('on_user_registration_error', app_name,
                         except_to_errdict(raised_error.value))

    def register_user(self, app_name, email, password, displayname,
                      captcha_id, captcha_solution):
        """Call the matching method in the processor."""
        self.root.register_user(app_name, email, password, displayname,
                                captcha_id, captcha_solution,
                                self.emit_user_registered,
                                self.emit_user_registration_error)

    # login signals
    def emit_logged_in(self, app_name, result):
        """Signal thrown when the user is logged in."""
        logger.debug('SSOLogin: emitting LoggedIn with app_name "%s" '
                     'and result %r', app_name, result)
        self.emit_signal('on_logged_in', app_name, result)

    def emit_login_error(self, app_name, raised_error):
        """Signal thrown when there is a problem in the login."""
        logger.debug('SSOLogin: emitting LoginError with '
                     'app_name "%s" and error %r', app_name, raised_error)
        self.emit_signal('on_login_error', app_name,
                         except_to_errdict(raised_error.value))

    def emit_user_not_validated(self, app_name, result):
        """Signal thrown when the user is not validated."""
        logger.debug('SSOLogin: emitting UserNotValidated with app_name "%s" '
                     'and result %r', app_name, result)
        self.emit_signal('on_user_not_validated', app_name, result)

    def login(self, app_name, email, password):
        """Call the matching method in the processor."""
        self.root.login(app_name, email, password,
                        self.emit_logged_in, self.emit_login_error,
                        self.emit_user_not_validated)

    # validate_email signals
    def emit_email_validated(self, app_name, result):
        """Signal thrown after the email is validated."""
        logger.debug('SSOLogin: emitting EmailValidated with app_name "%s" '
                     'and result %r', app_name, result)
        self.emit_signal('on_email_validated', app_name, result)

    def emit_email_validation_error(self, app_name, raised_error):
        """Signal thrown when there's a problem validating the email."""
        logger.debug('SSOLogin: emitting EmailValidationError with '
                     'app_name "%s" and error %r', app_name, raised_error)
        self.emit_signal('on_email_validation_error', app_name,
                         except_to_errdict(raised_error.value))

    def validate_email(self, app_name, email, password, email_token):
        """Call the matching method in the processor."""
        self.root.validate_email(app_name, email, password, email_token,
                                 self.emit_email_validated,
                                 self.emit_email_validation_error)

    # request_password_reset_token signals
    def emit_password_reset_token_sent(self, app_name, result):
        """Signal thrown when the token is successfully sent."""
        logger.debug('SSOLogin: emitting PasswordResetTokenSent with app_name '
                     '"%s" and result %r', app_name, result)
        self.emit_signal('on_password_reset_token_sent', app_name, result)

    def emit_password_reset_error(self, app_name, raised_error):
        """Signal thrown when there's a problem sending the token."""
        logger.debug('SSOLogin: emitting PasswordResetError with '
                     'app_name "%s" and error %r', app_name, raised_error)
        self.emit_signal('on_password_reset_error', app_name,
                         except_to_errdict(raised_error.value))

    def request_password_reset_token(self, app_name, email):
        """Call the matching method in the processor."""
        self.root.request_password_reset_token(app_name, email,
                                        self.emit_password_reset_token_sent,
                                        self.emit_password_reset_error)

    # set_new_password signals
    def emit_password_changed(self, app_name, result):
        """Signal thrown when the token is successfully sent."""
        logger.debug('SSOLogin: emitting PasswordChanged with app_name "%s" '
                     'and result %r', app_name, result)
        self.emit_signal('on_password_changed', app_name, result)

    def emit_password_change_error(self, app_name, raised_error):
        """Signal thrown when there's a problem sending the token."""
        logger.debug('SSOLogin: emitting PasswordChangeError with '
                     'app_name "%s" and error %r', app_name, raised_error)
        self.emit_signal('on_password_change_error', app_name,
                         except_to_errdict(raised_error.value))

    def set_new_password(self, app_name, email, token, new_password):
        """Call the matching method in the processor."""
        self.root.set_new_password(app_name, email, token, new_password,
                                   self.emit_password_changed,
                                   self.emit_password_change_error)
Exemple #2
0
class SSOLogin(dbus.service.Object):
    """Login thru the Single Sign On service."""

    # Operator not preceded by a space (fails with dbus decorators)
    # pylint: disable=C0322

    def __init__(self, bus_name, object_path=DBUS_ACCOUNT_PATH,
                 sso_login_processor_class=Account,
                 sso_service_class=None):
        """Initiate the Login object."""
        dbus.service.Object.__init__(self, object_path=object_path,
                                     bus_name=bus_name)
        self.root = SSOLoginRoot(sso_login_processor_class, sso_service_class)
        msg = 'Use ubuntu_sso.main.CredentialsManagement instead.'
        warnings.warn(msg, DeprecationWarning)

    # generate_capcha signals
    @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")
    def CaptchaGenerated(self, app_name, result):
        """Signal thrown after the captcha is generated."""
        logger.debug('SSOLogin: emitting CaptchaGenerated with app_name "%s" '
                     'and result %r', app_name, result)

    @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="sa{ss}")
    def CaptchaGenerationError(self, app_name, error):
        """Signal thrown when there's a problem generating the captcha."""
        logger.debug('SSOLogin: emitting CaptchaGenerationError with '
                     'app_name "%s" and error %r', app_name, error)

    @dbus.service.method(dbus_interface=DBUS_IFACE_USER_NAME,
                         in_signature='ss')
    def generate_captcha(self, app_name, filename):
        """Call the matching method in the processor."""
        self.root.generate_captcha(app_name, filename,
                                   self.CaptchaGenerated,
                                   self.CaptchaGenerationError)

    # register_user signals
    @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")
    def UserRegistered(self, app_name, result):
        """Signal thrown when the user is registered."""
        logger.debug('SSOLogin: emitting UserRegistered with app_name "%s" '
                     'and result %r', app_name, result)

    @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="sa{ss}")
    def UserRegistrationError(self, app_name, error):
        """Signal thrown when there's a problem registering the user."""
        logger.debug('SSOLogin: emitting UserRegistrationError with '
                     'app_name "%s" and error %r', app_name, error)

    @dbus.service.method(dbus_interface=DBUS_IFACE_USER_NAME,
                         in_signature='ssssss')
    def register_user(self, app_name, email, password, name,
                      captcha_id, captcha_solution):
        """Call the matching method in the processor."""
        self.root.register_user(app_name, email, password, name, captcha_id,
                                captcha_solution,
                                self.UserRegistered,
                                self.UserRegistrationError)

    # login signals
    @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")
    def LoggedIn(self, app_name, result):
        """Signal thrown when the user is logged in."""
        logger.debug('SSOLogin: emitting LoggedIn with app_name "%s" '
                     'and result %r', app_name, result)

    @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="sa{ss}")
    def LoginError(self, app_name, error):
        """Signal thrown when there is a problem in the login."""
        logger.debug('SSOLogin: emitting LoginError with '
                     'app_name "%s" and error %r', app_name, error)

    @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")
    def UserNotValidated(self, app_name, result):
        """Signal thrown when the user is not validated."""
        logger.debug('SSOLogin: emitting UserNotValidated with app_name "%s" '
                     'and result %r', app_name, result)

    @dbus.service.method(dbus_interface=DBUS_IFACE_USER_NAME,
                         in_signature='sss')
    def login(self, app_name, email, password):
        """Call the matching method in the processor."""
        self.root.login(app_name, email, password, self.LoggedIn,
                        self.LoginError, self.UserNotValidated)

    # validate_email signals
    @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")
    def EmailValidated(self, app_name, result):
        """Signal thrown after the email is validated."""
        logger.debug('SSOLogin: emitting EmailValidated with app_name "%s" '
                     'and result %r', app_name, result)

    @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="sa{ss}")
    def EmailValidationError(self, app_name, error):
        """Signal thrown when there's a problem validating the email."""
        logger.debug('SSOLogin: emitting EmailValidationError with '
                     'app_name "%s" and error %r', app_name, error)

    @dbus.service.method(dbus_interface=DBUS_IFACE_USER_NAME,
                         in_signature='ssss')
    def validate_email(self, app_name, email, password, email_token):
        """Call the matching method in the processor."""
        self.root.validate_email(app_name, email, password, email_token,
                                 self.EmailValidated,
                                 self.EmailValidationError)

    # request_password_reset_token signals
    @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")
    def PasswordResetTokenSent(self, app_name, result):
        """Signal thrown when the token is succesfully sent."""
        logger.debug('SSOLogin: emitting PasswordResetTokenSent with app_name '
                     '"%s" and result %r', app_name, result)

    @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="sa{ss}")
    def PasswordResetError(self, app_name, error):
        """Signal thrown when there's a problem sending the token."""
        logger.debug('SSOLogin: emitting PasswordResetError with '
                     'app_name "%s" and error %r', app_name, error)

    @dbus.service.method(dbus_interface=DBUS_IFACE_USER_NAME,
                         in_signature='ss')
    def request_password_reset_token(self, app_name, email):
        """Call the matching method in the processor."""
        self.root.request_password_reset_token(app_name, email,
                                               self.PasswordResetTokenSent,
                                               self.PasswordResetError)

    # set_new_password signals
    @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")
    def PasswordChanged(self, app_name, result):
        """Signal thrown when the token is succesfully sent."""
        logger.debug('SSOLogin: emitting PasswordChanged with app_name "%s" '
                     'and result %r', app_name, result)

    @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="sa{ss}")
    def PasswordChangeError(self, app_name, error):
        """Signal thrown when there's a problem sending the token."""
        logger.debug('SSOLogin: emitting PasswordChangeError with '
                     'app_name "%s" and error %r', app_name, error)

    @dbus.service.method(dbus_interface=DBUS_IFACE_USER_NAME,
                         in_signature='ssss')
    def set_new_password(self, app_name, email, token, new_password):
        """Call the matching method in the processor."""
        self.root.set_new_password(app_name, email, token, new_password,
                                   self.PasswordChanged,
                                   self.PasswordChangeError)