fixed: - - 短信登录未单元测试出现问题临时修复

This commit is contained in:
wangiegie@gmail.com 2018-01-09 09:46:50 +08:00
parent 0a62b89f88
commit a3c4f5940f
4 changed files with 51 additions and 21 deletions

View File

@ -54,23 +54,22 @@ public class UserController {
/**
* 自定义token
*
* @param clientId clientId
* @param clientSecret clientSecret
* @param authentication authentication
* @param params 参数信息
* @return OAuth2AccessToken
*/
@RequestMapping(value = "/oauth/token_key")
public OAuth2AccessToken getKey(String clientId, String clientSecret, Authentication authentication) {
ClientDetails clientDetails = clientDetailsService.loadClientByClientId(clientId);
if (clientDetails == null) {
throw new UnapprovedClientAuthenticationException("请求头中client信息不存在 clientId:" + clientId);
} else if (!StringUtils.equals(clientDetails.getClientSecret(), clientSecret)) {
throw new UnapprovedClientAuthenticationException("请求头中client信息不合法 clientSecret:" + clientSecret);
}
TokenRequest tokenRequest = new TokenRequest(MapUtil.newHashMap(), clientId, clientDetails.getScope(), "mobile");
OAuth2Request oAuth2Request = tokenRequest.createOAuth2Request(clientDetails);
OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(oAuth2Request, authentication);
return authorizationServerTokenServices.createAccessToken(oAuth2Authentication);
public OAuth2AccessToken getKey(String params) {
ClientDetails clientDetails = clientDetailsService.loadClientByClientId(params);
// if (clientDetails == null) {
// throw new UnapprovedClientAuthenticationException("请求头中client信息不存在 clientId:" + clientId);
// } else if (!StringUtils.equals(clientDetails.getClientSecret(), clientSecret)) {
// throw new UnapprovedClientAuthenticationException("请求头中client信息不合法 clientSecret:" + clientSecret);
// }
//
// TokenRequest tokenRequest = new TokenRequest(MapUtil.newHashMap(), clientId, clientDetails.getScope(), "mobile");
// OAuth2Request oAuth2Request = tokenRequest.createOAuth2Request(clientDetails);
// OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(oAuth2Request, authentication);
// return authorizationServerTokenServices.createAccessToken(oAuth2Authentication);
return null;
}
}

View File

@ -45,7 +45,7 @@ public class MobileLoginSuccessHandler implements org.springframework.security.w
assert tokens.length == 2;
String clientId = tokens[0];
String clientSecret = tokens[1];
OAuth2AccessToken oAuth2AccessToken = authSerivce.createToken(clientId,clientSecret,authentication);
OAuth2AccessToken oAuth2AccessToken = authSerivce.createToken(clientId);
} catch (IOException e) {
throw new BadCredentialsException(
"Failed to decode basic authentication token");

View File

@ -1,23 +1,26 @@
package com.github.pig.gateway.feign;
import com.github.pig.gateway.feign.fallback.AuthServiceFallbackImpl;
import com.github.pig.gateway.feign.fallback.MenuServiceFallbackImpl;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @author lengleng
* @date 2018/1/8
*/
@FeignClient(name = "pig-auth-service", fallback = MenuServiceFallbackImpl.class)
@FeignClient(name = "pig-auth-service", fallback = AuthServiceFallbackImpl.class)
public interface AuthSerivce {
/**
* 获取 OAuth2AccessToken
*
* @param clientId 客户端ID
* @param clientSecret 客户端Secret
* @param authentication 认证信息
* @param params 参数信息
* @return OAuth2AccessToken
*/
OAuth2AccessToken createToken(String clientId, String clientSecret, Authentication authentication);
@PostMapping(value = "/oauth/token_key")
OAuth2AccessToken createToken(@RequestParam("params") String params);
}

View File

@ -0,0 +1,28 @@
package com.github.pig.gateway.feign.fallback;
import com.github.pig.gateway.feign.AuthSerivce;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.stereotype.Service;
/**
* @author lengleng
* @date 2018/1/9
*/
@Service
public class AuthServiceFallbackImpl implements AuthSerivce {
private Logger logger = LoggerFactory.getLogger(this.getClass());
/**
* 获取 OAuth2AccessToken
*
* @param params 参数信息
* @return OAuth2AccessToken
*/
@Override
public OAuth2AccessToken createToken(String params) {
return null;
}
}