From 00084603333a1bbca3aabc3f7ed5f4d4fc47420c Mon Sep 17 00:00:00 2001 From: kleislicat <79645287+kleislicat@users.noreply.github.com> Date: Mon, 26 Aug 2024 13:39:37 +0100 Subject: [PATCH 1/4] Initial cleanup. Using .gitignore from gist.github.com/fedir/ --- .../target/classes/application.properties | 6 ------ .../com/example/demo/SareetaApplication.class | Bin 995 -> 0 bytes .../demo/controllers/CartController.class | Bin 4918 -> 0 bytes .../demo/controllers/ItemController.class | Bin 2756 -> 0 bytes .../demo/controllers/OrderController.class | Bin 3018 -> 0 bytes .../demo/controllers/UserController.class | Bin 3643 -> 0 bytes .../example/demo/model/persistence/Cart.class | Bin 2977 -> 0 bytes .../example/demo/model/persistence/Item.class | Bin 2322 -> 0 bytes .../example/demo/model/persistence/User.class | Bin 1771 -> 0 bytes .../demo/model/persistence/UserOrder.class | Bin 3034 -> 0 bytes .../repositories/CartRepository.class | Bin 518 -> 0 bytes .../repositories/ItemRepository.class | Bin 560 -> 0 bytes .../repositories/OrderRepository.class | Bin 618 -> 0 bytes .../repositories/UserRepository.class | Bin 503 -> 0 bytes .../demo/model/requests/CreateUserRequest.class | Bin 722 -> 0 bytes .../demo/model/requests/ModifyCartRequest.class | Bin 1184 -> 0 bytes starter_code/target/classes/data.sql | 2 -- .../example/demo/SareetaApplicationTests.class | Bin 631 -> 0 bytes 18 files changed, 8 deletions(-) delete mode 100644 starter_code/target/classes/application.properties delete mode 100644 starter_code/target/classes/com/example/demo/SareetaApplication.class delete mode 100644 starter_code/target/classes/com/example/demo/controllers/CartController.class delete mode 100644 starter_code/target/classes/com/example/demo/controllers/ItemController.class delete mode 100644 starter_code/target/classes/com/example/demo/controllers/OrderController.class delete mode 100644 starter_code/target/classes/com/example/demo/controllers/UserController.class delete mode 100644 starter_code/target/classes/com/example/demo/model/persistence/Cart.class delete mode 100644 starter_code/target/classes/com/example/demo/model/persistence/Item.class delete mode 100644 starter_code/target/classes/com/example/demo/model/persistence/User.class delete mode 100644 starter_code/target/classes/com/example/demo/model/persistence/UserOrder.class delete mode 100644 starter_code/target/classes/com/example/demo/model/persistence/repositories/CartRepository.class delete mode 100644 starter_code/target/classes/com/example/demo/model/persistence/repositories/ItemRepository.class delete mode 100644 starter_code/target/classes/com/example/demo/model/persistence/repositories/OrderRepository.class delete mode 100644 starter_code/target/classes/com/example/demo/model/persistence/repositories/UserRepository.class delete mode 100644 starter_code/target/classes/com/example/demo/model/requests/CreateUserRequest.class delete mode 100644 starter_code/target/classes/com/example/demo/model/requests/ModifyCartRequest.class delete mode 100644 starter_code/target/classes/data.sql delete mode 100644 starter_code/target/test-classes/com/example/demo/SareetaApplicationTests.class diff --git a/starter_code/target/classes/application.properties b/starter_code/target/classes/application.properties deleted file mode 100644 index ed303a7d4..000000000 --- a/starter_code/target/classes/application.properties +++ /dev/null @@ -1,6 +0,0 @@ -spring.datasource.driver-class-name=org.h2.Driver -spring.datasource.url=jdbc:h2:mem:bootapp;DB_CLOSE_DELAY=-1 -spring.datasource.username=sa -spring.datasource.password= -spring.jpa.hibernate.ddl-auto=update -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect \ No newline at end of file diff --git a/starter_code/target/classes/com/example/demo/SareetaApplication.class b/starter_code/target/classes/com/example/demo/SareetaApplication.class deleted file mode 100644 index 388a4f339063ea1af126a63fc5041daef0059d39..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 995 zcma)5%We}f6g|$HA&`NY?Psw9 zvET#vD8%)ow2_EJM;d$X!}lDYd*|2hA3p&+!*+lQ?$vQWzymz2W0RrwQfcLO8OoiV z5ksYKCX%5wP+Gprld-fP#W*HUdtf3FkAzj;K6h5!vC0^p4kD9qc`A}LmV6=;!-v93 z>BL@|#wrp{8Qr7eiBOtht#de-i4(zNp{IQ4tkTn70WR#6%B?O5GpxLo?$}H|2rCll zq@~1QXmT6LedP(R{|gy<6o!q1TsxJ>k;)Wt-_zQ-f)bV39~e93S?W0)`O066{mduA z2|h~&w=y-Ea>k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es/com/example/demo/controllers/ItemController.class b/starter_code/target/classes/com/example/demo/controllers/ItemController.class deleted file mode 100644 index 52ac532e6aed39ad1f16ac7462a25d8f053b5955..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2756 zcmbtWT~ixX7=BJjSV)$%Qbo|BEue;vcB@vbh0;QV77ZUlMQy#=BnQ~C*^Rp=MeO)H z9DjkgI^&GR3opI!H#v^a*$p8fsRJ^Z>^bk*_kG^)_v~N){Qd`koA^2n6Cd>=gWDO* zU^b0+aYygw^zN?S-OJzx<~6yHK^`9)STwLCkad)-Y{;q~I?4|Y1nw0|e#MgC+Lfv+ zt+K56R>dz%*Q&}ObV4P)lC**&0Y`?`atp$Yz|cm`Q%*&0IiXW@<-F(l%2tl=g#xz< zez0SO)xhy~wgbB&_x)hcDoWc6t!=xcZLsWyfHhxJ{=O5)GGV)C9nVp70$sWBErDd7 zW(iys+|YeR-r`X?9ZxH_O<@20ck*{T-Mpxx6;&K927Pi?EF9M>u^+OzHU zwr4{dI5Wqez|D>(?#rT8bi8tNWbaG0Vppq71I03RHx~|;%K|gG*b3M7cC3O=j$c9iVzdRe|G%QM1V$kB)OKskM9O;Rl)o1kX|2$PO)aH5ed<`Q z+iLfy-Wbj7QPC_MtkPG3JI#J>DqZ_$3Te`dVEUVaT1TNvx`7$Xdc+%*Lpugq8{wdO z)C@D{s4{`RO=Xw%SUgc{8MtrYfxvg?@$tN6Z(2G+)-(NNdefVJEhxz)M~{O`x;>7Y z`nqng7tNtgjl$Me$KniY=MmOf^qU%`kNd3Gva61zGiKr?^qc5I*1)ofPw=UU0#;0{ zV$H-lJ~Od_O%o6Cxrr@&W#EyC#~9)qYMak5o?tACXr4r!yjFZ7ON!;$I${Lg=`@l% zj5UF|Hr?&h=s)fT0b`qEXx?=>r8yK^4Pj^#{@#ghiH$x}xAbTo@g&PN7i9zLSnXO> zUrV+dsooa2Tj!6usPXbF(=Qz>kNbYCS$(7LkJal5Pt}GKE>^0FmoIO&N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bM{~->{*#f8R#ke|P~0`PsdbpWzAqv9&R_+sCv04GaSb%;f(>_B94qw8k$m@~@H9p!y(~mmC2%)C_7dB5aQPJs>3t)bnBsjfXeW;(iP=V4 z_K=vvj3CDtP7%M3a3uECjBp(1Fu@3ul#3(W!)NDlflM?aJJ*bCvKiS$s>JEI)Qapf g1^Y0?YXZ}e=nz+*bAP2Neif4YH21UQt~{9f7X}|GJOBUy diff --git a/starter_code/target/classes/com/example/demo/model/persistence/Cart.class b/starter_code/target/classes/com/example/demo/model/persistence/Cart.class deleted file mode 100644 index 5f60d7edd4cf8cd1d6adfc5c733169e068892fd2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2977 zcmb7`Yf}?f7{~t`a)A&5siJtHYA=SMuC=wT4N$Jy&;%j`6fc!SatuqeyUb?ez!&M~ zXlGEzcBXHg>4)m{e|DDy;!?v4&YsJ2`8}6&!ax81`8R-XP)%Y0g&y={Q4LFKD5~LM z0?SFnQRu}AN(rnc(Sx-l9^tW?t*h-PYW6gNX9+yl5HTtm2J+kDmC$R#s_J>$s%A9| zFE=dLFy)$2H#Tc>+Olj{xQ1=jH4J&;yZVlF>PFp_R$1z~3YD&f96XSgbc8D_YogYW z6zZvh@i1n%(queA_zl;n>3Igkqn;I`Y6-XDNDWy(JI&*9k3#MWbEhWt ziZpHAv@5c9G#@mbous9a5Q2iR_DZ%IDG+VcrK4fA6RWEfrOKrcn@g4~*&KM>ZHk>8 zS(#ymqh;Z^jMQcIY6q3mP2q0oGe&hzmJL(Xs1hGHEW@4D(3KutquMM3($JqbEVFb&>;esgdAlrXYr-+qI@pZ5TL#nEQ3SK(QHWLPmVBo3=}|wyA5wMKn^ME+a3MuI zP>}AHT`3Ajn3AnQmIUpqWN8?qdDS%^saKHM1U>qCH_{!eDTWvw=6IC`5287InPRl6 z4nGNkXq_olm5ZF;iB0WhvoTi_2PT`FC+k3!#lZdnK+{rI0Sp~2Dz9Bo*vWvmDSi^i z%5p+fD$2En&eEx5J*24NX?0XOPf5e66_?LJLF@$ZNryM{mGs>wSL}vUmiGc9Q{DGL~%jdlw!y)&~v(BnSEjC*U*O5-)3w)Wv6GzL?+h)b-s_oRB6n|2(r zryiCBeo5g4HZ+{^PTM+OSrZ9trcj2i1S=^>Y^3lKY@X{Kbg>GI_o4NgFKuqiGPn9# zGzx_GoR!gV_HaY`vf0rm3@)8h94^AS;aEyDK=P<^3$``;5 z+~kVs@RW`!?<4YioAS+2<=gm*E|l^lzY%`pnX%W1v|KAzP%4Hyo`oS_DsZpR{J8E= zDyDIvn7-!!5bXi&qpO|iZYa}Td`ll6Fm<&v-6PWv$1wSY2$-&TOyA-A5Te9$SCPh=HH;~? zF0Xz38s^Bha15JjZVgk^@Y^fSb|2wRKzoq~zQbv5&R{m6{>{5Uz*L6R@6ng}3-R^0 zNW5kPb7$-wx+8eRY2-cndDyew^%hC?S4QoPy+Q9Aq=I(yQAd!VuL8$KUdtlAKI8>j z#%+`s=ISB*sb&jKVGi@;x=&4B=)ube*mK;_@Zbcvr#_0?7lQkkxa-7yO5A6}eNNmL c#N9YKZUjFOI)a?{!l+kdf$N_cMxHOpe=>i9I{*Lx diff --git a/starter_code/target/classes/com/example/demo/model/persistence/Item.class b/starter_code/target/classes/com/example/demo/model/persistence/Item.class deleted file mode 100644 index 5bce916c6eeaeafeeb4d27346ef5a6c46d063e44..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2322 zcma)+TXWk)6vzLPEh}- zbU<_vaS$K0{%UxvPCT8DJzW7=zhPqb){$?~4% z3I)R*1+GVd9hZ1EgLct(+O8)ly|&|6tUSlQLV?x_>^dVQwVSRLHO>3>_L8XEuH|sU zKtqJ}z;4MNDJaa^o*m6A$W50viLvN6xOuQw<8=2u60XE;T46Iu!i?2~S5~g@yAX)5?L-Prtw-$Giq%RJ z6~tF<%VDaq>5c|H+1e5HXr}a(^#0aPclXjoCh()C2zYi@MAY;fYgWKcQx`_lwnbFs zu^OH(b%ae1m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(eAP zM8+)6(Gu2SSQ>VQJze}t>`PGaHr7n=v6JrLcP@0G5h}pK08$a_`QT$pe69-~jtw58 zaS*BCMeGUenc~<9CC*B>1YZjfX*9^t9ePFO65fGX0@b ks-9^UOmi17g_9F8wFgo>2-b(e#I>QoEbKW@VniPO0+T{~wEzGB diff --git a/starter_code/target/classes/com/example/demo/model/persistence/UserOrder.class b/starter_code/target/classes/com/example/demo/model/persistence/UserOrder.class deleted file mode 100644 index 2c62312c18c279ce0606b4a9ed1fc8086c9b789b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3034 zcmb7GYj+b>6x}z^HjID;`v430K>ENAf}#?rLLbd_ndvs-RDgH{^$2U0ep<0gaO>^M*-_Hd?UlRGHeua zzr^Rg5+2~YBQWrN2|wWB5&Q_Nh)vn6$zEOFw7fl%w?+|L3K_euaJ;f@J+Vy3@)~Bv z_Znq|k-IG~v|YV!H|FiVrqZ!|6xgIz3cBoy(lZ4+2ZO5!IAa3=q*$vMMTY*+6$Jyy@UyoSm zrmSl-m)9Bx@NnUL(hflwr7Xa3fZyob;dTsR4N>+*q&Z) zxtltuiW7x_ieIywbt|xCo-F3VEt?lO)oUhJf_jvWd_#u|3}RqxJigq6($6>J%@bqY zdqVK|k`A~0`l=N$KI)L}`@~u-rH;XlS{UMuwwKQ0>q)3j2*vi>oH~}u!fEhuZdf-- zex{QUI`G$VES8H5O(di+$snZq{zvzT-io9gpSw8L^D%KKxva*L8E&WTWzk4R64Xc% zVmC;P9jyhLt!6&(-5Dzg6*hVzBiM4!(Y7^}t3@t)Iv06h1M)?W3Z*r_71Z>+EkZvk zd5errNmowqVRLNGQG**vDeUO-sk>53iZ$|K;1WJEZ~`X{jN*)e^Z3BP6ikJSJ>F_W zsR-M^b=)wpjmJee23&YW_y%_H6S+s`H8^zQeZW-_J8$7_)nL|eIg)Q_g&PF&NsT@_wfD!G_N=@I!e?9o*LtGyom`+-p56J*rZ=Eo)IA= z&=O~Dhb692HXJV#B?!f5e&QL_FVV3p91GFn5dWcoe?1}qKEYMa6h6gg91kD<6`7yA z4o{^X{v6lHMGjB%nc=fAG5H%Z`>us6h{)qgWMMEyCGLeA7wq-j&?|c;pK7fxxI60KU zDdMnRjkG&EGyeQ~{{Vm!*o$C0f}IF<1;h)f^7G}rV=Lh9FwJz0{7SW{7;~;Q);i}3 z4O=IjXO%Iwv&m7P$qTYR5wL&F{!!<*WT|E!m;?-)?%-rD3q`)MEZ{9I>6x%1Rp8A- z$(c`5Z3}e9N>wb{-4|`2Fegt~8bZrPJL$Du;+3J<3Z3$15t78EI2B9{>$BJRd6-EJ#0~!g4LL0zl K_f8=0`qnqN7p5!# diff --git a/starter_code/target/classes/com/example/demo/model/persistence/repositories/ItemRepository.class b/starter_code/target/classes/com/example/demo/model/persistence/repositories/ItemRepository.class deleted file mode 100644 index fcdea8cef975b516a97eb24b94d28539bdc13b64..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 560 zcmbVJJ5Iwu5SwK1otYBTmMyyE^2T~Yy;|B5;lAYjC` e!>1Qxz7$LtPZ>=Fc-(fmMlj>*UOw!#ll?#K39xkl diff --git a/starter_code/target/classes/com/example/demo/model/persistence/repositories/OrderRepository.class b/starter_code/target/classes/com/example/demo/model/persistence/repositories/OrderRepository.class deleted file mode 100644 index e47ebf196d9c7c428bb7de9fee9cf5f4ae021d7e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 618 zcmbV~%}&EG49A_Zt*m_Qz(c?VU*J>(5(f^bXo!gi2#r^=wMmtvz#f5D;;;wcp%88- zjfvCP!Akx~Z2xTM>-%#70Ov4_;2?s-2#y5A6K&MZ{K=COkesBMEs@@3SrvqeN{gjc zRA5EUYahsDgw5OJG@Z&qk#c%ZdbC9w&u-l~_uh<1#p<^Y|o5 zO@;I>D_as~R2i&HMkQKuUim;eC2S~S0f)B~o=tWy9n%Hg3z*a$`*f*tEko^C>0?9a z?x~0?z*xbu2)@fX@#9q!vOxIg5Y_E?nmMjc4Y~$Dh9szlms@R_auy#YrmB#~LlwXj#xip0P73WkGY@k-Ang zQD!L5ywhg*S0!En+PZ1eFwO)W48(k$%%$#)d} zz~{^4#+%7=^Z`*Jc?TE)tLq#06g^AV$KDpiXT}xUMHChCp|xVBdE{0ENa$$+Hlp@F D$90~H diff --git a/starter_code/target/classes/com/example/demo/model/requests/ModifyCartRequest.class b/starter_code/target/classes/com/example/demo/model/requests/ModifyCartRequest.class deleted file mode 100644 index f5e3fa9a3e65867a6720f56db77f168cdb4e9802..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1184 zcmb7?TW=CU6vxjl3zSRk#e!mOD{AXP6E{ZRG)+ts6A0DXD(?eK>EK@4-C0w46_y$kNkKDwoZ397Vl)#O1lyIc7d2g)CsopnGk! zHde#p8MGQl470B46vF$797uy8YT`6zm^GD{J@rDr&EE(mMR9JMr|Jpwv_h+SO4CxF za+J^0GTqYXnR=}Mk_PKc|A=?39&bx3T2Fx4C7~FY4~8o zxrQnWR)bAee~|V)YO{`0HARqa<5W%6eS-?H*qrX*{I_^O`Zs*kX|ubaXa~7BH|FbtuMJqwxwY-u)hGlNubwv`P0TOge6Ap#den;&Pp-w2*0w zwviPxC7`Zi+8I(}mT3!2+cz-9+K-rW5z`Jmm@th+9+2^6hN--esZ0+iOkW=j-XL6B;|>>I^&oeKC54@-{pXdc-fIv5XzIQK2s^R|WKCsFQ6_#K|-A z^}QFcXMfxz+wjQ%Gqi6_3NVX+B8EAFD<0nWG39=O3tvDs1zS_udGZx3c-tm%piOay LgcoBhVHx-YE%BXl From b6588e1ee6716dc0a790bd3584500a7afba7e4c0 Mon Sep 17 00:00:00 2001 From: kleislicat <79645287+kleislicat@users.noreply.github.com> Date: Mon, 26 Aug 2024 13:43:29 +0100 Subject: [PATCH 2/4] Initial cleanup. Using .gitignore from gist.github.com/fedir/ --- .gitignore | 209 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 207 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index f98b419fc..346fd8b65 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,207 @@ -.idea/ -/starter_code/target/ +# Got this from https://gist.github.com/fedir/cd58012d42c8c1edbb3fff611de6c2f6 + +/target/ +*/target/** +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + + +# Created by https://www.gitignore.io/api/git,java,maven,eclipse,windows + +### Eclipse ### + +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +.recommenders + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# PyDev specific (Python IDE for Eclipse) +*.pydevproject + +# CDT-specific (C/C++ Development Tooling) +.cproject + +# CDT- autotools +.autotools + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target + +# Tern plugin +.tern-project + +# TeXlipse plugin +.texlipse + +# STS (Spring Tool Suite) +.springBeans + +# Code Recommenders +.recommenders/ + +# Annotation Processing +.apt_generated/ + +# Scala IDE specific (Scala & Java development for Eclipse) +.cache-main +.scala_dependencies +.worksheet + +### Eclipse Patch ### +# Eclipse Core +.project + +# JDT-specific (Eclipse Java Development Tools) +.classpath + +# Annotation Processing +.apt_generated + +.sts4-cache/ + +### Git ### +# Created by git for backups. To disable backups in Git: +# $ git config --global mergetool.keepBackup false +*.orig + +# Created by git when using merge tools for conflicts +*.BACKUP.* +*.BASE.* +*.LOCAL.* +*.REMOTE.* +*_BACKUP_*.txt +*_BASE_*.txt +*_LOCAL_*.txt +*_REMOTE_*.txt + +### Java ### +# Compiled class file +*.class + +# Log file +*.log +/logs + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +### Maven ### +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +.mvn/wrapper/maven-wrapper.jar + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Some additional ignores (sort later) +*.DS_Store +*.sw? +.#* +*# +*~ +.classpath +.project +.settings +bin +build +target +dependency-reduced-pom.xml +*.sublime-* +/scratch +.gradle +README.html +*.iml +.idea +.exercism +/starter_code/target/classes/ +/starter_code/target/classes/com/example/demo/controllers/ From f2caba5fb180d65706849618d30316f7db2a3536 Mon Sep 17 00:00:00 2001 From: kleislicat <79645287+kleislicat@users.noreply.github.com> Date: Mon, 26 Aug 2024 17:07:31 +0100 Subject: [PATCH 3/4] splunk and logging added --- starter_code/pom.xml | 175 ++++++++++++++++++++++++++++--------------- 1 file changed, 113 insertions(+), 62 deletions(-) diff --git a/starter_code/pom.xml b/starter_code/pom.xml index 608bb212f..77db84f27 100644 --- a/starter_code/pom.xml +++ b/starter_code/pom.xml @@ -1,68 +1,119 @@ - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.1.5.RELEASE - - - com.example - auth-course - war - 0.0.1-SNAPSHOT - auth-course - Demo project for Spring Boot + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.4.5 + + + com.example + auth-course + 0.0.1-SNAPSHOT + auth-course + Demo project for Spring Boot - - 1.8 - 3.1.1 - + + 17 + 3.1.1 + - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-tomcat - + + + splunk-artifactory + Splunk Releases + https://splunk.jfrog.io/artifactory/libs-releases + + - - com.h2database - h2 - runtime - - - org.springframework.boot - spring-boot-starter-test - test - - - - org.codehaus.mojo - tomcat-maven-plugin - 1.1 - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - org.apache.maven.plugins - maven-compiler-plugin - - - + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-security + + + spring-boot-starter-logging + org.springframework.boot + + + + + org.springframework.boot + spring-boot-starter-log4j2 + + + com.splunk.logging + splunk-library-javalogging + 1.8.0 + + + org.springframework.boot + spring-boot-starter-web + + + com.auth0 + java-jwt + 3.10.3 + + + com.h2database + h2 + runtime + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-test + test + + + org.springframework.boot + spring-boot-starter-tomcat + + + org.springframework.security + spring-security-config + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + junit + junit + 4.13 + test + + + + org.slf4j + slf4j-reload4j + 2.0.16 + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + + + From 60ee12cc91256aeecd2772beafef6db68ca86524 Mon Sep 17 00:00:00 2001 From: kleislicat <79645287+kleislicat@users.noreply.github.com> Date: Mon, 26 Aug 2024 20:05:46 +0100 Subject: [PATCH 4/4] lesson 1.12 changes --- .../com/example/demo/SareetaApplication.java | 10 ++- .../demo/controllers/UserController.java | 84 ++++++++++--------- .../example/demo/model/persistence/User.java | 24 +++--- .../model/requests/CreateUserRequest.java | 21 +++++ .../security/JWTAuthenticationFilter.java | 61 ++++++++++++++ .../JWTAuthenticationVerficationFilter.java | 58 +++++++++++++ .../demo/security/SecurityConstants.java | 10 +++ .../demo/security/UserDetailsServiceImpl.java | 28 +++++++ .../security/WebSecurityConfiguration.java | 48 +++++++++++ 9 files changed, 293 insertions(+), 51 deletions(-) create mode 100644 starter_code/src/main/java/com/example/demo/security/JWTAuthenticationFilter.java create mode 100644 starter_code/src/main/java/com/example/demo/security/JWTAuthenticationVerficationFilter.java create mode 100644 starter_code/src/main/java/com/example/demo/security/SecurityConstants.java create mode 100644 starter_code/src/main/java/com/example/demo/security/UserDetailsServiceImpl.java create mode 100644 starter_code/src/main/java/com/example/demo/security/WebSecurityConfiguration.java diff --git a/starter_code/src/main/java/com/example/demo/SareetaApplication.java b/starter_code/src/main/java/com/example/demo/SareetaApplication.java index f161f699d..7fdcc332f 100644 --- a/starter_code/src/main/java/com/example/demo/SareetaApplication.java +++ b/starter_code/src/main/java/com/example/demo/SareetaApplication.java @@ -3,13 +3,19 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; +import org.springframework.context.annotation.Bean; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; @EnableJpaRepositories("com.example.demo.model.persistence.repositories") @EntityScan("com.example.demo.model.persistence") -@SpringBootApplication +@SpringBootApplication(exclude = {SecurityAutoConfiguration.class}) public class SareetaApplication { - + @Bean + public BCryptPasswordEncoder bCryptPasswordEncoder(){ + return new BCryptPasswordEncoder(); + } public static void main(String[] args) { SpringApplication.run(SareetaApplication.class, args); } diff --git a/starter_code/src/main/java/com/example/demo/controllers/UserController.java b/starter_code/src/main/java/com/example/demo/controllers/UserController.java index 87e8089df..d05faaa1b 100644 --- a/starter_code/src/main/java/com/example/demo/controllers/UserController.java +++ b/starter_code/src/main/java/com/example/demo/controllers/UserController.java @@ -1,10 +1,13 @@ package com.example.demo.controllers; -import java.util.Optional; - +import com.example.demo.model.persistence.Cart; +import com.example.demo.model.persistence.User; +import com.example.demo.model.persistence.repositories.CartRepository; +import com.example.demo.model.persistence.repositories.UserRepository; +import com.example.demo.model.requests.CreateUserRequest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -12,42 +15,47 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import com.example.demo.model.persistence.Cart; -import com.example.demo.model.persistence.User; -import com.example.demo.model.persistence.repositories.CartRepository; -import com.example.demo.model.persistence.repositories.UserRepository; -import com.example.demo.model.requests.CreateUserRequest; - @RestController @RequestMapping("/api/user") public class UserController { - - @Autowired - private UserRepository userRepository; - - @Autowired - private CartRepository cartRepository; - - @GetMapping("/id/{id}") - public ResponseEntity findById(@PathVariable Long id) { - return ResponseEntity.of(userRepository.findById(id)); - } - - @GetMapping("/{username}") - public ResponseEntity findByUserName(@PathVariable String username) { - User user = userRepository.findByUsername(username); - return user == null ? ResponseEntity.notFound().build() : ResponseEntity.ok(user); - } - - @PostMapping("/create") - public ResponseEntity createUser(@RequestBody CreateUserRequest createUserRequest) { - User user = new User(); - user.setUsername(createUserRequest.getUsername()); - Cart cart = new Cart(); - cartRepository.save(cart); - user.setCart(cart); - userRepository.save(user); - return ResponseEntity.ok(user); - } - + + + @Autowired + private UserRepository userRepository; + + @Autowired + private CartRepository cartRepository; + + @Autowired + private BCryptPasswordEncoder bCryptPasswordEncoder; + + @GetMapping("/id/{id}") + public ResponseEntity findById(@PathVariable Long id) { + return ResponseEntity.of(userRepository.findById(id)); + } + + @GetMapping("/{username}") + public ResponseEntity findByUserName(@PathVariable String username) { + User user = userRepository.findByUsername(username); + return user == null ? ResponseEntity.notFound().build() : ResponseEntity.ok(user); + } + + @PostMapping("/create") + public ResponseEntity createUser(@RequestBody CreateUserRequest createUserRequest) { + + User user = new User(); + user.setUsername(createUserRequest.getUsername()); + Cart cart = new Cart(); + cartRepository.save(cart); + + user.setCart(cart); + if (createUserRequest.getPassword().length() < 7 || + !createUserRequest.getPassword().equals(createUserRequest.getConfirmPassword())) { + return ResponseEntity.badRequest().build(); + } + user.setPassword(bCryptPasswordEncoder.encode(createUserRequest.getPassword())); + userRepository.save(user); + return ResponseEntity.ok(user); + } + } diff --git a/starter_code/src/main/java/com/example/demo/model/persistence/User.java b/starter_code/src/main/java/com/example/demo/model/persistence/User.java index ab85ccc60..b9af58b8d 100644 --- a/starter_code/src/main/java/com/example/demo/model/persistence/User.java +++ b/starter_code/src/main/java/com/example/demo/model/persistence/User.java @@ -1,18 +1,10 @@ package com.example.demo.model.persistence; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.OneToOne; -import javax.persistence.Table; - import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import javax.persistence.*; + @Entity @Table(name = "user") @@ -26,7 +18,17 @@ public class User { @Column(nullable = false, unique = true) @JsonProperty private String username; - + + @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) + @Column(nullable = false) + private String password; + public String getPassword(){ + return password; + } + public void setPassword(String password) { + this.password = password; + } + @OneToOne(cascade = CascadeType.ALL) @JoinColumn(name = "cart_id", referencedColumnName = "id") @JsonIgnore diff --git a/starter_code/src/main/java/com/example/demo/model/requests/CreateUserRequest.java b/starter_code/src/main/java/com/example/demo/model/requests/CreateUserRequest.java index a92d0bbb6..5911f9e41 100644 --- a/starter_code/src/main/java/com/example/demo/model/requests/CreateUserRequest.java +++ b/starter_code/src/main/java/com/example/demo/model/requests/CreateUserRequest.java @@ -7,6 +7,12 @@ public class CreateUserRequest { @JsonProperty private String username; + @JsonProperty + private String password; + + @JsonProperty + private String confirmPassword; + public String getUsername() { return username; } @@ -14,4 +20,19 @@ public String getUsername() { public void setUsername(String username) { this.username = username; } + + public void setPassword(String password) { + this.password = password; + } + + public void setConfirmPassword(String confirmPassword) { + this.confirmPassword = confirmPassword; + } + public String getPassword() { + return password; + } + + public String getConfirmPassword() { + return confirmPassword; + } } diff --git a/starter_code/src/main/java/com/example/demo/security/JWTAuthenticationFilter.java b/starter_code/src/main/java/com/example/demo/security/JWTAuthenticationFilter.java new file mode 100644 index 000000000..896ffd9b2 --- /dev/null +++ b/starter_code/src/main/java/com/example/demo/security/JWTAuthenticationFilter.java @@ -0,0 +1,61 @@ +package com.example.demo.security; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Date; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; + +import com.auth0.jwt.JWT; +import com.example.demo.model.persistence.User; +import com.fasterxml.jackson.databind.ObjectMapper; + +import static com.auth0.jwt.algorithms.Algorithm.HMAC512; + +public class JWTAuthenticationFilter extends UsernamePasswordAuthenticationFilter { + + private AuthenticationManager authenticationManager; + + public JWTAuthenticationFilter(AuthenticationManager authenticationManager) { + this.authenticationManager = authenticationManager; + } + + @Override + public Authentication attemptAuthentication(HttpServletRequest req, + HttpServletResponse res) throws AuthenticationException { + try { + User credentials = new ObjectMapper() + .readValue(req.getInputStream(), User.class); + + return authenticationManager.authenticate( + new UsernamePasswordAuthenticationToken( + credentials.getUsername(), + credentials.getPassword(), + new ArrayList<>())); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + protected void successfulAuthentication(HttpServletRequest req, + HttpServletResponse res, + FilterChain chain, + Authentication auth) throws IOException, ServletException { + + String token = JWT.create() + .withSubject(((org.springframework.security.core.userdetails.User) auth.getPrincipal()).getUsername()) + .withExpiresAt(new Date(System.currentTimeMillis() + SecurityConstants.EXPIRATION_TIME)) + .sign(HMAC512(SecurityConstants.SECRET.getBytes())); + res.addHeader(SecurityConstants.HEADER_STRING, SecurityConstants.TOKEN_PREFIX + token); + } +} diff --git a/starter_code/src/main/java/com/example/demo/security/JWTAuthenticationVerficationFilter.java b/starter_code/src/main/java/com/example/demo/security/JWTAuthenticationVerficationFilter.java new file mode 100644 index 000000000..3d85ab18c --- /dev/null +++ b/starter_code/src/main/java/com/example/demo/security/JWTAuthenticationVerficationFilter.java @@ -0,0 +1,58 @@ +package com.example.demo.security; + +import java.io.IOException; +import java.util.ArrayList; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; +import org.springframework.stereotype.Component; + +import com.auth0.jwt.JWT; + +import static com.auth0.jwt.algorithms.Algorithm.HMAC512; + +@Component +public class JWTAuthenticationVerficationFilter extends BasicAuthenticationFilter { + + public JWTAuthenticationVerficationFilter(AuthenticationManager authManager) { + super(authManager); + } + + @Override + protected void doFilterInternal(HttpServletRequest req, HttpServletResponse res, FilterChain chain) + throws IOException, ServletException { + String header = req.getHeader(SecurityConstants.HEADER_STRING); + + if (header == null || !header.startsWith(SecurityConstants.TOKEN_PREFIX)) { + chain.doFilter(req, res); + return; + } + + UsernamePasswordAuthenticationToken authentication = getAuthentication(req); + + SecurityContextHolder.getContext().setAuthentication(authentication); + chain.doFilter(req, res); + } + + private UsernamePasswordAuthenticationToken getAuthentication(HttpServletRequest req) { + String token = req.getHeader(SecurityConstants.HEADER_STRING); + if (token != null) { + String user = JWT.require(HMAC512(SecurityConstants.SECRET.getBytes())).build() + .verify(token.replace(SecurityConstants.TOKEN_PREFIX, "")) + .getSubject(); + if (user != null) { + return new UsernamePasswordAuthenticationToken(user, null, new ArrayList<>()); + } + return null; + } + return null; + } + +} diff --git a/starter_code/src/main/java/com/example/demo/security/SecurityConstants.java b/starter_code/src/main/java/com/example/demo/security/SecurityConstants.java new file mode 100644 index 000000000..3f7cb5455 --- /dev/null +++ b/starter_code/src/main/java/com/example/demo/security/SecurityConstants.java @@ -0,0 +1,10 @@ +package com.example.demo.security; + +public class SecurityConstants { + + public static final String SECRET = "oursecretkey"; + public static final long EXPIRATION_TIME = 864_000_000; // 10 days + public static final String TOKEN_PREFIX = "Bearer "; + public static final String HEADER_STRING = "Authorization"; + public static final String SIGN_UP_URL = "/api/user/create"; +} diff --git a/starter_code/src/main/java/com/example/demo/security/UserDetailsServiceImpl.java b/starter_code/src/main/java/com/example/demo/security/UserDetailsServiceImpl.java new file mode 100644 index 000000000..5169b5884 --- /dev/null +++ b/starter_code/src/main/java/com/example/demo/security/UserDetailsServiceImpl.java @@ -0,0 +1,28 @@ +package com.example.demo.security; + +import java.util.Collections; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; + +import com.example.demo.model.persistence.User; +import com.example.demo.model.persistence.repositories.UserRepository; + +@Service +public class UserDetailsServiceImpl implements UserDetailsService { + + @Autowired + private UserRepository userRepository; + + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + User user = userRepository.findByUsername(username); + if (user == null) { + throw new UsernameNotFoundException(username); + } + return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), Collections.emptyList()); + } +} \ No newline at end of file diff --git a/starter_code/src/main/java/com/example/demo/security/WebSecurityConfiguration.java b/starter_code/src/main/java/com/example/demo/security/WebSecurityConfiguration.java new file mode 100644 index 000000000..dfa86fcc3 --- /dev/null +++ b/starter_code/src/main/java/com/example/demo/security/WebSecurityConfiguration.java @@ -0,0 +1,48 @@ +package com.example.demo.security; + +import org.springframework.context.annotation.Bean; +import org.springframework.http.HttpMethod; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; + +@EnableWebSecurity +public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter { + + private UserDetailsServiceImpl userDetailsService; + private BCryptPasswordEncoder bCryptPasswordEncoder; + + public WebSecurityConfiguration(UserDetailsServiceImpl userDetailsService, + BCryptPasswordEncoder bCryptPasswordEncoder) { + this.userDetailsService = userDetailsService; + this.bCryptPasswordEncoder = bCryptPasswordEncoder; + } + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.cors().and().csrf().disable().authorizeRequests() + .antMatchers(HttpMethod.POST, SecurityConstants.SIGN_UP_URL, "/login").permitAll() + .anyRequest().authenticated() + .and() + .addFilter(new JWTAuthenticationFilter(authenticationManager())) + .addFilter(new JWTAuthenticationVerficationFilter(authenticationManager())) + .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); + } + + @Override + @Bean + public AuthenticationManager authenticationManagerBean() throws Exception { + return super.authenticationManagerBean(); + } + + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + auth.parentAuthenticationManager(authenticationManagerBean()) + .userDetailsService(userDetailsService) + .passwordEncoder(bCryptPasswordEncoder); + } +}