99use OCP \Federation \ICloudFederationFactory ;
1010use OCP \Federation \ICloudFederationNotification ;
1111use OCP \Federation \ICloudFederationShare ;
12+ use OCP \Federation \ICloudIdManager ;
13+ use OCP \OCM \Exceptions \OCMProviderException ;
14+ use OCP \OCM \IOCMDiscoveryService ;
15+ use Psr \Log \LoggerInterface ;
1216
1317class CloudFederationFactory implements ICloudFederationFactory {
18+ public function __construct (
19+ private IOCMDiscoveryService $ ocmDiscoveryService ,
20+ private ICloudIdManager $ cloudIdManager ,
21+ private LoggerInterface $ logger ,
22+ ) {
23+ }
1424 /**
1525 * get a CloudFederationShare Object to prepare a share you want to send
1626 *
@@ -31,7 +41,51 @@ class CloudFederationFactory implements ICloudFederationFactory {
3141 */
3242 #[\Override]
3343 public function getCloudFederationShare ($ shareWith , $ name , $ description , $ providerId , $ owner , $ ownerDisplayName , $ sharedBy , $ sharedByDisplayName , $ sharedSecret , $ shareType , $ resourceType ) {
34- return new CloudFederationShare ($ shareWith , $ name , $ description , $ providerId , $ owner , $ ownerDisplayName , $ sharedBy , $ sharedByDisplayName , $ shareType , $ resourceType , $ sharedSecret );
44+ $ useExchangeToken = false ;
45+ $ remoteDomain = null ;
46+
47+ try {
48+ $ cloudId = $ this ->cloudIdManager ->resolveCloudId ($ shareWith );
49+ $ remoteDomain = $ cloudId ->getRemote ();
50+
51+ try {
52+ $ remoteProvider = $ this ->ocmDiscoveryService ->discover ($ remoteDomain );
53+ $ capabilities = $ remoteProvider ->getCapabilities ();
54+ $ useExchangeToken = $ capabilities ->hasExchangeToken ();
55+
56+ $ this ->logger ->debug ('OCM provider capabilities discovered ' , [
57+ 'remote ' => $ remoteDomain ,
58+ 'capabilities ' => $ capabilities ->toArray (),
59+ 'useExchangeToken ' => $ useExchangeToken ,
60+ ]);
61+ } catch (OCMProviderException $ e ) {
62+ $ this ->logger ->warning ('Failed to discover OCM provider, using legacy share method ' , [
63+ 'remote ' => $ remoteDomain ,
64+ 'exception ' => $ e ->getMessage (),
65+ ]);
66+ }
67+ } catch (\InvalidArgumentException $ e ) {
68+ $ this ->logger ->warning ('Invalid cloud ID format, using legacy share method ' , [
69+ 'shareWith ' => $ shareWith ,
70+ 'exception ' => $ e ->getMessage (),
71+ ]);
72+ }
73+
74+ return new CloudFederationShare (
75+ $ shareWith ,
76+ $ name ,
77+ $ description ,
78+ $ providerId ,
79+ $ owner ,
80+ $ ownerDisplayName ,
81+ $ sharedBy ,
82+ $ sharedByDisplayName ,
83+ $ shareType ,
84+ $ resourceType ,
85+ $ sharedSecret ,
86+ $ useExchangeToken ,
87+ $ remoteDomain
88+ );
3589 }
3690
3791 /**
0 commit comments