Skip to content

Commit 0f41060

Browse files
committed
Lookup device setup prompt from login feature.
1 parent 0712844 commit 0f41060

File tree

6 files changed

+31
-98
lines changed

6 files changed

+31
-98
lines changed

hub/src/main/java/cloud/katta/core/DeviceSetupCallbackFactory.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

hub/src/main/java/cloud/katta/protocols/hub/HubSession.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import cloud.katta.client.model.ConfigDto;
4646
import cloud.katta.client.model.UserDto;
4747
import cloud.katta.core.DeviceSetupCallback;
48-
import cloud.katta.core.DeviceSetupCallbackFactory;
4948
import cloud.katta.crypto.UserKeys;
5049
import cloud.katta.protocols.hub.exceptions.HubExceptionMappingService;
5150
import cloud.katta.protocols.hub.serializer.HubConfigDtoDeserializer;
@@ -143,7 +142,8 @@ protected HubApiClient connect(final ProxyFinder proxy, final HostKeyCallback ke
143142

144143
@Override
145144
public void login(final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException {
146-
final DeviceSetupCallback setup = DeviceSetupCallbackFactory.get();
145+
final DeviceSetupCallback setup = prompt.getFeature(DeviceSetupCallback.class);
146+
log.debug("Configured with setup prompt {}", setup);
147147
final Credentials credentials = authorizationService.validate();
148148
try {
149149
// Set username from OAuth ID Token for saving in keychain

hub/src/test/java/cloud/katta/core/util/MockableDeviceSetupCallback.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

hub/src/test/java/cloud/katta/testsetup/AbstractHubTest.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import ch.cyberduck.core.vault.VaultRegistryFactory;
1515
import ch.cyberduck.test.VaultTest;
1616

17-
import org.jetbrains.annotations.NotNull;
1817
import org.junit.jupiter.api.BeforeEach;
1918
import org.junit.jupiter.api.Named;
2019
import org.junit.jupiter.params.provider.Arguments;
@@ -28,7 +27,6 @@
2827
import java.util.function.Function;
2928

3029
import cloud.katta.core.DeviceSetupCallback;
31-
import cloud.katta.core.util.MockableDeviceSetupCallback;
3230
import cloud.katta.model.AccountKeyAndDeviceName;
3331
import cloud.katta.protocols.hub.HubProtocol;
3432
import cloud.katta.protocols.hub.HubSession;
@@ -152,7 +150,6 @@ protected void configureLogging(final String level) {
152150
preferences.setProperty("factory.vault.class", HubUVFVault.class.getName());
153151
preferences.setProperty("factory.supportdirectoryfinder.class", ch.cyberduck.core.preferences.TemporarySupportDirectoryFinder.class.getName());
154152
preferences.setProperty("factory.passwordstore.class", UnsecureHostPasswordStore.class.getName());
155-
preferences.setProperty("factory.devicesetupcallback.class", MockableDeviceSetupCallback.class.getName());
156153
preferences.setProperty("factory.vaultregistry.class", HubVaultRegistry.class.getName());
157154

158155
preferences.setProperty("oauth.handler.scheme", "katta");
@@ -191,19 +188,29 @@ protected static HubSession setupConnection(final HubTestConfig.Setup setup) thr
191188
assertTrue(factory.forName("s3").isEnabled());
192189
assertTrue(factory.forType(Protocol.Type.s3).isEnabled());
193190

194-
final DeviceSetupCallback proxy = deviceSetupCallback(setup);
195-
MockableDeviceSetupCallback.setProxy(proxy);
196-
197191
final Host hub = new HostParser(factory).get(setup.hubURL).withCredentials(new Credentials(setup.userConfig.username, setup.userConfig.password));
198192
final HubSession session = (HubSession) SessionFactory.create(hub, new DefaultX509TrustManager(), new DefaultX509KeyManager())
199193
.withRegistry(VaultRegistryFactory.get(new DisabledPasswordCallback()));
200-
final LoginConnectionService login = new LoginConnectionService(new DisabledLoginCallback(), new DisabledHostKeyCallback(),
194+
final LoginConnectionService login = new LoginConnectionService(loginCallback(setup), new DisabledHostKeyCallback(),
201195
PasswordStoreFactory.get(), new DisabledProgressListener());
202196
login.check(session, new DisabledCancelCallback());
203197
return session;
204198
}
205199

206-
protected static @NotNull DeviceSetupCallback deviceSetupCallback(HubTestConfig.Setup setup) {
200+
protected static LoginCallback loginCallback(HubTestConfig.Setup setup) {
201+
return new DisabledLoginCallback() {
202+
@SuppressWarnings("unchecked")
203+
@Override
204+
public <T> T getFeature(final Class<T> type) {
205+
if(DeviceSetupCallback.class == type) {
206+
return (T) deviceSetupCallback(setup);
207+
}
208+
return null;
209+
}
210+
};
211+
}
212+
213+
protected static DeviceSetupCallback deviceSetupCallback(HubTestConfig.Setup setup) {
207214
return new DeviceSetupCallback() {
208215
@Override
209216
public AccountKeyAndDeviceName displayAccountKeyAndAskDeviceName(final Host bookmark, final AccountKeyAndDeviceName accountKeyAndDeviceName) {

osx/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
</dependency>
2323
<dependency>
2424
<groupId>ch.cyberduck</groupId>
25-
<artifactId>binding</artifactId>
25+
<artifactId>osx</artifactId>
26+
<version>${cyberduck.version}</version>
2627
</dependency>
2728
</dependencies>
2829
</project>

osx/src/main/java/cloud/katta/controller/PromptDeviceSetupCallback.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import ch.cyberduck.binding.application.SheetCallback;
1010
import ch.cyberduck.core.Host;
1111
import ch.cyberduck.core.exception.ConnectionCanceledException;
12+
import ch.cyberduck.ui.cocoa.callback.PromptLoginCallback;
1213

1314
import org.apache.logging.log4j.LogManager;
1415
import org.apache.logging.log4j.Logger;
@@ -17,12 +18,13 @@
1718
import cloud.katta.model.AccountKeyAndDeviceName;
1819
import cloud.katta.workflows.exceptions.AccessException;
1920

20-
public class PromptDeviceSetupCallback implements DeviceSetupCallback {
21+
public class PromptDeviceSetupCallback extends PromptLoginCallback implements DeviceSetupCallback {
2122
private static final Logger log = LogManager.getLogger(PromptDeviceSetupCallback.class.getName());
2223

2324
private final ProxyController controller;
2425

2526
public PromptDeviceSetupCallback(final ProxyController controller) {
27+
super(controller);
2628
this.controller = controller;
2729
}
2830

@@ -54,4 +56,13 @@ public AccountKeyAndDeviceName askForAccountKeyAndDeviceName(final Host bookmark
5456
}
5557
return accountKeyAndDeviceName;
5658
}
59+
60+
@SuppressWarnings("unchecked")
61+
@Override
62+
public <T> T getFeature(final Class<T> type) {
63+
if(type == DeviceSetupCallback.class) {
64+
return (T) this;
65+
}
66+
return null;
67+
}
5768
}

0 commit comments

Comments
 (0)