Commit cf144d65 authored by YangZhaoJun1's avatar YangZhaoJun1

调整

parent 7e5ebffd
......@@ -186,5 +186,17 @@ public class Global {
@Value("${global.path.che_project_init_location}")
private String CHE_PROJECT_INIT_LOCATION;
/*管理员Code*/
@Value("global.code.admin")
private String adminCode;
/*教师Code*/
@Value("global.code.teacher")
private String teacherCode;
/*学生Code*/
@Value("global.code.student")
private String studentCode;
}
......@@ -32,8 +32,9 @@ public class AuthenticationController {
*/
@PostMapping(value = "${jwt.route.authentication.path}")
public Result login(@RequestParam("username")String username,
@RequestParam("password")String password){
final String token = authenticationServiceImpl.login(username, password);
@RequestParam("password")String password,
@RequestParam("userType")String userType){
final String token = authenticationServiceImpl.login(username, password, userType);
Result result = ResultGenerator.genSuccessResult(token);
return result;
}
......
......@@ -19,7 +19,7 @@ public interface AuthenticationService {
* @param password
* @return
*/
String login(String username, String password);
String login(String username, String password, String userType);
/**
* 刷新
......
package org.rcisoft.core.service.impl;
import org.rcisoft.common.component.Global;
import org.rcisoft.core.exception.ServiceException;
import org.rcisoft.core.result.ResultExceptionEnum;
import org.rcisoft.core.result.ResultServiceEnums;
import org.rcisoft.core.service.AuthenticationService;
import org.rcisoft.core.util.JwtUtil;
import org.rcisoft.sys.role.dao.SysRoleRepository;
import org.rcisoft.sys.role.entity.SysRole;
import org.rcisoft.sys.user.dao.SysUserMapper;
import org.rcisoft.sys.user.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -36,8 +40,13 @@ public class AuthenticationServiceImpl implements AuthenticationService {
@Autowired
private SysUserMapper sysUserMapper;
@Autowired
private SysRoleRepository sysRoleRepository;
@Autowired
private PasswordEncoder passwordEncoder;
@Autowired
private Global global;
@Value("${jwt.tokenHead}")
......@@ -58,13 +67,24 @@ public class AuthenticationServiceImpl implements AuthenticationService {
}
@Override
public String login(String username, String password) {
public String login(String username, String password, String userType) {
UsernamePasswordAuthenticationToken upToken = new UsernamePasswordAuthenticationToken(username, password);
/*进入到 UserDetailsService(JwtUserDetailServiceImpl) loadUserByUsername 方法*/
final Authentication authentication = authenticationManager.authenticate(upToken);
SecurityContextHolder.getContext().setAuthentication(authentication);
final UserDetails userDetails = userDetailsService.loadUserByUsername(username);
List<SysRole> role = sysRoleRepository.queryCodeByUsername(username);
if(role.size()!=0){
if (userType.equals("1")&&!global.getAdminCode().equals(role.get(0).getCode())){//1代表请求后台,只有管理员能够访问
throw new ServiceException(ResultServiceEnums.ROLE_ERROR);
}else if(global.getAdminCode().equals(role.get(0).getCode())){//代表请求前台,教师和学生可以请求,管理员不可以
throw new ServiceException(ResultServiceEnums.ROLE_ERROR);
}
}else{
throw new ServiceException(ResultServiceEnums.ROLE_ERROR);
}
final String token = JwtUtil.generateToken(userDetails);
SecurityContextHolder.getContext().setAuthentication(authentication);
return token;
}
......
......@@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Select;
import org.rcisoft.core.base.BaseMapper;
import org.rcisoft.sys.dept.entity.DeptRole;
import org.rcisoft.sys.role.entity.SysRole;
import org.rcisoft.sys.user.entity.SysUser;
import org.springframework.stereotype.Repository;
import java.util.List;
......@@ -146,6 +147,21 @@ public interface SysRoleRepository extends BaseMapper<SysRole> {
@Delete("<script>DELETE from sys_role_menu where ROLE_ID=#{roleId}</script>")
int deleteRoleMenuByRoleId(@Param("roleId") String roleId);
@Select("<script>select * from s_role where user_id = #{businessId} </script>")
@Select("<script>SELECT sr.* from s_role sr " +
"LEFT JOIN s_r_user_role sur ON sr.business_id = sur.role_id " +
"LEFT JOIN s_user su on su.business_id = sur.user_id " +
"where su.business_id = #{businessId} " +
"and sr.del_flag = '0' " +
"and sr.flag = '1'</script>")
@ResultMap(value = "BaseResultMap")
List<SysRole> findRolesByUserId(String businessId);
@Select("<script>SELECT sr.* from s_role sr " +
"LEFT JOIN s_r_user_role sur ON sr.business_id = sur.role_id " +
"LEFT JOIN s_user su on su.business_id = sur.user_id " +
"where su.login_name = #{username} " +
"and sr.del_flag = '0' " +
"and sr.flag = '1'</script>")
@ResultMap(value = "BaseResultMap")
List<SysRole> queryCodeByUsername(String username);
}
......@@ -17,4 +17,5 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
@Select("<script>select * from s_user where login_name = #{username}</script>")
@ResultMap(value = "BaseResultMap")
List<SysUser> queryUserByName(String username);
}
......@@ -120,3 +120,8 @@ global:
is_server_linux: 5
max_code_length: 15
session_admin_header_value: pYez25-y7nqPfm9seY2S
code:
admin: 1001
teacher: 1002
student: 1003
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