protected static function getSecurityIdentityForCurrentOrganization(
        OrganizationalContextInterface $context,
        $roleHierarchy = null
    ) {
        $sids = [];
        $org = $context->getCurrentOrganization();
        $userOrg = $context->getCurrentOrganizationUser();
        $orgRoles = [];

        if ($org) {
            $sids[] = self::fromAccount($org);
        }

        if (null !== $userOrg) {
            $sids = array_merge($sids, static::getOrganizationGroups($userOrg));
            $orgRoles = static::getOrganizationUserRoles($userOrg, $roleHierarchy);
        } elseif ($org && $org->isUserOrganization()) {
            $orgRoles = static::getOrganizationRoles($org, $roleHierarchy);
        }

        foreach ($orgRoles as $role) {
            $sids[] = RoleSecurityIdentity::fromAccount($role);
        }

        return $sids;
    }