Issues (3887)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

Bundle/IntegrationBundle/Manager/TypesRegistry.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Oro\Bundle\IntegrationBundle\Manager;
4
5
use Doctrine\Common\Util\ClassUtils;
6
use Doctrine\Common\Collections\ArrayCollection;
7
8
use Oro\Bundle\IntegrationBundle\Exception\LogicException;
9
use Oro\Bundle\IntegrationBundle\Entity\Channel as Integration;
10
use Oro\Bundle\IntegrationBundle\Entity\Transport;
11
use Oro\Bundle\IntegrationBundle\Provider\ChannelInterface as IntegrationInterface;
12
use Oro\Bundle\IntegrationBundle\Provider\ConnectorInterface;
13
use Oro\Bundle\IntegrationBundle\Provider\DefaultOwnerTypeAwareInterface;
14
use Oro\Bundle\IntegrationBundle\Provider\ForceConnectorInterface;
15
use Oro\Bundle\IntegrationBundle\Provider\IconAwareIntegrationInterface;
16
use Oro\Bundle\IntegrationBundle\Provider\TransportInterface;
17
18
class TypesRegistry
19
{
20
    /** @var ArrayCollection|IntegrationInterface[] */
21
    protected $integrationTypes = [];
22
23
    /** @var array|ArrayCollection[] */
24
    protected $transportTypes = [];
25
26
    /** @var array|ArrayCollection[] */
27
    protected $connectorTypes = [];
28
29
    public function __construct()
30
    {
31
        $this->integrationTypes = new ArrayCollection();
32
    }
33
34
    /**
35
     * Set registered types
36
     *
37
     * @param string               $typeName
38
     * @param IntegrationInterface $type
39
     *
40
     * @throws \LogicException
41
     * @return $this
42
     */
43
    public function addChannelType($typeName, IntegrationInterface $type)
44
    {
45
        if (!$this->integrationTypes->containsKey($typeName)) {
46
            $this->integrationTypes->set($typeName, $type);
47
        } else {
48
            throw new LogicException(sprintf('Trying to redeclare integration type "%s".', $typeName));
49
        }
50
51
        return $this;
52
    }
53
54
    /**
55
     * Return registered types
56
     *
57
     * @return ArrayCollection|IntegrationInterface[]
58
     */
59
    public function getRegisteredChannelTypes()
60
    {
61
        return $this->integrationTypes;
62
    }
63
64
    /**
65
     * Collect available types for choice field
66
     *
67
     * @return array
68
     */
69 View Code Duplication
    public function getAvailableChannelTypesChoiceList()
70
    {
71
        /** @var ArrayCollection $types */
72
        $types  = $this->getAvailableIntegrationTypes();
73
        $keys   = $types->getKeys();
74
        $values = $types->map(
75
            function (IntegrationInterface $type) {
76
                return $type->getLabel();
77
            }
78
        )->toArray();
79
80
        return array_combine($keys, $values);
81
    }
82
83
    /**
84
     * Collect available types for choice field with icon
85
     *
86
     * @return array
87
     */
88
    public function getAvailableIntegrationTypesDetailedData()
89
    {
90
        /** @var ArrayCollection $types */
91
        $types  = $this->getAvailableIntegrationTypes();
92
        $keys   = $types->getKeys();
93
        $values = $types->map(
94
            function (IntegrationInterface $type) {
95
                $result = ['label' => $type->getLabel()];
96
                if ($type instanceof IconAwareIntegrationInterface) {
97
                    $result['icon'] = $type->getIcon();
98
                }
99
                return $result;
100
            }
101
        )->toArray();
102
103
        return array_combine($keys, $values);
104
    }
105
106
    /**
107
     * Register transport for integration type
108
     *
109
     * @param string             $typeName
110
     * @param string             $integrationTypeName
111
     * @param TransportInterface $type
112
     *
113
     * @return $this
114
     * @throws \LogicException
115
     */
116 View Code Duplication
    public function addTransportType($typeName, $integrationTypeName, TransportInterface $type)
117
    {
118
        if (!isset($this->transportTypes[$integrationTypeName])) {
119
            $this->transportTypes[$integrationTypeName] = new ArrayCollection();
120
        }
121
122
        if ($this->transportTypes[$integrationTypeName]->containsKey($typeName)) {
123
            throw new LogicException(
124
                sprintf(
125
                    'Trying to redeclare transport type "%s" for "%s" integration type.',
126
                    $typeName,
127
                    $integrationTypeName
128
                )
129
            );
130
        }
131
132
        $this->transportTypes[$integrationTypeName]->set($typeName, $type);
133
134
        return $this;
135
    }
136
137
    /**
138
     * @param string $integrationTypeName
139
     * @param string $transportType
140
     *
141
     * @return TransportInterface
142
     * @throws \LogicException
143
     */
144 View Code Duplication
    public function getTransportType($integrationTypeName, $transportType)
145
    {
146
        if (!isset($this->transportTypes[$integrationTypeName])) {
147
            throw new LogicException(sprintf('Transports not found for integration "%s".', $integrationTypeName));
148
        } elseif (!$this->transportTypes[$integrationTypeName]->containsKey($transportType)) {
149
            throw new LogicException(
150
                sprintf(
151
                    'Transports type "%s"  not found for integration "%s".',
152
                    $transportType,
153
                    $integrationTypeName
154
                )
155
            );
156
        }
157
158
        return $this->transportTypes[$integrationTypeName]->get($transportType);
159
    }
160
161
    /**
162
     * Returns registered transports for integration by type
163
     *
164
     * @param string $integrationType
165
     *
166
     * @return ArrayCollection
167
     */
168
    public function getRegisteredTransportTypes($integrationType)
169
    {
170
        if (!isset($this->transportTypes[$integrationType])) {
171
            $this->transportTypes[$integrationType] = new ArrayCollection();
172
        }
173
174
        return $this->transportTypes[$integrationType];
175
    }
176
177
    /**
178
     * Collect available types for choice field
179
     *
180
     * @param string $integrationType
181
     *
182
     * @return array
183
     */
184 View Code Duplication
    public function getAvailableTransportTypesChoiceList($integrationType)
185
    {
186
        $types  = $this->getRegisteredTransportTypes($integrationType);
187
        $keys   = $types->getKeys();
188
        $values = $types->map(
189
            function (TransportInterface $type) {
190
                return $type->getLabel();
191
            }
192
        )->toArray();
193
194
        return array_combine($keys, $values);
195
    }
196
197
    /**
198
     * @param Transport $transportEntity
199
     * @param string    $integrationType
200
     * @param bool      $typeNameOnly
201
     *
202
     * @throws \LogicException
203
     * @return string|TransportInterface
204
     */
205
    public function getTransportTypeBySettingEntity(Transport $transportEntity, $integrationType, $typeNameOnly = false)
206
    {
207
        $class = ClassUtils::getClass($transportEntity);
208
        $types = $this->getRegisteredTransportTypes($integrationType)->filter(
209
            function (TransportInterface $transport) use ($transportEntity, $class) {
210
                return $transport->getSettingsEntityFQCN() === $class;
211
            }
212
        );
213
        $keys  = $types->getKeys();
214
        $key   = reset($keys);
0 ignored issues
show
Bug Compatibility introduced by
The expression reset($keys); of type integer|string|false adds the type integer to the return on line 220 which is incompatible with the return type documented by Oro\Bundle\IntegrationBu...portTypeBySettingEntity of type string|Oro\Bundle\Integr...ider\TransportInterface.
Loading history...
215
216
        if ($key === false) {
217
            throw new LogicException(sprintf('Transport not found for integration type "%s".', $integrationType));
218
        }
219
        if ($typeNameOnly) {
220
            return $key;
221
        }
222
223
        return $types->first();
224
    }
225
226
    /**
227
     * Register connector for integration type
228
     *
229
     * @param string             $typeName
230
     * @param string             $integrationTypeName
231
     * @param ConnectorInterface $type
232
     *
233
     * @throws \LogicException
234
     * @return $this
235
     */
236 View Code Duplication
    public function addConnectorType($typeName, $integrationTypeName, ConnectorInterface $type)
237
    {
238
        if (!isset($this->connectorTypes[$integrationTypeName])) {
239
            $this->connectorTypes[$integrationTypeName] = new ArrayCollection();
240
        }
241
242
        if ($this->connectorTypes[$integrationTypeName]->containsKey($typeName)) {
243
            throw new LogicException(
244
                sprintf(
245
                    'Trying to redeclare connector type "%s" for "%s" integration type.',
246
                    $typeName,
247
                    $integrationTypeName
248
                )
249
            );
250
        }
251
252
        $this->connectorTypes[$integrationTypeName]->set($typeName, $type);
253
254
        return $this;
255
    }
256
257
    /**
258
     * @param string $integrationType
259
     * @param string $type
260
     *
261
     * @return ConnectorInterface
262
     * @throws LogicException
263
     */
264 View Code Duplication
    public function getConnectorType($integrationType, $type)
265
    {
266
        if (!isset($this->connectorTypes[$integrationType])) {
267
            throw new LogicException(sprintf('Connectors not found for integration "%s".', $integrationType));
268
        } elseif (!$this->connectorTypes[$integrationType]->containsKey($type)) {
269
            throw new LogicException(
270
                sprintf(
271
                    'Connector type "%s"  not found for integration "%s".',
272
                    $type,
273
                    $integrationType
274
                )
275
            );
276
        }
277
278
        return $this->connectorTypes[$integrationType]->get($type);
279
    }
280
281
    /**
282
     * Returns registered connectors for integration by type
283
     *
284
     * @param string        $integrationType
285
     * @param null|\Closure $filterClosure
286
     *
287
     * @return ArrayCollection
288
     */
289
    public function getRegisteredConnectorsTypes($integrationType, $filterClosure = null)
290
    {
291
        if (!isset($this->connectorTypes[$integrationType])) {
292
            $this->connectorTypes[$integrationType] = new ArrayCollection();
293
        }
294
295
        if (is_callable($filterClosure)) {
296
            return $this->connectorTypes[$integrationType]->filter($filterClosure);
297
        } else {
298
            return $this->connectorTypes[$integrationType];
299
        }
300
    }
301
302
    /**
303
     * Collect available types for choice field
304
     *
305
     * @param string        $integrationType
306
     * @param null|\Closure $filterClosure
307
     *
308
     * @return array
309
     */
310 View Code Duplication
    public function getAvailableConnectorsTypesChoiceList($integrationType, $filterClosure = null)
311
    {
312
        $types  = $this->getRegisteredConnectorsTypes($integrationType, $filterClosure);
313
        $keys   = $types->getKeys();
314
        $values = $types->map(
315
            function (ConnectorInterface $type) {
316
                return $type->getLabel();
317
            }
318
        )->toArray();
319
320
        return array_combine($keys, $values);
321
    }
322
323
    /**
324
     * Checks if there is at least one connector that supports force sync.
325
     *
326
     * @param Integration $integration
327
     *
328
     * @return boolean
329
     */
330
    public function supportsForceSync(Integration $integration)
331
    {
332
        $connectors = $this->getRegisteredConnectorsTypes($integration->getType());
333
334
        foreach ($connectors as $connector) {
335
            if ($connector instanceof ForceConnectorInterface) {
336
                if ($connector->supportsForceSync()) {
337
                    return true;
338
                }
339
            }
340
        }
341
342
        return false;
343
    }
344
345
    /**
346
     * Returns type of default owner for entities created by this integration.
347
     *
348
     * @param string|null $integrationType
349
     *
350
     * @return string 'user'\'business_unit'
351
     */
352
    public function getDefaultOwnerType($integrationType = null)
353
    {
354
        if ($integrationType === null) {
355
            return DefaultOwnerTypeAwareInterface::USER;
356
        }
357
        $type = $this->integrationTypes[$integrationType];
358
359
        if ($type instanceof DefaultOwnerTypeAwareInterface) {
360
            return $type->getDefaultOwnerType();
361
        }
362
363
        return DefaultOwnerTypeAwareInterface::USER;
364
    }
365
366
    /**
367
     * @return array
368
     */
369
    protected function getAvailableIntegrationTypes()
370
    {
371
        $registry = $this;
372
        $types    = $registry->getRegisteredChannelTypes();
373
        $types    = $types->partition(
374
            function ($key, IntegrationInterface $type) use ($registry) {
375
                return !$registry->getRegisteredTransportTypes($key)->isEmpty();
376
            }
377
        );
378
        return $types[0];
379
    }
380
}
381