|
@@ -10,14 +10,29 @@ import java.io.IOException;
|
|
|
import java.net.URI;
|
|
import java.net.URI;
|
|
|
import java.net.URISyntaxException;
|
|
import java.net.URISyntaxException;
|
|
|
import java.nio.charset.Charset;
|
|
import java.nio.charset.Charset;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.Optional;
|
|
|
|
|
+
|
|
|
|
|
+import net.ranides.assira.collection.maps.GenericHashMap;
|
|
|
|
|
+import net.ranides.assira.collection.maps.GenericMap;
|
|
|
|
|
+import net.ranides.assira.collection.maps.HashMap;
|
|
|
|
|
+import net.ranides.assira.collection.query.CQuery;
|
|
|
|
|
+import net.ranides.assira.collection.query.CQueryBuilder;
|
|
|
|
|
+import net.ranides.assira.credentials.UserProperty;
|
|
|
|
|
+import net.ranides.assira.credentials.UserStore;
|
|
|
import net.ranides.assira.io.uri.URIHandle;
|
|
import net.ranides.assira.io.uri.URIHandle;
|
|
|
import net.ranides.assira.io.uri.URIResolver;
|
|
import net.ranides.assira.io.uri.URIResolver;
|
|
|
|
|
+import net.ranides.assira.io.uri.URIUtils;
|
|
|
|
|
+import net.ranides.assira.reflection.util.ReflectUtils;
|
|
|
import net.ranides.assira.text.IOStrings;
|
|
import net.ranides.assira.text.IOStrings;
|
|
|
import static net.ranides.assira.junit.NewAssert.*;
|
|
import static net.ranides.assira.junit.NewAssert.*;
|
|
|
import net.ranides.assira.text.Charsets;
|
|
import net.ranides.assira.text.Charsets;
|
|
|
|
|
|
|
|
|
|
+import net.ranides.assira.trace.ExceptionUtils;
|
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
+import javax.naming.spi.Resolver;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
*
|
|
*
|
|
|
* @author Ranides Atterwim <ranides@gmail.com>
|
|
* @author Ranides Atterwim <ranides@gmail.com>
|
|
@@ -28,6 +43,48 @@ public class CFTPHandlerTest {
|
|
|
|
|
|
|
|
private static final String TEXT_2 = "infov1";
|
|
private static final String TEXT_2 = "infov1";
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void testScan() throws URISyntaxException, IOException {
|
|
|
|
|
+ // @todo (assira#1) zjebane to jest
|
|
|
|
|
+ // FTPHandler jest konstruowany bez-argumentowo i wstawiany do URIResolver.DEFAULT
|
|
|
|
|
+ // w efekcie FTPHandler ma parent-resolver ustawiony na DEFAULT
|
|
|
|
|
+ // i ten handler będzie używany we wszystkich resolverach
|
|
|
|
|
+ // więc we wszystkich "user defined" resolverach FTPHandler nie będzie miał rodzica ustawionego na ten "user-defined"
|
|
|
|
|
+ // więc w efekcie zawsze będzie FTPHandler czytał np hasła/loginy z DEFAULT bazy userów
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ TStore users = new TStore();
|
|
|
|
|
+ System.out.println("!!!!! " + users);
|
|
|
|
|
+ URIResolver.DEFAULT.users(users);
|
|
|
|
|
+ URIResolver re = new URIResolver().users(users);
|
|
|
|
|
+
|
|
|
|
|
+ users.add("fu", "f12357_assira_ftp_test", "TTYKYbg25ijGxlnYBGfN");
|
|
|
|
|
+
|
|
|
|
|
+ URI u1 = new URI("ftp://f12357_assira_ftp_test:TTYKYbg25ijGxlnYBGfN@ftp.ranides.net/dir");
|
|
|
|
|
+ URI u2 = new URI("ftp://fu@ftp.ranides.net/dir");
|
|
|
|
|
+ URI u3 = new URI("ftp://fu@ftp.ranides.net/");
|
|
|
|
|
+ try(URIHandle handle1 = re.resolve(u1)) {
|
|
|
|
|
+ System.out.println(handle1.scan().map(e -> asName(e)).list());
|
|
|
|
|
+ }
|
|
|
|
|
+ try(URIHandle handle1 = re.resolve(u2)) {
|
|
|
|
|
+ System.out.println(handle1.scan().map(e -> asName(e)).list());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try(URIHandle handle1 = re.resolve(u3)) {
|
|
|
|
|
+ System.out.println(handle1.scan().map(e -> asName(e)).list());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static String asName(URIHandle handle) {
|
|
|
|
|
+ try {
|
|
|
|
|
+// return handle.path().toString();
|
|
|
|
|
+ return handle.uri().toString();
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ throw ExceptionUtils.rethrow(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Test
|
|
@Test
|
|
|
public void testUser() throws URISyntaxException, IOException {
|
|
public void testUser() throws URISyntaxException, IOException {
|
|
|
URIResolver resolver = new URIResolver().register(CFTPHandler.class);
|
|
URIResolver resolver = new URIResolver().register(CFTPHandler.class);
|
|
@@ -82,5 +139,31 @@ public class CFTPHandlerTest {
|
|
|
private static String cast(String text, Charset source, Charset target) {
|
|
private static String cast(String text, Charset source, Charset target) {
|
|
|
return new String(text.getBytes(source), target);
|
|
return new String(text.getBytes(source), target);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private static final class TStore implements UserStore {
|
|
|
|
|
+
|
|
|
|
|
+ private Map<String, GenericMap<String>> users = new HashMap<>();
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public CQuery<GenericMap<String>> match(URI uri) {
|
|
|
|
|
+ System.out.println("???");
|
|
|
|
|
+ Optional<String> key = URIUtils.getLogin(uri);
|
|
|
|
|
+ return key.isPresent() ? find(key.get()) : CQueryBuilder.empty();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public CQuery<GenericMap<String>> find(String user) {
|
|
|
|
|
+ GenericMap<String> map = users.get(user);
|
|
|
|
|
+ return map!=null ? CQueryBuilder.of(map) : CQueryBuilder.empty();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void add(String id, String login, String pass) {
|
|
|
|
|
+ GenericMap<String> map = new GenericHashMap<>();
|
|
|
|
|
+ map.put(UserProperty.LOGIN, login);
|
|
|
|
|
+ map.put(UserProperty.PASSWORD, pass);
|
|
|
|
|
+ users.put(id, map);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|