Esempio n. 1
0
    def login(self):
        ''' Log-in to the Data Lab.
        '''
        try:
            self.token = self.dl.get(self.user.value, 'authtoken')
            if authClient.isValidToken(self.token):
                # FIXME --  What we really want here is a login-by-token call
                # to the AuthMgr so the login is recorded on the server.
                self.login_error = None
                return True
        except Exception as e:
            pass

        # Get the security token for the user
        self.token = authClient.login(self.user.value, self.password.value)
        if not authClient.isValidToken(self.token):
            self.dl.save("login", "status", "loggedout")
            self.dl.save("login", "user", '')
            self.dl.save("login", "authtoken", '')
            self.dl.save(self.user.value, "authtoken", self.token)
            self.login_error = self.token
            return False
        else:
            self.login_error = None
            return True
    def authenticate(self, handler, data):
        username = data["username"]
        password = data["password"]

        # Allow password-less login for specific users. Typically used
        # for upport purposes only to debug a user's environment.
        if username in self.debug_user:
            return username

        # Punt on any attempted login to excluded account names.
        for user in self.excluded_users:
            if user == username:
                self.log.warning("Auth error: %s: Excluded login denied", user)
                return None

        try:
            authClient.set_svc_url(DEF_SERVICE_URL)
            token = authClient.login(username, password)
            if not authClient.isValidToken(token):
                self.log.warning("Invalid token: %s: %s" % (username, token))
                return None
        except Exception as e:
            self.log.error("Exception Auth error: %s: %s" % (username, str(e)))
            return None

        return data['username']
Esempio n. 3
0
    def _getToken(self, username):
        """Get authentication token through :func:`authClient.login()`

        Parameters
        ----------
        username : str
            If 'anonymous', use default password and obtain default
            auth token. Otherwise prompt for password while trying to
            obtain a valid auth token.

            :func:`authClient.login() returns either a valid token, or
            an error message (as string), so we check the return value
            using :func:`authClient.isValidToken()`. If this returns
            False, we raise an Exception here.
        """

        if username == 'anonymous':
            token = authClient.login('anonymous', '')
        else:
            #            print("Enter password:"******"Invalid user name and/or password provided. Please try again."
            )
        else:
            print("Authentication successful.")
            return token
Esempio n. 4
0
    def run(self):
        ''' Execute the Login Task.
        '''
        # Check if we are already logged in.  The 'user' field of the
        # configuration contains the currently active user and token,
        # however previous logins will have preserved tokens from other
        # accounts we may be able to use.
        if self.status == "loggedin":
            _user = self.dl.get("login", "user")
            if self.user.value == _user:
                # See whether current token is still valid for this user.
                _token = self.dl.get("login", "authtoken")
                if not authClient.isValidToken(_token):
                    if self.do_login() != "OK":
                        print(self.login_error)
                        sys.exit(-1)
                else:
                    print ("User '%s' is already logged in to the Data Lab" % \
                            self.user.value)
            else:
                # We're logging in as a different user.
                if self.do_login() != "OK":
                    print(self.login_error)
                    sys.exit(-1)
                else:
                    # Log a user into the Data Lab
                    print("Welcome back to the Data Lab, %s" % self.user.value)
        else:
            # If we're not logged in, do so using the name/password provided.
            if self.do_login() != "OK":
                print(self.login_error)
                sys.exit(-1)
            else:
                # Log a user into the Data Lab
                print("Welcome to the Data Lab, %s" % self.user.value)

        # Default parameters if the VOSpace mount is requested.
        if self.mount.value != "":
            print("Initializing virtual storage mount")
            mount = Mountvofs(self.dl)
            mount.setOption('vospace', 'vos:')
            mount.setOption('mount', self.mount.value)
            mount.setOption('cache_dir', None)
            mount.setOption('cache_limit', 50 * 2**(10 + 10 + 10))
            mount.setOption('cache_nodes', False)
            mount.setOption('max_flush_threads', 10)
            mount.setOption('secure_get', False)
            mount.setOption('allow_other', False)
            mount.setOption('foreground', False)
            mount.setOption('nothreads', True)
            mount.run()
Esempio n. 5
0
 def test_invalidtoken3(self):
     token = 'abcdefghijklmnopqrstuvwxyz12345678910111213'
     res = authClient.isValidToken(token)
     self.assertFalse(res)
Esempio n. 6
0
 def test_invalidtoken2(self):
     token = 'datalabtest.1148.1148.abcdefghijklmnopqrstuvwxyz12345678910111213'
     res = authClient.isValidToken(token)
     self.assertEqual(res,'False')
Esempio n. 7
0
 def test_validtoken(self):
     token = login('datalabtest','DataLabTest1')
     res = authClient.isValidToken(token)
     self.assertTrue(res)
     res = logout(token)
     res2 = deleteTokenFile(token)