Exemplo n.º 1
0
    def authenticate(self, handler, data):
        """Authenticate with PAM, and return the username if login is successful.

        Return None otherwise.
        """
        username = data['username']
        try:
            pamela.authenticate(username, data['password'], service=self.service, encoding=self.encoding)
        except pamela.PAMError as e:
            if handler is not None:
                self.log.warning("PAM Authentication failed (%s@%s): %s", username, handler.request.remote_ip, e)
            else:
                self.log.warning("PAM Authentication failed: %s", e)
        else:
            if not self.check_account:
                return username
            try:
                pamela.check_account(username, service=self.service, encoding=self.encoding)
            except pamela.PAMError as e:
                if handler is not None:
                    self.log.warning("PAM Account Check failed (%s@%s): %s", username, handler.request.remote_ip, e)
                else:
                    self.log.warning("PAM Account Check failed: %s", e)
            else:
                return username
Exemplo n.º 2
0
    def authenticate(self, handler, data):
        """Authenticate with PAM, and return the username if login is successful.

        Return None otherwise.
        """
        username = data['username']
        try:
            pamela.authenticate(username,
                                data['password'],
                                service=self.service,
                                encoding=self.encoding)
        except pamela.PAMError as e:
            if handler is not None:
                self.log.warning("PAM Authentication failed (%s@%s): %s",
                                 username, handler.request.remote_ip, e)
            else:
                self.log.warning("PAM Authentication failed: %s", e)
        else:
            if not self.check_account:
                return username
            try:
                pamela.check_account(username,
                                     service=self.service,
                                     encoding=self.encoding)
            except pamela.PAMError as e:
                if handler is not None:
                    self.log.warning("PAM Account Check failed (%s@%s): %s",
                                     username, handler.request.remote_ip, e)
                else:
                    self.log.warning("PAM Account Check failed: %s", e)
            else:
                return username
Exemplo n.º 3
0
    def authenticate(self, handler, data):
        """Authenticate with PAM, and return the username if login is successful.

        Return None otherwise.
        """
        # ADDED IN -chance
        try:
            if data['custom'] == 'on':
                self.log.debug("Changing spawner class...")
                self.custom = True

                if data['memory']:
                    self.memory = int(data['memory'])

                if data['cpus']:
                    self.cpu = int(data['cpus'])

                if data['tasks']:
                    self.tasks = int(data['tasks'])

                if data['time']:
                    self.time = data['time']

                if data['node']:
                    self.nodes = int(data['node'])

        except KeyError as e:
            self.log.debug("Ignoring custom settings...")

        username = data['username']
        try:
            pamela.authenticate(username,
                                data['password'],
                                service=self.service,
                                encoding=self.encoding)
        except pamela.PAMError as e:
            if handler is not None:
                self.log.warning("PAM Authentication failed (%s@%s): %s",
                                 username, handler.request.remote_ip, e)
            else:
                self.log.warning("PAM Authentication failed: %s", e)
        else:
            if not self.check_account:
                return username
            try:
                pamela.check_account(username,
                                     service=self.service,
                                     encoding=self.encoding)
            except pamela.PAMError as e:
                if handler is not None:
                    self.log.warning("PAM Account Check failed (%s@%s): %s",
                                     username, handler.request.remote_ip, e)
                else:
                    self.log.warning("PAM Account Check failed: %s", e)
            else:
                return username
Exemplo n.º 4
0
Arquivo: auth.py Projeto: nauhpc/rtcvt
 def user_can_authenticate(self, user):
     try:
         logger.debug("USER AUTHENTICATED: %s" % user.username)
         # if no exception is raised, the user exists in PAM LDAP on this system
         pamela.check_account(user.username)
     except Exception:
         logger.error("PROBLEM WITH LOGIN: %s" % user.username +
                      ". Deleting user.")
         user.delete()
         return False
     return True
Exemplo n.º 5
0
 def get(self, identifier):
     try:
         pamela.check_account(identifier)
     except pamela.PAMError:
         return None
     user = super().get(identifier)
     if not user:
         user = self.create({
             'username': identifier,
             'email': '%s@%s' % (identifier, socket.gethostname())
         })
     return user
Exemplo n.º 6
0
        async def authenticate(
            self,
            request: Request,
            data: Optional[dict] = None,
            dao=None,
            config=None,
            **kwargs,
        ) -> Optional[str]:
            """Authenticate with PAM, and return the username if login is successful.
            Return None otherwise.
            """
            if data is None:
                return None

            username = data['username']
            try:
                pamela.authenticate(
                    username,
                    data['password'],
                    service=self.service,
                    encoding=self.encoding,
                )
            except pamela.PAMError as e:
                logger.warning(
                    "PAM Authentication failed (%s@%s): %s",
                    username,
                    request.client.host,
                    e,
                )
                return None

            if self.check_account:
                try:
                    pamela.check_account(username,
                                         service=self.service,
                                         encoding=self.encoding)
                except pamela.PAMError as e:
                    logger.warning(
                        "PAM Account Check failed (%s@%s): %s",
                        username,
                        request.client.host,
                        e,
                    )
                    return None

            return username
Exemplo n.º 7
0
    def authenticate(self, handler, data):
        """Authenticate with PAM, and return the username if login is successful.

        Return None otherwise.
        """
        # we use lowercase username, since JupyterHub is using the lowercase later anyway. There are
        # system calls with this lowercase username. So this lowercase username must exist, otherwise
        # system calls will fail. So the user has to be added as lower case either way...
        username = data["username"].lower()
        try:
            pamela.authenticate(username,
                                data["password"],
                                service=self.service,
                                encoding=self.encoding)
        except pamela.PAMError as e:
            if handler is not None:
                self.log.warning(
                    "PAM Authentication failed (%s@%s): %s",
                    username,
                    handler.request.remote_ip,
                    e,
                )
            else:
                self.log.warning("PAM Authentication failed: %s", e)
            return None

        if self.check_account:
            try:
                pamela.check_account(username,
                                     service=self.service,
                                     encoding=self.encoding)
            except pamela.PAMError as e:
                if handler is not None:
                    self.log.warning(
                        "PAM Account Check failed (%s@%s): %s",
                        username,
                        handler.request.remote_ip,
                        e,
                    )
                else:
                    self.log.warning("PAM Account Check failed: %s", e)
                return None

        return username