Skip to content

Commit b7b0744

Browse files
committed
fix: ResourceServer::isOwn checking
Change-Id: I9ee576f0fa8fc705af6fd6176f27c784fdecc8b0
1 parent 0f2b58e commit b7b0744

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

app/Models/OAuth2/ResourceServer.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use App\Models\Utils\BaseEntity;
1515
use Doctrine\Common\Collections\ArrayCollection;
1616
use Doctrine\ORM\Mapping AS ORM;
17+
use Illuminate\Support\Facades\Log;
18+
1719
/**
1820
* @package Models\OAuth2
1921
*/
@@ -63,9 +65,22 @@ class ResourceServer extends BaseEntity
6365
* @return bool
6466
*/
6567
public function isOwn($ip)
66-
{
67-
$ips = explode(',', $this->ips);
68-
return in_array($ip, $ips);
68+
{ $provided_ips = array_map('trim', explode(',', $ip));
69+
$own_ips = array_map('trim', explode(',', $this->ips));
70+
Log::debug
71+
(
72+
sprintf
73+
(
74+
"ResourceServer::isOwn resource server %s checking if %s is in %s",
75+
$this->id,
76+
$ip,
77+
$this->ips
78+
)
79+
);
80+
foreach ($provided_ips as $provided_ip){
81+
if(in_array($provided_ip, $own_ips)) return true;
82+
}
83+
return false;
6984
}
7085

7186
/**

app/Repositories/DoctrineResourceServerRepository.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,20 @@ public function getByHost(string $host):?ResourceServer
5959
public function getByIp(string $ip):?ResourceServer
6060
{
6161
Log::debug(sprintf("DoctrineResourceServerRepository::getByIp ip %s", $ip));
62-
return $this->getEntityManager()
63-
->createQueryBuilder()
64-
->select("r")
65-
->from($this->getBaseEntity(), "r")
66-
->where("r.ips like :ip")
67-
->setParameter("ip", '%'.trim($ip).'%')
68-
->setMaxResults(1)
69-
->getQuery()
70-
->getOneOrNullResult();
62+
$provided_ips = array_map('trim', explode(',', $ip));
63+
foreach ($provided_ips as $provided_ip) {
64+
$res = $this->getEntityManager()
65+
->createQueryBuilder()
66+
->select("r")
67+
->from($this->getBaseEntity(), "r")
68+
->where("r.ips like :ip")
69+
->setParameter("ip", '%' . trim($provided_ip) . '%')
70+
->setMaxResults(1)
71+
->getQuery()
72+
->getOneOrNullResult();
73+
if ($res instanceof ResourceServer) return $res;
74+
}
75+
return null;
7176
}
7277

7378
/**

0 commit comments

Comments
 (0)