diff options
Diffstat (limited to 'src/main/java/kr')
5 files changed, 15 insertions, 28 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/DungeonsGuideMain.java b/src/main/java/kr/syeyoung/dungeonsguide/DungeonsGuideMain.java index 2ffa1cc7..c1f3966f 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/DungeonsGuideMain.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/DungeonsGuideMain.java @@ -46,9 +46,9 @@ public class DungeonsGuideMain try { token = authenticator.authenticate(); if (token != null) { - URL.setURLStreamHandlerFactory(new DGURLStreamHandlerFactory(authenticator)); + URL.setURLStreamHandlerFactory(new DGURLStreamHandlerFactory()); LaunchClassLoader launchClassLoader = (LaunchClassLoader) DungeonsGuideMain.class.getClassLoader(); - launchClassLoader.addURL(new URL("dungeonsguide:///")); + launchClassLoader.addURL(new URL("dungeonsguide://"+token+"@/")); try { dungeonsGuideInterface = new DungeonsGuide(); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/customurl/DGURLConnection.java b/src/main/java/kr/syeyoung/dungeonsguide/customurl/DGURLConnection.java index 5335f7b3..56eab8c8 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/customurl/DGURLConnection.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/customurl/DGURLConnection.java @@ -1,6 +1,7 @@ package kr.syeyoung.dungeonsguide.customurl; import kr.syeyoung.dungeonsguide.Authenticator; +import kr.syeyoung.dungeonsguide.DungeonsGuideMain; import lombok.SneakyThrows; import javax.crypto.Cipher; @@ -17,30 +18,24 @@ import java.net.URLConnection; import java.net.URLEncoder; public class DGURLConnection extends URLConnection { - private Authenticator authenticator; - protected DGURLConnection(URL url, Authenticator authenticator) { + private static final String DOMAIN = "http://localhost:8080/"; + + protected DGURLConnection(URL url) { super(url); - this.authenticator = authenticator; - try { - connect(); - } catch (IOException e) { - e.printStackTrace(); - } } - private static final String DOMAIN = "http://localhost:8080/"; - @SneakyThrows @Override public void connect() throws IOException { + if (!(url.getPath().contains("kr/syeyoung") ||url.getPath().contains("roomdata"))) return; this.connected = true; - System.out.println("loading "+url.getPath()); + System.out.println("loading "+url.getPath().substring(1)); - HttpURLConnection huc = (HttpURLConnection) new URL(DOMAIN+"resource/resource?class="+ URLEncoder.encode(url.getPath())).openConnection(); + HttpURLConnection huc = (HttpURLConnection) new URL(DOMAIN+"resource/resource?class="+ URLEncoder.encode(url.getPath().substring(1))).openConnection(); huc.setRequestProperty("User-Agent", "DungeonsGuide/1.0"); huc.setRequestProperty("Content-Type", "application/json"); - huc.setRequestProperty("Authorization", authenticator.getToken()); + huc.setRequestProperty("Authorization", url.getUserInfo()); huc.setDoInput(true); huc.setDoOutput(true); @@ -57,7 +52,7 @@ public class DGURLConnection extends URLConnection { Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); byte[] byteEncrypted = pubKey; - cipher.init(Cipher.DECRYPT_MODE, authenticator.getKeyPair().getPrivate()); + cipher.init(Cipher.DECRYPT_MODE, DungeonsGuideMain.getDungeonsGuideMain().getAuthenticator().getKeyPair().getPrivate()); byte[] bytePlain = cipher.doFinal(byteEncrypted); cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/customurl/DGURLStreamHandler.java b/src/main/java/kr/syeyoung/dungeonsguide/customurl/DGURLStreamHandler.java index 0a8f53a9..727e6e78 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/customurl/DGURLStreamHandler.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/customurl/DGURLStreamHandler.java @@ -8,12 +8,8 @@ import java.net.URLConnection; import java.net.URLStreamHandler; public class DGURLStreamHandler extends URLStreamHandler { - private Authenticator authenticator; - public DGURLStreamHandler(Authenticator authenticator) { - this.authenticator = authenticator; - } @Override protected URLConnection openConnection(URL url) throws IOException { - return new DGURLConnection(url, authenticator); + return new DGURLConnection(url); } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/customurl/DGURLStreamHandlerFactory.java b/src/main/java/kr/syeyoung/dungeonsguide/customurl/DGURLStreamHandlerFactory.java index 15defa5e..a27bda87 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/customurl/DGURLStreamHandlerFactory.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/customurl/DGURLStreamHandlerFactory.java @@ -6,14 +6,10 @@ import java.net.URLStreamHandler; import java.net.URLStreamHandlerFactory; public class DGURLStreamHandlerFactory implements URLStreamHandlerFactory { - private Authenticator authenticator; - public DGURLStreamHandlerFactory(Authenticator authenticator) { - this.authenticator = authenticator; - } @Override public URLStreamHandler createURLStreamHandler(String s) { if ("dungeonsguide".equals(s)) { - return new DGURLStreamHandler(authenticator); + return new DGURLStreamHandler(); } return null; diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoomInfoRegistry.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoomInfoRegistry.java index 04dac612..83b9d395 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoomInfoRegistry.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoomInfoRegistry.java @@ -69,12 +69,12 @@ public class DungeonRoomInfoRegistry { registered.clear(); shapeMap.clear(); uuidMap.clear(); - URL url = new URL("dungeonsguide:///roomdata/data.txt"); + URL url = new URL("dungeonsguide://"+DungeonsGuideMain.getDungeonsGuideMain().getAuthenticator().getToken()+"@/roomdata/data.txt"); List<String> lines = IOUtils.readLines(url.openConnection().getInputStream()); for (String name : lines) { if (name.endsWith(".roomdata")) continue; try { - InputStream fis = new URL("dungeonsguide:///"+name).openStream(); + InputStream fis = new URL("dungeonsguide://"+DungeonsGuideMain.getDungeonsGuideMain().getAuthenticator().getToken()+"@/"+name).openStream(); ObjectInputStream ois = new ObjectInputStream(fis); DungeonRoomInfo dri = (DungeonRoomInfo) ois.readObject(); ois.close(); |