修复但数据源时报错。增加查询用户未拥有的角色接口

This commit is contained in:
winLsy
2018-03-16 13:13:02 +08:00
parent 8a69fb8eee
commit b1017df4f0
11 changed files with 80 additions and 11 deletions
@@ -29,6 +29,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
@@ -21,7 +21,7 @@ import java.util.ArrayList;
import java.util.List;
/**
* OAuth2协议标准服务商实现配置类,配置token的生成存储策略
* OAuth2协议标准服务商实现配置类,配置token的生成存储策略。用于第三方的应用进行登录
* @author lsy
*/
@Configuration
@@ -15,7 +15,7 @@ import org.springframework.security.oauth2.config.annotation.web.configuration.R
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
/**
* OAuth2协议标准服务提供实现配置类,资源服务器的配置
* OAuth2协议标准服务提供实现配置类,资源服务器的配置。用于受信任的自家的应用和进行密码模式的直接登录
* @author lsy
*/
@Configuration
@@ -65,12 +65,14 @@ public class AuthorizationResourceConfig extends ResourceServerConfigurerAdapter
//定义身份认证失败后处理对象
.failureHandler(msAuthenticationFailureHandler)
.and()
.authorizeRequests()//下面是权限配置
//下面是权限配置
.authorizeRequests()
//当访问这个页面的时候不进行身份认证,对用户自定义的登录页也不进行权限认证
.antMatchers(SecurityConstants.MOBILE_LOGIN_PROCESSOR_URI
, SecurityConstants.FORM_LOGIN_PROCESSOR_URI
, SecurityConstants.GET_VALIDATE_CODE_URI
, SecurityConstants.LOGIN_PAGE
, "/druid/**"
)
.permitAll()
//任何请求
@@ -84,6 +86,4 @@ public class AuthorizationResourceConfig extends ResourceServerConfigurerAdapter
.apply(smsCodeAuthenticationSecurityConfig)
.and();
}
}
@@ -33,15 +33,15 @@ public class DynamicDataSourceConfig {
public static final String DYNAMIC_DATA_SOURCE = "dynamicDataSource";
/**
* 当dataSource存在时
* 当masterDataSource存在时,dataSource是从数据源
*/
@Resource(name = DATA_SOURCE)
private DataSource dataSource;
/**
* 从数据源
* 主数据源
*/
@Autowired
@Autowired(required = false)
@Qualifier(MASTER_DATA_SOURCE)
private DataSource masterDataSource;
@@ -24,7 +24,7 @@ import java.util.ArrayList;
@Setter
public class MybatisParamConfig {
/**
* pojo所在的包
* entity所在的包,多个请使用逗号分隔
*/
@NotNull
private String typeAliasesPackage;
@@ -38,7 +38,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
//刷新令牌必须有ROLE_USER权限
User user = new User(username,upmsUser.getPassword()
,enable,true,true,enable
, AuthorityUtils.createAuthorityList("admin","ROLE_USER"));
, AuthorityUtils.createAuthorityList("admin","ROLE_USER"));
return user;
}
}
@@ -13,6 +13,7 @@ import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.websocket.server.PathParam;
import java.util.ArrayList;
@@ -65,10 +66,31 @@ public class UpmsRoleController {
return upmsRoleService.deleteByIds(ids);
}
/**
* 根据用户的id 查询用户所拥有的角色
* @param userId
* @return
*/
@ApiOperation("根据用户id查询角色")
@GetMapping("/userId")
public ServerResponse getRolesByUserId(@RequestParam("userId") Integer userId){
return upmsRoleService.getRolesByUserId(userId);
}
/**
* @param userId 用户的id
* @param roleName 角色名称
* @param pageNum
* @param pageSize
* @return
*/
@ApiOperation("根据用户id和角色名称查询角色")
@GetMapping("/selectRolesUserNotHaveByConditionPage")
public ServerResponse selectRolesUserNotHaveByConditionPage(@RequestParam("userId") @NotNull Integer userId,
@RequestParam(value = "roleName",required = false) String roleName,
@RequestParam(required = false,defaultValue = "1") int pageNum,
@RequestParam(required = false,defaultValue = "10") int pageSize){
return upmsRoleService.selectRolesUserNotHaveByConditionPage(userId, roleName, pageSize, pageNum);
}
}
@@ -32,5 +32,19 @@ public interface UpmsRoleMapper extends SsmMapper<UpmsRole,Integer> {
@Override
int deleteByPrimaryKeys(List<Integer> integers);
/**
* 根据用户
* @param userId 根据用户id查询已拥有的角色
* @return
*/
List<Role> selectRoleJoinWithUserId(@Param("userId") Integer userId);
/**
* 根据角色名称查询用户未拥有的角色
* @param userId 用户的id
* @param roleName 角色的名称
* @return
*/
List<Role> selectRolesUserNotHaveByConditionPage(@Param("userId") Integer userId,@Param("roleName") String roleName);
}
@@ -8,4 +8,14 @@ import com.micro.fast.common.service.SsmService;
*/
public interface UpmsRoleService<T,ID> extends SsmService<T,ID>{
ServerResponse getRolesByUserId(Integer useId);
/**
* 根据用户id和角色名称查询用户所拥有的角色
* @param userId 用户的id
* @param roleName 角色名称
* @param pageSize 单页的数量
* @param pageNum 页码
* @return
*/
ServerResponse selectRolesUserNotHaveByConditionPage(Integer userId,String roleName,int pageSize,int pageNum);
}
@@ -1,5 +1,7 @@
package com.micro.fast.upms.service.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.micro.fast.boot.starter.common.response.ServerResponse;
import com.micro.fast.common.service.impl.SsmServiceImpl;
import com.micro.fast.upms.dao.UpmsRoleMapper;
@@ -35,4 +37,12 @@ implements UpmsRoleService<UpmsRole,Integer>,InitializingBean {
List<Role> roles = mapper.selectRoleJoinWithUserId(useId);
return ServerResponse.successMsgData("根据用户id查询角色成功",roles);
}
@Override
public ServerResponse selectRolesUserNotHaveByConditionPage(Integer userId, String roleName, int pageSize, int pageNum) {
PageHelper.startPage(pageNum,pageSize,"ctime_desc");
List<Role> roles = mapper.selectRolesUserNotHaveByConditionPage(userId, roleName);
PageInfo pageInfo = new PageInfo(roles);
return ServerResponse.successData(pageInfo);
}
}
@@ -116,6 +116,7 @@
version = #{version,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
<!--自定义-->
<select id="selectByCondition" resultType="com.micro.fast.upms.pojo.UpmsRole">
SELECT <include refid="Base_Column_List"/> FROM upms_role
@@ -137,6 +138,13 @@
<select id="selectRoleJoinWithUserId" resultType="javax.management.relation.Role">
SELECT <include refid="Base_Column_List"/> FROM upms_role WHERE
id IN (SELECT upms_user_role.user_role_id WHERE user_id = #{userId})
id IN (SELECT role_id from upms_user_role WHERE user_id = #{userId})
</select>
<select id="selectRolesUserNotHaveByConditionPage" resultType="javax.management.relation.Role">
SELECT <include refid="Base_Column_List" /> FROM upms_role WHERE id not in (select role_id from upms_user_role WHERE upms_user_role.user_id = #{userId})
<if test="roleName !=null">
and name like #{roleName}
</if>
</select>
</mapper>