Commit b6c0aea8 by hewei

Merge branch 'future-appLogin' into 'master'

Future app login

See merge request hewei/Jumeirah!6
parents 6ae677c5 a0cbabe1
package com.jumeirah.api.app.controller;
import com.jumeirah.api.app.service.AppSmsService;
import com.jumeirah.api.app.vo.SmsCode;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* APP用户 控制器
*
* @author wei
* @since 2020-09-23
*/
@Slf4j
@RestController
//@Module("api-app")
@Api(value = "短信验证码", tags = {"APP短信验证码相关"})
@RequestMapping("/app/sms/")
public class AppSmsController extends BaseController {
@Autowired
private AppSmsService appSmsService;
/**
* 获取注册验证码
*/
@GetMapping("/registerOrLoginCode")
@OperationLog(name = "获取注册或登陆的验证码", type = OperationLogType.INFO)
@ApiOperation(value = "获取注册或登陆的验证码", response = SmsCode.class, notes = "本地环境默认666666")
public ApiResult<Object> register(@RequestParam String phoneArea, @RequestParam String phone) throws Exception {
return appSmsService.registerType(phoneArea, phone);
}
}
package com.jumeirah.api.app.controller; package com.jumeirah.api.app.controller;
import com.jumeirah.api.app.service.AppUserApiService;
import com.jumeirah.common.entity.AppUser; import com.jumeirah.common.entity.AppUser;
import com.jumeirah.common.param.AppUserPageParam; import com.jumeirah.common.param.AppUserPageParam;
import com.jumeirah.common.param.LoginParam; import com.jumeirah.common.param.app.AppSmsRegisterParam;
import com.jumeirah.common.param.RegisterParam; import com.jumeirah.common.param.app.AppUserInfoParam;
import com.jumeirah.common.service.AppUserService; import com.jumeirah.common.service.AppUserService;
import com.jumeirah.common.vo.AppUserQueryVo; import com.jumeirah.common.vo.AppUserQueryVo;
import com.jumeirah.common.vo.LoginSysUserTokenVo; import com.jumeirah.common.vo.LoginSysUserTokenVo;
import com.jumeirah.common.vo.app.LoginAppUserTokenVo;
import io.geekidea.springbootplus.framework.common.api.ApiResult; import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.common.controller.BaseController; import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.core.pagination.Paging; import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.validator.groups.Add; import io.geekidea.springbootplus.framework.core.validator.groups.Add;
import io.geekidea.springbootplus.framework.core.validator.groups.Update; import io.geekidea.springbootplus.framework.core.validator.groups.Update;
import io.geekidea.springbootplus.framework.log.annotation.Module;
import io.geekidea.springbootplus.framework.log.annotation.OperationLog; import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
import io.geekidea.springbootplus.framework.log.annotation.OperationLogIgnore;
import io.geekidea.springbootplus.framework.log.enums.OperationLogType; import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -28,8 +31,6 @@ import org.springframework.web.bind.annotation.RequestHeader; ...@@ -28,8 +31,6 @@ import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
/** /**
* APP用户 控制器 * APP用户 控制器
* *
...@@ -38,7 +39,7 @@ import javax.servlet.http.HttpServletResponse; ...@@ -38,7 +39,7 @@ import javax.servlet.http.HttpServletResponse;
*/ */
@Slf4j @Slf4j
@RestController @RestController
//@Module("api-app") @Module("api-app")
@Api(value = "用户API", tags = {"APP用户相关"}) @Api(value = "用户API", tags = {"APP用户相关"})
@RequestMapping("/app/user/") @RequestMapping("/app/user/")
public class AppUserController extends BaseController { public class AppUserController extends BaseController {
...@@ -46,12 +47,27 @@ public class AppUserController extends BaseController { ...@@ -46,12 +47,27 @@ public class AppUserController extends BaseController {
@Autowired @Autowired
private AppUserService appUserService; private AppUserService appUserService;
@Autowired
private AppUserApiService appUserApiService;
/**
* 添加APP用户
*/
@PostMapping("/updateAppUserInfo")
// @OperationLog(name = "补充或修改APP用户信息", type = OperationLogType.ADD)
@ApiOperation(value = "补充或修改APP用户信息", notes = "不需要修改的字段传入null", response = ApiResult.class)
public ApiResult<Boolean> updateAppUserInfo(@RequestBody AppUserInfoParam appUserInfoParam) throws Exception {
boolean flag = appUserApiService.updateAppUser(appUserInfoParam);
return ApiResult.result(flag);
}
/** /**
* 添加APP用户 * 添加APP用户
*/ */
@PostMapping("/add") @PostMapping("/add")
@OperationLog(name = "添加APP用户", type = OperationLogType.ADD) @OperationLog(name = "添加APP用户", type = OperationLogType.ADD)
@ApiOperation(value = "添加APP用户", response = ApiResult.class) @ApiOperation(value = "添加APP用户", response = ApiResult.class)
@RequiresRoles("sys:admin")
public ApiResult<Boolean> addAppUser(@Validated(Add.class) @RequestBody AppUser appUser) throws Exception { public ApiResult<Boolean> addAppUser(@Validated(Add.class) @RequestBody AppUser appUser) throws Exception {
boolean flag = appUserService.saveAppUser(appUser); boolean flag = appUserService.saveAppUser(appUser);
return ApiResult.result(flag); return ApiResult.result(flag);
...@@ -63,6 +79,7 @@ public class AppUserController extends BaseController { ...@@ -63,6 +79,7 @@ public class AppUserController extends BaseController {
@PostMapping("/update") @PostMapping("/update")
@OperationLog(name = "修改APP用户", type = OperationLogType.UPDATE) @OperationLog(name = "修改APP用户", type = OperationLogType.UPDATE)
@ApiOperation(value = "修改APP用户", response = ApiResult.class) @ApiOperation(value = "修改APP用户", response = ApiResult.class)
@RequiresRoles("sys:admin")
public ApiResult<Boolean> updateAppUser(@Validated(Update.class) @RequestBody AppUser appUser) throws Exception { public ApiResult<Boolean> updateAppUser(@Validated(Update.class) @RequestBody AppUser appUser) throws Exception {
boolean flag = appUserService.updateAppUser(appUser); boolean flag = appUserService.updateAppUser(appUser);
return ApiResult.result(flag); return ApiResult.result(flag);
...@@ -74,6 +91,7 @@ public class AppUserController extends BaseController { ...@@ -74,6 +91,7 @@ public class AppUserController extends BaseController {
@PostMapping("/delete/{id}") @PostMapping("/delete/{id}")
@OperationLog(name = "删除APP用户", type = OperationLogType.DELETE) @OperationLog(name = "删除APP用户", type = OperationLogType.DELETE)
@ApiOperation(value = "删除APP用户", response = ApiResult.class) @ApiOperation(value = "删除APP用户", response = ApiResult.class)
@RequiresRoles("sys:admin")
public ApiResult<Boolean> deleteAppUser(@PathVariable("id") Long id) throws Exception { public ApiResult<Boolean> deleteAppUser(@PathVariable("id") Long id) throws Exception {
boolean flag = appUserService.deleteAppUser(id); boolean flag = appUserService.deleteAppUser(id);
return ApiResult.result(flag); return ApiResult.result(flag);
...@@ -85,6 +103,7 @@ public class AppUserController extends BaseController { ...@@ -85,6 +103,7 @@ public class AppUserController extends BaseController {
@GetMapping("/info/{id}") @GetMapping("/info/{id}")
@OperationLog(name = "APP用户详情", type = OperationLogType.INFO) @OperationLog(name = "APP用户详情", type = OperationLogType.INFO)
@ApiOperation(value = "APP用户详情", response = AppUserQueryVo.class) @ApiOperation(value = "APP用户详情", response = AppUserQueryVo.class)
@RequiresRoles("sys:admin")
public ApiResult<AppUserQueryVo> getAppUser(@PathVariable("id") Long id) throws Exception { public ApiResult<AppUserQueryVo> getAppUser(@PathVariable("id") Long id) throws Exception {
AppUserQueryVo appUserQueryVo = appUserService.getAppUserById(id); AppUserQueryVo appUserQueryVo = appUserService.getAppUserById(id);
return ApiResult.ok(appUserQueryVo); return ApiResult.ok(appUserQueryVo);
...@@ -96,31 +115,24 @@ public class AppUserController extends BaseController { ...@@ -96,31 +115,24 @@ public class AppUserController extends BaseController {
@PostMapping("/getPageList") @PostMapping("/getPageList")
@OperationLog(name = "APP用户分页列表", type = OperationLogType.PAGE) @OperationLog(name = "APP用户分页列表", type = OperationLogType.PAGE)
@ApiOperation(value = "APP用户分页列表", response = AppUserQueryVo.class) @ApiOperation(value = "APP用户分页列表", response = AppUserQueryVo.class)
@RequiresRoles("sys:admin")
public ApiResult<Paging<AppUserQueryVo>> getAppUserPageList(@Validated @RequestBody AppUserPageParam appUserPageParam) throws Exception { public ApiResult<Paging<AppUserQueryVo>> getAppUserPageList(@Validated @RequestBody AppUserPageParam appUserPageParam) throws Exception {
Paging<AppUserQueryVo> paging = appUserService.getAppUserPageList(appUserPageParam); Paging<AppUserQueryVo> paging = appUserService.getAppUserPageList(appUserPageParam);
return ApiResult.ok(paging); return ApiResult.ok(paging);
} }
@PostMapping("/registerOrLogin")
@PostMapping("/register") @ApiOperation(value = "手机号注册+登陆", notes = "app用户注册+登陆", response = LoginSysUserTokenVo.class)
@OperationLogIgnore public ApiResult<LoginAppUserTokenVo> registerOrLogin(@Validated @RequestBody AppSmsRegisterParam appSmsRegisterParam, @RequestHeader(required = false) String language) throws Exception {
@ApiOperation(value = "注册", notes = "web用户注册", response = LoginSysUserTokenVo.class) return appUserApiService.register(appSmsRegisterParam, language);
public ApiResult<LoginSysUserTokenVo> register(@Validated @RequestBody RegisterParam registerParam, HttpServletResponse response, @RequestHeader(required = false) String language) throws Exception {
return appUserService.register(registerParam, language);
}
@PostMapping("/login")
@OperationLogIgnore
@ApiOperation(value = "登录", notes = "系统用户登录", response = LoginSysUserTokenVo.class)
public ApiResult<LoginSysUserTokenVo> login(@Validated @RequestBody LoginParam loginParam, HttpServletResponse response, @RequestHeader(required = false) String language) throws Exception {
return appUserService.login(loginParam, language);
} }
// @PostMapping("/phoneLogin") // @PostMapping("/login")
// @OperationLogIgnore // @ApiOperation(value = "手机号登陆", notes = "app用户登录", response = LoginSysUserTokenVo.class)
// @ApiOperation(value = "手机号登陆", notes = "手机号登陆", response = LoginSysUserTokenVo.class) // public ApiResult<LoginAppUserTokenVo> login(@Validated @RequestBody AppSmsRegisterParam loginParam, @RequestHeader(required = false) String language) throws Exception {
// public ApiResult<LoginSysUserTokenVo> phoneLogin(@Validated @RequestBody RegisterParam registerParam, HttpServletResponse response, @RequestHeader(required = false) String language) throws Exception { //// return appRegisterService.login(loginParam, language);
// return appUserService.register(registerParam, language); // return null;
// } // }
} }
package com.jumeirah.api.app.service;
public interface AppRegisterService {
void regiest();
}
package com.jumeirah.api.app.service;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
public interface AppSmsService {
void deleteRegisterCode(String area, String number);
/**
* 获取注册验证码
*/
ApiResult<Object> registerType(String phoneArea, String phone);
/**
* 获取注册验证码
*/
ApiResult LoginType(String area, String number);
/**
* 校验注册验证码
*
* @param area
* @param number
* @param code
* @return
*/
boolean equalsRegisterCode(String area, String number, String code);
/**
* 校验验登陆证码
*
* @param area
* @param number
* @param code
* @return
*/
boolean equalsLoginCode(String area, String number, String code);
}
package com.jumeirah.api.app.service;
import com.jumeirah.common.param.app.AppSmsRegisterParam;
import com.jumeirah.common.param.app.AppUserInfoParam;
import com.jumeirah.common.vo.app.LoginAppUserTokenVo;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
public interface AppUserApiService {
/**
* 注册
* @param loginParam
* @param language
* @return
* @throws Exception
*/
ApiResult<LoginAppUserTokenVo> register(AppSmsRegisterParam loginParam, String language) throws Exception;
ApiResult<LoginAppUserTokenVo> login(AppSmsRegisterParam loginParam, String language) throws Exception;
/**
* 修改或补充用户信息
* @param appUserInfoParam
* @return
* @throws Exception
*/
boolean updateAppUser(AppUserInfoParam appUserInfoParam) throws Exception;
}
package com.jumeirah.api.app.service.impl;
import com.jumeirah.api.app.service.AppRegisterService;
import org.springframework.stereotype.Service;
@Service
public class AppRegisterServiceImpl implements AppRegisterService {
@Override
public void regiest() {
}
}
package com.jumeirah.api.app.service.impl;
import cn.hutool.core.util.RandomUtil;
import com.jumeirah.api.app.service.AppSmsService;
import com.jumeirah.api.app.vo.SmsCode;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.time.Duration;
import java.util.Arrays;
@Service
@Slf4j
public class AppSmsServiceImpl implements AppSmsService {
/**
* 获取当前环境
*/
@Value("${spring.profiles.active}")
private String profiles;
@Autowired
private RedisTemplate redisTemplate;
/**
* 测试环境
*/
private static final String DEV_PROFILE = "dev";
/**
* 测试环境默认短信验证码
*/
private static final String DEFAULT_DEV_SMS_CODE = "666666";
/**
* 短信验证码redis的key值
*/
private static final String SMS_REGIEST = "sms:register:%s_%s";
/**
* 短信验证码redis的key值
*/
private static final String SMS_LOGIN = "sms:login:%s_%s";
@Override
public void deleteRegisterCode(String area, String number) {
redisTemplate.delete(String.format(SMS_REGIEST, area, number));
}
@Override
public ApiResult<Object> registerType(String area, String number) {
return getSmsCodeApiResult(String.format(SMS_REGIEST, area, number), area, number);
}
private ApiResult<Object> getSmsCodeApiResult(String key, String area, String number) {
String randomCode = getRandomCode();
// 过期时间(秒)
long expire = 120L;
Duration expireDuration = Duration.ofSeconds(expire);
redisTemplate.opsForValue().set(key, randomCode, expireDuration);
SmsCode smsCode = new SmsCode();
smsCode.setSmsCode(randomCode);
log.info(area + "," + number + ":" + randomCode);
// TODO 需要补充调用短信平台发送短信代码 2020年09月30日09:48:42
return ApiResult.ok(null);
}
@Override
public ApiResult LoginType(String area, String number) {
return getSmsCodeApiResult(String.format(SMS_LOGIN, area, number), area, number);
}
@Override
public boolean equalsRegisterCode(String area, String number, String code) {
return equalsSms(SMS_REGIEST, area, number, code);
}
private boolean equalsSms(String type, String area, String number, String code) {
String formatKey = String.format(type, area, number);
Object key = redisTemplate.opsForValue().get(formatKey);
if (key == null) {
return false;
}
return String.valueOf(key).equals(code);
}
@Override
public boolean equalsLoginCode(String area, String number, String code) {
return equalsSms(SMS_LOGIN, area, number, code);
}
/**
* 生成验证码code
*
* @return
*/
String getRandomCode() {
// 如果为测试环境则生成默认
if (profiles.equals(DEV_PROFILE)) {
return DEFAULT_DEV_SMS_CODE;
} else {
return Arrays.toString(RandomUtil.randomInts(6));
}
}
}
package com.jumeirah.api.app.service.impl;
import com.jumeirah.api.app.service.AppSmsService;
import com.jumeirah.api.app.service.AppUserApiService;
import com.jumeirah.common.entity.AppUser;
import com.jumeirah.common.param.app.AppSmsRegisterParam;
import com.jumeirah.common.param.app.AppUserInfoParam;
import com.jumeirah.common.service.AppUserService;
import com.jumeirah.common.vo.app.LoginAppUserTokenVo;
import io.geekidea.springbootplus.framework.common.api.ApiCode;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class AppUserApiServiceImpl implements AppUserApiService {
@Autowired
private AppSmsService appSmsService;
@Autowired
private AppUserService appUserService;
@Override
public ApiResult<LoginAppUserTokenVo> register(AppSmsRegisterParam loginParam, String language) throws Exception {
// 校验验证码
boolean equalsRegisterCode = appSmsService.equalsRegisterCode(loginParam.getPhoneArea(), loginParam.getPhone(), loginParam.getSmsCode());
if (!equalsRegisterCode) {
return ApiResult.fail(ApiCode.FAIL, new LoginAppUserTokenVo());
}
// 删除已使用的验证码
appSmsService.deleteRegisterCode(loginParam.getPhoneArea(), loginParam.getPhone());
// 判断是否已经注册
if (appUserService.hasUserByPhoneNumer(loginParam.getPhoneArea(), loginParam.getPhone())) {
// 如果已经注册直接走登陆的代码
return appUserService.login(loginParam, language);
}
// 没注册则先保存到数据库
AppUser appUser = new AppUser();
appUser.setPhoneArea(loginParam.getPhoneArea());
appUser.setPhone(loginParam.getPhone());
boolean isDbOk = appUserService.saveAppUser(appUser);
if (!isDbOk) {
return ApiResult.fail(ApiCode.FAIL, new LoginAppUserTokenVo());
}
// 走登陆的代码
return appUserService.login(loginParam, language);
}
@Override
public ApiResult<LoginAppUserTokenVo> login(AppSmsRegisterParam loginParam, String language) throws Exception {
return null;
}
@Override
public boolean updateAppUser(AppUserInfoParam appUserInfoParam) throws Exception {
AppUser appUser = new AppUser();
BeanUtils.copyProperties(appUserInfoParam, appUser);
JwtToken jwtToken = (JwtToken) SecurityUtils.getSubject().getPrincipal();
appUser.setId(jwtToken.getUserId());
return appUserService.updateAppUser(appUser);
}
}
package com.jumeirah.api.app.vo;
import lombok.Data;
import java.io.Serializable;
@Data
public class SmsCode implements Serializable {
private String smsCode;
}
...@@ -18,7 +18,7 @@ package com.jumeirah.common.convert; ...@@ -18,7 +18,7 @@ package com.jumeirah.common.convert;
import com.jumeirah.common.entity.MerchantUser; import com.jumeirah.common.entity.MerchantUser;
import com.jumeirah.common.entity.SysUser; import com.jumeirah.common.entity.SysUser;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserVo;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
...@@ -39,9 +39,9 @@ public interface SysUserConvert { ...@@ -39,9 +39,9 @@ public interface SysUserConvert {
* @param sysUser * @param sysUser
* @return * @return
*/ */
LoginSysUserVo sysUserToLoginSysUserVo(SysUser sysUser); LoginUserVo sysUserToLoginSysUserVo(SysUser sysUser);
LoginSysUserVo merchantUserToLoginSysUserVo(MerchantUser sysUser); LoginUserVo merchantUserToLoginSysUserVo(MerchantUser sysUser);
} }
...@@ -37,6 +37,21 @@ public class AppUser extends BaseEntity { ...@@ -37,6 +37,21 @@ public class AppUser extends BaseEntity {
@ApiModelProperty("用户名") @ApiModelProperty("用户名")
private String username; private String username;
@ApiModelProperty("姓")
private String surname;
@ApiModelProperty("名")
private String name;
@ApiModelProperty("公司名")
private String companyName;
@ApiModelProperty("微信号")
private String wechat;
@ApiModelProperty("出生日期")
private String dateOfBirth;
@ApiModelProperty("昵称") @ApiModelProperty("昵称")
private String nickname; private String nickname;
......
/*
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jumeirah.common.param.app;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 登录参数
*
* @author geekidea
* @date 2019-05-15
**/
@Data
@ApiModel("登录参数")
public class AppLoginParam implements Serializable {
private static final long serialVersionUID = 2854217576695117356L;
private String area;
private String number;
@ApiModelProperty("验证码")
private String code;
}
/*
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jumeirah.common.param.app;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
/**
* 注册参数
*
* @author geekidea
* @date 2019-05-15
**/
@Data
@ApiModel("app手机验证码注册参数")
public class AppSmsRegisterParam implements Serializable {
@NotBlank(message = "请输入手机区号")
@ApiModelProperty(value = "手机区号", example = "855")
private String phoneArea;
@NotBlank(message = "请输入手机号")
@ApiModelProperty(value = "手机号", example = "081611122")
private String phone;
@ApiModelProperty(value = "短信验证码", example = "666666")
private String smsCode;
}
package com.jumeirah.common.param.app;
import io.geekidea.springbootplus.framework.common.entity.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* APP用户
*
* @author wei
* @since 2020-09-23
*/
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "AppUserInfoParam对象")
public class AppUserInfoParam extends BaseEntity {
@ApiModelProperty("姓")
private String surname;
@ApiModelProperty("名")
private String name;
@ApiModelProperty("公司名")
private String companyName;
@ApiModelProperty("微信号")
private String wechat;
@ApiModelProperty("出生日期")
private String dateOfBirth;
@ApiModelProperty("昵称")
private String nickname;
@ApiModelProperty("性别,0:女,1:男,默认1")
private Integer gender;
@ApiModelProperty("头像")
private String head;
}
...@@ -2,10 +2,9 @@ package com.jumeirah.common.service; ...@@ -2,10 +2,9 @@ package com.jumeirah.common.service;
import com.jumeirah.common.entity.AppUser; import com.jumeirah.common.entity.AppUser;
import com.jumeirah.common.param.AppUserPageParam; import com.jumeirah.common.param.AppUserPageParam;
import com.jumeirah.common.param.LoginParam; import com.jumeirah.common.param.app.AppSmsRegisterParam;
import com.jumeirah.common.param.RegisterParam;
import com.jumeirah.common.vo.AppUserQueryVo; import com.jumeirah.common.vo.AppUserQueryVo;
import com.jumeirah.common.vo.LoginSysUserTokenVo; import com.jumeirah.common.vo.app.LoginAppUserTokenVo;
import io.geekidea.springbootplus.framework.common.api.ApiResult; import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.common.service.BaseService; import io.geekidea.springbootplus.framework.common.service.BaseService;
import io.geekidea.springbootplus.framework.core.pagination.Paging; import io.geekidea.springbootplus.framework.core.pagination.Paging;
...@@ -18,12 +17,32 @@ import io.geekidea.springbootplus.framework.core.pagination.Paging; ...@@ -18,12 +17,32 @@ import io.geekidea.springbootplus.framework.core.pagination.Paging;
*/ */
public interface AppUserService extends BaseService<AppUser> { public interface AppUserService extends BaseService<AppUser> {
ApiResult<LoginSysUserTokenVo> register(RegisterParam registerParam, String language); /**
* 根据手机号判断用户是否存在
* @param phoneArea
* @param phone
* @return
*/
boolean hasUserByPhoneNumer(String phoneArea,String phone);
ApiResult<LoginSysUserTokenVo> login(LoginParam loginParam, String language); // /**
// * 注册
// *
// * @param appSmsRegisterParam
// * @param language
// * @return
// */
// ApiResult<LoginAppUserTokenVo> register(AppSmsRegisterParam appSmsRegisterParam, String language);
/**
* 登陆
*
* @param loginParam
* @param language
* @return
*/
ApiResult<LoginAppUserTokenVo> login(AppSmsRegisterParam loginParam, String language);
ApiResult<LoginSysUserTokenVo> phoneLogin(RegisterParam registerParam, String language);
/** /**
* 保存 * 保存
......
...@@ -8,11 +8,10 @@ import com.jumeirah.common.entity.AppUser; ...@@ -8,11 +8,10 @@ import com.jumeirah.common.entity.AppUser;
import com.jumeirah.common.enums.StateEnum; import com.jumeirah.common.enums.StateEnum;
import com.jumeirah.common.mapper.AppUserMapper; import com.jumeirah.common.mapper.AppUserMapper;
import com.jumeirah.common.param.AppUserPageParam; import com.jumeirah.common.param.AppUserPageParam;
import com.jumeirah.common.param.LoginParam; import com.jumeirah.common.param.app.AppSmsRegisterParam;
import com.jumeirah.common.param.RegisterParam;
import com.jumeirah.common.service.AppUserService; import com.jumeirah.common.service.AppUserService;
import com.jumeirah.common.vo.AppUserQueryVo; import com.jumeirah.common.vo.AppUserQueryVo;
import com.jumeirah.common.vo.LoginSysUserTokenVo; import com.jumeirah.common.vo.app.LoginAppUserTokenVo;
import io.geekidea.springbootplus.config.properties.JwtProperties; import io.geekidea.springbootplus.config.properties.JwtProperties;
import io.geekidea.springbootplus.config.properties.SpringBootPlusProperties; import io.geekidea.springbootplus.config.properties.SpringBootPlusProperties;
import io.geekidea.springbootplus.framework.common.api.ApiCode; import io.geekidea.springbootplus.framework.common.api.ApiCode;
...@@ -24,8 +23,7 @@ import io.geekidea.springbootplus.framework.shiro.cache.AppLoginRedisService; ...@@ -24,8 +23,7 @@ import io.geekidea.springbootplus.framework.shiro.cache.AppLoginRedisService;
import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken; import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken;
import io.geekidea.springbootplus.framework.shiro.util.JwtUtil; import io.geekidea.springbootplus.framework.shiro.util.JwtUtil;
import io.geekidea.springbootplus.framework.shiro.util.SaltUtil; import io.geekidea.springbootplus.framework.shiro.util.SaltUtil;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserVo;
import io.geekidea.springbootplus.framework.util.PasswordUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
...@@ -68,56 +66,54 @@ public class AppUserServiceImpl extends BaseServiceImpl<AppUserMapper, AppUser> ...@@ -68,56 +66,54 @@ public class AppUserServiceImpl extends BaseServiceImpl<AppUserMapper, AppUser>
private AppUserMapper appUserMapper; private AppUserMapper appUserMapper;
@Override @Override
public ApiResult<LoginSysUserTokenVo> register(RegisterParam registerParam, String language) { public boolean hasUserByPhoneNumer(String phoneArea, String phone) {
return null; Integer selectCount = appUserMapper.selectCount(new QueryWrapper<AppUser>(
new AppUser().setPhoneArea(phoneArea).setPhone(phone)
));
return selectCount > 0;
} }
@Override // @Override
public ApiResult<LoginSysUserTokenVo> login(LoginParam loginParam, String language) { // public ApiResult<LoginAppUserTokenVo> register(AppSmsRegisterParam appSmsRegisterParam, String language) {
//// JwtToken jwtToken = (JwtToken) SecurityUtils.getSubject().getPrincipal();
//
// 校验验证码 // // 校验短信验证码是否正确
// checkVerifyCode(loginParam.getVerifyToken(), loginParam.getCode()); //
// return null;
// }
String username = loginParam.getUsername(); @Override
public ApiResult<LoginAppUserTokenVo> login(AppSmsRegisterParam loginParam, String language) {
// 从数据库中获取登录用户信息 // 从数据库中获取登录用户信息
AppUser appUser = appUserMapper.selectOne(new QueryWrapper<AppUser>(new AppUser().setUsername(username))); AppUser appUser = appUserMapper.selectOne(new QueryWrapper<>(
new AppUser().setPhoneArea(loginParam.getPhoneArea()).setPhone(loginParam.getPhone()))
);
if (appUser == null) { if (appUser == null) {
log.error("登录失败,用户名或密码错误 loginParam:{}", loginParam);
log.error("登录失败,loginParam:{}", loginParam);
// throw new AuthenticationException("用户名或密码错误");
return ApiResult.fail(ApiCode.PWD_OR_USERNAME_ERROR, language); return ApiResult.fail(ApiCode.PWD_OR_USERNAME_ERROR, language);
} }
if (StateEnum.DISABLE.getCode().equals(appUser.getState())) { if (StateEnum.DISABLE.getCode().equals(appUser.getState())) {
throw new AuthenticationException("账号已禁用"); throw new AuthenticationException("账号已禁用");
} }
// 实际项目中,前端传过来的密码应先加密
// 原始密码明文:123456
// 原始密码前端加密:sha256(123456)
// 后台加密规则:sha256(sha256(123456) + salt)
String encryptPassword = PasswordUtil.encrypt(loginParam.getPassword(), appUser.getSalt());
if (!encryptPassword.equals(appUser.getPassword())) {
return ApiResult.fail(ApiCode.PWD_OR_USERNAME_ERROR, language);
}
// 将系统用户对象转换成登录用户对象 // 将系统用户对象转换成登录用户对象
LoginSysUserVo loginSysUserVo = new LoginSysUserVo(); LoginUserVo loginSysUserVo = new LoginUserVo();
loginSysUserVo.setUsername(username);
loginSysUserVo.setId(appUser.getId());
loginSysUserVo.setUsername(appUser.getId().toString());
// 获取数据库中保存的盐值 // 获取数据库中保存的盐值
String newSalt = SaltUtil.getSalt(appUser.getSalt(), jwtProperties); String newSalt = SaltUtil.getSalt(appUser.getSalt(), jwtProperties);
// 生成token字符串并返回 // 生成token字符串并返回
Long expireSecond = jwtProperties.getExpireSecond(); Long expireSecond = jwtProperties.getExpireSecond();
String token = JwtUtil.generateToken(username, newSalt, Duration.ofSeconds(expireSecond)); String token = JwtUtil.generateToken(appUser.getId().toString(), newSalt, Duration.ofSeconds(expireSecond));
log.debug("token:{}", token); log.debug("token:{}", token);
// 创建AuthenticationToken // 创建AuthenticationToken
JwtToken jwtToken = JwtToken.build(token, username, newSalt, expireSecond, "app"); JwtToken jwtToken = JwtToken.build(token, appUser.getId().toString(), appUser.getId(), newSalt, expireSecond, "app");
boolean enableShiro = springBootPlusProperties.getShiro().isEnable(); boolean enableShiro = springBootPlusProperties.getShiro().isEnable();
if (enableShiro) { if (enableShiro) {
...@@ -131,28 +127,20 @@ public class AppUserServiceImpl extends BaseServiceImpl<AppUserMapper, AppUser> ...@@ -131,28 +127,20 @@ public class AppUserServiceImpl extends BaseServiceImpl<AppUserMapper, AppUser>
// 缓存登录信息到Redis // 缓存登录信息到Redis
appLoginRedisService.cacheLoginInfo(jwtToken, loginSysUserVo); appLoginRedisService.cacheLoginInfo(jwtToken, loginSysUserVo);
log.debug("登录成功,username:{}", username); log.debug("登录成功,id:{}", appUser.getId().toString());
// 缓存登录信息到redis // 缓存登录信息到redis
String tokenSha256 = DigestUtils.sha256Hex(token); String tokenSha256 = DigestUtils.sha256Hex(token);
redisTemplate.opsForValue().set(tokenSha256, loginSysUserVo, 1, TimeUnit.DAYS); redisTemplate.opsForValue().set(tokenSha256, loginSysUserVo, 1, TimeUnit.DAYS);
// 返回token和登录用户信息对象 // 返回token和登录用户信息对象
LoginSysUserTokenVo loginSysUserTokenVo = new LoginSysUserTokenVo(); LoginAppUserTokenVo loginSysUserTokenVo = new LoginAppUserTokenVo();
loginSysUserTokenVo.setToken(token); loginSysUserTokenVo.setToken(token);
loginSysUserTokenVo.setLoginSysUserVo(loginSysUserVo); loginSysUserTokenVo.setUserId(appUser.getId());
// 设置token响应头
// response.setHeader(JwtTokenUtil.getTokenName(), loginSysUserTokenVo.getToken());
return ApiResult.ok(loginSysUserTokenVo, language); return ApiResult.ok(loginSysUserTokenVo, language);
} }
@Override
public ApiResult<LoginSysUserTokenVo> phoneLogin(RegisterParam registerParam, String language) {
return null;
}
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
......
...@@ -28,7 +28,7 @@ import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken; ...@@ -28,7 +28,7 @@ import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken;
import io.geekidea.springbootplus.framework.shiro.util.JwtTokenUtil; import io.geekidea.springbootplus.framework.shiro.util.JwtTokenUtil;
import io.geekidea.springbootplus.framework.shiro.util.JwtUtil; import io.geekidea.springbootplus.framework.shiro.util.JwtUtil;
import io.geekidea.springbootplus.framework.shiro.util.SaltUtil; import io.geekidea.springbootplus.framework.shiro.util.SaltUtil;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserVo;
import io.geekidea.springbootplus.framework.util.PasswordUtil; import io.geekidea.springbootplus.framework.util.PasswordUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
...@@ -114,7 +114,7 @@ public class MerchantUserServiceImpl extends BaseServiceImpl<MerchantUserMapper, ...@@ -114,7 +114,7 @@ public class MerchantUserServiceImpl extends BaseServiceImpl<MerchantUserMapper,
} }
// 将系统用户对象转换成登录用户对象 // 将系统用户对象转换成登录用户对象
LoginSysUserVo loginSysUserVo = SysUserConvert.INSTANCE.merchantUserToLoginSysUserVo(merchantUser); LoginUserVo loginSysUserVo = SysUserConvert.INSTANCE.merchantUserToLoginSysUserVo(merchantUser);
// // 获取部门 // // 获取部门
// SysDepartment sysDepartment = sysDepartmentService.getById(merchantUser.getDepartmentId()); // SysDepartment sysDepartment = sysDepartmentService.getById(merchantUser.getDepartmentId());
...@@ -156,7 +156,7 @@ public class MerchantUserServiceImpl extends BaseServiceImpl<MerchantUserMapper, ...@@ -156,7 +156,7 @@ public class MerchantUserServiceImpl extends BaseServiceImpl<MerchantUserMapper,
log.debug("token:{}", token); log.debug("token:{}", token);
// 创建AuthenticationToken // 创建AuthenticationToken
JwtToken jwtToken = JwtToken.build(token, username, newSalt, expireSecond, "mer"); JwtToken jwtToken = JwtToken.build(token, username,merchantUser.getId(), newSalt, expireSecond, "mer");
boolean enableShiro = springBootPlusProperties.getShiro().isEnable(); boolean enableShiro = springBootPlusProperties.getShiro().isEnable();
if (enableShiro) { if (enableShiro) {
......
/*
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jumeirah.common.service.impl; package com.jumeirah.common.service.impl;
...@@ -40,7 +25,7 @@ import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken; ...@@ -40,7 +25,7 @@ import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken;
import io.geekidea.springbootplus.framework.shiro.util.JwtTokenUtil; import io.geekidea.springbootplus.framework.shiro.util.JwtTokenUtil;
import io.geekidea.springbootplus.framework.shiro.util.JwtUtil; import io.geekidea.springbootplus.framework.shiro.util.JwtUtil;
import io.geekidea.springbootplus.framework.shiro.util.SaltUtil; import io.geekidea.springbootplus.framework.shiro.util.SaltUtil;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserVo;
import io.geekidea.springbootplus.framework.util.PasswordUtil; import io.geekidea.springbootplus.framework.util.PasswordUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -134,7 +119,7 @@ public class SysLoginServiceImpl implements SysLoginService { ...@@ -134,7 +119,7 @@ public class SysLoginServiceImpl implements SysLoginService {
} }
// 将系统用户对象转换成登录用户对象 // 将系统用户对象转换成登录用户对象
LoginSysUserVo loginSysUserVo = SysUserConvert.INSTANCE.sysUserToLoginSysUserVo(sysUser); LoginUserVo loginSysUserVo = SysUserConvert.INSTANCE.sysUserToLoginSysUserVo(sysUser);
// 获取部门 // 获取部门
SysDepartment sysDepartment = sysDepartmentService.getById(sysUser.getDepartmentId()); SysDepartment sysDepartment = sysDepartmentService.getById(sysUser.getDepartmentId());
...@@ -176,7 +161,7 @@ public class SysLoginServiceImpl implements SysLoginService { ...@@ -176,7 +161,7 @@ public class SysLoginServiceImpl implements SysLoginService {
log.debug("token:{}", token); log.debug("token:{}", token);
// 创建AuthenticationToken // 创建AuthenticationToken
JwtToken jwtToken = JwtToken.build(token, username, newSalt, expireSecond, "sys"); JwtToken jwtToken = JwtToken.build(token, username,sysUser.getId(), newSalt, expireSecond, "sys");
boolean enableShiro = springBootPlusProperties.getShiro().isEnable(); boolean enableShiro = springBootPlusProperties.getShiro().isEnable();
if (enableShiro) { if (enableShiro) {
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
package com.jumeirah.common.vo; package com.jumeirah.common.vo;
import io.geekidea.springbootplus.framework.shiro.service.LoginToken; import io.geekidea.springbootplus.framework.shiro.service.LoginToken;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserVo;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
...@@ -40,5 +40,5 @@ public class LoginSysUserTokenVo implements LoginToken { ...@@ -40,5 +40,5 @@ public class LoginSysUserTokenVo implements LoginToken {
/** /**
* 登录用户对象 * 登录用户对象
*/ */
private LoginSysUserVo loginSysUserVo; private LoginUserVo loginSysUserVo;
} }
/*
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jumeirah.common.vo.app;
import io.geekidea.springbootplus.framework.shiro.service.LoginToken;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* @author geekidea
* @date 2019-10-26
**/
@Data
@Accessors(chain = true)
@ApiModel("登录用户信息TokenVO")
public class LoginAppUserTokenVo implements LoginToken {
@ApiModelProperty("token")
private String token;
@ApiModelProperty("主键")
private Long userId;
@ApiModelProperty("用户名")
private String username;
// @ApiModelProperty("昵称")
// private String nickname;
// /**
// * 登录用户对象
// */
// private LoginUserVo loginSysUserVo;
}
...@@ -183,7 +183,10 @@ spring-boot-plus: ...@@ -183,7 +183,10 @@ spring-boot-plus:
# 权限配置 # 权限配置
anon: anon:
# 排除登录 注册 登出 # 排除登录 注册 登出
- /app/user/register,/app/user/phoneLogin,/app/user/login,/sys/login,/sys/logout,/sys/register,/merchantUser/login - /app/user/registerOrLogin,/app/user/login
- /sys/login,/sys/logout,/sys/register
- /merchantUser/login
- /app/sms/registerOrLoginCode
# 排除静态资源 # 排除静态资源
- /static/**,/templates/** - /static/**,/templates/**
# 排除Swagger # 排除Swagger
......
...@@ -34,21 +34,22 @@ public enum LanguageEnum { ...@@ -34,21 +34,22 @@ public enum LanguageEnum {
/** /**
* 获取指定语言类型(如果没有对应的语言类型,则返回文) * 获取指定语言类型(如果没有对应的语言类型,则返回文)
* *
* @param language 语言类型 * @param language 语言类型
* @return * @return
*/ */
public static String getLanguageType(String language) { public static String getLanguageType(String language) {
// 设置默认为中文
if (StringUtils.isEmpty(language)) { if (StringUtils.isEmpty(language)) {
return LANGUAGE_EN_US.language; return LANGUAGE_ZH_CN.language;
} }
for (LanguageEnum languageEnum : LanguageEnum.values()) { for (LanguageEnum languageEnum : LanguageEnum.values()) {
if (languageEnum.language.equalsIgnoreCase(language)) { if (languageEnum.language.equalsIgnoreCase(language)) {
return languageEnum.language; return languageEnum.language;
} }
} }
return LANGUAGE_EN_US.language; return LANGUAGE_ZH_CN.language;
} }
} }
...@@ -18,8 +18,8 @@ package io.geekidea.springbootplus.framework.shiro.cache; ...@@ -18,8 +18,8 @@ package io.geekidea.springbootplus.framework.shiro.cache;
import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken; import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserRedisVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserRedisVo;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserVo;
/** /**
* 登录信息Redis缓存操作服务 * 登录信息Redis缓存操作服务
...@@ -36,7 +36,7 @@ public interface AppLoginRedisService { ...@@ -36,7 +36,7 @@ public interface AppLoginRedisService {
* @param jwtToken * @param jwtToken
* @param loginSysUserVo * @param loginSysUserVo
*/ */
void cacheLoginInfo(JwtToken jwtToken, LoginSysUserVo loginSysUserVo); void cacheLoginInfo(JwtToken jwtToken, LoginUserVo loginSysUserVo);
/** /**
...@@ -54,7 +54,7 @@ public interface AppLoginRedisService { ...@@ -54,7 +54,7 @@ public interface AppLoginRedisService {
* @param username * @param username
* @return * @return
*/ */
LoginSysUserRedisVo getLoginSysUserRedisVo(String username); LoginUserRedisVo getLoginSysUserRedisVo(String username);
/** /**
* 获取登录用户对象 * 获取登录用户对象
...@@ -62,7 +62,7 @@ public interface AppLoginRedisService { ...@@ -62,7 +62,7 @@ public interface AppLoginRedisService {
* @param username * @param username
* @return * @return
*/ */
LoginSysUserVo getLoginSysUserVo(String username); LoginUserVo getLoginSysUserVo(String username);
/** /**
* 通过用户名称获取盐值 * 通过用户名称获取盐值
......
...@@ -18,8 +18,8 @@ package io.geekidea.springbootplus.framework.shiro.cache; ...@@ -18,8 +18,8 @@ package io.geekidea.springbootplus.framework.shiro.cache;
import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken; import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserRedisVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserRedisVo;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserVo;
/** /**
* 登录信息Redis缓存操作服务 * 登录信息Redis缓存操作服务
...@@ -36,7 +36,7 @@ public interface MerchantLoginRedisService { ...@@ -36,7 +36,7 @@ public interface MerchantLoginRedisService {
* @param jwtToken * @param jwtToken
* @param loginSysUserVo * @param loginSysUserVo
*/ */
void cacheLoginInfo(JwtToken jwtToken, LoginSysUserVo loginSysUserVo); void cacheLoginInfo(JwtToken jwtToken, LoginUserVo loginSysUserVo);
/** /**
...@@ -54,7 +54,7 @@ public interface MerchantLoginRedisService { ...@@ -54,7 +54,7 @@ public interface MerchantLoginRedisService {
* @param username * @param username
* @return * @return
*/ */
LoginSysUserRedisVo getLoginSysUserRedisVo(String username); LoginUserRedisVo getLoginSysUserRedisVo(String username);
/** /**
* 获取登录用户对象 * 获取登录用户对象
...@@ -62,7 +62,7 @@ public interface MerchantLoginRedisService { ...@@ -62,7 +62,7 @@ public interface MerchantLoginRedisService {
* @param username * @param username
* @return * @return
*/ */
LoginSysUserVo getLoginSysUserVo(String username); LoginUserVo getLoginSysUserVo(String username);
/** /**
* 通过用户名称获取盐值 * 通过用户名称获取盐值
......
...@@ -18,8 +18,8 @@ package io.geekidea.springbootplus.framework.shiro.cache; ...@@ -18,8 +18,8 @@ package io.geekidea.springbootplus.framework.shiro.cache;
import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken; import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserRedisVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserRedisVo;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserVo;
/** /**
* 登录信息Redis缓存操作服务 * 登录信息Redis缓存操作服务
...@@ -36,7 +36,7 @@ public interface SysLoginRedisService { ...@@ -36,7 +36,7 @@ public interface SysLoginRedisService {
* @param jwtToken * @param jwtToken
* @param loginSysUserVo * @param loginSysUserVo
*/ */
void cacheLoginInfo(JwtToken jwtToken, LoginSysUserVo loginSysUserVo); void cacheLoginInfo(JwtToken jwtToken, LoginUserVo loginSysUserVo);
/** /**
...@@ -54,7 +54,7 @@ public interface SysLoginRedisService { ...@@ -54,7 +54,7 @@ public interface SysLoginRedisService {
* @param username * @param username
* @return * @return
*/ */
LoginSysUserRedisVo getLoginSysUserRedisVo(String username); LoginUserRedisVo getLoginSysUserRedisVo(String username);
/** /**
* 获取登录用户对象 * 获取登录用户对象
...@@ -62,7 +62,7 @@ public interface SysLoginRedisService { ...@@ -62,7 +62,7 @@ public interface SysLoginRedisService {
* @param username * @param username
* @return * @return
*/ */
LoginSysUserVo getLoginSysUserVo(String username); LoginUserVo getLoginSysUserVo(String username);
/** /**
* 通过用户名称获取盐值 * 通过用户名称获取盐值
......
...@@ -9,8 +9,8 @@ import io.geekidea.springbootplus.framework.shiro.convert.LoginSysUserVoConvert; ...@@ -9,8 +9,8 @@ import io.geekidea.springbootplus.framework.shiro.convert.LoginSysUserVoConvert;
import io.geekidea.springbootplus.framework.shiro.convert.ShiroMapstructConvert; import io.geekidea.springbootplus.framework.shiro.convert.ShiroMapstructConvert;
import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken; import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken;
import io.geekidea.springbootplus.framework.shiro.vo.JwtTokenRedisVo; import io.geekidea.springbootplus.framework.shiro.vo.JwtTokenRedisVo;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserRedisVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserRedisVo;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserVo;
import io.geekidea.springbootplus.framework.util.ClientInfoUtil; import io.geekidea.springbootplus.framework.util.ClientInfoUtil;
import io.geekidea.springbootplus.framework.util.HttpServletRequestUtil; import io.geekidea.springbootplus.framework.util.HttpServletRequestUtil;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
...@@ -42,7 +42,7 @@ public class AppLoginRedisServiceImpl implements AppLoginRedisService { ...@@ -42,7 +42,7 @@ public class AppLoginRedisServiceImpl implements AppLoginRedisService {
* username:num * username:num
*/ */
@Override @Override
public void cacheLoginInfo(JwtToken jwtToken, LoginSysUserVo loginSysUserVo) { public void cacheLoginInfo(JwtToken jwtToken, LoginUserVo loginSysUserVo) {
if (jwtToken == null) { if (jwtToken == null) {
throw new IllegalArgumentException("jwtToken不能为空"); throw new IllegalArgumentException("jwtToken不能为空");
} }
...@@ -61,13 +61,14 @@ public class AppLoginRedisServiceImpl implements AppLoginRedisService { ...@@ -61,13 +61,14 @@ public class AppLoginRedisServiceImpl implements AppLoginRedisService {
// Redis缓存JWT Token信息 // Redis缓存JWT Token信息
JwtTokenRedisVo jwtTokenRedisVo = ShiroMapstructConvert.INSTANCE.jwtTokenToJwtTokenRedisVo(jwtToken); JwtTokenRedisVo jwtTokenRedisVo = ShiroMapstructConvert.INSTANCE.jwtTokenToJwtTokenRedisVo(jwtToken);
jwtTokenRedisVo.setUserId(loginSysUserVo.getId());
// 用户客户端信息 // 用户客户端信息
ClientInfo clientInfo = ClientInfoUtil.get(HttpServletRequestUtil.getRequest()); ClientInfo clientInfo = ClientInfoUtil.get(HttpServletRequestUtil.getRequest());
// Redis缓存登录用户信息 // Redis缓存登录用户信息
// 将LoginSysUserVo对象复制到LoginSysUserRedisVo,使用mapstruct进行对象属性复制 // 将LoginSysUserVo对象复制到LoginSysUserRedisVo,使用mapstruct进行对象属性复制
LoginSysUserRedisVo loginSysUserRedisVo = LoginSysUserVoConvert.INSTANCE.voToRedisVo(loginSysUserVo); LoginUserRedisVo loginSysUserRedisVo = LoginSysUserVoConvert.INSTANCE.voToRedisVo(loginSysUserVo);
loginSysUserRedisVo.setSalt(salt); loginSysUserRedisVo.setSalt(salt);
loginSysUserRedisVo.setClientInfo(clientInfo); loginSysUserRedisVo.setClientInfo(clientInfo);
...@@ -94,7 +95,7 @@ public class AppLoginRedisServiceImpl implements AppLoginRedisService { ...@@ -94,7 +95,7 @@ public class AppLoginRedisServiceImpl implements AppLoginRedisService {
@Override @Override
public void refreshLoginInfo(String oldToken, String username, JwtToken newJwtToken) { public void refreshLoginInfo(String oldToken, String username, JwtToken newJwtToken) {
// 获取缓存的登录用户信息 // 获取缓存的登录用户信息
LoginSysUserRedisVo loginSysUserRedisVo = getLoginSysUserRedisVo(username); LoginUserRedisVo loginSysUserRedisVo = getLoginSysUserRedisVo(username);
// 删除之前的token信息 // 删除之前的token信息
deleteLoginInfo(oldToken, username); deleteLoginInfo(oldToken, username);
// 缓存登录信息 // 缓存登录信息
...@@ -102,19 +103,19 @@ public class AppLoginRedisServiceImpl implements AppLoginRedisService { ...@@ -102,19 +103,19 @@ public class AppLoginRedisServiceImpl implements AppLoginRedisService {
} }
@Override @Override
public LoginSysUserRedisVo getLoginSysUserRedisVo(String username) { public LoginUserRedisVo getLoginSysUserRedisVo(String username) {
if (StringUtils.isBlank(username)) { if (StringUtils.isBlank(username)) {
throw new IllegalArgumentException("username不能为空"); throw new IllegalArgumentException("username不能为空");
} }
return (LoginSysUserRedisVo) redisTemplate.opsForValue().get(String.format(AppLoginRedisKey.LOGIN_USER, username)); return (LoginUserRedisVo) redisTemplate.opsForValue().get(String.format(AppLoginRedisKey.LOGIN_USER, username));
} }
@Override @Override
public LoginSysUserVo getLoginSysUserVo(String username) { public LoginUserVo getLoginSysUserVo(String username) {
if (StringUtils.isBlank(username)) { if (StringUtils.isBlank(username)) {
throw new IllegalArgumentException("username不能为空"); throw new IllegalArgumentException("username不能为空");
} }
LoginSysUserRedisVo userRedisVo = getLoginSysUserRedisVo(username); LoginUserRedisVo userRedisVo = getLoginSysUserRedisVo(username);
return userRedisVo; return userRedisVo;
} }
......
...@@ -9,8 +9,8 @@ import io.geekidea.springbootplus.framework.shiro.convert.LoginSysUserVoConvert; ...@@ -9,8 +9,8 @@ import io.geekidea.springbootplus.framework.shiro.convert.LoginSysUserVoConvert;
import io.geekidea.springbootplus.framework.shiro.convert.ShiroMapstructConvert; import io.geekidea.springbootplus.framework.shiro.convert.ShiroMapstructConvert;
import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken; import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken;
import io.geekidea.springbootplus.framework.shiro.vo.JwtTokenRedisVo; import io.geekidea.springbootplus.framework.shiro.vo.JwtTokenRedisVo;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserRedisVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserRedisVo;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserVo;
import io.geekidea.springbootplus.framework.util.ClientInfoUtil; import io.geekidea.springbootplus.framework.util.ClientInfoUtil;
import io.geekidea.springbootplus.framework.util.HttpServletRequestUtil; import io.geekidea.springbootplus.framework.util.HttpServletRequestUtil;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
...@@ -42,7 +42,7 @@ public class MerchantLoginRedisServiceImpl implements MerchantLoginRedisService ...@@ -42,7 +42,7 @@ public class MerchantLoginRedisServiceImpl implements MerchantLoginRedisService
* username:num * username:num
*/ */
@Override @Override
public void cacheLoginInfo(JwtToken jwtToken, LoginSysUserVo loginSysUserVo) { public void cacheLoginInfo(JwtToken jwtToken, LoginUserVo loginSysUserVo) {
if (jwtToken == null) { if (jwtToken == null) {
throw new IllegalArgumentException("jwtToken不能为空"); throw new IllegalArgumentException("jwtToken不能为空");
} }
...@@ -60,13 +60,14 @@ public class MerchantLoginRedisServiceImpl implements MerchantLoginRedisService ...@@ -60,13 +60,14 @@ public class MerchantLoginRedisServiceImpl implements MerchantLoginRedisService
// Redis缓存JWT Token信息 // Redis缓存JWT Token信息
JwtTokenRedisVo jwtTokenRedisVo = ShiroMapstructConvert.INSTANCE.jwtTokenToJwtTokenRedisVo(jwtToken); JwtTokenRedisVo jwtTokenRedisVo = ShiroMapstructConvert.INSTANCE.jwtTokenToJwtTokenRedisVo(jwtToken);
jwtTokenRedisVo.setUserId(loginSysUserVo.getId());
// 用户客户端信息 // 用户客户端信息
ClientInfo clientInfo = ClientInfoUtil.get(HttpServletRequestUtil.getRequest()); ClientInfo clientInfo = ClientInfoUtil.get(HttpServletRequestUtil.getRequest());
// Redis缓存登录用户信息 // Redis缓存登录用户信息
// 将LoginSysUserVo对象复制到LoginSysUserRedisVo,使用mapstruct进行对象属性复制 // 将LoginSysUserVo对象复制到LoginSysUserRedisVo,使用mapstruct进行对象属性复制
LoginSysUserRedisVo loginSysUserRedisVo = LoginSysUserVoConvert.INSTANCE.voToRedisVo(loginSysUserVo); LoginUserRedisVo loginSysUserRedisVo = LoginSysUserVoConvert.INSTANCE.voToRedisVo(loginSysUserVo);
loginSysUserRedisVo.setSalt(salt); loginSysUserRedisVo.setSalt(salt);
loginSysUserRedisVo.setClientInfo(clientInfo); loginSysUserRedisVo.setClientInfo(clientInfo);
...@@ -93,7 +94,7 @@ public class MerchantLoginRedisServiceImpl implements MerchantLoginRedisService ...@@ -93,7 +94,7 @@ public class MerchantLoginRedisServiceImpl implements MerchantLoginRedisService
@Override @Override
public void refreshLoginInfo(String oldToken, String username, JwtToken newJwtToken) { public void refreshLoginInfo(String oldToken, String username, JwtToken newJwtToken) {
// 获取缓存的登录用户信息 // 获取缓存的登录用户信息
LoginSysUserRedisVo loginSysUserRedisVo = getLoginSysUserRedisVo(username); LoginUserRedisVo loginSysUserRedisVo = getLoginSysUserRedisVo(username);
// 删除之前的token信息 // 删除之前的token信息
deleteLoginInfo(oldToken, username); deleteLoginInfo(oldToken, username);
// 缓存登录信息 // 缓存登录信息
...@@ -101,19 +102,19 @@ public class MerchantLoginRedisServiceImpl implements MerchantLoginRedisService ...@@ -101,19 +102,19 @@ public class MerchantLoginRedisServiceImpl implements MerchantLoginRedisService
} }
@Override @Override
public LoginSysUserRedisVo getLoginSysUserRedisVo(String username) { public LoginUserRedisVo getLoginSysUserRedisVo(String username) {
if (StringUtils.isBlank(username)) { if (StringUtils.isBlank(username)) {
throw new IllegalArgumentException("username不能为空"); throw new IllegalArgumentException("username不能为空");
} }
return (LoginSysUserRedisVo) redisTemplate.opsForValue().get(String.format(MerchantLoginRedisKey.LOGIN_USER, username)); return (LoginUserRedisVo) redisTemplate.opsForValue().get(String.format(MerchantLoginRedisKey.LOGIN_USER, username));
} }
@Override @Override
public LoginSysUserVo getLoginSysUserVo(String username) { public LoginUserVo getLoginSysUserVo(String username) {
if (StringUtils.isBlank(username)) { if (StringUtils.isBlank(username)) {
throw new IllegalArgumentException("username不能为空"); throw new IllegalArgumentException("username不能为空");
} }
LoginSysUserRedisVo userRedisVo = getLoginSysUserRedisVo(username); LoginUserRedisVo userRedisVo = getLoginSysUserRedisVo(username);
return userRedisVo; return userRedisVo;
} }
......
...@@ -25,8 +25,8 @@ import io.geekidea.springbootplus.framework.shiro.convert.LoginSysUserVoConvert; ...@@ -25,8 +25,8 @@ import io.geekidea.springbootplus.framework.shiro.convert.LoginSysUserVoConvert;
import io.geekidea.springbootplus.framework.shiro.convert.ShiroMapstructConvert; import io.geekidea.springbootplus.framework.shiro.convert.ShiroMapstructConvert;
import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken; import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken;
import io.geekidea.springbootplus.framework.shiro.vo.JwtTokenRedisVo; import io.geekidea.springbootplus.framework.shiro.vo.JwtTokenRedisVo;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserRedisVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserRedisVo;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserVo;
import io.geekidea.springbootplus.framework.util.ClientInfoUtil; import io.geekidea.springbootplus.framework.util.ClientInfoUtil;
import io.geekidea.springbootplus.framework.util.HttpServletRequestUtil; import io.geekidea.springbootplus.framework.util.HttpServletRequestUtil;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
...@@ -65,7 +65,7 @@ public class SysLoginRedisServiceImpl implements SysLoginRedisService { ...@@ -65,7 +65,7 @@ public class SysLoginRedisServiceImpl implements SysLoginRedisService {
* username:num * username:num
*/ */
@Override @Override
public void cacheLoginInfo(JwtToken jwtToken, LoginSysUserVo loginSysUserVo) { public void cacheLoginInfo(JwtToken jwtToken, LoginUserVo loginSysUserVo) {
if (jwtToken == null) { if (jwtToken == null) {
throw new IllegalArgumentException("jwtToken不能为空"); throw new IllegalArgumentException("jwtToken不能为空");
} }
...@@ -84,12 +84,13 @@ public class SysLoginRedisServiceImpl implements SysLoginRedisService { ...@@ -84,12 +84,13 @@ public class SysLoginRedisServiceImpl implements SysLoginRedisService {
// Redis缓存JWT Token信息 // Redis缓存JWT Token信息
JwtTokenRedisVo jwtTokenRedisVo = ShiroMapstructConvert.INSTANCE.jwtTokenToJwtTokenRedisVo(jwtToken); JwtTokenRedisVo jwtTokenRedisVo = ShiroMapstructConvert.INSTANCE.jwtTokenToJwtTokenRedisVo(jwtToken);
jwtTokenRedisVo.setUserId(loginSysUserVo.getId());
// 用户客户端信息 // 用户客户端信息
ClientInfo clientInfo = ClientInfoUtil.get(HttpServletRequestUtil.getRequest()); ClientInfo clientInfo = ClientInfoUtil.get(HttpServletRequestUtil.getRequest());
// Redis缓存登录用户信息 // Redis缓存登录用户信息
// 将LoginSysUserVo对象复制到LoginSysUserRedisVo,使用mapstruct进行对象属性复制 // 将LoginSysUserVo对象复制到LoginSysUserRedisVo,使用mapstruct进行对象属性复制
LoginSysUserRedisVo loginSysUserRedisVo = LoginSysUserVoConvert.INSTANCE.voToRedisVo(loginSysUserVo); LoginUserRedisVo loginSysUserRedisVo = LoginSysUserVoConvert.INSTANCE.voToRedisVo(loginSysUserVo);
loginSysUserRedisVo.setSalt(salt); loginSysUserRedisVo.setSalt(salt);
loginSysUserRedisVo.setClientInfo(clientInfo); loginSysUserRedisVo.setClientInfo(clientInfo);
...@@ -116,7 +117,7 @@ public class SysLoginRedisServiceImpl implements SysLoginRedisService { ...@@ -116,7 +117,7 @@ public class SysLoginRedisServiceImpl implements SysLoginRedisService {
@Override @Override
public void refreshLoginInfo(String oldToken, String username, JwtToken newJwtToken) { public void refreshLoginInfo(String oldToken, String username, JwtToken newJwtToken) {
// 获取缓存的登录用户信息 // 获取缓存的登录用户信息
LoginSysUserRedisVo loginSysUserRedisVo = getLoginSysUserRedisVo(username); LoginUserRedisVo loginSysUserRedisVo = getLoginSysUserRedisVo(username);
// 删除之前的token信息 // 删除之前的token信息
deleteLoginInfo(oldToken, username); deleteLoginInfo(oldToken, username);
// 缓存登录信息 // 缓存登录信息
...@@ -124,19 +125,19 @@ public class SysLoginRedisServiceImpl implements SysLoginRedisService { ...@@ -124,19 +125,19 @@ public class SysLoginRedisServiceImpl implements SysLoginRedisService {
} }
@Override @Override
public LoginSysUserRedisVo getLoginSysUserRedisVo(String username) { public LoginUserRedisVo getLoginSysUserRedisVo(String username) {
if (StringUtils.isBlank(username)) { if (StringUtils.isBlank(username)) {
throw new IllegalArgumentException("username不能为空"); throw new IllegalArgumentException("username不能为空");
} }
return (LoginSysUserRedisVo) redisTemplate.opsForValue().get(String.format(SysLoginRedisKey.LOGIN_USER, username)); return (LoginUserRedisVo) redisTemplate.opsForValue().get(String.format(SysLoginRedisKey.LOGIN_USER, username));
} }
@Override @Override
public LoginSysUserVo getLoginSysUserVo(String username) { public LoginUserVo getLoginSysUserVo(String username) {
if (StringUtils.isBlank(username)) { if (StringUtils.isBlank(username)) {
throw new IllegalArgumentException("username不能为空"); throw new IllegalArgumentException("username不能为空");
} }
LoginSysUserRedisVo userRedisVo = getLoginSysUserRedisVo(username); LoginUserRedisVo userRedisVo = getLoginSysUserRedisVo(username);
return userRedisVo; return userRedisVo;
} }
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
package io.geekidea.springbootplus.framework.shiro.convert; package io.geekidea.springbootplus.framework.shiro.convert;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserRedisVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserRedisVo;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserVo;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
...@@ -38,6 +38,6 @@ public interface LoginSysUserVoConvert { ...@@ -38,6 +38,6 @@ public interface LoginSysUserVoConvert {
* @param loginSysUserVo * @param loginSysUserVo
* @return * @return
*/ */
LoginSysUserRedisVo voToRedisVo(LoginSysUserVo loginSysUserVo); LoginUserRedisVo voToRedisVo(LoginUserVo loginSysUserVo);
} }
...@@ -95,6 +95,12 @@ public class JwtFilter extends AuthenticatingFilter { ...@@ -95,6 +95,12 @@ public class JwtFilter extends AuthenticatingFilter {
} }
} }
JwtTokenRedisVo jwt = (JwtTokenRedisVo) jwtTokenRedisVo;
if (jwt == null) {
throw new AuthenticationException("Redis Token不存在,token:" + token);
}
String username = JwtUtil.getUsername(token); String username = JwtUtil.getUsername(token);
String salt; String salt;
...@@ -103,8 +109,8 @@ public class JwtFilter extends AuthenticatingFilter { ...@@ -103,8 +109,8 @@ public class JwtFilter extends AuthenticatingFilter {
} else { } else {
salt = jwtProperties.getSecret(); salt = jwtProperties.getSecret();
} }
JwtTokenRedisVo jwt = (JwtTokenRedisVo) jwtTokenRedisVo;
return JwtToken.build(token, username, salt, jwtProperties.getExpireSecond(), jwt.getType()); return JwtToken.build(token, username, jwt.getUserId(), salt, jwtProperties.getExpireSecond(), jwt.getType());
} }
/** /**
......
...@@ -43,6 +43,12 @@ public class JwtToken implements HostAuthenticationToken { ...@@ -43,6 +43,12 @@ public class JwtToken implements HostAuthenticationToken {
* 登录ip * 登录ip
*/ */
private String host; private String host;
/**
* 登录用户ID
*/
private Long userId;
/** /**
* 登录用户名称 * 登录用户名称
*/ */
...@@ -72,12 +78,13 @@ public class JwtToken implements HostAuthenticationToken { ...@@ -72,12 +78,13 @@ public class JwtToken implements HostAuthenticationToken {
private String credentials; private String credentials;
public static JwtToken build(String token, String username, String salt, long expireSecond, String type) { public static JwtToken build(String token, String username,Long userId, String salt, long expireSecond, String type) {
DecodedJWT decodedJwt = JwtUtil.getJwtInfo(token); DecodedJWT decodedJwt = JwtUtil.getJwtInfo(token);
Date createDate = decodedJwt.getIssuedAt(); Date createDate = decodedJwt.getIssuedAt();
Date expireDate = decodedJwt.getExpiresAt(); Date expireDate = decodedJwt.getExpiresAt();
return new JwtToken() return new JwtToken()
.setUsername(username) .setUsername(username)
.setUserId(userId)
.setToken(token) .setToken(token)
.setHost(IpUtil.getRequestIp()) .setHost(IpUtil.getRequestIp())
.setSalt(salt) .setSalt(salt)
......
...@@ -18,7 +18,7 @@ package io.geekidea.springbootplus.framework.shiro.jwt.realm; ...@@ -18,7 +18,7 @@ package io.geekidea.springbootplus.framework.shiro.jwt.realm;
import io.geekidea.springbootplus.framework.shiro.cache.MerchantLoginRedisService; import io.geekidea.springbootplus.framework.shiro.cache.MerchantLoginRedisService;
import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken; import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserRedisVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserRedisVo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.SetUtils; import org.apache.commons.collections4.SetUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -73,7 +73,7 @@ public class JwtRealmMerchant extends AuthorizingRealm { ...@@ -73,7 +73,7 @@ public class JwtRealmMerchant extends AuthorizingRealm {
// 获取username // 获取username
String username = jwtToken.getUsername(); String username = jwtToken.getUsername();
// 获取登录用户角色权限信息 // 获取登录用户角色权限信息
LoginSysUserRedisVo loginSysUserRedisVo = merchantLoginRedisService.getLoginSysUserRedisVo(username); LoginUserRedisVo loginSysUserRedisVo = merchantLoginRedisService.getLoginSysUserRedisVo(username);
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo(); SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
// 设置角色 // 设置角色
authorizationInfo.setRoles(SetUtils.hashSet(loginSysUserRedisVo.getRoleCode())); authorizationInfo.setRoles(SetUtils.hashSet(loginSysUserRedisVo.getRoleCode()));
......
...@@ -18,7 +18,7 @@ package io.geekidea.springbootplus.framework.shiro.jwt.realm; ...@@ -18,7 +18,7 @@ package io.geekidea.springbootplus.framework.shiro.jwt.realm;
import io.geekidea.springbootplus.framework.shiro.cache.SysLoginRedisService; import io.geekidea.springbootplus.framework.shiro.cache.SysLoginRedisService;
import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken; import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserRedisVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserRedisVo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.SetUtils; import org.apache.commons.collections4.SetUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -69,7 +69,7 @@ public class JwtRealmSystem extends AuthorizingRealm { ...@@ -69,7 +69,7 @@ public class JwtRealmSystem extends AuthorizingRealm {
// 获取username // 获取username
String username = jwtToken.getUsername(); String username = jwtToken.getUsername();
// 获取登录用户角色权限信息 // 获取登录用户角色权限信息
LoginSysUserRedisVo loginSysUserRedisVo = sysLoginRedisService.getLoginSysUserRedisVo(username); LoginUserRedisVo loginSysUserRedisVo = sysLoginRedisService.getLoginSysUserRedisVo(username);
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo(); SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
// 设置角色 // 设置角色
......
...@@ -103,7 +103,7 @@ public class ShiroLoginServiceImpl implements ShiroLoginService { ...@@ -103,7 +103,7 @@ public class ShiroLoginServiceImpl implements ShiroLoginService {
// 生成新token字符串 // 生成新token字符串
String newToken = JwtUtil.generateToken(username, salt, Duration.ofSeconds(expireSecond)); String newToken = JwtUtil.generateToken(username, salt, Duration.ofSeconds(expireSecond));
// 生成新JwtToken对象 // 生成新JwtToken对象
JwtToken newJwtToken = JwtToken.build(newToken, username, salt, expireSecond, jwtToken.getType()); JwtToken newJwtToken = JwtToken.build(newToken, username,jwtToken.getUserId(), salt, expireSecond, jwtToken.getType());
// 更新redis缓存 // 更新redis缓存
sysLoginRedisService.refreshLoginInfo(token, username, newJwtToken); sysLoginRedisService.refreshLoginInfo(token, username, newJwtToken);
log.debug("刷新token成功,原token:{},新token:{}", token, newToken); log.debug("刷新token成功,原token:{},新token:{}", token, newToken);
......
...@@ -39,6 +39,12 @@ public class JwtTokenRedisVo implements Serializable { ...@@ -39,6 +39,12 @@ public class JwtTokenRedisVo implements Serializable {
* 登录ip * 登录ip
*/ */
private String host; private String host;
/**
* 登录用户ID
*/
private Long userId;
/** /**
* 登录用户名称 * 登录用户名称
*/ */
......
...@@ -30,7 +30,7 @@ import lombok.experimental.Accessors; ...@@ -30,7 +30,7 @@ import lombok.experimental.Accessors;
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
public class LoginSysUserRedisVo extends LoginSysUserVo { public class LoginUserRedisVo extends LoginUserVo {
private static final long serialVersionUID = -3858850188055605806L; private static final long serialVersionUID = -3858850188055605806L;
......
...@@ -33,7 +33,7 @@ import java.util.Set; ...@@ -33,7 +33,7 @@ import java.util.Set;
**/ **/
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
public class LoginSysUserVo implements Serializable { public class LoginUserVo implements Serializable {
private static final long serialVersionUID = -1758338570596088158L; private static final long serialVersionUID = -1758338570596088158L;
......
...@@ -18,7 +18,7 @@ package io.geekidea.springbootplus.framework.util; ...@@ -18,7 +18,7 @@ package io.geekidea.springbootplus.framework.util;
import io.geekidea.springbootplus.framework.shiro.util.JwtTokenUtil; import io.geekidea.springbootplus.framework.shiro.util.JwtTokenUtil;
import io.geekidea.springbootplus.framework.shiro.util.JwtUtil; import io.geekidea.springbootplus.framework.shiro.util.JwtUtil;
import io.geekidea.springbootplus.framework.shiro.vo.LoginSysUserRedisVo; import io.geekidea.springbootplus.framework.shiro.vo.LoginUserRedisVo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
...@@ -47,7 +47,7 @@ public class LoginUtil { ...@@ -47,7 +47,7 @@ public class LoginUtil {
* *
* @return * @return
*/ */
public static LoginSysUserRedisVo getLoginSysUserRedisVo() { public static LoginUserRedisVo getLoginSysUserRedisVo() {
// 获取当前登录用户 // 获取当前登录用户
String token = JwtTokenUtil.getToken(); String token = JwtTokenUtil.getToken();
String username = JwtUtil.getUsername(token); String username = JwtUtil.getUsername(token);
...@@ -56,7 +56,7 @@ public class LoginUtil { ...@@ -56,7 +56,7 @@ public class LoginUtil {
} }
// return (LoginSysUserRedisVo) redisTemplate.opsForValue().get(String.format(CommonRedisKey.LOGIN_USER, username)); // return (LoginSysUserRedisVo) redisTemplate.opsForValue().get(String.format(CommonRedisKey.LOGIN_USER, username));
LoginSysUserRedisVo loginSysUserRedisVo = new LoginSysUserRedisVo(); LoginUserRedisVo loginSysUserRedisVo = new LoginUserRedisVo();
loginSysUserRedisVo.setUsername(username); loginSysUserRedisVo.setUsername(username);
return loginSysUserRedisVo; return loginSysUserRedisVo;
} }
...@@ -67,7 +67,7 @@ public class LoginUtil { ...@@ -67,7 +67,7 @@ public class LoginUtil {
* @return * @return
*/ */
public static Long getUserId() { public static Long getUserId() {
LoginSysUserRedisVo loginSysUserRedisVo = getLoginSysUserRedisVo(); LoginUserRedisVo loginSysUserRedisVo = getLoginSysUserRedisVo();
if (loginSysUserRedisVo == null) { if (loginSysUserRedisVo == null) {
return null; return null;
} }
...@@ -80,7 +80,7 @@ public class LoginUtil { ...@@ -80,7 +80,7 @@ public class LoginUtil {
* @return * @return
*/ */
public static String getUsername() { public static String getUsername() {
LoginSysUserRedisVo loginSysUserRedisVo = getLoginSysUserRedisVo(); LoginUserRedisVo loginSysUserRedisVo = getLoginSysUserRedisVo();
if (loginSysUserRedisVo == null) { if (loginSysUserRedisVo == null) {
return null; return null;
} }
......
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