Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
kou | zhao
micro-service-skeleton
提交
506a9ac4
M
micro-service-skeleton
项目概览
kou | zhao
/
micro-service-skeleton
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
micro-service-skeleton
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
506a9ac4
编写于
12月 29, 2017
作者:
M
ManongJu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Zuul 网关统一token校验
上级
c8d0db66
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
142 addition
and
7 deletion
+142
-7
auth-center/src/main/java/com/microservice/skeleton/auth/config/AuthorizationServerConfig.java
...rvice/skeleton/auth/config/AuthorizationServerConfig.java
+14
-5
auth-center/src/main/java/com/microservice/skeleton/auth/config/ResourceServerConfig.java
...croservice/skeleton/auth/config/ResourceServerConfig.java
+2
-2
auth-center/src/main/java/com/microservice/skeleton/auth/config/WebSecurityConfig.java
.../microservice/skeleton/auth/config/WebSecurityConfig.java
+1
-0
auth-center/src/main/java/com/microservice/skeleton/auth/repository/PermissionRepository.java
...ervice/skeleton/auth/repository/PermissionRepository.java
+19
-0
auth-center/src/main/java/com/microservice/skeleton/auth/repository/RoleRepository.java
...microservice/skeleton/auth/repository/RoleRepository.java
+6
-0
auth-center/src/main/java/com/microservice/skeleton/auth/service/PermissionService.java
...microservice/skeleton/auth/service/PermissionService.java
+14
-0
auth-center/src/main/java/com/microservice/skeleton/auth/service/RoleService.java
...a/com/microservice/skeleton/auth/service/RoleService.java
+14
-0
auth-center/src/main/java/com/microservice/skeleton/auth/service/impl/PermissionServiceImpl.java
...ice/skeleton/auth/service/impl/PermissionServiceImpl.java
+24
-0
auth-center/src/main/java/com/microservice/skeleton/auth/service/impl/RoleServiceImpl.java
...roservice/skeleton/auth/service/impl/RoleServiceImpl.java
+24
-0
auth-center/src/main/java/com/microservice/skeleton/auth/service/impl/UserDetailsServiceImpl.java
...ce/skeleton/auth/service/impl/UserDetailsServiceImpl.java
+24
-0
未找到文件。
auth-center/src/main/java/com/microservice/skeleton/auth/config/AuthorizationServerConfig.java
浏览文件 @
506a9ac4
...
@@ -4,6 +4,7 @@ import com.microservice.skeleton.auth.service.impl.UserDetailsServiceImpl;
...
@@ -4,6 +4,7 @@ import com.microservice.skeleton.auth.service.impl.UserDetailsServiceImpl;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.security.authentication.AuthenticationManager
;
import
org.springframework.security.authentication.AuthenticationManager
;
import
org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer
;
import
org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer
;
import
org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter
;
import
org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter
;
...
@@ -13,7 +14,6 @@ import org.springframework.security.oauth2.config.annotation.web.configurers.Aut
...
@@ -13,7 +14,6 @@ import org.springframework.security.oauth2.config.annotation.web.configurers.Aut
import
org.springframework.security.oauth2.provider.ClientDetailsService
;
import
org.springframework.security.oauth2.provider.ClientDetailsService
;
import
org.springframework.security.oauth2.provider.client.JdbcClientDetailsService
;
import
org.springframework.security.oauth2.provider.client.JdbcClientDetailsService
;
import
org.springframework.security.oauth2.provider.token.DefaultTokenServices
;
import
org.springframework.security.oauth2.provider.token.DefaultTokenServices
;
import
org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore
;
import
org.springframework.security.oauth2.provider.token.store.JdbcTokenStore
;
import
org.springframework.security.oauth2.provider.token.store.JdbcTokenStore
;
import
javax.sql.DataSource
;
import
javax.sql.DataSource
;
...
@@ -54,13 +54,22 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
...
@@ -54,13 +54,22 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
endpoints
.
tokenStore
(
jdbcTokenStore
())
endpoints
.
tokenStore
(
jdbcTokenStore
())
.
userDetailsService
(
userDetailsService
)
.
userDetailsService
(
userDetailsService
)
.
authenticationManager
(
authenticationManager
);
.
authenticationManager
(
authenticationManager
);
endpoints
.
tokenServices
(
defaultTokenServices
());
}
/**
* <p>注意,自定义TokenServices的时候,需要设置@Primary,否则报错,</p>
* @return
*/
@Primary
@Bean
public
DefaultTokenServices
defaultTokenServices
(){
DefaultTokenServices
tokenServices
=
new
DefaultTokenServices
();
DefaultTokenServices
tokenServices
=
new
DefaultTokenServices
();
tokenServices
.
setTokenStore
(
endpoints
.
get
TokenStore
());
tokenServices
.
setTokenStore
(
jdbc
TokenStore
());
tokenServices
.
setSupportRefreshToken
(
true
);
tokenServices
.
setSupportRefreshToken
(
true
);
tokenServices
.
setClientDetailsService
(
endpoints
.
getClientDetailsService
());
tokenServices
.
setClientDetailsService
(
clientDetails
());
tokenServices
.
setTokenEnhancer
(
endpoints
.
getTokenEnhancer
());
// tokenServices.setAccessTokenValiditySeconds( (int) TimeUnit.DAYS.toSeconds(30)); // token有效期自定义设置,默认12小时
// tokenServices.setAccessTokenValiditySeconds( (int) TimeUnit.DAYS.toSeconds(30)); // token有效期自定义设置,默认12小时
endpoints
.
tokenServices
(
tokenServices
)
;
return
tokenServices
;
}
}
@Override
@Override
...
...
auth-center/src/main/java/com/microservice/skeleton/auth/config/ResourceServerConfig.java
浏览文件 @
506a9ac4
...
@@ -12,8 +12,8 @@ import org.springframework.security.oauth2.config.annotation.web.configuration.R
...
@@ -12,8 +12,8 @@ import org.springframework.security.oauth2.config.annotation.web.configuration.R
* Time:10:46
* Time:10:46
* ProjectName:Mirco-Service-Skeleton
* ProjectName:Mirco-Service-Skeleton
*/
*/
//
@Configuration
@Configuration
//
@EnableResourceServer
@EnableResourceServer
public
class
ResourceServerConfig
extends
ResourceServerConfigurerAdapter
{
public
class
ResourceServerConfig
extends
ResourceServerConfigurerAdapter
{
@Override
@Override
public
void
configure
(
HttpSecurity
http
)
throws
Exception
{
public
void
configure
(
HttpSecurity
http
)
throws
Exception
{
...
...
auth-center/src/main/java/com/microservice/skeleton/auth/config/WebSecurityConfig.java
浏览文件 @
506a9ac4
...
@@ -53,4 +53,5 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
...
@@ -53,4 +53,5 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
public
void
configure
(
WebSecurity
web
)
throws
Exception
{
public
void
configure
(
WebSecurity
web
)
throws
Exception
{
web
.
ignoring
().
antMatchers
(
"/favor.ioc"
);
web
.
ignoring
().
antMatchers
(
"/favor.ioc"
);
}
}
}
}
auth-center/src/main/java/com/microservice/skeleton/auth/repository/PermissionRepository.java
0 → 100644
浏览文件 @
506a9ac4
package
com.microservice.skeleton.auth.repository
;
import
com.microservice.skeleton.auth.entity.RcMenuEntity
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
/**
* Created by Mr.Yangxiufeng on 2017/12/29.
* Time:12:39
* ProjectName:Mirco-Service-Skeleton
*/
@Repository
public
interface
PermissionRepository
extends
JpaRepository
<
RcMenuEntity
,
Integer
>
{
@Query
(
value
=
"select menu.* from rc_menu menu,rc_privilege p where menu.id=p.menu_id and p.role_id=?1"
,
nativeQuery
=
true
)
List
<
RcMenuEntity
>
getPermissionsByRoleId
(
Integer
roleId
);
}
auth-center/src/main/java/com/microservice/skeleton/auth/repository/RoleRepository.java
浏览文件 @
506a9ac4
...
@@ -2,8 +2,11 @@ package com.microservice.skeleton.auth.repository;
...
@@ -2,8 +2,11 @@ package com.microservice.skeleton.auth.repository;
import
com.microservice.skeleton.auth.entity.RcRoleEntity
;
import
com.microservice.skeleton.auth.entity.RcRoleEntity
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.stereotype.Repository
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
/**
/**
* Created by Mr.Yangxiufeng on 2017/12/27.
* Created by Mr.Yangxiufeng on 2017/12/27.
* Time:16:09
* Time:16:09
...
@@ -11,4 +14,7 @@ import org.springframework.stereotype.Repository;
...
@@ -11,4 +14,7 @@ import org.springframework.stereotype.Repository;
*/
*/
@Repository
@Repository
public
interface
RoleRepository
extends
JpaRepository
<
RcRoleEntity
,
Integer
>{
public
interface
RoleRepository
extends
JpaRepository
<
RcRoleEntity
,
Integer
>{
@Query
(
value
=
"select role.* from rc_role role,rc_user_role ur where role.id=ur.role_id and ur.user_id=?1"
,
nativeQuery
=
true
)
List
<
RcRoleEntity
>
getRoleValuesByUserId
(
Integer
userId
);
}
}
auth-center/src/main/java/com/microservice/skeleton/auth/service/PermissionService.java
0 → 100644
浏览文件 @
506a9ac4
package
com.microservice.skeleton.auth.service
;
import
com.microservice.skeleton.auth.entity.RcMenuEntity
;
import
java.util.List
;
/**
* Created by Mr.Yangxiufeng on 2017/12/29.
* Time:12:37
* ProjectName:Mirco-Service-Skeleton
*/
public
interface
PermissionService
{
List
<
RcMenuEntity
>
getPermissionsByRoleId
(
Integer
roleId
);
}
auth-center/src/main/java/com/microservice/skeleton/auth/service/RoleService.java
0 → 100644
浏览文件 @
506a9ac4
package
com.microservice.skeleton.auth.service
;
import
com.microservice.skeleton.auth.entity.RcRoleEntity
;
import
java.util.List
;
/**
* Created by Mr.Yangxiufeng on 2017/12/29.
* Time:12:30
* ProjectName:Mirco-Service-Skeleton
*/
public
interface
RoleService
{
List
<
RcRoleEntity
>
getRoleValuesByUserId
(
Integer
userId
);
}
auth-center/src/main/java/com/microservice/skeleton/auth/service/impl/PermissionServiceImpl.java
0 → 100644
浏览文件 @
506a9ac4
package
com.microservice.skeleton.auth.service.impl
;
import
com.microservice.skeleton.auth.entity.RcMenuEntity
;
import
com.microservice.skeleton.auth.repository.PermissionRepository
;
import
com.microservice.skeleton.auth.service.PermissionService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
/**
* Created by Mr.Yangxiufeng on 2017/12/29.
* Time:12:38
* ProjectName:Mirco-Service-Skeleton
*/
@Service
public
class
PermissionServiceImpl
implements
PermissionService
{
@Autowired
private
PermissionRepository
permissionRepository
;
@Override
public
List
<
RcMenuEntity
>
getPermissionsByRoleId
(
Integer
roleId
)
{
return
permissionRepository
.
getPermissionsByRoleId
(
roleId
);
}
}
auth-center/src/main/java/com/microservice/skeleton/auth/service/impl/RoleServiceImpl.java
0 → 100644
浏览文件 @
506a9ac4
package
com.microservice.skeleton.auth.service.impl
;
import
com.microservice.skeleton.auth.entity.RcRoleEntity
;
import
com.microservice.skeleton.auth.repository.RoleRepository
;
import
com.microservice.skeleton.auth.service.RoleService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
/**
* Created by Mr.Yangxiufeng on 2017/12/29.
* Time:12:31
* ProjectName:Mirco-Service-Skeleton
*/
@Service
public
class
RoleServiceImpl
implements
RoleService
{
@Autowired
private
RoleRepository
roleRepository
;
@Override
public
List
<
RcRoleEntity
>
getRoleValuesByUserId
(
Integer
userId
)
{
return
roleRepository
.
getRoleValuesByUserId
(
userId
);
}
}
auth-center/src/main/java/com/microservice/skeleton/auth/service/impl/UserDetailsServiceImpl.java
浏览文件 @
506a9ac4
package
com.microservice.skeleton.auth.service.impl
;
package
com.microservice.skeleton.auth.service.impl
;
import
com.microservice.skeleton.auth.entity.RcMenuEntity
;
import
com.microservice.skeleton.auth.entity.RcRoleEntity
;
import
com.microservice.skeleton.auth.entity.RcUserEntity
;
import
com.microservice.skeleton.auth.entity.RcUserEntity
;
import
com.microservice.skeleton.auth.service.PermissionService
;
import
com.microservice.skeleton.auth.service.RoleService
;
import
com.microservice.skeleton.auth.service.UserService
;
import
com.microservice.skeleton.auth.service.UserService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.GrantedAuthority
;
import
org.springframework.security.core.GrantedAuthority
;
import
org.springframework.security.core.authority.SimpleGrantedAuthority
;
import
org.springframework.security.core.userdetails.User
;
import
org.springframework.security.core.userdetails.User
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.security.core.userdetails.UsernameNotFoundException
;
import
org.springframework.security.core.userdetails.UsernameNotFoundException
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.Set
;
/**
/**
...
@@ -22,6 +29,10 @@ import java.util.Set;
...
@@ -22,6 +29,10 @@ import java.util.Set;
public
class
UserDetailsServiceImpl
implements
UserDetailsService
{
public
class
UserDetailsServiceImpl
implements
UserDetailsService
{
@Autowired
@Autowired
private
UserService
userService
;
private
UserService
userService
;
@Autowired
private
RoleService
roleService
;
@Autowired
private
PermissionService
permissionService
;
@Override
@Override
public
UserDetails
loadUserByUsername
(
String
username
)
throws
UsernameNotFoundException
{
public
UserDetails
loadUserByUsername
(
String
username
)
throws
UsernameNotFoundException
{
...
@@ -34,6 +45,19 @@ public class UserDetailsServiceImpl implements UserDetailsService {
...
@@ -34,6 +45,19 @@ public class UserDetailsServiceImpl implements UserDetailsService {
boolean
accountNonExpired
=
true
;
// 过期性 :true:没过期 false:过期
boolean
accountNonExpired
=
true
;
// 过期性 :true:没过期 false:过期
boolean
credentialsNonExpired
=
true
;
// 有效性 :true:凭证有效 false:凭证无效
boolean
credentialsNonExpired
=
true
;
// 有效性 :true:凭证有效 false:凭证无效
boolean
accountNonLocked
=
true
;
// 锁定性 :true:未锁定 false:已锁定
boolean
accountNonLocked
=
true
;
// 锁定性 :true:未锁定 false:已锁定
List
<
RcRoleEntity
>
roleValues
=
roleService
.
getRoleValuesByUserId
(
userEntity
.
getId
());
for
(
RcRoleEntity
role:
roleValues
){
//角色必须是ROLE_开头,可以在数据库中设置
GrantedAuthority
grantedAuthority
=
new
SimpleGrantedAuthority
(
"ROLE_"
+
role
.
getValue
());
grantedAuthorities
.
add
(
grantedAuthority
);
//获取权限
List
<
RcMenuEntity
>
permissionList
=
permissionService
.
getPermissionsByRoleId
(
role
.
getId
());
for
(
RcMenuEntity
menu:
permissionList
)
{
GrantedAuthority
authority
=
new
SimpleGrantedAuthority
(
menu
.
getCode
());
grantedAuthorities
.
add
(
authority
);
}
}
User
user
=
new
User
(
userEntity
.
getUsername
(),
userEntity
.
getPassword
(),
User
user
=
new
User
(
userEntity
.
getUsername
(),
userEntity
.
getPassword
(),
enabled
,
accountNonExpired
,
credentialsNonExpired
,
accountNonLocked
,
grantedAuthorities
);
enabled
,
accountNonExpired
,
credentialsNonExpired
,
accountNonLocked
,
grantedAuthorities
);
return
user
;
return
user
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录