@@ -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 /**
@@ -104,26 +109,37 @@ public function getByAudienceAndIpAndActive(array $audience, string $ip):?Resour
104109 )
105110 );
106111
112+
107113 $ query = <<<SQL
108- SELECT r.* FROM oauth2_resource_server r
109- WHERE FIND_IN_SET(' {$ ip }', r.ips) AND r.active = 1
114+ SELECT r.* FROM oauth2_resource_server r WHERE r.active = 1
110115SQL ;
116+ $ ips_query = "" ;
117+ $ provided_ips = array_map ('trim ' , explode (', ' , $ ip ));
118+ foreach ($ provided_ips as $ index => $ provided_ip ) {
119+ if ($ index > 0 ) {
120+ $ ips_query .= " OR " ;
121+ }
122+ $ ips_query .= sprintf (" FIND_IN_SET('%s',r.ips) " , $ provided_ip );
123+ }
111124
112- $ hosts_query = "" ;
125+ Log:: debug ( sprintf ( " DoctrineResourceServerRepository::getByAudienceAndIpAndActive ips_query %s " , $ ips_query )) ;
113126
127+ $ hosts_query = "" ;
114128 foreach ($ audience as $ index => $ audience_item ) {
115129 if ($ index > 0 ) {
116130 $ hosts_query .= " OR " ;
117131 }
118132 $ hosts_query .= sprintf (" FIND_IN_SET('%s',r.host) " , $ audience_item );
119133 }
120134
121- if (!empty ($ hosts_query ))
122- $ hosts_query = " AND ( " . $ hosts_query .") " ;
123135
124136 Log::debug (sprintf ("DoctrineResourceServerRepository::getByAudienceAndIpAndActive hosts_query %s " , $ hosts_query ));
137+ if (!empty ($ ips_query ))
138+ $ query = $ query . " AND ( " . $ ips_query . ") " ;
139+ if (!empty ($ hosts_query ))
140+ $ query = $ query . " AND ( " . $ hosts_query . ") " ;
125141
126- $ query = $ query . $ hosts_query . " LIMIT 1; " ;
142+ $ query = $ query . " LIMIT 1; " ;
127143
128144 Log::debug (sprintf ("DoctrineResourceServerRepository::getByAudienceAndIpAndActive query %s " , $ query ));
129145
0 commit comments