<commit_before>#
# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

"""Extensions supporting Strong Passwords."""

import uuid

from keystone import auth
from keystone.auth.plugins import password
from keystone.common import dependency
from keystone.common import extension
from keystone.common import wsgi
from keystone import exception
from keystone import identity
try: from oslo_log import log
except ImportError: from keystone.openstack.common import log
try: from oslo_log import versionutils
except ImportError: from keystone.openstack.common import versionutils
from keystone.common import manager
from keystone_spassword.contrib.spassword.controllers import SPasswordScimUserV3Controller
from keystone_spassword.contrib.spassword.controllers import SPasswordUserV3Controller
LOG = log.getLogger(__name__)

try: from oslo_config import cfg
except ImportError: from oslo.config import cfg
CONF = cfg.CONF
CONF.register_opt(cfg.BoolOpt('enabled', default=False), group='spassword')
CONF.register_opt(cfg.IntOpt('pwd_exp_days', default=365), group='spassword')
CONF.register_opt(cfg.IntOpt('pwd_max_tries', default=3), group='spassword')
CONF.register_opt(cfg.IntOpt('pwd_block_minutes', default=30), group='spassword')
CONF.register_opt(cfg.ListOpt('pwd_user_blacklist'), group='spassword')
CONF.register_opt(cfg.StrOpt('smtp_server', default='0.0.0.0'), group='spassword')
CONF.register_opt(cfg.IntOpt('smtp_port', default=587), group='spassword')
CONF.register_opt(cfg.BoolOpt('smtp_tls', default=True), group='spassword')
CONF.register_opt(cfg.StrOpt('smtp_user', default='user'), group='spassword')
CONF.register_opt(cfg.StrOpt('smtp_password', default='password'), group='spassword')
CONF.register_opt(cfg.StrOpt('smtp_from', default='from'), group='spassword')


@dependency.provider('spassword_api')
class SPasswordManager(manager.Manager):
    """SPassword Manager.

    See :mod:`keystone.common.manager.Manager` for more details on
    how this dynamically calls the backend.

    """

    def __init__(self):
        LOG.debug("Manager INIT")
        self.event_callbacks = {
            # Here we add the event_callbacks class attribute that
            # calls project_deleted_callback when a project is deleted.
            'updated': {
                'user': [
                    self.user_updated_callback]
                },
            'created': {
                'user': [
                    self.user_created_callback]
                },
            }

        super(SPasswordManager, self).__init__(
            'keystone_spassword.contrib.spassword.backends.sql.SPassword')

    def user_updated_callback(self, service, resource_type, operation,
                              payload):
        user = self.driver.get_user(payload['resource_info'])
        LOG.debug("User %s updated." % user['id'])
        # TODO: Already is done in any update operations.
        # But only admin can modify user is password were blocked
        # Minor bug: user acount is unlocker when admin user modifies any issue
        # about user not just password
        if CONF.spassword.enabled:
            self.driver.update_user_modification_time(user)

    def user_created_callback(self, service, resource_type, operation,
                              payload):
        user = self.driver.get_user(payload['resource_info'])
        LOG.debug("User %s created." % user['id'])
        if CONF.spassword.enabled:
            user_password = self.driver.set_user_creation_time(user)


class Driver(object):
    """Interface description for SPassword driver."""

    def get_user(self, user_id):
        """Getuser

        :param data: example data
        :type data: string
        :raises: keystone.exception,
        :returns: None.

        """
        raise exception.NotImplemented()

    def set_user_creation_time(self, user):
        """Setuser

        :param data: example data
        :type data: string
        :raises: keystone.exception,
        :returns: None.

        """
        raise exception.NotImplemented()
<commit_msg>add user_deleted_callback<commit_after>#
# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

"""Extensions supporting Strong Passwords."""

import uuid

from keystone import auth
from keystone.auth.plugins import password
from keystone.common import dependency
from keystone.common import extension
from keystone.common import wsgi
from keystone import exception
from keystone import identity
try: from oslo_log import log
except ImportError: from keystone.openstack.common import log
try: from oslo_log import versionutils
except ImportError: from keystone.openstack.common import versionutils
from keystone.common import manager
from keystone_spassword.contrib.spassword.controllers import SPasswordScimUserV3Controller
from keystone_spassword.contrib.spassword.controllers import SPasswordUserV3Controller
LOG = log.getLogger(__name__)

try: from oslo_config import cfg
except ImportError: from oslo.config import cfg
CONF = cfg.CONF
CONF.register_opt(cfg.BoolOpt('enabled', default=False), group='spassword')
CONF.register_opt(cfg.IntOpt('pwd_exp_days', default=365), group='spassword')
CONF.register_opt(cfg.IntOpt('pwd_max_tries', default=3), group='spassword')
CONF.register_opt(cfg.IntOpt('pwd_block_minutes', default=30), group='spassword')
CONF.register_opt(cfg.ListOpt('pwd_user_blacklist'), group='spassword')
CONF.register_opt(cfg.StrOpt('smtp_server', default='0.0.0.0'), group='spassword')
CONF.register_opt(cfg.IntOpt('smtp_port', default=587), group='spassword')
CONF.register_opt(cfg.BoolOpt('smtp_tls', default=True), group='spassword')
CONF.register_opt(cfg.StrOpt('smtp_user', default='user'), group='spassword')
CONF.register_opt(cfg.StrOpt('smtp_password', default='password'), group='spassword')
CONF.register_opt(cfg.StrOpt('smtp_from', default='from'), group='spassword')


@dependency.provider('spassword_api')
class SPasswordManager(manager.Manager):
    """SPassword Manager.

    See :mod:`keystone.common.manager.Manager` for more details on
    how this dynamically calls the backend.

    """

    def __init__(self):
        LOG.debug("Manager INIT")
        self.event_callbacks = {
            # Here we add the event_callbacks class attribute that
            # calls project_deleted_callback when a project is deleted.
            'updated': {
                'user': [
                    self.user_updated_callback]
                },
            'created': {
                'user': [
                    self.user_created_callback]
                },
            'deleted': {
                'user': [
                    self.user_deleted_callback]
                },
            }

        super(SPasswordManager, self).__init__(
            'keystone_spassword.contrib.spassword.backends.sql.SPassword')

    def user_updated_callback(self, service, resource_type, operation,
                              payload):
        user = self.driver.get_user(payload['resource_info'])
        LOG.debug("User %s updated." % user['id'])
        # TODO: Already is done in any update operations.
        # But only admin can modify user is password were blocked
        # Minor bug: user acount is unlocker when admin user modifies any issue
        # about user not just password
        if CONF.spassword.enabled:
            self.driver.update_user_modification_time(user)

    def user_created_callback(self, service, resource_type, operation,
                              payload):
        user = self.driver.get_user(payload['resource_info'])
        LOG.debug("User %s created." % user['id'])
        if CONF.spassword.enabled:
            user_password = self.driver.set_user_creation_time(user)

    def user_deleted_callback(self, service, resource_type, operation,
                              payload):
        user = self.driver.get_user(payload['resource_info'])
        LOG.debug("User %s deleted." % user['id'])
        if CONF.spassword.enabled:
            self.driver.remove_user(user['id'])


class Driver(object):
    """Interface description for SPassword driver."""

    def get_user(self, user_id):
        """Getuser

        :param data: example data
        :type data: string
        :raises: keystone.exception,
        :returns: None.

        """
        raise exception.NotImplemented()

    def set_user_creation_time(self, user):
        """Setuser

        :param data: example data
        :type data: string
        :raises: keystone.exception,
        :returns: None.

        """
        raise exception.NotImplemented()

{'fraction_non_alphanumeric': 0.09665024630541871, 'fraction_numerical': 0.004532019704433498, 'mean_word_length': 3.3810962451445836, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '814904', 'n_tokens_mistral': 2881, 'n_tokens_neox': 2772, 'n_words': 795}