Produced by Araxis Merge on 12/8/2017 1:33:40 PM Central Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | PC_CP4_CiF.zip\FPPS_Backend\fpps_app\src\test\java\gov\va\med\fee\integration | OAuthIntegrationTest.java | Fri Dec 8 17:51:36 2017 UTC |
| 2 | PC_CP4_CiF.zip\FPPS_Backend\fpps_app\src\test\java\gov\va\med\fee\integration | OAuthIntegrationTest.java | Fri Dec 8 18:30:10 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 256 |
| Changed | 1 | 2 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | /** | |
| 2 | * | |
| 3 | */ | |
| 4 | package go v.va.med.f ee.integra tion; | |
| 5 | ||
| 6 | import sta tic org.ju nit.Assert .assertEqu als; | |
| 7 | import sta tic org.ju nit.Assert .assertTru e; | |
| 8 | ||
| 9 | import jav a.io.IOExc eption; | |
| 10 | import jav a.net.Inet Address; | |
| 11 | import jav a.util.Arr ays; | |
| 12 | import jav a.util.Has hMap; | |
| 13 | import jav a.util.Lin kedHashMap ; | |
| 14 | import jav a.util.Lis t; | |
| 15 | ||
| 16 | import org .apache.co mmons.code c.binary.B ase64; | |
| 17 | import org .apache.lo gging.log4 j.LogManag er; | |
| 18 | import org .apache.lo gging.log4 j.Logger; | |
| 19 | import org .junit.Tes t; | |
| 20 | import org .junit.run ner.RunWit h; | |
| 21 | import org .springfra mework.bea ns.factory .annotatio n.Autowire d; | |
| 22 | import org .springfra mework.cor e.env.Envi ronment; | |
| 23 | import org .springfra mework.htt p.HttpEnti ty; | |
| 24 | import org .springfra mework.htt p.HttpHead ers; | |
| 25 | import org .springfra mework.htt p.HttpMeth od; | |
| 26 | import org .springfra mework.htt p.HttpStat us; | |
| 27 | import org .springfra mework.htt p.MediaTyp e; | |
| 28 | import org .springfra mework.htt p.Response Entity; | |
| 29 | import org .springfra mework.sec urity.jwt. Jwt; | |
| 30 | import org .springfra mework.sec urity.jwt. JwtHelper; | |
| 31 | import org .springfra mework.tes t.context. ActiveProf iles; | |
| 32 | import org .springfra mework.tes t.context. ContextCon figuration ; | |
| 33 | import org .springfra mework.tes t.context. junit4.Spr ingJUnit4C lassRunner ; | |
| 34 | import org .springfra mework.tes t.context. web.WebApp Configurat ion; | |
| 35 | import org .springfra mework.web .client.Re stClientEx ception; | |
| 36 | import org .springfra mework.web .client.Re stTemplate ; | |
| 37 | ||
| 38 | import com .fasterxml .jackson.c ore.JsonPa rseExcepti on; | |
| 39 | import com .fasterxml .jackson.d atabind.Js onMappingE xception; | |
| 40 | import com .fasterxml .jackson.d atabind.Ob jectMapper ; | |
| 41 | ||
| 42 | /** | |
| 43 | * @author Vamsi Gan garapu | |
| 44 | * | |
| 45 | */ | |
| 46 | //Test cas e to test OAuth 2.0 configurat ion | |
| 47 | //Test cas e will dec ode JWT to ken and te st accordi ngly | |
| 48 | @WebAppCon figuration | |
| 49 | @RunWith(S pringJUnit 4ClassRunn er.class) | |
| 50 | @ContextCo nfiguratio n(classes = { gov.va .med.fee.c onfigurati on.AppConf ig.class, | |
| 51 | gov. va.med.fee .configura tion.hiber nate.Persi stenceConf ig.class, | |
| 52 | gov. va.med.fee .configura tion.sprin g.SpringMv cConfig.cl ass }) | |
| 53 | @ActivePro files("dev ") | |
| 54 | public cla ss OAuthIn tegrationT est { | |
| 55 | pr ivate stat ic final L ogger logg er = LogMa nager.getL ogger(OAut hIntegrati onTest.cla ss); | |
| 56 | ||
| 57 | @A utowired | |
| 58 | En vironment env; | |
| 59 | ||
| 60 | st atic final String PR OJECT_ID = "/fpps/oa uth/token" ; | |
| 61 | st atic final String OA UTH_SERVIC E_URI = "h ttp://"; | |
| 62 | // static fin al String OAUTH_PASS WORD_GRANT = "?grant _type=pass word&usern ame=fpps&p assword=fp ps"; | |
| 63 | st atic final String OA UTH_PASSWO RD_GRANT = "?grant_t ype=passwo rd&usernam e=fpps&pas sword=mHqw nM}yT~={k2 "; | |
| 64 | st atic final String OA UTH_ACCESS _TOKEN = " ?access_to ken="; | |
| 65 | st atic final String CL IENT_USERN AME = "FPP S_FRONTEND _APP:fpps1 23456"; | |
| 66 | ||
| 67 | /* * | |
| 68 | * @throws J sonParseEx ception | |
| 69 | * @throws J sonMapping Exception | |
| 70 | * @throws I OException | |
| 71 | * / | |
| 72 | @S uppressWar nings({ "u nchecked", "rawtypes " }) | |
| 73 | @T est | |
| 74 | pu blic void getJwtToke n() throws JsonParse Exception, JsonMappi ngExceptio n, IOExcep tion { | |
| 75 | ||
| 76 | Stri ng port = env.getPro perty("oau th2.port") ; | |
| 77 | ||
| 78 | Stri ng hostAdd ress = Ine tAddress.g etLocalHos t().getHos tAddress() ; | |
| 79 | //ho stAddress = hostAddr ess + ":"; | |
| 80 | hostAddres s = " IP :"; | |
| 81 | ||
| 82 | ||
| 83 | logg er.info(ho stAddress) ; | |
| 84 | ||
| 85 | logg er.info("T esting OAu th 2.0"); | |
| 86 | ||
| 87 | Http Headers he aders = ne w HttpHead ers(); | |
| 88 | head ers.setAcc ept(Arrays .asList(Me diaType.AP PLICATION_ JSON)); | |
| 89 | ||
| 90 | Stri ng base64C lientCrede ntials = n ew String( Base64.enc odeBase64( CLIENT_USE RNAME.getB ytes())); | |
| 91 | head ers.add("A uthorizati on", "Basi c " + base 64ClientCr edentials) ; | |
| 92 | Http Entity<Str ing> reque st = new H ttpEntity< String>(he aders); | |
| 93 | try { | |
| 94 | RestTe mplate res tTemplate = new Rest Template() ; | |
| 95 | Respon seEntity<O bject> res ponse = re stTemplate .exchange( | |
| 96 | OAUTH_SERV ICE_URI + hostAddres s + port + PROJECT_I D + OAUTH_ PASSWORD_G RANT, Http Method.POS T, | |
| 97 | request, O bject.clas s); | |
| 98 | assert Equals(Htt pStatus.OK , response .getStatus Code()); | |
| 99 | Linked HashMap<St ring, Obje ct> map = (LinkedHas hMap<Strin g, Object> ) response .getBody() ; | |
| 100 | ||
| 101 | if (ma p != null) { | |
| 102 | assertTr ue(map.con tainsKey(" access_tok en")); | |
| 103 | assertTr ue(map.con tainsKey(" token_type ")); | |
| 104 | assertEq uals("bear er", map.g et("token_ type")); | |
| 105 | assertTr ue(map.con tainsKey(" refresh_to ken")); | |
| 106 | assertTr ue(map.con tainsKey(" expires_in ")); | |
| 107 | assertTr ue(map.con tainsKey(" scope")); | |
| 108 | assertTr ue(map.con tainsKey(" jti")); | |
| 109 | ||
| 110 | String a ccessToken = (String ) map.get( "access_to ken"); | |
| 111 | ||
| 112 | Jwt jwtT oken = Jwt Helper.dec ode(access Token); | |
| 113 | ||
| 114 | String c laims = jw tToken.get Claims(); | |
| 115 | ||
| 116 | HashMap claimsMap = new Obje ctMapper() .readValue (claims, H ashMap.cla ss); | |
| 117 | assertEq uals("FPPS _FRONTEND_ APP", clai msMap.get( "client_id ")); | |
| 118 | assertEq uals("fpps ", claimsM ap.get("us er_name")) ; | |
| 119 | assertEq uals("read ", (((List <String>) claimsMap. get("scope ")).get(0) )); | |
| 120 | assertEq uals("writ e", (((Lis t<String>) claimsMap .get("scop e")).get(1 ))); | |
| 121 | assertEq uals("trus t", (((Lis t<String>) claimsMap .get("scop e")).get(2 ))); | |
| 122 | assertEq uals("ROLE _ADMIN", ( ((List<Str ing>) clai msMap.get( "authoriti es")).get( 0))); | |
| 123 | logger.i nfo("OAuth 2.0 TestC ase Succes sful"); | |
| 124 | } | |
| 125 | } ca tch (RestC lientExcep tion ex) { | |
| 126 | logger .info("Exc eption is " + ex); | |
| 127 | } | |
| 128 | } | |
| 129 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.