1- package org .joychou .controller . jsonp ;
1+ package org .joychou .controller ;
22
33import com .alibaba .fastjson .JSON ;
44import com .alibaba .fastjson .JSONObject ;
55
6- import com .netflix .ribbon .proxy .annotation .Http ;
76import org .joychou .security .SecurityUtil ;
7+ import org .joychou .util .LoginUtils ;
88import org .springframework .http .MediaType ;
99import org .springframework .security .web .csrf .CsrfToken ;
1010import org .springframework .web .bind .annotation .*;
1515
1616import javax .servlet .http .HttpServletRequest ;
1717import java .security .Principal ;
18- import java .util .HashMap ;
19- import java .util .Map ;
18+
2019
2120
2221/**
2625
2726@ RestController
2827@ RequestMapping ("/jsonp" )
29- public class JSONP {
28+ public class Jsonp {
3029
3130 private String callback = WebConfig .getBusinessCallback ();
3231
33- // get current login username
34- public static String getUserInfo2JsonStr (HttpServletRequest request ) {
35- Principal principal = request .getUserPrincipal ();
36-
37- String username = principal .getName ();
38-
39- Map <String , String > m = new HashMap <>();
40- m .put ("Username" , username );
41-
42- return JSON .toJSONString (m );
43- }
44-
4532 /**
4633 * Set the response content-type to application/javascript.
4734 * <p>
@@ -50,7 +37,7 @@ public static String getUserInfo2JsonStr(HttpServletRequest request) {
5037 @ RequestMapping (value = "/vuln/referer" , produces = "application/javascript" )
5138 public String referer (HttpServletRequest request ) {
5239 String callback = request .getParameter (this .callback );
53- return WebUtils .json2Jsonp (callback , getUserInfo2JsonStr (request ));
40+ return WebUtils .json2Jsonp (callback , LoginUtils . getUserInfo2JsonStr (request ));
5441 }
5542
5643 /**
@@ -67,20 +54,20 @@ public String emptyReferer(HttpServletRequest request) {
6754 return "error" ;
6855 }
6956 String callback = request .getParameter (this .callback );
70- return WebUtils .json2Jsonp (callback , getUserInfo2JsonStr (request ));
57+ return WebUtils .json2Jsonp (callback , LoginUtils . getUserInfo2JsonStr (request ));
7158 }
7259
7360 /**
7461 * Adding callback or cback on parameter can automatically return jsonp data.
75- * http://localhost:8080/jsonp/vuln/advice ?callback=test
76- * http://localhost:8080/jsonp/vuln/advice ?_callback=test
62+ * http://localhost:8080/jsonp/object2jsonp ?callback=test
63+ * http://localhost:8080/jsonp/object2jsonp ?_callback=test
7764 *
7865 * @return Only return object, AbstractJsonpResponseBodyAdvice can be used successfully.
7966 * Such as JSONOjbect or JavaBean. String type cannot be used.
8067 */
81- @ RequestMapping (value = "/vuln/advice " , produces = MediaType .APPLICATION_JSON_VALUE )
68+ @ RequestMapping (value = "/object2jsonp " , produces = MediaType .APPLICATION_JSON_VALUE )
8269 public JSONObject advice (HttpServletRequest request ) {
83- return JSON .parseObject (getUserInfo2JsonStr (request ));
70+ return JSON .parseObject (LoginUtils . getUserInfo2JsonStr (request ));
8471 }
8572
8673
@@ -112,7 +99,7 @@ public String safecode(HttpServletRequest request) {
11299 return "error" ;
113100 }
114101 String callback = request .getParameter (this .callback );
115- return WebUtils .json2Jsonp (callback , getUserInfo2JsonStr (request ));
102+ return WebUtils .json2Jsonp (callback , LoginUtils . getUserInfo2JsonStr (request ));
116103 }
117104
118105
0 commit comments