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

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

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