Add default permissions.
16199
public static function addPermissions(array $permissions)
    {
        $rows = [];

        foreach ($permissions as $permission => $groups) {
            foreach ((array) $groups as $group) {
                $rows[] = [
                    'group_id' => $group,
                    'permission' => $permission,
                ];
            }
        }

        return [
            'up' => function (Builder $schema) use ($rows) {
                $db = $schema->getConnection();

                foreach ($rows as $row) {
                    if ($db->table('group_permission')->where($row)->exists()) {
                        continue;
                    }

                    if ($db->table('groups')->where('id', $row['group_id'])->doesntExist()) {
                        continue;
                    }

                    $db->table('group_permission')->insert($row);
                }
            },

            'down' => function (Builder $schema) use ($rows) {
                $db = $schema->getConnection();

                foreach ($rows as $row) {
                    $db->table('group_permission')->where($row)->delete();
                }
            }
        ];
    }
1018522
private function registerModulePermissions()
    {
        foreach ($this->app['modules']->enabled() as $module) {
            if ($this->app['society.isInstalled']) {
                $permissionManager = new PermissionManager();
                $permissionManager->registerDefault($module);
            }
        }
    }
738629
public function bootPermissions()
    {
        foreach ($this->permissions as $token => $permission) {
            $this->permissions[$token] = sprintf($permission, Str::kebab($this->getManager()->getName()), Str::kebab($this->getName()));
        }
    }
573027
def _insert_defaults(self):
        
        merged = merge_defaults(self.structure, self)
        self.update(merged)
74452
def ensure_permissions(mode_flags=stat.S_IWUSR):
    

    def decorator(f):
        def modify(filename, *args, **kwargs):
            m = chmod_perms(filename) if exists(filename) else mode_flags
            if not m & mode_flags:
                os.chmod(filename, m | mode_flags)
            try:
                return f(filename, *args, **kwargs)
            finally:
                # restore original permissions
                if not m & mode_flags:
                    os.chmod(filename, m)
        return modify

    return decorator
1004176
def set_access_control(self, mode, onerror = None):
        """"""
        request.SetAccessControl(display = self.display,
                                 onerror = onerror,
                                 mode = mode)
1070348
public void setPermissions(UnsignedInteger32 permissions) {
		this.permissions = permissions;

		// Set the flag
		if (permissions != null) {
			flags |= SSH_FILEXFER_ATTR_PERMISSIONS;
		} else {
			flags ^= SSH_FILEXFER_ATTR_PERMISSIONS;
		}
	}
138325
def set_content_permissions(self, user, obj, payload):
        """"""
        # Data doesn't have "ADD" permission, so it has to be removed
        payload = remove_permission(payload, 'add')

        for data in obj.data.all():
            if user.has_perm('share_data', data):
                update_permission(data, payload)
737728
def setPermissions(self, dbName, access) :
        """"""
        import json

        if not self.URL :
            raise CreationError("Please save user first", None, None)

        rights = []
        if access :
            rights.append("rw")

        rights = ''.join(rights)

        if not self.connection.hasDatabase(dbName) :
            raise KeyError("Unknown database: %s" % dbName)

        url = "%s/database/%s" % (self.URL, dbName)
        r = self.connection.session.put(url, data = json.dumps({"grant": rights}, default=str))
        if r.status_code < 200 or r.status_code > 202 :
            raise CreationError("Unable to grant rights", r.content)
887814
def global_permission_set(self):
        ''''''
        only_admins_create_admins = Or(
            AllowAdmin,
            And(
                ObjAttrTrue(
                    lambda r, _: r.data.get('admin') is not True),
                Or(
                    AllowPermission('org:admin')
                )
            )
        )

        return And(
            AllowOnlyAuthenticated,
            Or(
                Not(AllowCreate),
                only_admins_create_admins
            )
        )
1088562
private void initializePermissions() {
        // Set the default restrictable permissions
        int count = 0;
        if (tc.isDebugEnabled()) {
            if (isServer) {
                Tr.debug(tc, "running on server ");
            } else {
                Tr.debug(tc, "running on client ");
            }
        }
        
        if (isServer) {
            count = DEFAULT_SERVER_RESTRICTABLE_PERMISSIONS.length;
            originationFile = SERVER_XML;
        } else {
            count = DEFAULT_CLIENT_RESTRICTABLE_PERMISSIONS.length;
            originationFile = CLIENT_XML;
        }

        for (int i = 0; i < count; i++) {
            if (isServer) {
                restrictablePermissions.add(DEFAULT_SERVER_RESTRICTABLE_PERMISSIONS[i]);
            } else {
                restrictablePermissions.add(DEFAULT_CLIENT_RESTRICTABLE_PERMISSIONS[i]);
            }
        }

        // Iterate through the configured Permissions.
        if (permissions != null && !permissions.isEmpty()) {
            Iterable<JavaPermissionsConfiguration> javaPermissions = permissions.services();
            if (javaPermissions != null) {
                for (JavaPermissionsConfiguration permission : javaPermissions) {
                    String permissionClass = String.valueOf(permission.get(JavaPermissionsConfiguration.PERMISSION));
                    String target = String.valueOf(permission.get(JavaPermissionsConfiguration.TARGET_NAME));
                    String action = String.valueOf(permission.get(JavaPermissionsConfiguration.ACTIONS));
                    String credential = String.valueOf(permission.get(JavaPermissionsConfiguration.SIGNED_BY));
                    String principalType = String.valueOf(permission.get(JavaPermissionsConfiguration.PRINCIPAL_TYPE));
                    String principalName = String.valueOf(permission.get(JavaPermissionsConfiguration.PRINCIPAL_NAME));
                    String codebase = normalize(String.valueOf(permission.get(JavaPermissionsConfiguration.CODE_BASE)));

                    // Create the permission object
                    Permission perm = createPermissionObject(permissionClass, target, action, credential, principalType, principalName, originationFile);

                    boolean isRestriction = false;
                    // Is this a restriciton or a grant?
                    if (permission.get(JavaPermissionsConfiguration.RESTRICTION) != null) {
                        isRestriction = ((Boolean) permission.get(JavaPermissionsConfiguration.RESTRICTION)).booleanValue();
                    }

                    if (isRestriction) {
                        // If this is a restriction
                        if (perm != null) {
                            restrictablePermissions.add(perm);
                        }
                    } else {
                        // If this is not a restriction, then set is a grant
                        if (perm != null) {
                            // if codebase is present, then set the permission on the shared lib classloader
                            if (codebase != null && !codebase.equalsIgnoreCase("null")) {
                                setCodeBasePermission(codebase, perm);
                            } else {
                                grantedPermissions.add(perm);
                            }
                        }
                    }
                }

                if (tc.isDebugEnabled()) {
                    Tr.debug(tc, "restrictablePermissions : " + restrictablePermissions);
                    Tr.debug(tc, "grantedPermissions : " + grantedPermissions);
                }
            }
        }

        setSharedLibraryPermission();
    }
47746
def add(self, auth, method, args, notimeout=False):
        """"""
        authstr = self._authstr(auth)
        self._requests.setdefault(authstr, []).append((method, args))
        self._notimeouts.setdefault(authstr, False)
        if notimeout:
            self._notimeouts[authstr] = notimeout
834438
private function updatePermissions()
    {
        $pathNames = $this->resolver->names();
        // These should be moved to PathResolver paths eventually.
        $pathNames[] = '%web%/extensions';
        $pathNames[] = '%web%/thumbs';

        $dirMode = $this->options->getDirMode();
        foreach ($pathNames as $name) {
            $path = $this->resolver->resolve($name);
            if (!$this->filesystem->exists($path)) {
                $this->filesystem->mkdir($path);
            }
            $this->filesystem->chmod($path, $dirMode);
        }
    }
871762
def assign_contributor_permissions(obj, contributor=None):
    """"""
    for permission in get_all_perms(obj):
        assign_perm(permission, contributor if contributor else obj.contributor, obj)
317087
def _permission_trees(permissions):
        """"""
        treecache = PermissionTreeCache()
        cached = treecache.get()
        if not cached:
            tree = PermissionTreeBuilder()
            for permission in permissions:
                tree.insert(permission)
            result = tree.serialize()
            treecache.set(result)
            return result
        return cached
699954
def setup_default_permissions(session, instance):
    
    if instance not in session.new or not isinstance(instance, Entity):
        return

    if not current_app:
        # working outside app_context. Raw object manipulation
        return

    _setup_default_permissions(instance)
94763
def add_permission(self):
        """"""
        statement_id = '{}_api_{}'.format(self.app_name, self.trigger_settings['api_name'])
        principal = 'apigateway.amazonaws.com'
        lambda_alias_arn = get_lambda_alias_arn(self.app_name, self.env, self.region)
        lambda_unqualified_arn = get_lambda_arn(self.app_name, self.env, self.region)
        resource_name = self.trigger_settings.get('resource', '')
        resource_name = resource_name.replace('/', '')
        method_api_source_arn = 'arn:aws:execute-api:{}:{}:{}/{}/{}/{}'.format(
            self.region, self.account_id, self.api_id, self.env, self.trigger_settings['method'], resource_name)
        global_api_source_arn = 'arn:aws:execute-api:{}:{}:{}/*/*/{}'.format(self.region, self.account_id, self.api_id,
                                                                             resource_name)
        add_lambda_permissions(
            function=lambda_alias_arn,
            statement_id=statement_id + self.trigger_settings['method'],
            action='lambda:InvokeFunction',
            principal=principal,
            env=self.env,
            region=self.region,
            source_arn=method_api_source_arn)
        add_lambda_permissions(
            function=lambda_alias_arn,
            statement_id=statement_id,
            action='lambda:InvokeFunction',
            principal=principal,
            env=self.env,
            region=self.region,
            source_arn=global_api_source_arn)
        add_lambda_permissions(
            function=lambda_unqualified_arn,
            statement_id=statement_id + self.trigger_settings['method'],
            action='lambda:InvokeFunction',
            principal=principal,
            env=self.env,
            region=self.region,
            source_arn=method_api_source_arn)
        add_lambda_permissions(
            function=lambda_unqualified_arn,
            statement_id=statement_id,
            action='lambda:InvokeFunction',
            principal=principal,
            env=self.env,
            region=self.region,
            source_arn=global_api_source_arn)