Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
education
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李丛阳
education
Commits
cf144d65
Commit
cf144d65
authored
Dec 06, 2017
by
YangZhaoJun1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整
parent
7e5ebffd
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
61 additions
and
6 deletions
+61
-6
Global.java
src/main/java/org/rcisoft/common/component/Global.java
+12
-0
AuthenticationController.java
...org/rcisoft/core/controller/AuthenticationController.java
+3
-2
AuthenticationService.java
.../java/org/rcisoft/core/service/AuthenticationService.java
+1
-1
AuthenticationServiceImpl.java
.../rcisoft/core/service/impl/AuthenticationServiceImpl.java
+22
-2
SysRoleRepository.java
...main/java/org/rcisoft/sys/role/dao/SysRoleRepository.java
+17
-1
SysUserMapper.java
src/main/java/org/rcisoft/sys/user/dao/SysUserMapper.java
+1
-0
application-dev.yml
src/main/resources/application-dev.yml
+5
-0
No files found.
src/main/java/org/rcisoft/common/component/Global.java
View file @
cf144d65
...
...
@@ -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
;
}
src/main/java/org/rcisoft/core/controller/AuthenticationController.java
View file @
cf144d65
...
...
@@ -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
;
}
...
...
src/main/java/org/rcisoft/core/service/AuthenticationService.java
View file @
cf144d65
...
...
@@ -19,7 +19,7 @@ public interface AuthenticationService {
* @param password
* @return
*/
String
login
(
String
username
,
String
password
);
String
login
(
String
username
,
String
password
,
String
userType
);
/**
* 刷新
...
...
src/main/java/org/rcisoft/core/service/impl/AuthenticationServiceImpl.java
View file @
cf144d65
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
;
}
...
...
src/main/java/org/rcisoft/sys/role/dao/SysRoleRepository.java
View file @
cf144d65
...
...
@@ -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
);
}
src/main/java/org/rcisoft/sys/user/dao/SysUserMapper.java
View file @
cf144d65
...
...
@@ -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
);
}
src/main/resources/application-dev.yml
View file @
cf144d65
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment