예제 #1
0
    def test_is_enterprise_customer_user(self):
        """
        Verify that if user is an enterprise learner.
        """
        # Create users from factory

        user = UserFactory(username='******', email='*****@*****.**')
        other_user = UserFactory(username='******', email='*****@*****.**')
        customer_idp = EnterpriseCustomerIdentityProviderFactory.create(
            provider_id='the-provider',
        )
        customer = customer_idp.enterprise_customer
        EnterpriseCustomerUserFactory.create(
            enterprise_customer=customer,
            user_id=user.id,
        )

        assert is_enterprise_customer_user('the-provider', user)
        assert not is_enterprise_customer_user('the-provider', other_user)
예제 #2
0
    def associate_by_email_if_enterprise_user():
        """
        If the learner arriving via SAML is already linked to the enterprise customer linked to the same IdP,
        they should not be prompted for their edX password.
        """
        try:
            enterprise_customer_user = is_enterprise_customer_user(current_provider.provider_id, current_user)
            logger.info(
                u'[Multiple_SSO_SAML_Accounts_Association_to_User] Enterprise user verification:'
                u'User Email: {email}, User ID: {user_id}, Provider ID: {provider_id},'
                u' is_enterprise_customer_user: {enterprise_customer_user}'.format(
                    email=current_user.email,
                    user_id=current_user.id,
                    provider_id=current_provider.provider_id,
                    enterprise_customer_user=enterprise_customer_user,
                )
            )

            if enterprise_customer_user:
                # this is python social auth pipeline default method to automatically associate social accounts
                # if the email already matches a user account.
                association_response = associate_by_email(backend, details, user, *args, **kwargs)

                if (
                    association_response and
                    association_response.get('user') and
                    association_response['user'].is_active
                ):
                    # Only return the user matched by email if their email has been activated.
                    # Otherwise, an illegitimate user can create an account with another user's
                    # email address and the legitimate user would now login to the illegitimate
                    # account.
                    return association_response
                elif (
                    association_response and
                    association_response.get('user') and
                    not association_response['user'].is_active
                ):
                    logger.info(
                        u'[Multiple_SSO_SAML_Accounts_Association_to_User] User association account is not'
                        u' active: User Email: {email}, User ID: {user_id}, Provider ID: {provider_id},'
                        u' is_enterprise_customer_user: {enterprise_customer_user}'.format(
                            email=current_user.email,
                            user_id=current_user.id,
                            provider_id=current_provider.provider_id,
                            enterprise_customer_user=enterprise_customer_user
                        )
                    )
                    return None

        except Exception as ex:  # pylint: disable=broad-except
            logger.exception('[Multiple_SSO_SAML_Accounts_Association_to_User] Error in'
                             ' saml multiple accounts association: User ID: %s, User Email: %s:,'
                             'Provider ID: %s, Exception: %s', current_user.id, current_user.email,
                             current_provider.provider_id, ex)
예제 #3
0
    def associate_by_email_if_enterprise_user():
        """
        If the learner arriving via SAML is already linked to the enterprise customer linked to the same IdP,
        they should not be prompted for their edX password.
        """
        try:
            enterprise_customer_user = is_enterprise_customer_user(
                current_provider.provider_id, current_user)
            logger.info(
                '[Multiple_SSO_SAML_Accounts_Association_to_User] Enterprise user verification:'
                'User Email: {email}, User ID: {user_id}, Provider ID: {provider_id},'
                ' is_enterprise_customer_user: {enterprise_customer_user}'.
                format(
                    email=current_user.email,
                    user_id=current_user.id,
                    provider_id=current_provider.provider_id,
                    enterprise_customer_user=enterprise_customer_user,
                ))

            if enterprise_customer_user:
                # this is python social auth pipeline default method to automatically associate social accounts
                # if the email already matches a user account.
                association_response, user_is_active = get_associated_user_by_email_response(
                    backend, details, user, *args, **kwargs)

                if not user_is_active:
                    logger.info(
                        '[Multiple_SSO_SAML_Accounts_Association_to_User] User association account is not'
                        ' active: User Email: {email}, User ID: {user_id}, Provider ID: {provider_id},'
                        ' is_enterprise_customer_user: {enterprise_customer_user}'
                        .format(
                            email=current_user.email,
                            user_id=current_user.id,
                            provider_id=current_provider.provider_id,
                            enterprise_customer_user=enterprise_customer_user))
                    return None

                return association_response

        except Exception as ex:  # pylint: disable=broad-except
            logger.exception(
                '[Multiple_SSO_SAML_Accounts_Association_to_User] Error in'
                ' saml multiple accounts association: User ID: %s, User Email: %s:,'
                'Provider ID: %s, Exception: %s', current_user.id,
                current_user.email, current_provider.provider_id, ex)