Compare commits

...

4 Commits

Author SHA1 Message Date
wuy d27f7f500e 修复shiro2.0.3组件bug 2020-04-14 12:18:50 +08:00
wuy 4d36d8aefe 修复shiro2.0.3组件bug 2020-02-21 23:10:40 +08:00
wuy 0b5c8d6633 Merge tag '2.0.3' of https://github.com/dibo-software/diboot-v2 into 2.0.3 2020-02-20 17:01:14 +08:00
Zhaoyang 12f38db53a 优化文档备案链接 2019-12-12 09:59:18 +08:00
16 changed files with 188 additions and 53 deletions

View File

@ -3,8 +3,10 @@ buildscript {
springBootVersion = '2.2.1.RELEASE'
}
repositories {
mavenLocal() //maven库
// mavenLocal() //maven库
maven { url 'http://maven.diboot.com/repository/diboot' }
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
@ -29,7 +31,8 @@ subprojects {
[compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8'
repositories {
mavenLocal() //maven库
// mavenLocal() //maven库
maven { url 'http://maven.diboot.com/repository/diboot' }
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
}
ext {//
@ -42,7 +45,7 @@ subprojects {
}
dependencies {
// Gradle 5.0使
// annotationProcessor("org.projectlombok:lombok:$lombokVersion")
annotationProcessor("org.projectlombok:lombok:$lombokVersion")
//gradle 5.0使
compileOnly("org.projectlombok:lombok:$lombokVersion")

View File

@ -56,7 +56,7 @@
</div>
<p class="copy-right">© 2015-2020 <a href="http://www.dibo.ltd">苏州帝博信息技术有限公司</a>
<br>
<a class="ba-a" href="http://www.beian.miit.gov.cn/">
<a class="ba-a" href="http://www.beian.miit.gov.cn/" target="_blank">
<u>
苏ICP备15013001号
</u>

View File

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
import com.diboot.core.entity.BaseEntity;
import com.diboot.shiro.entity.SysUser;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
/***
* @author Wangyl
@ -15,13 +16,57 @@ public class WxMpMember extends BaseEntity {
private static final long serialVersionUID = -106928701430810778L;
@TableField
private String openid;
@TableField("openid")
private String openId;
@TableField
private Boolean subscribe;
@TableField
private String nickname;
/**
* 绑定用户的认证
* 性别描述信息未知等.
*/
@TableField
private String sexDesc;
/**
* 性别表示12等数字.
*/
@TableField
private Integer sex;
@TableField
private String language;
@TableField
private String city;
@TableField
private String province;
@TableField
private String country;
@TableField
private String headImgUrl;
@TableField
private String unionId;
@TableField
private String remark;
@TableField
private Integer groupId;
/**
* subscribe_scene 返回用户关注的渠道来源.
* ADD_SCENE_SEARCH 公众号搜索ADD_SCENE_ACCOUNT_MIGRATION 公众号迁移ADD_SCENE_PROFILE_CARD 名片分享ADD_SCENE_QR_CODE 扫描二维码ADD_SCENEPROFILE LINK 图文页内名称点击ADD_SCENE_PROFILE_ITEM 图文页右上角菜单ADD_SCENE_PAID 支付后关注ADD_SCENE_OTHERS 其他
*/
@TableField
private String subscribeScene;
@Autowired
private Long sysUserId;
@TableField(exist = false)

View File

@ -1,6 +1,5 @@
package com.diboot.shiro.wx.mp.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.diboot.core.util.V;
import com.diboot.shiro.config.AuthType;
@ -8,8 +7,6 @@ import com.diboot.shiro.entity.SysUser;
import com.diboot.shiro.jwt.BaseJwtAuthenticationToken;
import com.diboot.shiro.service.AuthWayService;
import com.diboot.shiro.service.SysUserService;
import com.diboot.shiro.wx.mp.entity.WxMpMember;
import com.diboot.shiro.wx.mp.service.WxMpMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -24,9 +21,6 @@ import java.util.List;
@Service
public class WxMpAuthWayServiceImpl implements AuthWayService {
@Autowired
private WxMpMemberService wxMpMemberService;
@Autowired
private SysUserService sysUserService;
@ -46,14 +40,16 @@ public class WxMpAuthWayServiceImpl implements AuthWayService {
@Override
public SysUser getUser() {
LambdaQueryWrapper<WxMpMember> query = Wrappers.<WxMpMember>lambdaQuery()
.eq(WxMpMember::getOpenid, token.getAccount());
List<WxMpMember> wxMpMemberList = wxMpMemberService.getEntityList(query);
if (V.isEmpty(wxMpMemberList)){
//查看绑定的账户
List<SysUser> sysUserList = sysUserService.getEntityList(
Wrappers.<SysUser>lambdaQuery()
.eq(SysUser::getOpenid, token.getAccount())
.eq(SysUser::getUserType, token.getIUserType().getType())
);
if (V.isEmpty(sysUserList)) {
return null;
}
//查看绑定的账户
return sysUserService.getEntity(wxMpMemberList.get(0).getSysUserId());
return sysUserList.get(0);
}
@Override

View File

@ -1,6 +1,7 @@
dependencies {
compile project(":diboot-core")
compile 'com.diboot:diboot-core-spring-boot-starter:2.0.3-RC1'
// compile("com.diboot:diboot-core-spring-boot-starter:2.0.3-RC3")
compile("org.apache.shiro:shiro-spring:1.4.1")
compile("org.aspectj:aspectjweaver")
@ -9,6 +10,10 @@ dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
group 'com.diboot'
version '2.0.3'
apply plugin: 'idea'
jar.enabled = true
sourceSets {
main {

View File

@ -15,7 +15,8 @@ public enum AuthType {
USERNAME_PASSWORD(1, true, "账号密码"),
WX_MP(2, false, "公众号"),
WX_CP(3, false, "企业微信");
WX_CP(3, false, "企业微信"),
WX_USERNAME_NO_PASSWORD(4, false, "微信绑定,用户免密登录"),;
private int code;
private boolean requirePassword;

View File

@ -54,7 +54,7 @@ public class PermissionController extends BaseCrudRestController {
@GetMapping("/list")
@AuthorizationWrapper(value = @RequiresPermissions("list"), name = "列表")
public JsonResult getVOList(PermissionDto permissionDto, Pagination pagination, HttpServletRequest request) throws Exception{
QueryWrapper<PermissionDto> queryWrapper = super.buildQueryWrapper(permissionDto, request);
QueryWrapper<PermissionDto> queryWrapper = super.buildQueryWrapper(permissionDto);
// 查询当前页的Entity主表数据
List<Permission> entityList = permissionService.getPermissionList(queryWrapper, pagination);
return new JsonResult(Status.OK, entityList).bindPagination(pagination);
@ -81,13 +81,13 @@ public class PermissionController extends BaseCrudRestController {
*/
@PostMapping("/")
@AuthorizationWrapper(value = @RequiresPermissions("create"), name = "新建")
public JsonResult createEntity(@ModelAttribute PermissionVO viewObject, HttpServletRequest request)
public JsonResult createEntity(@ModelAttribute PermissionVO viewObject, HttpServletRequest request, BindingResult result)
throws Exception{
// 转换
Permission entity = BeanUtils.convert(viewObject, Permission.class);
// 创建
entity.setApplication(systemParamConfig.getApplication());
return super.createEntity(entity, request);
return super.createEntity(entity, result);
}
/***
@ -99,9 +99,9 @@ public class PermissionController extends BaseCrudRestController {
@PutMapping("/{id}")
@AuthorizationWrapper(value = @RequiresPermissions("update"), name = "更新")
public JsonResult updateModel(@PathVariable("id")Long id, @ModelAttribute Permission entity,
HttpServletRequest request) throws Exception{
HttpServletRequest request, BindingResult result) throws Exception{
entity.setApplication(systemParamConfig.getApplication());
return super.updateEntity(id, entity, request);
return super.updateEntity(entity, result);
}
/***
@ -113,7 +113,7 @@ public class PermissionController extends BaseCrudRestController {
@DeleteMapping("/{id}")
@AuthorizationWrapper(value = @RequiresPermissions("delete"), name = "删除")
public JsonResult deleteModel(@PathVariable("id")Long id, HttpServletRequest request) throws Exception{
return super.deleteEntity(id, request);
return super.deleteEntity(id);
}
@Override

View File

@ -62,7 +62,7 @@ public class RoleController extends BaseCrudRestController {
@GetMapping("/list")
@AuthorizationWrapper(value = @RequiresPermissions("list"), name = "列表")
public JsonResult getVOList(RoleDto roleDto, Pagination pagination, HttpServletRequest request) throws Exception{
QueryWrapper<RoleDto> queryWrapper = super.buildQueryWrapper(roleDto, request);
QueryWrapper<RoleDto> queryWrapper = super.buildQueryWrapper(roleDto);
// 获取结果
List<RoleVO> voList = roleService.getRoleList(queryWrapper, pagination);
// 返回结果
@ -92,10 +92,6 @@ public class RoleController extends BaseCrudRestController {
@AuthorizationWrapper(value = @RequiresPermissions("update"), name = "更新")
public JsonResult updateModel(@PathVariable("id")Long id, @RequestBody Role entity, BindingResult result,
HttpServletRequest request) throws Exception{
// Model属性值验证结果
if(result.hasErrors()) {
return new JsonResult(Status.FAIL_INVALID_PARAM, V.getBindingError(result));
}
entity.setId(id);
roleService.updateRole(entity);
return new JsonResult(Status.OK);

View File

@ -35,6 +35,9 @@ public class Role extends BaseEntity {
@TableField
private String userType;
@TableField
private Long businessId;
@TableField(exist = false)
private List<Permission> permissionList;

View File

@ -73,6 +73,12 @@ public class SysUser extends BaseEntity {
@TableField
private String comment;
@TableField
private Long wxMpMemberId;
@TableField
private String openid;
@TableField(exist = false)
private List<Role> roleList;

View File

@ -12,8 +12,8 @@
<if test="ew.roleId">
AND role_id = #{ew.roleId}
</if>
<if test="ew.permission_id">
AND user_type = #{ew.userType}
<if test="ew.permissionId">
AND permission_id = #{ew.permissionId}
</if>
</when>
<otherwise>

View File

@ -51,7 +51,7 @@ public class RolePermissionServiceImpl extends BaseServiceImpl<RolePermissionMap
else if (entity.isDeleted()){
Map<String, Object> criteria = new HashMap(){{
put("roleId", entity.getRoleId());
put("permissionId", entity.getId());
put("permissionId", entity.getPermissionId());
}};
deletePhysics(criteria);
}

View File

@ -317,7 +317,7 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, Role> implement
role.getPermissionList()
.stream()
.forEach(permission -> {
if (!dbPermissionIdBuffer.toString().contains(S.join("_", role.getId(), "_"))) {
if (!dbPermissionIdBuffer.toString().contains(S.join("_", permission.getId(), "_"))) {
RolePermission entity = new RolePermission();
entity.setRoleId(role.getId());
entity.setPermissionId(permission.getId());

View File

@ -147,10 +147,12 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
put("userId", sysUser.getId());
put("userType", iUserType.getType());
}};
if (!userRoleService.deletePhysics(criteria)) {
throw new ShiroCustomException(Status.FAIL_VALIDATION, "删除用户失败!");
try {
userRoleService.deletePhysics(criteria);
} catch (Exception e) {
log.error("删除用户绑定角色失败!");
}
return true;
}

View File

@ -0,0 +1,80 @@
package com.diboot.shiro.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.diboot.core.util.V;
import com.diboot.shiro.config.AuthType;
import com.diboot.shiro.entity.SysUser;
import com.diboot.shiro.jwt.BaseJwtAuthenticationToken;
import com.diboot.shiro.service.AuthWayService;
import com.diboot.shiro.service.SysUserService;
import com.diboot.shiro.util.AuthHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/***
* 用户名无密码认证实现
* @author Yangzhao
* @version v2.0
* @date 2019/6/6
*/
@Service
public class UsernameNoPasswordAuthWayServiceImpl implements AuthWayService {
private final Logger logger = LoggerFactory.getLogger(UsernameNoPasswordAuthWayServiceImpl.class);
@Autowired
private SysUserService sysUserService;
private AuthType authType = AuthType.WX_USERNAME_NO_PASSWORD;
private BaseJwtAuthenticationToken token;
@Override
public AuthType authType() {
return authType;
}
@Override
public void initByToken(BaseJwtAuthenticationToken token) {
this.token = token;
}
@Override
public SysUser getUser() {
logger.debug("【获取用户】==>当前登陆用户类型 - {}- 账号{}", token.getIUserType().getType(), token.getAccount());
LambdaQueryWrapper<SysUser> query = Wrappers.<SysUser>lambdaQuery()
.eq(SysUser::getUsername, token.getAccount())
.eq(SysUser::getUserType, token.getIUserType().getType());
List<SysUser> userList = sysUserService.getEntityList(query);
if (V.isEmpty(userList)){
return null;
}
return userList.get(0);
}
@Override
public boolean requirePassword() {
return authType.isRequirePassword();
}
@Override
public boolean isPasswordMatch() {
return true;
}
@Override
public boolean isPreliminaryVerified() {
return false;
}
@Override
public Long getExpiresInMinutes() {
return null;
}
}

View File

@ -22,13 +22,11 @@ import java.util.Date;
public class JwtHelper {
private static final Logger logger = LoggerFactory.getLogger(JwtHelper.class);
private static final String ISSUER = V.notEmpty(BaseConfig.getProperty("diboot.shiro.jwt.issuer")) ? BaseConfig.getProperty("diboot.shiro.jwt.issuer") : "diboot.com";
private static final String AUTH_HEADER = V.notEmpty(BaseConfig.getProperty("diboot.shiro.jwt.authz.header.key")) ? BaseConfig.getProperty("diboot.shiro.jwt.authz.header.key") : "authtoken";
private static final String TOKEN_PREFIX = V.notEmpty(BaseConfig.getProperty("diboot.shiro.jwt.token.prefix")) ? BaseConfig.getProperty("diboot.shiro.jwt.token.prefix") : "Bearer ";
public static final String SIGN_KEY = V.notEmpty(BaseConfig.getProperty("diboot.shiro.jwt.signkey"))? BaseConfig.getProperty("diboot.shiro.jwt.signkey") : "Dibo2016Mazc";
// 默认过期时间 2小时
public static final int EXPIRES_IN_MINUTES = V.notEmpty(BaseConfig.getProperty("diboot.shiro.jwt.token.expires.hours")) ? Integer.valueOf(BaseConfig.getProperty("diboot.shiro.jwt.token.expires.hours")) * 60 : 2 * 60;
private static final String ISSUER = V.notEmpty(BaseConfig.getProperty("diboot.shiro.jwt.issuer", new String[0])) ? BaseConfig.getProperty("diboot.shiro.jwt.issuer", new String[0]) : "diboot.com";
private static final String AUTH_HEADER = V.notEmpty(BaseConfig.getProperty("diboot.shiro.jwt.authz.header.key", new String[0])) ? BaseConfig.getProperty("diboot.shiro.jwt.authz.header.key", new String[0]) : "authtoken";
private static final String TOKEN_PREFIX = V.notEmpty(BaseConfig.getProperty("diboot.shiro.jwt.token.prefix", new String[0])) ? BaseConfig.getProperty("diboot.shiro.jwt.token.prefix", new String[0]) : "Bearer ";
public static final String SIGN_KEY = V.notEmpty(BaseConfig.getProperty("diboot.shiro.jwt.signkey", new String[0])) ? BaseConfig.getProperty("diboot.shiro.jwt.signkey", new String[0]) : "Dibo2016Mazc";
public static final int EXPIRES_IN_MINUTES = V.notEmpty(BaseConfig.getProperty("diboot.shiro.jwt.token.expires.hours", new String[0])) ? Integer.valueOf(BaseConfig.getProperty("diboot.shiro.jwt.token.expires.hours", new String[0])) * 60 : 120;
private static final SignatureAlgorithm SIGNATURE_ALGORITHM = SignatureAlgorithm.HS256;
/***