Commit ed0c0115 authored by 技术部-任文超's avatar 技术部-任文超

与H5协商调整One-Time-Token的参数传递方式为param参数方式

parent 7f6a40eb
...@@ -12,7 +12,7 @@ public interface Constants { ...@@ -12,7 +12,7 @@ public interface Constants {
String PASSWORD_SALT = "_lkb"; String PASSWORD_SALT = "_lkb";
String IMAGE_CAPTCHA_KEY = "img_captcha:"; String IMAGE_CAPTCHA_KEY = "img_captcha:";
String ONE_TIME_TOKEN = "One-Time-Token"; String ONE_TIME_TOKEN = "oneTimeToken";
String REDIS_CAPTCHA_KEY = "auth:"; String REDIS_CAPTCHA_KEY = "auth:";
String REDIS_CAPTCHA_KEY_PATTERN = REDIS_CAPTCHA_KEY + IMAGE_CAPTCHA_KEY + "*"; String REDIS_CAPTCHA_KEY_PATTERN = REDIS_CAPTCHA_KEY + IMAGE_CAPTCHA_KEY + "*";
......
...@@ -53,7 +53,7 @@ public class OneTimeTokenValidateAdvisor { ...@@ -53,7 +53,7 @@ public class OneTimeTokenValidateAdvisor {
if (valid) { if (valid) {
return pjp.proceed(); return pjp.proceed();
} }
return JsonResult.buildSuccessResult("Token过期,请重新请求", "", 2L); return JsonResult.buildSuccessResult("令牌已失效", "", 2L);
} }
/** /**
...@@ -63,7 +63,7 @@ public class OneTimeTokenValidateAdvisor { ...@@ -63,7 +63,7 @@ public class OneTimeTokenValidateAdvisor {
private boolean oneTimeTokenValid() { private boolean oneTimeTokenValid() {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
// 当前请求的OneTimeToken // 当前请求的OneTimeToken
String oneTimeToken = request.getHeader(Constants.ONE_TIME_TOKEN); String oneTimeToken = request.getParameter(Constants.ONE_TIME_TOKEN);
if (StringUtils.isBlank(oneTimeToken)){ if (StringUtils.isBlank(oneTimeToken)){
return false; return false;
} }
...@@ -77,7 +77,7 @@ public class OneTimeTokenValidateAdvisor { ...@@ -77,7 +77,7 @@ public class OneTimeTokenValidateAdvisor {
if(valid) { if(valid) {
redisTemplate.delete(oneTimeToken); redisTemplate.delete(oneTimeToken);
}else { }else {
LOGGER.info("Token过期,请重新请求, One-Time-Token={}, clientIp={}", oneTimeToken, request.getRemoteAddr()); LOGGER.info("令牌已失效,请重新请求, oneTimeToken={}, clientIp={}", oneTimeToken, request.getRemoteAddr());
} }
return valid; return valid;
} }
......
...@@ -239,7 +239,7 @@ public class UserController implements IBaseController { ...@@ -239,7 +239,7 @@ public class UserController implements IBaseController {
* @return * @return
*/ */
private Map<String, JsonResult> getHeaderParam(HttpServletRequest request) { private Map<String, JsonResult> getHeaderParam(HttpServletRequest request) {
Map<String, JsonResult> result = new HashMap<>(); Map<String, JsonResult> result = new HashMap<String, JsonResult>();
String verificationHeader = "Verification "; String verificationHeader = "Verification ";
String credential = request.getHeader("authorization"); String credential = request.getHeader("authorization");
if (StringUtils.isBlank(credential)) { if (StringUtils.isBlank(credential)) {
......
...@@ -63,8 +63,8 @@ public class JsonResult implements Serializable { ...@@ -63,8 +63,8 @@ public class JsonResult implements Serializable {
return new JsonResult(msg, SUCCESS_CODE, data, SUCCESS_BUSSINESS_CODE); return new JsonResult(msg, SUCCESS_CODE, data, SUCCESS_BUSSINESS_CODE);
} }
public static JsonResult buildSuccessResult(String msg, Object data, Long bussinessId) { public static JsonResult buildSuccessResult(String msg, Object data, Long businessCode) {
return new JsonResult(msg, SUCCESS_CODE, data, bussinessId); return new JsonResult(msg, SUCCESS_CODE, data, businessCode);
} }
/** /**
...@@ -78,12 +78,12 @@ public class JsonResult implements Serializable { ...@@ -78,12 +78,12 @@ public class JsonResult implements Serializable {
return new JsonResult(msg, SUCCESS_CODE, data, ERROR_BUSSINESS_CODE); return new JsonResult(msg, SUCCESS_CODE, data, ERROR_BUSSINESS_CODE);
} }
public static JsonResult buildErrorStateResult(String msg, Object data, Long busniessId) { public static JsonResult buildErrorStateResult(String msg, Object data, Long businessCode) {
return new JsonResult(msg, SUCCESS_CODE, data, busniessId); return new JsonResult(msg, SUCCESS_CODE, data, businessCode);
} }
public static JsonResult buildFatalErrorStateResult(String msg, Object data, Long busniessId) { public static JsonResult buildFatalErrorStateResult(String msg, Object data, Long businessCode) {
return new JsonResult(msg, ERROR_STATE_CODE, data, busniessId); return new JsonResult(msg, ERROR_STATE_CODE, data, businessCode);
} }
public String getMsg() { public String getMsg() {
......
...@@ -29,6 +29,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. ...@@ -29,6 +29,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@SpringApplicationConfiguration(classes = Bootstrap.class) @SpringApplicationConfiguration(classes = Bootstrap.class)
@WebAppConfiguration @WebAppConfiguration
public class OneTimeTokenTests { public class OneTimeTokenTests {
final String userName = "root";
final String password = "!QAZ2wsx";
final String phoneNo = "13461067662"; final String phoneNo = "13461067662";
private MockMvc mvc; private MockMvc mvc;
...@@ -58,7 +60,7 @@ public class OneTimeTokenTests { ...@@ -58,7 +60,7 @@ public class OneTimeTokenTests {
* @throws Exception * @throws Exception
*/ */
@Test @Test
public void testTokenOnce() throws Exception{ public void testOneTimeToken() throws Exception{
String tokenOnceUri = "/token/oneTime"; String tokenOnceUri = "/token/oneTime";
MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(tokenOnceUri).accept(MediaType.APPLICATION_JSON)) MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(tokenOnceUri).accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()) .andExpect(status().isOk())
...@@ -96,10 +98,9 @@ public class OneTimeTokenTests { ...@@ -96,10 +98,9 @@ public class OneTimeTokenTests {
// 第一次使用OneTime-Token // 第一次使用OneTime-Token
String aspectUri = "/user/loginForH5"; String aspectUri = "/user/loginForH5";
mvcResult = mvc.perform(MockMvcRequestBuilders.get(aspectUri).accept(MediaType.APPLICATION_JSON) mvcResult = mvc.perform(MockMvcRequestBuilders.get(aspectUri).accept(MediaType.APPLICATION_JSON)
.header(Constants.ONE_TIME_TOKEN, oneTimeToken) .param(Constants.ONE_TIME_TOKEN, oneTimeToken)
.param("phoneNo", phoneNo) .param("phoneNo", userName)
.param("password", "Qg123456") .param("password", password))
.param("verificationCode", "1234"))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andReturn(); .andReturn();
content = mvcResult.getResponse().getContentAsString(); content = mvcResult.getResponse().getContentAsString();
...@@ -110,10 +111,9 @@ public class OneTimeTokenTests { ...@@ -110,10 +111,9 @@ public class OneTimeTokenTests {
Assert.assertNotEquals("0002", businessCode); Assert.assertNotEquals("0002", businessCode);
// 使用过期的TokenOnce // 使用过期的TokenOnce
mvcResult = mvc.perform(MockMvcRequestBuilders.get(aspectUri).accept(MediaType.APPLICATION_JSON) mvcResult = mvc.perform(MockMvcRequestBuilders.get(aspectUri).accept(MediaType.APPLICATION_JSON)
.header("TokenOnce", oneTimeToken) .param(Constants.ONE_TIME_TOKEN, oneTimeToken)
.param("phoneNo", phoneNo) .param("phoneNo", userName)
.param("password", "Qg123456") .param("password", password))
.param("verificationCode", "1234"))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andReturn(); .andReturn();
content = mvcResult.getResponse().getContentAsString(); content = mvcResult.getResponse().getContentAsString();
...@@ -124,9 +124,8 @@ public class OneTimeTokenTests { ...@@ -124,9 +124,8 @@ public class OneTimeTokenTests {
Assert.assertEquals("0002", businessCode); Assert.assertEquals("0002", businessCode);
// 不使用TokenOnce // 不使用TokenOnce
mvcResult = mvc.perform(MockMvcRequestBuilders.get(aspectUri).accept(MediaType.APPLICATION_JSON) mvcResult = mvc.perform(MockMvcRequestBuilders.get(aspectUri).accept(MediaType.APPLICATION_JSON)
.param("phoneNo", phoneNo) .param("phoneNo", userName)
.param("password", "Qg123456") .param("password", password))
.param("verificationCode", "1234"))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andReturn(); .andReturn();
content = mvcResult.getResponse().getContentAsString(); content = mvcResult.getResponse().getContentAsString();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment