55package cloud .katta .protocols .s3 ;
66
77import ch .cyberduck .core .Credentials ;
8- import ch .cyberduck .core .DisabledCancelCallback ;
9- import ch .cyberduck .core .DisabledHostKeyCallback ;
10- import ch .cyberduck .core .DisabledLoginCallback ;
11- import ch .cyberduck .core .DisabledPasswordCallback ;
12- import ch .cyberduck .core .DisabledProgressListener ;
138import ch .cyberduck .core .Host ;
14- import ch .cyberduck .core .HostParser ;
159import ch .cyberduck .core .LoginCallback ;
16- import ch .cyberduck .core .LoginConnectionService ;
1710import ch .cyberduck .core .OAuthTokens ;
18- import ch .cyberduck .core .PasswordStoreFactory ;
19- import ch .cyberduck .core .ProtocolFactory ;
20- import ch .cyberduck .core .SessionFactory ;
2111import ch .cyberduck .core .exception .BackgroundException ;
2212import ch .cyberduck .core .exception .LoginCanceledException ;
2313import ch .cyberduck .core .exception .LoginFailureException ;
2414import ch .cyberduck .core .oauth .OAuth2RequestInterceptor ;
2515import ch .cyberduck .core .preferences .HostPreferences ;
2616import ch .cyberduck .core .preferences .PreferencesReader ;
27- import ch .cyberduck .core .ssl .DefaultX509KeyManager ;
28- import ch .cyberduck .core .ssl .DefaultX509TrustManager ;
29- import ch .cyberduck .core .vault .VaultRegistryFactory ;
30-
31- import static cloud .katta .protocols .hub .HubSession .SKIP_LISTING_UPON_LOGIN ;
3217
3318import org .apache .http .client .HttpClient ;
3419import org .apache .logging .log4j .LogManager ;
3722import java .util .Arrays ;
3823import java .util .List ;
3924
40- import cloud .katta .client .ApiClient ;
4125import cloud .katta .client .ApiException ;
4226import cloud .katta .client .api .StorageResourceApi ;
4327import cloud .katta .client .model .AccessTokenResponse ;
4731import com .auth0 .jwt .exceptions .JWTDecodeException ;
4832import com .auth0 .jwt .interfaces .DecodedJWT ;
4933
50- import static cloud .katta .protocols .s3 .S3AssumeRoleProtocol .OAUTH_TOKENEXCHANGE_BASEPATH ;
51-
5234/**
5335 * Exchange OIDC token to scoped token using OAuth 2.0 Token Exchange. Used for S3-STS in Katta.
5436 */
@@ -61,14 +43,11 @@ public class TokenExchangeRequestInterceptor extends OAuth2RequestInterceptor {
6143 */
6244 public static final String OIDC_AUTHORIZED_PARTY = "azp" ;
6345
64-
6546 private final Host bookmark ;
66- private final HttpClient client ;
6747
6848 public TokenExchangeRequestInterceptor (final HttpClient client , final Host bookmark , final LoginCallback prompt ) throws LoginCanceledException {
6949 super (client , bookmark , prompt );
7050 this .bookmark = bookmark ;
71- this .client = client ;
7251 }
7352
7453 @ Override
@@ -92,9 +71,9 @@ public OAuthTokens refresh(final OAuthTokens previous) throws BackgroundExceptio
9271 public OAuthTokens exchange (final OAuthTokens previous ) throws BackgroundException {
9372 log .info ("Exchange tokens {} for {}" , previous , bookmark );
9473 final PreferencesReader preferences = new HostPreferences (bookmark );
95- final ApiClient apiClient = getHubApiClient ( previous , preferences );
96-
97- final StorageResourceApi api = new StorageResourceApi (apiClient );
74+ final HubSession hub = bookmark . getProtocol (). getFeature ( HubSession . class );
75+ log . debug ( "Exchange token with hub {}" , hub );
76+ final StorageResourceApi api = new StorageResourceApi (hub . getClient () );
9877 try {
9978 AccessTokenResponse tokenExchangeResponse = api .apiStorageS3TokenPost (preferences .getProperty (S3AssumeRoleProtocol .OAUTH_TOKENEXCHANGE_VAULT ));
10079 // N.B. token exchange with Id token does not work!
@@ -109,18 +88,6 @@ public OAuthTokens exchange(final OAuthTokens previous) throws BackgroundExcepti
10988 }
11089 }
11190
112- private static ApiClient getHubApiClient (final OAuthTokens previous , final PreferencesReader preferences ) throws BackgroundException {
113- final ProtocolFactory factory = ProtocolFactory .get ();
114- final Host hub = new HostParser (factory ).get (preferences .getProperty (OAUTH_TOKENEXCHANGE_BASEPATH )).withCredentials (new Credentials ().withOauth (new OAuthTokens (previous )));
115- hub .setProperty (SKIP_LISTING_UPON_LOGIN , "true" ); // prevent infinite recursion
116- final HubSession session = (HubSession ) SessionFactory .create (hub , new DefaultX509TrustManager (), new DefaultX509KeyManager ())
117- .withRegistry (VaultRegistryFactory .get (new DisabledPasswordCallback ()));
118- final LoginConnectionService login = new LoginConnectionService (new DisabledLoginCallback (), new DisabledHostKeyCallback (),
119- PasswordStoreFactory .get (), new DisabledProgressListener ());
120- login .check (session , new DisabledCancelCallback ());
121- return session .getClient ();
122- }
123-
12491 @ Override
12592 public Credentials validate () throws BackgroundException {
12693 final Credentials credentials = super .validate ();
0 commit comments