2121 public function __construct (
2222 private QueryBuilderFactoryInterface $ queryBuilderFactory ,
2323 private RoleResolverInterface $ roleResolver ,
24- private ContextInterface $ context
24+ private ContextInterface $ context,
2525 ) {
2626 }
2727
@@ -44,14 +44,29 @@ public function loadUserByIdentifier(string $identifier): UserInterface
4444 throw new UserNotFoundException (sprintf ('User "%s" not found. ' , $ identifier ));
4545 }
4646
47- $ roles = $ this ->roleResolver ->resolveRoles ($ userData ['OXRIGHTS ' ]);
47+ return $ this ->createApiUser ($ userData );
48+ }
4849
49- return new ApiUser (
50- $ userData ['OXID ' ],
51- $ userData ['OXUSERNAME ' ],
52- $ roles ,
53- $ userData ['OXPASSWORD ' ]
54- );
50+ public function loadByOxid (string $ oxid ): UserInterface
51+ {
52+ $ queryBuilder = $ this ->queryBuilderFactory ->create ();
53+ $ queryBuilder
54+ ->select ('OXID ' , 'OXUSERNAME ' , 'OXPASSWORD ' , 'OXRIGHTS ' )
55+ ->from ('oxuser ' )
56+ ->where ('OXID = :userId ' )
57+ ->andWhere ('OXACTIVE = 1 ' )
58+ ->andWhere ('(OXSHOPID = :shopId OR OXRIGHTS = :mallAdmin) ' )
59+ ->setParameter ('userId ' , $ oxid )
60+ ->setParameter ('shopId ' , $ this ->context ->getCurrentShopId ())
61+ ->setParameter ('mallAdmin ' , 'malladmin ' );
62+
63+ $ userData = $ queryBuilder ->execute ()->fetchAssociative ();
64+
65+ if (!$ userData ) {
66+ throw new UserNotFoundException (sprintf ('User "%s" not found. ' , $ oxid ));
67+ }
68+
69+ return $ this ->createApiUser ($ userData );
5570 }
5671
5772 public function refreshUser (UserInterface $ user ): UserInterface
@@ -60,11 +75,23 @@ public function refreshUser(UserInterface $user): UserInterface
6075 throw new UnsupportedUserException ();
6176 }
6277
63- return $ this ->loadUserByIdentifier ($ user ->getUserIdentifier ());
78+ return $ this ->loadByOxid ($ user ->getOxid ());
6479 }
6580
6681 public function supportsClass (string $ class ): bool
6782 {
6883 return ApiUser::class === $ class ;
6984 }
85+
86+ private function createApiUser (array $ userData ): ApiUser
87+ {
88+ $ roles = $ this ->roleResolver ->resolveRoles ($ userData ['OXRIGHTS ' ]);
89+
90+ return new ApiUser (
91+ $ userData ['OXID ' ],
92+ $ userData ['OXUSERNAME ' ],
93+ $ roles ,
94+ $ userData ['OXPASSWORD ' ]
95+ );
96+ }
7097}
0 commit comments