Skip to content

Commit 4185ef4

Browse files
committed
Auth: Replace usages for User::setAuthSource with User::addAuthSourceByAuthentication for more flexible handling of auth sources
1 parent 521f53d commit 4185ef4

File tree

7 files changed

+25
-18
lines changed

7 files changed

+25
-18
lines changed

src/CoreBundle/Entity/User.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -940,18 +940,6 @@ public function setClasses(Collection $classes): self
940940
return $this;
941941
}
942942

943-
public function getAuthSource(): ?string
944-
{
945-
return $this->authSource;
946-
}
947-
948-
public function setAuthSource(string $authSource): self
949-
{
950-
$this->authSource = $authSource;
951-
952-
return $this;
953-
}
954-
955943
public function getEmail(): string
956944
{
957945
return $this->email;

src/CoreBundle/Migrations/Schema/V200/Version20230720142900.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Chamilo\CoreBundle\Entity\User;
1010
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
1111
use Chamilo\CoreBundle\Repository\Node\UserRepository;
12+
use Chamilo\CoreBundle\ServiceHelper\AccessUrlHelper;
1213
use Doctrine\DBAL\Schema\Schema;
1314

1415
use const PASSWORD_DEFAULT;
@@ -48,7 +49,10 @@ public function up(Schema $schema): void
4849
->setLastname('Fallback')
4950
->setFirstname('User')
5051
->setOfficialCode('FALLBACK')
51-
->setAuthSource('platform')
52+
->addAuthSourceByAuthentication(
53+
'platform',
54+
$this->container->get(AccessUrlHelper::class)->getCurrent()
55+
)
5256
->setPhone('0000000000')
5357
->setLocale('en')
5458
->setActive(User::SOFT_DELETED)

src/CoreBundle/Security/Authenticator/OAuth2/FacebookAuthenticator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ protected function userLoader(AccessToken $accessToken): User
6767
->setUsername($this->changeToValidChamiloLogin($resourceOwner->getEmail()))
6868
->setPlainPassword('facebook')
6969
->setStatus(STUDENT)
70-
->setAuthSource('facebook')
70+
->addAuthSourceByAuthentication(
71+
'facebook',
72+
$this->urlHelper->getCurrent()
73+
)
7174
->setRoleFromStatus(STUDENT)
7275
;
7376

src/CoreBundle/Security/Authenticator/OAuth2/GenericAuthenticator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,10 @@ public function saveUserInfo(User $user, array $resourceOwnerData, array $provid
170170
$user->getEmail()
171171
)
172172
)
173-
->setAuthSource('oauth2')
173+
->addAuthSourceByAuthentication(
174+
'oauth2',
175+
$this->urlHelper->getCurrent()
176+
)
174177
->setStatus($status)
175178
->setRoleFromStatus($status)
176179
;

src/CoreBundle/Security/Authenticator/OAuth2/KeycloakAuthenticator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ protected function userLoader(AccessToken $accessToken): User
4444
->setUsername($username)
4545
->setPlainPassword('keycloak')
4646
->setStatus(STUDENT)
47-
->setAuthSource('keycloak')
47+
->addAuthSourceByAuthentication(
48+
'keycloak',
49+
$this->urlHelper->getCurrent()
50+
)
4851
->setRoleFromStatus(STUDENT)
4952
;
5053

src/CoreBundle/ServiceHelper/AzureAuthenticatorHelper.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ public function registerUser(array $azureUserInfo, string $azureUidKey = 'object
6767
->setUsername($username)
6868
->setPlainPassword('azure')
6969
->setStatus(STUDENT)
70-
->setAuthSource($authSource)
70+
->addAuthSourceByAuthentication(
71+
$authSource,
72+
$this->urlHelper->getCurrent()
73+
)
7174
->setPhone($phone)
7275
->setActive($active)
7376
->setRoleFromStatus(STUDENT)

tests/CoreBundle/Repository/Node/UserRepositoryTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,10 @@ public function testCreateUserSkipResourceNode(): void
228228
->setExpired(false)
229229
->setTeach('teach')
230230
->setApiToken('tok')
231-
->setAuthSource('auth')
231+
->addAuthSourceByAuthentication(
232+
'auth',
233+
$this->getAccessUrl()
234+
)
232235
->setProductions('prod')
233236
->setCompetences('comp')
234237
->setDiplomas('diploma')

0 commit comments

Comments
 (0)