From 9aa25a2849caec157bd147ceec4b82f5f134a7c6 Mon Sep 17 00:00:00 2001 From: JoyChou Date: Tue, 5 Sep 2017 18:07:51 +0800 Subject: [PATCH] add checkUrl --- .idea/compiler.xml | 16 + .idea/inspectionProfiles/Project_Default.xml | 10 + .idea/kotlinc.xml | 7 + .../Maven__com_google_guava_guava_21_0.xml | 13 + .idea/misc.xml | 29 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .idea/workspace.xml | 758 ++++++++++++++++++ pom.xml | 18 + src/main/java/main.java | 43 + src/main/java/test.java | 11 + target/classes/main.class | Bin 0 -> 1459 bytes target/classes/test.class | Bin 0 -> 829 bytes trident.iml | 16 + 14 files changed, 935 insertions(+) create mode 100644 .idea/compiler.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/kotlinc.xml create mode 100644 .idea/libraries/Maven__com_google_guava_guava_21_0.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 pom.xml create mode 100644 src/main/java/main.java create mode 100644 src/main/java/test.java create mode 100644 target/classes/main.class create mode 100644 target/classes/test.class create mode 100644 trident.iml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..870a325 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..146ab09 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 0000000..1c24f9a --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_google_guava_guava_21_0.xml b/.idea/libraries/Maven__com_google_guava_guava_21_0.xml new file mode 100644 index 0000000..a923456 --- /dev/null +++ b/.idea/libraries/Maven__com_google_guava_guava_21_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..5faeabe --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + 1.8 + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..9f4bb74 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..fc96c37 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,758 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + Spelling + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1504604417100 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..e15928a --- /dev/null +++ b/pom.xml @@ -0,0 +1,18 @@ + + + 4.0.0 + + trident + trident + 1.0.0 + + + + com.google.guava + guava + 21.0 + + + \ No newline at end of file diff --git a/src/main/java/main.java b/src/main/java/main.java new file mode 100644 index 0000000..ea54c97 --- /dev/null +++ b/src/main/java/main.java @@ -0,0 +1,43 @@ +/** + * Created by Viarus on 17/9/5. + */ + +import java.net.URL; +import com.google.common.net.InternetDomainName; + +public class main { + + /* + * 检测传入的URL是否在白名单的域名里 + * url:需要检测的URL + * urlWList: 一级域名的域名列表,比如String[] urlWList = {"joychou.com", "joychou.me"}; + * 合法URL返回true,非法URL返回false + */ + public static Boolean checkUrlWlist(String url, String[] urlWList) { + try { + URL u = new URL(url); + // 只允许http和https的协议 + if (!u.getProtocol().startsWith("http") && !u.getProtocol().startsWith("https")) { + return false; + } + // 获取域名,并转为小写 + String host = u.getHost().toLowerCase(); + // 获取一级域名 + String rootDomain = InternetDomainName.from(host).topPrivateDomain().toString(); + + for (String whiteUrl: urlWList){ + if (rootDomain.equals(whiteUrl)) { + return true; + } + } + return false; + + } catch (Exception e) { + return false; + } + } + + public static void main(String[] args) throws Exception { + + } +} diff --git a/src/main/java/test.java b/src/main/java/test.java new file mode 100644 index 0000000..87e5660 --- /dev/null +++ b/src/main/java/test.java @@ -0,0 +1,11 @@ +/** + * Created by Viarus on 17/9/5. + */ +public class test { + public static void main(String[] args) throws Exception { + main checkUrl = new main(); + String[] urlWList = {"joychou.com", "joychou.me"}; + Boolean ret = checkUrl.checkUrlWlist("http://test.joychou.me", urlWList); + System.out.println(ret); + } +} diff --git a/target/classes/main.class b/target/classes/main.class new file mode 100644 index 0000000000000000000000000000000000000000..090f851f0f1ecd745308a7927214bf8e50901863 GIT binary patch literal 1459 zcmb7E+j0{}5Itk9v@3bR#Y)_q^MXh&wHg%}|K?XhA_JbP`r$o44$OKBv~)dalEZ8GK{P9{r&^cQCwJp;Eex7k zpj`AG`2WIkU7ulftDmQ!FSLIh?cFynm zPF7u+z`0l{eN~yXc#!GmyBMxLugVP_C=(>rGW-t5H7`kdaF_f@+hH0m?y{T6=EpS( zk^4ez7OSciSLOA<$d@$)Q>F?R0~i!=lZv(yH`pZ?moaB5(0aqh6&LfkDv&nIrj2VZ zuH%M_1J{p#UhqmEE{+Qw*>~brTUVMK>s$nTzM?3)F{78b4)G0HK|u( zrBzi?nxSHMceZ-?6<-Hqy-n@My15qU`hSqG3+&s@W2@5w_NE`UY0q^{U&8CR#l@^Q>qrq63vE+N=DL~k(M!y&J9@d8$4<~id944;%-%Y z-%7(9)34RWN*rwZT7JG@lho*cFgRL$)+{5Rw)~Kn<*R0NIy5`Jj#2dUQ#Vfv{0uP2 zafquDXTdpr;xC9lY4jk^F_VA}hH1N<1NaX6xyqt|14QU74w5WOtoa^2zmp)fIN63Z zkZvRM5<`h?C$^J%3+D}iY#X_ylW)=6hTF!TvNcgo7t$YQGN~CmZ|5_waJZ1p+tX#I zU=^G;_Wl9KGQKZt@%o>S3C&_MGBofb8tB6q{A8{mOy*7r(@Y$!I?HNDS??H&nPLfL zroW2s@c<*J(5~Y!y+#q?Xj1M1Z0`5*#0VUEKg2;CGQUS$;>i)lE#owf(6Z>0rsq-a vQUv@!%sfpTV`ltR8S^;zjLs8$jm|qXE_P|mYe+|6oUg^>eSA;Q?!m;r_XSLI literal 0 HcmV?d00001 diff --git a/target/classes/test.class b/target/classes/test.class new file mode 100644 index 0000000000000000000000000000000000000000..98187cf2fb9e0712649695528d7a20c8ba389376 GIT binary patch literal 829 zcmZvaU2oGc6oy|nX_IEz2iZElM+a=Q+h`acHyh#t1Xmp(6*g5|rNL@llDJA;#C{fB zFa&}hz>h*4Cmqeua$)nx29;AJ$Up^w(spJI(nuV&_H5C0Hj}<4!hMW+!mX{0ZzorLJ#N|Ou_m+D)D>GOl zT@=yl)rxNNM(FXdjyd|Z^j8A4fCU;CDe`G%G?%wdz&>Z`B^oQ4XyO8`-Mj!EmMN-Y z1vP@`%_Edy(7gErrS1ug_V$rymVct$HM~lvYkF4a8|;HGsP24)GoyPjX;%d{EUXc6 m15S2QJ*Qz67b$O3?h-E3>1(vUf~$1uHPTH|u4k%l=Eh$TMY$^g literal 0 HcmV?d00001 diff --git a/trident.iml b/trident.iml new file mode 100644 index 0000000..e24b78b --- /dev/null +++ b/trident.iml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file