@Ignore @Test(expected = ConnectionTimeoutException.class) public void testLoginRadius() throws Exception { final ProtocolFactory factory = new ProtocolFactory(new HashSet<>(Collections.singleton(new SDSProtocol()))); final Profile profile = new ProfilePlistReader(factory).read( new Local("../profiles/DRACOON (Radius).cyberduckprofile")); final Host host = new Host(profile, "duck.dracoon.com", new Credentials( "rsa.user1", "1234" )); final SDSSession session = new SDSSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager()); assertNotNull(session.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback())); assertTrue(session.isConnected()); assertNotNull(session.getClient()); session.login(Proxy.DIRECT, new DisabledLoginCallback() { @Override public Credentials prompt(final Host bookmark, final String title, final String reason, final LoginOptions options) { assertEquals("Multi-Factor Authentication", reason); assertFalse(options.user); assertTrue(options.password); return new Credentials(StringUtils.EMPTY, "889153"); } }, new DisabledCancelCallback()); assertFalse(new SDSListService(session, new SDSNodeIdProvider(session)).list(new Path("/", EnumSet.of(Path.Type.directory)), new DisabledListProgressListener()).isEmpty()); }
@Override public void login(final Proxy proxy, final LoginCallback controller, final CancelCallback cancel) throws BackgroundException { final SoftwareVersionData version = this.softwareVersion(); final Matcher matcher = Pattern.compile(VERSION_REGEX).matcher(version.getRestApiVersion()); if(matcher.matches()) { if(new Version(matcher.group(1)).compareTo(new Version(PreferencesFactory.get().getProperty("sds.version.lts"))) < 0) { throw new InteroperabilityException( LocaleFactory.localizedString("DRACOON environment needs to be updated", "SDS"), LocaleFactory.localizedString("Your DRACOON environment is outdated and no longer works with this application. Please contact your administrator.", "SDS")); } } final Credentials credentials = host.getCredentials(); final String login = credentials.getUsername(); final String password = credentials.getPassword(); switch(SDSProtocol.Authorization.valueOf(host.getProtocol().getAuthorization())) { case oauth: if("x-dracoon-action:oauth".equals(CYBERDUCK_REDIRECT_URI)) { if(matcher.matches()) { if(new Version(matcher.group(1)).compareTo(new Version("4.15.0")) >= 0) { authorizationService.withRedirectUri(CYBERDUCK_REDIRECT_URI); } } else { log.warn(String.format("Failure to parse software version %s", version)); } } authorizationService.setTokens(authorizationService.authorize(host, controller, cancel)); break; case radius: final Credentials additional = controller.prompt(host, LocaleFactory.localizedString("Provide additional login credentials", "Credentials"), LocaleFactory.localizedString("Multi-Factor Authentication", "S3"), new LoginOptions() .icon(host.getProtocol().disk()) .user(false) .keychain(false) ); retryHandler.setTokens(login, password, this.login(controller, new LoginRequest() .authType(LoginRequest.AuthTypeEnum.fromValue(host.getProtocol().getAuthorization())) .login(login) .password(additional.getPassword()) )); break; default: retryHandler.setTokens(login, password, this.login(controller, new LoginRequest() .authType(LoginRequest.AuthTypeEnum.fromValue(host.getProtocol().getAuthorization())) .login(login) .password(password) )); break; } try { configuration.addAll(new ConfigApi(client).requestSystemSettings(StringUtils.EMPTY).getItems()); } catch(ApiException e) { log.warn(String.format("Ignore failure reading configuration. %s", new SDSExceptionMappingService().map(e))); } try { final UserAccount account = new UserApi(client).requestUserInfo(StringUtils.EMPTY, false, null); if(log.isDebugEnabled()) { log.debug(String.format("Authenticated as user %s", account)); } switch(SDSProtocol.Authorization.valueOf(host.getProtocol().getAuthorization())) { case oauth: credentials.setUsername(account.getLogin()); } userAccount.set(new UserAccountWrapper(account)); keyPair.set(new UserApi(client).requestUserKeyPair(StringUtils.EMPTY)); final UserPrivateKey privateKey = new UserPrivateKey(); final UserKeyPairContainer keyPairContainer = keyPair.get(); privateKey.setPrivateKey(keyPairContainer.getPrivateKeyContainer().getPrivateKey()); privateKey.setVersion(keyPairContainer.getPrivateKeyContainer().getVersion()); final UserKeyPair userKeyPair = new UserKeyPair(); userKeyPair.setUserPrivateKey(privateKey); if(log.isDebugEnabled()) { log.debug(String.format("Attempt to unlock private key %s", privateKey)); } try { new TripleCryptKeyPair().unlock(controller, host, userKeyPair); } catch(LoginCanceledException e) { log.warn("Ignore cancel unlocking triple crypt private key pair"); } } catch(CryptoException e) { throw new TripleCryptExceptionMappingService().map(e); } catch(ApiException e) { log.warn(String.format("Ignore failure reading user key pair. %s", new SDSExceptionMappingService().map(e))); } try { softwareVersion.set(new PublicApi(client).requestSoftwareVersion(null)); } catch(ApiException e) { log.warn(String.format("Ignore failure reading version. %s", new SDSExceptionMappingService().map(e))); } }
SDSSession extends HttpSession<SDSApiClient> { @Override public void login(final Proxy proxy, final LoginCallback controller, final CancelCallback cancel) throws BackgroundException { final SoftwareVersionData version = this.softwareVersion(); final Matcher matcher = Pattern.compile(VERSION_REGEX).matcher(version.getRestApiVersion()); if(matcher.matches()) { if(new Version(matcher.group(1)).compareTo(new Version(PreferencesFactory.get().getProperty("sds.version.lts"))) < 0) { throw new InteroperabilityException( LocaleFactory.localizedString("DRACOON environment needs to be updated", "SDS"), LocaleFactory.localizedString("Your DRACOON environment is outdated and no longer works with this application. Please contact your administrator.", "SDS")); } } final Credentials credentials = host.getCredentials(); final String login = credentials.getUsername(); final String password = credentials.getPassword(); switch(SDSProtocol.Authorization.valueOf(host.getProtocol().getAuthorization())) { case oauth: if("x-dracoon-action:oauth".equals(CYBERDUCK_REDIRECT_URI)) { if(matcher.matches()) { if(new Version(matcher.group(1)).compareTo(new Version("4.15.0")) >= 0) { authorizationService.withRedirectUri(CYBERDUCK_REDIRECT_URI); } } else { log.warn(String.format("Failure to parse software version %s", version)); } } authorizationService.setTokens(authorizationService.authorize(host, controller, cancel)); break; case radius: final Credentials additional = controller.prompt(host, LocaleFactory.localizedString("Provide additional login credentials", "Credentials"), LocaleFactory.localizedString("Multi-Factor Authentication", "S3"), new LoginOptions() .icon(host.getProtocol().disk()) .user(false) .keychain(false) ); retryHandler.setTokens(login, password, this.login(controller, new LoginRequest() .authType(LoginRequest.AuthTypeEnum.fromValue(host.getProtocol().getAuthorization())) .login(login) .password(additional.getPassword()) )); break; default: retryHandler.setTokens(login, password, this.login(controller, new LoginRequest() .authType(LoginRequest.AuthTypeEnum.fromValue(host.getProtocol().getAuthorization())) .login(login) .password(password) )); break; } try { configuration.addAll(new ConfigApi(client).requestSystemSettings(StringUtils.EMPTY).getItems()); } catch(ApiException e) { log.warn(String.format("Ignore failure reading configuration. %s", new SDSExceptionMappingService().map(e))); } try { final UserAccount account = new UserApi(client).requestUserInfo(StringUtils.EMPTY, false, null); if(log.isDebugEnabled()) { log.debug(String.format("Authenticated as user %s", account)); } switch(SDSProtocol.Authorization.valueOf(host.getProtocol().getAuthorization())) { case oauth: credentials.setUsername(account.getLogin()); } userAccount.set(new UserAccountWrapper(account)); keyPair.set(new UserApi(client).requestUserKeyPair(StringUtils.EMPTY)); final UserPrivateKey privateKey = new UserPrivateKey(); final UserKeyPairContainer keyPairContainer = keyPair.get(); privateKey.setPrivateKey(keyPairContainer.getPrivateKeyContainer().getPrivateKey()); privateKey.setVersion(keyPairContainer.getPrivateKeyContainer().getVersion()); final UserKeyPair userKeyPair = new UserKeyPair(); userKeyPair.setUserPrivateKey(privateKey); if(log.isDebugEnabled()) { log.debug(String.format("Attempt to unlock private key %s", privateKey)); } try { new TripleCryptKeyPair().unlock(controller, host, userKeyPair); } catch(LoginCanceledException e) { log.warn("Ignore cancel unlocking triple crypt private key pair"); } } catch(CryptoException e) { throw new TripleCryptExceptionMappingService().map(e); } catch(ApiException e) { log.warn(String.format("Ignore failure reading user key pair. %s", new SDSExceptionMappingService().map(e))); } try { softwareVersion.set(new PublicApi(client).requestSoftwareVersion(null)); } catch(ApiException e) { log.warn(String.format("Ignore failure reading version. %s", new SDSExceptionMappingService().map(e))); } } }
SDSSession extends HttpSession<SDSApiClient> { @Override public void login(final Proxy proxy, final LoginCallback controller, final CancelCallback cancel) throws BackgroundException { final SoftwareVersionData version = this.softwareVersion(); final Matcher matcher = Pattern.compile(VERSION_REGEX).matcher(version.getRestApiVersion()); if(matcher.matches()) { if(new Version(matcher.group(1)).compareTo(new Version(PreferencesFactory.get().getProperty("sds.version.lts"))) < 0) { throw new InteroperabilityException( LocaleFactory.localizedString("DRACOON environment needs to be updated", "SDS"), LocaleFactory.localizedString("Your DRACOON environment is outdated and no longer works with this application. Please contact your administrator.", "SDS")); } } final Credentials credentials = host.getCredentials(); final String login = credentials.getUsername(); final String password = credentials.getPassword(); switch(SDSProtocol.Authorization.valueOf(host.getProtocol().getAuthorization())) { case oauth: if("x-dracoon-action:oauth".equals(CYBERDUCK_REDIRECT_URI)) { if(matcher.matches()) { if(new Version(matcher.group(1)).compareTo(new Version("4.15.0")) >= 0) { authorizationService.withRedirectUri(CYBERDUCK_REDIRECT_URI); } } else { log.warn(String.format("Failure to parse software version %s", version)); } } authorizationService.setTokens(authorizationService.authorize(host, controller, cancel)); break; case radius: final Credentials additional = controller.prompt(host, LocaleFactory.localizedString("Provide additional login credentials", "Credentials"), LocaleFactory.localizedString("Multi-Factor Authentication", "S3"), new LoginOptions() .icon(host.getProtocol().disk()) .user(false) .keychain(false) ); retryHandler.setTokens(login, password, this.login(controller, new LoginRequest() .authType(LoginRequest.AuthTypeEnum.fromValue(host.getProtocol().getAuthorization())) .login(login) .password(additional.getPassword()) )); break; default: retryHandler.setTokens(login, password, this.login(controller, new LoginRequest() .authType(LoginRequest.AuthTypeEnum.fromValue(host.getProtocol().getAuthorization())) .login(login) .password(password) )); break; } try { configuration.addAll(new ConfigApi(client).requestSystemSettings(StringUtils.EMPTY).getItems()); } catch(ApiException e) { log.warn(String.format("Ignore failure reading configuration. %s", new SDSExceptionMappingService().map(e))); } try { final UserAccount account = new UserApi(client).requestUserInfo(StringUtils.EMPTY, false, null); if(log.isDebugEnabled()) { log.debug(String.format("Authenticated as user %s", account)); } switch(SDSProtocol.Authorization.valueOf(host.getProtocol().getAuthorization())) { case oauth: credentials.setUsername(account.getLogin()); } userAccount.set(new UserAccountWrapper(account)); keyPair.set(new UserApi(client).requestUserKeyPair(StringUtils.EMPTY)); final UserPrivateKey privateKey = new UserPrivateKey(); final UserKeyPairContainer keyPairContainer = keyPair.get(); privateKey.setPrivateKey(keyPairContainer.getPrivateKeyContainer().getPrivateKey()); privateKey.setVersion(keyPairContainer.getPrivateKeyContainer().getVersion()); final UserKeyPair userKeyPair = new UserKeyPair(); userKeyPair.setUserPrivateKey(privateKey); if(log.isDebugEnabled()) { log.debug(String.format("Attempt to unlock private key %s", privateKey)); } try { new TripleCryptKeyPair().unlock(controller, host, userKeyPair); } catch(LoginCanceledException e) { log.warn("Ignore cancel unlocking triple crypt private key pair"); } } catch(CryptoException e) { throw new TripleCryptExceptionMappingService().map(e); } catch(ApiException e) { log.warn(String.format("Ignore failure reading user key pair. %s", new SDSExceptionMappingService().map(e))); } try { softwareVersion.set(new PublicApi(client).requestSoftwareVersion(null)); } catch(ApiException e) { log.warn(String.format("Ignore failure reading version. %s", new SDSExceptionMappingService().map(e))); } } SDSSession(final Host host, final X509TrustManager trust, final X509KeyManager key); }
SDSSession extends HttpSession<SDSApiClient> { @Override public void login(final Proxy proxy, final LoginCallback controller, final CancelCallback cancel) throws BackgroundException { final SoftwareVersionData version = this.softwareVersion(); final Matcher matcher = Pattern.compile(VERSION_REGEX).matcher(version.getRestApiVersion()); if(matcher.matches()) { if(new Version(matcher.group(1)).compareTo(new Version(PreferencesFactory.get().getProperty("sds.version.lts"))) < 0) { throw new InteroperabilityException( LocaleFactory.localizedString("DRACOON environment needs to be updated", "SDS"), LocaleFactory.localizedString("Your DRACOON environment is outdated and no longer works with this application. Please contact your administrator.", "SDS")); } } final Credentials credentials = host.getCredentials(); final String login = credentials.getUsername(); final String password = credentials.getPassword(); switch(SDSProtocol.Authorization.valueOf(host.getProtocol().getAuthorization())) { case oauth: if("x-dracoon-action:oauth".equals(CYBERDUCK_REDIRECT_URI)) { if(matcher.matches()) { if(new Version(matcher.group(1)).compareTo(new Version("4.15.0")) >= 0) { authorizationService.withRedirectUri(CYBERDUCK_REDIRECT_URI); } } else { log.warn(String.format("Failure to parse software version %s", version)); } } authorizationService.setTokens(authorizationService.authorize(host, controller, cancel)); break; case radius: final Credentials additional = controller.prompt(host, LocaleFactory.localizedString("Provide additional login credentials", "Credentials"), LocaleFactory.localizedString("Multi-Factor Authentication", "S3"), new LoginOptions() .icon(host.getProtocol().disk()) .user(false) .keychain(false) ); retryHandler.setTokens(login, password, this.login(controller, new LoginRequest() .authType(LoginRequest.AuthTypeEnum.fromValue(host.getProtocol().getAuthorization())) .login(login) .password(additional.getPassword()) )); break; default: retryHandler.setTokens(login, password, this.login(controller, new LoginRequest() .authType(LoginRequest.AuthTypeEnum.fromValue(host.getProtocol().getAuthorization())) .login(login) .password(password) )); break; } try { configuration.addAll(new ConfigApi(client).requestSystemSettings(StringUtils.EMPTY).getItems()); } catch(ApiException e) { log.warn(String.format("Ignore failure reading configuration. %s", new SDSExceptionMappingService().map(e))); } try { final UserAccount account = new UserApi(client).requestUserInfo(StringUtils.EMPTY, false, null); if(log.isDebugEnabled()) { log.debug(String.format("Authenticated as user %s", account)); } switch(SDSProtocol.Authorization.valueOf(host.getProtocol().getAuthorization())) { case oauth: credentials.setUsername(account.getLogin()); } userAccount.set(new UserAccountWrapper(account)); keyPair.set(new UserApi(client).requestUserKeyPair(StringUtils.EMPTY)); final UserPrivateKey privateKey = new UserPrivateKey(); final UserKeyPairContainer keyPairContainer = keyPair.get(); privateKey.setPrivateKey(keyPairContainer.getPrivateKeyContainer().getPrivateKey()); privateKey.setVersion(keyPairContainer.getPrivateKeyContainer().getVersion()); final UserKeyPair userKeyPair = new UserKeyPair(); userKeyPair.setUserPrivateKey(privateKey); if(log.isDebugEnabled()) { log.debug(String.format("Attempt to unlock private key %s", privateKey)); } try { new TripleCryptKeyPair().unlock(controller, host, userKeyPair); } catch(LoginCanceledException e) { log.warn("Ignore cancel unlocking triple crypt private key pair"); } } catch(CryptoException e) { throw new TripleCryptExceptionMappingService().map(e); } catch(ApiException e) { log.warn(String.format("Ignore failure reading user key pair. %s", new SDSExceptionMappingService().map(e))); } try { softwareVersion.set(new PublicApi(client).requestSoftwareVersion(null)); } catch(ApiException e) { log.warn(String.format("Ignore failure reading version. %s", new SDSExceptionMappingService().map(e))); } } SDSSession(final Host host, final X509TrustManager trust, final X509KeyManager key); @Override void login(final Proxy proxy, final LoginCallback controller, final CancelCallback cancel); UserAccountWrapper userAccount(); UserKeyPairContainer keyPair(); SoftwareVersionData softwareVersion(); List<KeyValueEntry> configuration(); @Override @SuppressWarnings("unchecked") T _getFeature(final Class<T> type); }
SDSSession extends HttpSession<SDSApiClient> { @Override public void login(final Proxy proxy, final LoginCallback controller, final CancelCallback cancel) throws BackgroundException { final SoftwareVersionData version = this.softwareVersion(); final Matcher matcher = Pattern.compile(VERSION_REGEX).matcher(version.getRestApiVersion()); if(matcher.matches()) { if(new Version(matcher.group(1)).compareTo(new Version(PreferencesFactory.get().getProperty("sds.version.lts"))) < 0) { throw new InteroperabilityException( LocaleFactory.localizedString("DRACOON environment needs to be updated", "SDS"), LocaleFactory.localizedString("Your DRACOON environment is outdated and no longer works with this application. Please contact your administrator.", "SDS")); } } final Credentials credentials = host.getCredentials(); final String login = credentials.getUsername(); final String password = credentials.getPassword(); switch(SDSProtocol.Authorization.valueOf(host.getProtocol().getAuthorization())) { case oauth: if("x-dracoon-action:oauth".equals(CYBERDUCK_REDIRECT_URI)) { if(matcher.matches()) { if(new Version(matcher.group(1)).compareTo(new Version("4.15.0")) >= 0) { authorizationService.withRedirectUri(CYBERDUCK_REDIRECT_URI); } } else { log.warn(String.format("Failure to parse software version %s", version)); } } authorizationService.setTokens(authorizationService.authorize(host, controller, cancel)); break; case radius: final Credentials additional = controller.prompt(host, LocaleFactory.localizedString("Provide additional login credentials", "Credentials"), LocaleFactory.localizedString("Multi-Factor Authentication", "S3"), new LoginOptions() .icon(host.getProtocol().disk()) .user(false) .keychain(false) ); retryHandler.setTokens(login, password, this.login(controller, new LoginRequest() .authType(LoginRequest.AuthTypeEnum.fromValue(host.getProtocol().getAuthorization())) .login(login) .password(additional.getPassword()) )); break; default: retryHandler.setTokens(login, password, this.login(controller, new LoginRequest() .authType(LoginRequest.AuthTypeEnum.fromValue(host.getProtocol().getAuthorization())) .login(login) .password(password) )); break; } try { configuration.addAll(new ConfigApi(client).requestSystemSettings(StringUtils.EMPTY).getItems()); } catch(ApiException e) { log.warn(String.format("Ignore failure reading configuration. %s", new SDSExceptionMappingService().map(e))); } try { final UserAccount account = new UserApi(client).requestUserInfo(StringUtils.EMPTY, false, null); if(log.isDebugEnabled()) { log.debug(String.format("Authenticated as user %s", account)); } switch(SDSProtocol.Authorization.valueOf(host.getProtocol().getAuthorization())) { case oauth: credentials.setUsername(account.getLogin()); } userAccount.set(new UserAccountWrapper(account)); keyPair.set(new UserApi(client).requestUserKeyPair(StringUtils.EMPTY)); final UserPrivateKey privateKey = new UserPrivateKey(); final UserKeyPairContainer keyPairContainer = keyPair.get(); privateKey.setPrivateKey(keyPairContainer.getPrivateKeyContainer().getPrivateKey()); privateKey.setVersion(keyPairContainer.getPrivateKeyContainer().getVersion()); final UserKeyPair userKeyPair = new UserKeyPair(); userKeyPair.setUserPrivateKey(privateKey); if(log.isDebugEnabled()) { log.debug(String.format("Attempt to unlock private key %s", privateKey)); } try { new TripleCryptKeyPair().unlock(controller, host, userKeyPair); } catch(LoginCanceledException e) { log.warn("Ignore cancel unlocking triple crypt private key pair"); } } catch(CryptoException e) { throw new TripleCryptExceptionMappingService().map(e); } catch(ApiException e) { log.warn(String.format("Ignore failure reading user key pair. %s", new SDSExceptionMappingService().map(e))); } try { softwareVersion.set(new PublicApi(client).requestSoftwareVersion(null)); } catch(ApiException e) { log.warn(String.format("Ignore failure reading version. %s", new SDSExceptionMappingService().map(e))); } } SDSSession(final Host host, final X509TrustManager trust, final X509KeyManager key); @Override void login(final Proxy proxy, final LoginCallback controller, final CancelCallback cancel); UserAccountWrapper userAccount(); UserKeyPairContainer keyPair(); SoftwareVersionData softwareVersion(); List<KeyValueEntry> configuration(); @Override @SuppressWarnings("unchecked") T _getFeature(final Class<T> type); static final String SDS_AUTH_TOKEN_HEADER; static final int DEFAULT_CHUNKSIZE; static final String VERSION_REGEX; }