Collecting and initialising roles over all app
545803
public function initRolesAndActions() {
    $classes = $this->loadClasses();
    foreach ($classes as $item) {
      $this->initRolesForClass($item);
    }
  }
281884
def init(self, app):
        
        cfg = app.config
        self.welcome_message = cfg.get('USER_SEND_WELCOME_MESSAGE')
        self.require_confirmation = cfg.get(
            'USER_ACCOUNTS_REQUIRE_CONFIRMATION'
        )

        subjects = cfg.get('USER_EMAIL_SUBJECTS')
        self.email_subjects = subjects if subjects else dict()

        self.jwt_secret = cfg.get('USER_JWT_SECRET')
        self.jwt_algo = cfg.get('USER_JWT_ALGO')
        self.jwt_lifetime = cfg.get('USER_JWT_LIFETIME_SECONDS')
        self.jwt_implementation = cfg.get('USER_JWT_IMPLEMENTATION')
        self.jwt_loader_implementation = cfg.get(
            'USER_JWT_LOADER_IMPLEMENTATION'
        )
775585
function initAdminAPI () {
  this.clients = {
    list: clients.list.bind(this),
    get: clients.get.bind(this),
    create: clients.create.bind(this),
    update: clients.update.bind(this),
    delete: clients.delete.bind(this),
    roles: {
      list: clientRoles.listRoles.bind(this),
      add: clientRoles.addRole.bind(this),
      delete: clientRoles.deleteRole.bind(this)
    }
  }

  this.roles = {
    list: roles.list.bind(this),
    get: roles.get.bind(this),
    create: roles.create.bind(this),
    update: roles.update.bind(this),
    delete: roles.delete.bind(this),
    scopes: {
      list: roleScopes.listScopes.bind(this),
      add: roleScopes.addScope.bind(this),
      delete: roleScopes.deleteScope.bind(this)
    }
  }

  this.scopes = {
    list: scopes.list.bind(this),
    get: scopes.get.bind(this),
    create: scopes.create.bind(this),
    update: scopes.update.bind(this),
    delete: scopes.delete.bind(this)
  }

  this.users = {
    list: users.list.bind(this),
    get: users.get.bind(this),
    create: users.create.bind(this),
    update: users.update.bind(this),
    delete: users.delete.bind(this),
    roles: {
      list: userRoles.listRoles.bind(this),
      add: userRoles.addRole.bind(this),
      delete: userRoles.deleteRole.bind(this)
    }
  }
}
705669
def create_role(self, role_name, mount_point='approle', **kwargs):
        

        return self._adapter.post('/v1/auth/{0}/role/{1}'.format(mount_point, role_name), json=kwargs)
25697
def init_app(app):
        

        app.config.setdefault('LDAP_HOST', 'localhost')
        app.config.setdefault('LDAP_PORT', 389)
        app.config.setdefault('LDAP_SCHEMA', 'ldap')
        app.config.setdefault('LDAP_USERNAME', None)
        app.config.setdefault('LDAP_PASSWORD', None)
        app.config.setdefault('LDAP_TIMEOUT', 10)
        app.config.setdefault('LDAP_USE_SSL', False)
        app.config.setdefault('LDAP_USE_TLS', False)
        app.config.setdefault('LDAP_REQUIRE_CERT', False)
        app.config.setdefault('LDAP_CERT_PATH', '/path/to/cert')
        app.config.setdefault('LDAP_BASE_DN', None)
        app.config.setdefault('LDAP_OBJECTS_DN', 'distinguishedName')
        app.config.setdefault('LDAP_USER_FIELDS', [])
        app.config.setdefault('LDAP_USER_OBJECT_FILTER',
                              '(&(objectclass=Person)(userPrincipalName=%s))')
        app.config.setdefault('LDAP_USER_GROUPS_FIELD', 'memberOf')
        app.config.setdefault('LDAP_GROUP_FIELDS', [])
        app.config.setdefault('LDAP_GROUP_OBJECT_FILTER',
                              '(&(objectclass=Group)(userPrincipalName=%s))')
        app.config.setdefault('LDAP_GROUP_MEMBERS_FIELD', 'member')
        app.config.setdefault('LDAP_LOGIN_VIEW', 'login')
        app.config.setdefault('LDAP_REALM_NAME', 'LDAP authentication')
        app.config.setdefault('LDAP_OPENLDAP', False)
        app.config.setdefault('LDAP_GROUP_MEMBER_FILTER', '*')
        app.config.setdefault('LDAP_GROUP_MEMBER_FILTER_FIELD', '*')
        app.config.setdefault('LDAP_CUSTOM_OPTIONS', None)

        if app.config['LDAP_USE_SSL'] or app.config['LDAP_USE_TLS']:
            ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT,
                            ldap.OPT_X_TLS_NEVER)

        if app.config['LDAP_REQUIRE_CERT']:
            ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT,
                            ldap.OPT_X_TLS_DEMAND)
            ldap.set_option(ldap.OPT_X_TLS_CACERTFILE,
                            current_app.config['LDAP_CERT_PATH'])

        for option in ['USERNAME', 'PASSWORD', 'BASE_DN']:
            if app.config['LDAP_{0}'.format(option)] is None:
                raise LDAPException('LDAP_{0} cannot be None!'.format(option))
1349808
def roles(self):
        """"""
        result = AuthGroup.objects(creator=self.client).only('role')
        return json.loads(result.to_json())
1126128
function loadRoles() {
  const roleConfigsPath = path.join(process.cwd(), plugin.config.rolesPath);

  // This event allows to inject code before loading all APIs
  return plugin.myrmex.fire('beforeRolesLoad')
  .then(() => {
    // Retrieve configuration path of all API specifications
    return fs.readdirAsync(roleConfigsPath);
  })
  .catch(e => {
    if (e.code === 'ENOENT' && path.basename(e.path) === 'roles') {
      return Promise.resolve([]);
    }
    return Promise.reject(e);
  })
  .then((roleConfigFiles) => {
    // Load all the role configurations
    const rolePromises = [];
    _.forEach(roleConfigFiles, (filename) => {
      const roleConfigPath = path.join(roleConfigsPath, filename);
      const roleName = path.parse(filename).name;
      rolePromises.push(loadRole(roleConfigPath, roleName));
    });
    return Promise.all(rolePromises);
  })
  .then((roles) => {
    // This event allows to inject code to add or delete or alter role configurations
    return plugin.myrmex.fire('afterRolesLoad', roles);
  })
  .spread((roles) => {
    return Promise.resolve(roles);
  });
}
1022076
def _setup(self):
        
        role_directory = os.path.join(self._config.scenario.directory,
                                      self.options['roles-path'])
        if not os.path.isdir(role_directory):
            os.makedirs(role_directory)
987611
def get_roles(server_context, container_path=None):
    
    url = server_context.build_url(security_controller, 'getRoles.api', container_path=container_path)
    return server_context.make_request(url, None)
1041711
def init_token(self):
        """"""

        app_filename = appid_file()
        token_filename = token_file()
        approle_filename = approle_file()
        token = None
        if 'VAULT_ROLE_ID' in os.environ and \
           'VAULT_SECRET_ID' in os.environ and \
           os.environ['VAULT_ROLE_ID'] and os.environ['VAULT_SECRET_ID']:
            token = approle_token(self,
                                  os.environ['VAULT_ROLE_ID'],
                                  os.environ['VAULT_SECRET_ID'])
            LOG.debug("Token derived from VAULT_ROLE_ID and VAULT_SECRET_ID")
        elif 'VAULT_TOKEN' in os.environ and os.environ['VAULT_TOKEN']:
            LOG.debug('Token derived from VAULT_TOKEN environment variable')
            token = os.environ['VAULT_TOKEN'].strip()
        elif 'VAULT_USER_ID' in os.environ and \
             'VAULT_APP_ID' in os.environ and \
             os.environ['VAULT_USER_ID'] and os.environ['VAULT_APP_ID']:
            LOG.debug("Token derived from VAULT_APP_ID and VAULT_USER_ID")
            token = app_token(self,
                              os.environ['VAULT_APP_ID'].strip(),
                              os.environ['VAULT_USER_ID'].strip())
        elif approle_filename:
            creds = yaml.safe_load(open(approle_filename).read().strip())
            if 'role_id' in creds and 'secret_id' in creds:
                LOG.debug("Token derived from approle file")
                token = approle_token(self,
                                      creds['role_id'],
                                      creds['secret_id'])
        elif token_filename:
            LOG.debug("Token derived from %s", token_filename)
            try:
                token = open(token_filename, 'r').read().strip()
            except IOError as os_exception:
                if os_exception.errno == 21:
                    raise aomi.exceptions.AomiFile('Bad Vault token file')

                raise
        elif app_filename:
            token = yaml.safe_load(open(app_filename).read().strip())
            if 'app_id' in token and 'user_id' in token:
                LOG.debug("Token derived from %s", app_filename)
                token = app_token(self,
                                  token['app_id'],
                                  token['user_id'])
        else:
            raise aomi.exceptions.AomiCredentials('unknown method')

        return token
1025684
def user_got_role_event(user, role):
    
    msg = 'User ({}){} got new role [{}]'
    current_app.logger.info(msg.format(user.id, user.email, role.handle))
186473
def persist_registered_roles!
      @roles.each do |name, description|
        Sipity::Role.find_or_create_by!(name: name).tap do |role|
          role.description = description
          role.save!
        end
      end
    end
879983
def sync(cls):
        
        try:
            settings_roles = set(settings.ARCTIC_ROLES.keys())
        except AttributeError:
            settings_roles = set()

        saved_roles = set(Role.objects.values_list("name", flat=True))
        unsaved_roles = settings_roles - saved_roles
        unused_roles = saved_roles - settings_roles - set([cls.ADMIN])

        # ensure that admin is not defined in settings
        if cls.ADMIN in settings_roles:
            raise ImproperlyConfigured(
                '"' + cls.ADMIN + '" role is reserved '
                "and cannot be defined in settings"
            )

        # ensure that admin exists in the database
        if cls.ADMIN not in saved_roles:
            Role(name=cls.ADMIN, is_active=True).save()

        # check if the role defined in settings already exists in the database
        # and if it does ensure it is enabled.
        for role in saved_roles:
            if role in settings_roles:
                saved_role = Role.objects.get(name=role)
                if not saved_role.is_active:
                    saved_role.is_active = True
                    saved_role.save()

        for role in unsaved_roles:
            Role(name=role).save()

        for role in unused_roles:
            unused_role = Role.objects.get(name=role)
            unused_role.is_active = False
            unused_role.save()
993416
private void init(List<CmsRole> roles) {

        CmsRole.applySystemRoleOrder(roles);
        m_menu = new CmsContextMenu();
        m_menu.setAsTableContextMenu(this);

        m_container = new IndexedContainer();

        for (TableProperty prop : TableProperty.values()) {
            m_container.addContainerProperty(prop, prop.getType(), prop.getDefault());
            setColumnHeader(prop, prop.getName());
        }
        setContainerDataSource(m_container);
        setItemIconPropertyId(TableProperty.Icon);
        setRowHeaderMode(RowHeaderMode.ICON_ONLY);

        setColumnWidth(null, 40);
        setSelectable(true);

        setVisibleColumns(TableProperty.Name, TableProperty.OU);

        for (CmsRole role : roles) {

            Item item = m_container.addItem(role);
            item.getItemProperty(TableProperty.Name).setValue(role.getName(A_CmsUI.get().getLocale()));
            item.getItemProperty(TableProperty.Description).setValue(role.getDescription(A_CmsUI.get().getLocale()));
            item.getItemProperty(TableProperty.OU).setValue(role.getOuFqn());
        }

        addItemClickListener(new ItemClickListener() {

            private static final long serialVersionUID = 4807195510202231174L;

            public void itemClick(ItemClickEvent event) {

                setValue(null);
                select(event.getItemId());
                if (event.getButton().equals(MouseButton.RIGHT) || (event.getPropertyId() == null)) {
                    m_menu.setEntries(
                        getMenuEntries(),
                        Collections.singleton(((CmsRole)getValue()).getId().getStringValue()));
                    m_menu.openForTable(event, event.getItemId(), event.getPropertyId(), CmsRoleTable.this);
                } else if (event.getButton().equals(MouseButton.LEFT)
                    && event.getPropertyId().equals(TableProperty.Name)) {
                    updateApp((CmsRole)getValue());
                }

            }

        });
        setCellStyleGenerator(new CellStyleGenerator() {

            private static final long serialVersionUID = 1L;

            public String getStyle(Table source, Object itemId, Object propertyId) {

                if (TableProperty.Name.equals(propertyId)) {
                    return " " + OpenCmsTheme.HOVER_COLUMN;
                }

                return "";
            }
        });
        setVisibleColumns(TableProperty.Name, TableProperty.Description, TableProperty.OU);
    }
163175
def role_list(profile=None, **connection_args):
    '''
    
    '''
    kstone = auth(profile, **connection_args)
    ret = {}
    for role in kstone.roles.list():
        ret[role.name] = dict((value, getattr(role, value)) for value in dir(role)
                              if not value.startswith('_') and
                              isinstance(getattr(role, value), (six.string_types, dict, bool)))
    return ret
713044
def _update_user_roles_names_from_roles_id(self, user, users_roles,
                                               roles_list):
        
        user_roles_names = [role.name for role in roles_list
                            if role.id in users_roles]
        current_user_roles_names = set(getattr(user, "roles", []))
        user.roles = list(current_user_roles_names.union(user_roles_names))
670144
def load_entry_point_system_roles(self, entry_point_group):
        
        for ep in pkg_resources.iter_entry_points(group=entry_point_group):
            self.register_system_role(ep.load())