新增了oauth2客户端创建默认用户与app获取登录token功能
This commit is contained in:
parent
dac76f4d24
commit
67b9bc9889
@ -1,7 +1,5 @@
|
||||
package ink.wgink.interfaces.app;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
|
@ -20,6 +20,17 @@ import java.util.Map;
|
||||
**/
|
||||
public interface IUserBaseService {
|
||||
|
||||
/**
|
||||
* 新增默认用户
|
||||
*
|
||||
* @param userUsername 用户名
|
||||
* @param username 昵称
|
||||
* @param userState 状态
|
||||
* @param userType 类型
|
||||
* @return 用户ID
|
||||
*/
|
||||
String saveDefaultUserAndReturnId(String userUsername, String username, Integer userState, Integer userType);
|
||||
|
||||
/**
|
||||
* 用户详情
|
||||
*
|
||||
|
@ -15,7 +15,12 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import java.lang.reflect.Type;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
@ -34,6 +39,38 @@ public class RestRemoteRequest {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RestRemoteRequest.class);
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
static {
|
||||
try {
|
||||
trustAllHttpsCertificates();
|
||||
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
|
||||
public boolean verify(String urlHostName, SSLSession session) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
private static void trustAllHttpsCertificates() throws NoSuchAlgorithmException, KeyManagementException {
|
||||
TrustManager[] trustAllCerts = new TrustManager[1];
|
||||
trustAllCerts[0] = new TrustAllManager();
|
||||
SSLContext sc = SSLContext.getInstance("SSL");
|
||||
sc.init(null, trustAllCerts, null);
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
||||
}
|
||||
|
||||
private static class TrustAllManager implements X509TrustManager {
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException {
|
||||
}
|
||||
|
||||
public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException {
|
||||
}
|
||||
}
|
||||
|
||||
public RestRemoteRequest() {
|
||||
HttpComponentsClientHttpRequestFactory httpComponentsClientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory();
|
||||
httpComponentsClientHttpRequestFactory.setConnectTimeout(20 * 1000);
|
||||
|
@ -0,0 +1,44 @@
|
||||
package ink.wgink.login.app.controller.resource.appsign;
|
||||
|
||||
import ink.wgink.common.base.DefaultBaseController;
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
import ink.wgink.login.app.service.appsign.IAppSignService;
|
||||
import ink.wgink.pojo.result.ErrorResult;
|
||||
import ink.wgink.pojo.result.SuccessResultData;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: AppSignResourceController
|
||||
* @Description: APP登录
|
||||
* @Author: wanggeng
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Api(tags = ISystemConstant.API_TAGS_APP_PREFIX + "APP登录")
|
||||
@RestController
|
||||
@RequestMapping(ISystemConstant.RESOURCE_PREFIX + "/appsign")
|
||||
public class AppSignResourceController extends DefaultBaseController {
|
||||
|
||||
@Autowired
|
||||
private IAppSignService appSignService;
|
||||
|
||||
@ApiOperation(value = "通过用户ID获取token", notes = "通过用户ID获取token接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "userId", value = "用户ID", paramType = "path")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("get-token/user-id/{userId}")
|
||||
public SuccessResultData<String> getTokenByUserId(@PathVariable("userId") String userId) throws Exception {
|
||||
LOG.debug("Get token by userId: {}", userId);
|
||||
return new SuccessResultData<>(appSignService.userIdSign(userId));
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package ink.wgink.login.oauth2.client.remote.appsign;
|
||||
|
||||
import ink.wgink.annotation.rpc.rest.RemoteService;
|
||||
import ink.wgink.annotation.rpc.rest.method.RemoteGetMethod;
|
||||
import ink.wgink.annotation.rpc.rest.params.RemotePathParams;
|
||||
import ink.wgink.annotation.rpc.rest.params.RemoteQueryParams;
|
||||
import ink.wgink.annotation.rpc.rest.params.RemoteServerParams;
|
||||
import ink.wgink.pojo.result.SuccessResultData;
|
||||
|
||||
/**
|
||||
* @ClassName: IAppSignRemoteService
|
||||
* @Description: app远程登录
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/9/22 10:45 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@RemoteService("/resource/appsign")
|
||||
public interface IAppSignRemoteService {
|
||||
|
||||
@RemoteGetMethod("/get-token/user-id/{userId}")
|
||||
SuccessResultData<String> getTokenByUserId(@RemoteServerParams String userCenter, @RemoteQueryParams("access_token") String accessToken, @RemotePathParams("userId") String userId);
|
||||
|
||||
}
|
@ -25,6 +25,9 @@ import java.util.Map;
|
||||
@RemoteService("/resource/user")
|
||||
public interface IUserRemoteService {
|
||||
|
||||
@RemotePostMethod("/save-default-user")
|
||||
SuccessResultData<String> saveDefaultUser(@RemoteServerParams String userCenter, @RemoteQueryParams("access_token") String accessToken, @RemoteJsonBodyParams Map<String, Object> params);
|
||||
|
||||
@RemoteGetMethod("/get/{userId}")
|
||||
UserDTO get(@RemoteServerParams String userCenter, @RemotePathParams("userId") String userId, @RemoteQueryParams("access_token") String accessToken);
|
||||
|
||||
|
@ -0,0 +1,28 @@
|
||||
package ink.wgink.login.oauth2.client.service.appsign;
|
||||
|
||||
import ink.wgink.exceptions.ParamsException;
|
||||
import ink.wgink.interfaces.app.IAppSignBaseService;
|
||||
import ink.wgink.login.oauth2.client.remote.appsign.IAppSignRemoteService;
|
||||
import ink.wgink.module.oauth2.manager.OAuth2ClientTokenManager;
|
||||
import ink.wgink.pojo.result.SuccessResultData;
|
||||
import ink.wgink.properties.ApiPathProperties;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class AppSignServiceImpl implements IAppSignBaseService {
|
||||
@Autowired
|
||||
private ApiPathProperties apiPathProperties;
|
||||
@Autowired
|
||||
private IAppSignRemoteService appSignRemoteService;
|
||||
|
||||
@Override
|
||||
public String userIdSign(String userId) throws Exception {
|
||||
if (StringUtils.isBlank(userId)) {
|
||||
throw new ParamsException("userId不能为空");
|
||||
}
|
||||
SuccessResultData<String> successResultData = appSignRemoteService.getTokenByUserId(apiPathProperties.getUserCenter(), OAuth2ClientTokenManager.getInstance().getToken().getAccessToken(), userId);
|
||||
return successResultData.getData();
|
||||
}
|
||||
}
|
@ -34,6 +34,17 @@ public class UserServiceImpl extends DefaultBaseService implements IUserService
|
||||
@Autowired
|
||||
private ApiPathProperties apiPathProperties;
|
||||
|
||||
@Override
|
||||
public String saveDefaultUserAndReturnId(String userUsername, String username, Integer userState, Integer userType) {
|
||||
Map<String, Object> params = getHashMap(8);
|
||||
params.put("userUsername", userUsername);
|
||||
params.put("username", username);
|
||||
params.put("userState", userState);
|
||||
params.put("userType", userType);
|
||||
SuccessResultData<String> successResultData = userRemoteService.saveDefaultUser(apiPathProperties.getUserCenter(), OAuth2ClientTokenManager.getInstance().getToken().getAccessToken(), params);
|
||||
return successResultData.getData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDTO get(String userId) {
|
||||
return userRemoteService.get(apiPathProperties.getUserCenter(), userId, OAuth2ClientTokenManager.getInstance().getToken().getAccessToken());
|
||||
|
@ -13,6 +13,7 @@ import ink.wgink.pojo.result.SuccessResultData;
|
||||
import ink.wgink.pojo.result.SuccessResultList;
|
||||
import ink.wgink.pojo.vos.IdsVO;
|
||||
import ink.wgink.pojo.vos.UpdatePasswordVO;
|
||||
import ink.wgink.service.user.pojo.vos.UserVO;
|
||||
import ink.wgink.service.user.service.IUserService;
|
||||
import ink.wgink.util.ReflectUtil;
|
||||
import ink.wgink.util.RegexUtil;
|
||||
@ -42,10 +43,16 @@ public class UserResourceController extends DefaultBaseController {
|
||||
@Autowired
|
||||
private IUserService userService;
|
||||
|
||||
@ApiOperation(value = "新增默认用户", notes = "新增默认用户接口")
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("save-default-user")
|
||||
public SuccessResultData<String> save(@RequestBody UserVO userVO) {
|
||||
String userId = userService.saveDefaultUserAndReturnId(userVO.getUserUsername(), userVO.getUserName(), userVO.getUserState(), userVO.getUserType());
|
||||
return new SuccessResultData<>(userId);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "修改密码", notes = "修改密码接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "userId", value = "用户ID", paramType = "path"),
|
||||
})
|
||||
@ApiImplicitParams({@ApiImplicitParam(name = "userId", value = "用户ID", paramType = "path"),})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PutMapping("update-password/{userId}")
|
||||
@CheckRequestBodyAnnotation
|
||||
@ -88,13 +95,7 @@ public class UserResourceController extends DefaultBaseController {
|
||||
}
|
||||
|
||||
@ApiOperation(value = "用户分页列表", notes = "用户分页列表接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
|
||||
@ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
|
||||
@ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
|
||||
@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
|
||||
@ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
|
||||
})
|
||||
@ApiImplicitParams({@ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"), @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"), @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"), @ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"), @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("listpage")
|
||||
public SuccessResultList<List<UserDTO>> listPage(ListPage page) {
|
||||
@ -104,9 +105,7 @@ public class UserResourceController extends DefaultBaseController {
|
||||
}
|
||||
|
||||
@ApiOperation(value = "用户详情", notes = "用户详情接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "userId", value = "用户ID", paramType = "path")
|
||||
})
|
||||
@ApiImplicitParams({@ApiImplicitParam(name = "userId", value = "用户ID", paramType = "path")})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("get/{userId}")
|
||||
public UserDTO getUser(@PathVariable("userId") String userId) {
|
||||
@ -114,9 +113,7 @@ public class UserResourceController extends DefaultBaseController {
|
||||
}
|
||||
|
||||
@ApiOperation(value = "用户详情", notes = "用户详情接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "userId", value = "用户ID", paramType = "path")
|
||||
})
|
||||
@ApiImplicitParams({@ApiImplicitParam(name = "userId", value = "用户ID", paramType = "path")})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("get/username/{username}")
|
||||
public UserDTO getByUsername(@PathVariable("username") String username) {
|
||||
@ -144,9 +141,7 @@ public class UserResourceController extends DefaultBaseController {
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取密码状态", notes = "获取密码状态接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "userId", value = "用户ID", paramType = "path"),
|
||||
})
|
||||
@ApiImplicitParams({@ApiImplicitParam(name = "userId", value = "用户ID", paramType = "path"),})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("get-password-status/{userId}")
|
||||
public SuccessResultData<String> getPasswordStatus(@PathVariable("userId") String userId) throws ReflectUtil.ReflectException {
|
||||
@ -154,10 +149,7 @@ public class UserResourceController extends DefaultBaseController {
|
||||
}
|
||||
|
||||
@ApiOperation(value = "统计用户", notes = "统计用户接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "startDate", value = "开始时间", paramType = "path"),
|
||||
@ApiImplicitParam(name = "endDate", value = "结束时间", paramType = "path")
|
||||
})
|
||||
@ApiImplicitParams({@ApiImplicitParam(name = "startDate", value = "开始时间", paramType = "path"), @ApiImplicitParam(name = "endDate", value = "结束时间", paramType = "path")})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("count-date-range/{startDate}/{endDate}")
|
||||
public SuccessResultData<Integer> countDateRange(@PathVariable("startDate") String startDate, @PathVariable("endDate") String endDate) {
|
||||
@ -174,9 +166,7 @@ public class UserResourceController extends DefaultBaseController {
|
||||
}
|
||||
|
||||
@ApiOperation(value = "统计类型用户", notes = "统计类型用户接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "type", value = "用户类型", paramType = "path"),
|
||||
})
|
||||
@ApiImplicitParams({@ApiImplicitParam(name = "type", value = "用户类型", paramType = "path"),})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("count-type/{type}")
|
||||
public SuccessResultData<Integer> countType(@PathVariable("type") Integer type) {
|
||||
@ -193,9 +183,7 @@ public class UserResourceController extends DefaultBaseController {
|
||||
}
|
||||
|
||||
@ApiOperation(value = "统计错误类型用户", notes = "统计用户接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "state", value = "用户状态", paramType = "path"),
|
||||
})
|
||||
@ApiImplicitParams({@ApiImplicitParam(name = "state", value = "用户状态", paramType = "path"),})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("count-state/{state}")
|
||||
public SuccessResultData<Integer> countState(@PathVariable("state") Integer state) {
|
||||
|
@ -5,6 +5,7 @@ import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import ink.wgink.common.base.DefaultBaseService;
|
||||
import ink.wgink.exceptions.FileException;
|
||||
import ink.wgink.exceptions.ParamsException;
|
||||
import ink.wgink.exceptions.SearchException;
|
||||
import ink.wgink.exceptions.UpdateException;
|
||||
import ink.wgink.exceptions.base.SystemException;
|
||||
@ -356,6 +357,23 @@ public class UserServiceImpl extends DefaultBaseService implements IUserService
|
||||
userDao.updateLoginInfo(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String saveDefaultUserAndReturnId(String userUsername, String username, Integer userState, Integer userType) {
|
||||
if (StringUtils.isBlank(userUsername)) {
|
||||
throw new ParamsException("用户名不能为空");
|
||||
}
|
||||
if (StringUtils.isBlank(username)) {
|
||||
throw new ParamsException("昵称不能为空");
|
||||
}
|
||||
UserVO userVO = new UserVO();
|
||||
userVO.setUserUsername(userUsername);
|
||||
userVO.setUserName(username);
|
||||
userVO.setUserState(userState == null ? 0 : userState);
|
||||
userVO.setUserType(userType == null ? 3 : userType);
|
||||
userVO.setUserPassword(defaultPassword);
|
||||
return saveAndReturnId(userVO, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDTO get(String userId) {
|
||||
Map<String, Object> params = getHashMap(2);
|
||||
|
Loading…
Reference in New Issue
Block a user