Ejemplo n.º 1
0
 def _makeLoginProcess(self):
     # Check for automatic login
     authManager = AuthenticatorMgr()
     if (
         authManager.isSSOLoginActive()
         and len(authManager.getList()) == 1
         and not Config.getInstance().getDisplayLoginPage()
     ):
         self._redirect(urlHandlers.UHSignInSSO.getURL(authId=authManager.getDefaultAuthenticator().getId()))
         return
     if request.method != "POST":
         return self._signInPage.display(returnURL=self._returnURL)
     else:
         li = LoginInfo(self._login, self._password)
         av = authManager.getAvatar(li)
         if not av:
             return self._signInPageFailed.display(returnURL=self._returnURL)
         elif not av.isActivated():
             if av.isDisabled():
                 self._redirect(self._disabledAccountURL(av))
             else:
                 self._redirect(self._unactivatedAccountURL(av))
             return _("Your account is not active\nPlease activate it and try again")
         else:
             self._setSessionVars(av)
         self._addExtraParamsToURL()
         self._redirect(self._url)
Ejemplo n.º 2
0
class TestAuthentication(IndicoTestCase):
    _requires = ['db.Database']

    def setUp(self):
        super(TestAuthentication, self).setUp()

        with self._context("database"):
            # Create few users and groups
            gh = GroupHolder()
            ah = AvatarHolder()
            self._authMgr = AuthenticatorMgr()

            for i in xrange(1, 3):
                group = Group()
                group.setName("fake-group-%d" % i)
                group.setDescription("fake")
                group.setEmail("*****@*****.**" % i)
                group.setId("fake-group-%d" % i)
                avatar = Avatar()
                avatar.setName("fake-%d" % i)
                avatar.setSurName("fake")
                avatar.setOrganisation("fake")
                avatar.setLang("en_GB")
                avatar.setEmail("*****@*****.**" % i)
                avatar.setId("fake-%d" % i)
                avatar.activateAccount()
                group.addMember(avatar)
                ah.add(avatar)
                gh.add(group)
                identity = self._authMgr.createIdentity(LoginInfo("fake-%d" % i, "fake-%d" % i), avatar, "Local")
                self._authMgr.add(identity)

    @with_context('database')
    def testAvatarHolder(self):
        """
        Test Avatar Holder
        """
        ah = AvatarHolder()
        self.assertEqual(ah.getById("fake-1").getName(), "fake-1")
        self.assertEqual(ah.match({"name": "fake-1"}, searchInAuthenticators=False)[0].getEmail(), "*****@*****.**")
        self.assertEqual(len(ah.matchFirstLetter("name", "f", searchInAuthenticators=False)), 2)

    @with_context('database')
    def testGroupHolder(self):
        gh = GroupHolder()
        ah = AvatarHolder()
        self.assert_(gh.getById("fake-group-1").containsUser(ah.getById("fake-1")))
        self.assertEqual(gh.match({"groupname": "fake-group-1"}, searchInAuthenticators=False)[0].getEmail(),
                         "*****@*****.**")
        self.assertEqual(len(gh.matchFirstLetter("f", searchInAuthenticators=False)), 2)

    @with_context('database')
    def testIdentities(self):
        ah = AvatarHolder()
        for i in xrange(1, 3):
            self.assertEqual(self._authMgr.getAvatar(LoginInfo("fake-%d" % i, "fake-%d" % i)),
                             ah.getById("fake-%d" % i))
Ejemplo n.º 3
0
    def _getAnswer(self):
        li = LoginInfo( self._username, self._password )
        auth = AuthenticatorMgr()
        av = auth.getAvatar(li)
        if not av:
            from MaKaC.services.interface.rpc.common import ServiceError
            raise ServiceError(message="Wrong login or password")

        elif not av.isActivated():
            from MaKaC.services.interface.rpc.common import ServiceError
            raise ServiceError(message="Your account is not active. Please activate it and retry.")
        else:
            self._getSession().setUser( av )
        return '%s OK %s' % (self._username, datetime.datetime.now())
Ejemplo n.º 4
0
    def _getAnswer(self):
        li = LoginInfo(self._username, self._password)
        auth = AuthenticatorMgr()
        av = auth.getAvatar(li)
        if not av:
            from MaKaC.services.interface.rpc.common import ServiceError
            raise ServiceError("Wrong login or password")

        elif not av.isActivated():
            from MaKaC.services.interface.rpc.common import ServiceError
            raise ServiceError(
                "Your account is not active. Please activate it and retry.")
        else:
            self._getSession().setUser(av)
        return '%s OK %s' % (self._username, datetime.datetime.now())
Ejemplo n.º 5
0
    def _process(self):
        self._disableCaching()
        #Check for automatic login
        auth = AuthenticatorMgr()
        av = auth.autoLogin(self)
        if av:
            url = self._returnURL
            tzUtil = timezoneUtils.SessionTZ(av)
            tz = tzUtil.getSessionTZ()
            self._getSession().setVar("ActiveTimezone", tz)
            self._getSession().setUser(av)
            if Config.getInstance().getBaseSecureURL().startswith('https://'):
                url = str(url).replace('http://', 'https://')
            self._redirect(url, noCache=True)
        if not self._signIn:
            p = signIn.WPSignIn(self)
            return p.display(returnURL=self._returnURL)
        else:
            li = LoginInfo(self._login, self._password)
            av = auth.getAvatar(li)
            if not av:
                p = signIn.WPSignIn(self,
                                    login=self._login,
                                    msg=_("Wrong login or password"))
                return p.display(returnURL=self._returnURL)
            elif not av.isActivated():
                if av.isDisabled():
                    self._redirect(urlHandlers.UHDisabledAccount.getURL(av))
                else:
                    self._redirect(urlHandlers.UHUnactivatedAccount.getURL(av))
                return _(
                    "your account is not activate\nPlease active it and retry")
            else:
                url = self._returnURL
                #raise(str(dir(av)))
                self._getSession().setUser(av)
                tzUtil = timezoneUtils.SessionTZ(av)
                tz = tzUtil.getSessionTZ()
                self._getSession().setVar("ActiveTimezone", tz)

            if self._userId != "":
                if "?" in url:
                    url += "&userId=%s" % self._userId
                else:
                    url += "?userId=%s" % self._userId
            if Config.getInstance().getBaseSecureURL().startswith('https://'):
                url = str(url).replace('http://', 'https://')
            self._redirect(url, noCache=True)
Ejemplo n.º 6
0
    def _process(self):
        #Check for automatic login
        authManager = AuthenticatorMgr()
        if (authManager.isSSOLoginActive() and len(authManager.getList()) == 1 and
           not Config.getInstance().getDisplayLoginPage()):
            self._redirect(urlHandlers.UHSignInSSO.getURL(authId=authManager.getDefaultAuthenticator().getId()))
            return

        li = LoginInfo( self._login, self._password )
        av = authManager.getAvatar(li)
        self._responseUtil.content_type='application/json'
        if not av:
            return '{"success":false,"message":"User not authenticated or found"}'
        elif not av.isActivated():
            return '{"success":false,"message":"User not activated"}'
        else:
            return '{"success":true}'
Ejemplo n.º 7
0
    def _process( self ):
        self._disableCaching()
        #Check for automatic login
        auth = AuthenticatorMgr()
        av = auth.autoLogin(self)
        if av:
            url = self._returnURL
            tzUtil = timezoneUtils.SessionTZ(av)
            tz = tzUtil.getSessionTZ()
            self._getSession().setVar("ActiveTimezone",tz)
            self._getSession().setUser( av )
            if Config.getInstance().getBaseSecureURL().startswith('https://'):
                url = str(url).replace('http://', 'https://')
            self._redirect( url, noCache = True )
        if not self._signIn:
            p = signIn.WPSignIn( self )
            return p.display( returnURL = self._returnURL )
        else:
            li = LoginInfo( self._login, self._password )
            av = auth.getAvatar(li)
            if not av:
                p = signIn.WPSignIn( self, login = self._login, msg = _("Wrong login or password") )
                return p.display( returnURL = self._returnURL )
            elif not av.isActivated():
                if av.isDisabled():
                    self._redirect(urlHandlers.UHDisabledAccount.getURL(av))
                else:
                    self._redirect(urlHandlers.UHUnactivatedAccount.getURL(av))
                return _("your account is not activate\nPlease active it and retry")
            else:
                url = self._returnURL
                #raise(str(dir(av)))
                self._getSession().setUser( av )
                tzUtil = timezoneUtils.SessionTZ(av)
                tz = tzUtil.getSessionTZ()
                self._getSession().setVar("ActiveTimezone",tz)

            if self._userId != "":
                if "?" in url:
                    url += "&userId=%s"%self._userId
                else:
                    url += "?userId=%s"%self._userId
            if Config.getInstance().getBaseSecureURL().startswith('https://'):
                url = str(url).replace('http://', 'https://')
            self._redirect( url, noCache = True )
Ejemplo n.º 8
0
    def _process(self):
        #Check for automatic login
        authManager = AuthenticatorMgr()
        if (authManager.isSSOLoginActive() and len(authManager.getList()) == 1
                and not Config.getInstance().getDisplayLoginPage()):
            self._redirect(
                urlHandlers.UHSignInSSO.getURL(
                    authId=authManager.getDefaultAuthenticator().getId()))
            return

        li = LoginInfo(self._login, self._password)
        av = authManager.getAvatar(li)
        self._responseUtil.content_type = 'application/json'
        if not av:
            return '{"success":false,"message":"User not authenticated or found"}'
        elif not av.isActivated():
            return '{"success":false,"message":"User not activated"}'
        else:
            return '{"success":true}'
Ejemplo n.º 9
0
    def _process( self ):

        li = LoginInfo( self._login, self._password )
        auth = AuthenticatorMgr()
        av = auth.getAvatar(li)
        value = "OK"
        message = ""
        if not av:
            value = "ERROR"
            message = "Login failed"
        elif not av.isActivated():
            if av.isDisabled():
                value = "ERROR"
                message = "Acount is disabled"
            else:
                value = "ERROR"
                message = "Acount is not activated"
        else:
            value = "OK"
            message = "Login succesful"
            self._getSession().setUser( av )

        return self._createResponse(value, message)
Ejemplo n.º 10
0
    def _process(self):

        li = LoginInfo(self._login, self._password)
        auth = AuthenticatorMgr()
        av = auth.getAvatar(li)
        value = "OK"
        message = ""
        if not av:
            value = "ERROR"
            message = "Login failed"
        elif not av.isActivated():
            if av.isDisabled():
                value = "ERROR"
                message = "Acount is disabled"
            else:
                value = "ERROR"
                message = "Acount is not activated"
        else:
            value = "OK"
            message = "Login succesful"
            self._getSession().setUser(av)

        return self._createResponse(value, message)
Ejemplo n.º 11
0
class TestAuthentication(IndicoTestCase):
    _requires = ['db.Database']

    def setUp(self):
        super(TestAuthentication, self).setUp()

        with self._context("database"):
            # Create few users and groups
            gh = GroupHolder()
            ah = AvatarHolder()
            self._authMgr = AuthenticatorMgr()

            for i in xrange(1, 3):
                group = Group()
                group.setName("fake-group-%d" % i)
                group.setDescription("fake")
                group.setEmail("*****@*****.**" % i)
                group.setId("fake-group-%d" % i)
                avatar = Avatar()
                avatar.setName("fake-%d" % i)
                avatar.setSurName("fake")
                avatar.setOrganisation("fake")
                avatar.setLang("en_GB")
                avatar.setEmail("*****@*****.**" % i)
                avatar.setId("fake-%d" % i)
                avatar.activateAccount()
                group.addMember(avatar)
                ah.add(avatar)
                gh.add(group)
                identity = self._authMgr.createIdentity(
                    LoginInfo("fake-%d" % i, "fake-%d" % i), avatar, "Local")
                self._authMgr.add(identity)

    @with_context('database')
    def testAvatarHolder(self):
        """
        Test Avatar Holder
        """
        ah = AvatarHolder()
        self.assertEqual(ah.getById("fake-1").getName(), "fake-1")
        self.assertEqual(
            ah.match({"name": "fake-1"},
                     searchInAuthenticators=False)[0].getEmail(),
            "*****@*****.**")
        self.assertEqual(
            len(ah.matchFirstLetter("name", "f",
                                    searchInAuthenticators=False)), 2)

    @with_context('database')
    def testGroupHolder(self):
        gh = GroupHolder()
        ah = AvatarHolder()
        self.assert_(
            gh.getById("fake-group-1").containsUser(ah.getById("fake-1")))
        self.assertEqual(
            gh.match({"groupname": "fake-group-1"},
                     searchInAuthenticators=False)[0].getEmail(),
            "*****@*****.**")
        self.assertEqual(
            len(gh.matchFirstLetter("f", searchInAuthenticators=False)), 2)

    @with_context('database')
    def testIdentities(self):
        ah = AvatarHolder()
        for i in xrange(1, 3):
            self.assertEqual(
                self._authMgr.getAvatar(LoginInfo("fake-%d" % i,
                                                  "fake-%d" % i)),
                ah.getById("fake-%d" % i))