当前位置:   article > 正文

spring security oauth2 常用授权方式配置详细教程(一)_tokenkeyaccess

tokenkeyaccess

1 spring security oauth2 简单配置说明(一)

配套源码:https://download.csdn.net/download/tiancxz/12902941

1.1 工程说明:

授权服务端口10101

资源服务端口10201

  1. <modules>
  2. <!-- 项目依赖-->
  3. <module>spring-security-oauth2-dependencies</module>
  4. <!-- 认证服务器-->
  5. <module>spring-security-oauth2-server</module>
  6. <!--资源服务器-->
  7. <module>spring-security-oauth2-resource</module>
  8. </modules>

2 spring-security-oauth2-server认证服务器配置

2.1 项目结构

OAuth2简单集成使用只需要继承配置两个适配器就行。

AuthorizationServerConfigurerAdapter授权服务配置适配器

WebSecurityConfigurerAdapter网站安全配置适配器

2.2 pom.xml引入

  1. <dependency>
  2. <groupId>org.springframework.cloud</groupId>
  3. <artifactId>spring-cloud-starter-oauth2</artifactId>
  4. </dependency>

2.3 AuthorizationServerConfiguration授权服务配置适配器

  1. @Configuration
  2. //标注为授权服务
  3. @EnableAuthorizationServer
  4. public class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {
  5. //使用内存存储令牌(普通令牌)
  6. @Bean
  7. public TokenStore tokenStore() {
  8. return new InMemoryTokenStore();
  9. }
  10. //设置授权码模式的授权码如何存取,暂时采用内存方式
  11. @Bean
  12. public AuthorizationCodeServices authorizationCodeServices() {
  13. return new InMemoryAuthorizationCodeServices();
  14. }
  15. //配置服务端点信息
  16. @Override
  17. public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
  18. endpoints
  19. .authorizationCodeServices(authorizationCodeServices())//授权码服务
  20. .tokenStore(tokenStore())//令牌管理服务
  21. .allowedTokenEndpointRequestMethods(HttpMethod.POST);
  22. }
  23. //客户端详情服务
  24. @Override
  25. public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
  26. clients.inMemory()// 使用in-memory存储
  27. .withClient("client")// client_id
  28. .secret(new BCryptPasswordEncoder().encode("secret"))//客户端密钥
  29. .authorizedGrantTypes("authorization_code", "password","client_credentials","implicit","refresh_token")// 该client允许的授权类型authorization_code,password,refresh_token,implicit,client_credentials
  30. .scopes("all")// 允许的授权范围
  31. .autoApprove(true)//false跳转到授权页面
  32. //加上验证回调地址
  33. .redirectUris("http://www.baidu.com")
  34. ;
  35. }
  36. //设置认证令牌放行
  37. @Override
  38. public void configure(AuthorizationServerSecurityConfigurer security){
  39. security
  40. .tokenKeyAccess("permitAll()") //oauth/token_key是公开
  41. .checkTokenAccess("permitAll()") //oauth/check_token公开
  42. .allowFormAuthenticationForClients() //表单认证(申请令牌)
  43. ;
  44. }
  45. }

2.4 WebSecurityConfiguration Security网站安配置全适配器

  1. @Configuration
  2. @EnableWebSecurity
  3. @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, jsr250Enabled = true)
  4. public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
  5. //密码编码器
  6. @Bean
  7. public PasswordEncoder passwordEncoder() {
  8. return new BCryptPasswordEncoder();
  9. }
  10. //认证服务器 配置用户认证
  11. @Override
  12. protected void configure(AuthenticationManagerBuilder auth) throws Exception {
  13. auth.inMemoryAuthentication()
  14. //注意roles authorities 在后面的才会生效。
  15. //.roles("r1","r2").authorities("r3","r4") roles无效 authorities有效
  16. //两种选一种
  17. //一般我们简单系统只需根据authorities权限配置就行
  18. .withUser("admin").password(passwordEncoder().encode("123456")).roles("r1","r2").authorities("r3","r4")
  19. .and()
  20. .withUser("user").password(passwordEncoder().encode("123456")).authorities("r3","r4").roles("r1","r2")
  21. ;
  22. }
  23. //安全拦截机制(最重要)
  24. @Override
  25. protected void configure(HttpSecurity http) throws Exception {
  26. http.csrf().disable()
  27. .authorizeRequests()
  28. .antMatchers("/login*").permitAll()
  29. .anyRequest().authenticated()
  30. .and()
  31. .formLogin()
  32. .and()
  33. .csrf().disable() //打开的csrf保护
  34. // .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)//禁用session 默认授权页面将失效
  35. ;
  36. ;
  37. }
  38. }

3 spring-security-oauth2-resource 资源服务器配置

3.1 pom.xml引入

  1. <!-- Spring Security -->
  2. <dependency>
  3. <groupId>org.springframework.cloud</groupId>
  4. <artifactId>spring-cloud-starter-oauth2</artifactId>
  5. </dependency>

3.2 ResourceServerConfiguration 资源服务适配器配置

  1. @Configuration
  2. @EnableResourceServer
  3. //方法拦截器
  4. @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, jsr250Enabled = true)
  5. public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
  6. @Override
  7. public void configure(HttpSecurity http) throws Exception {
  8. http.authorizeRequests()
  9. // 此处r1 r2 使用角色 r3 r4 使用权限
  10. // 验证WebSecurityConfiguration roles authorities 在后面的才会生效。
  11. // roles("r1","r2").authorities("r3","r4") roles无效 authorities有效
  12. .antMatchers("/r1").hasAnyRole("r1")
  13. .antMatchers("/r2").hasAnyRole("r2")
  14. .antMatchers("/r3").hasAnyAuthority("r3")
  15. .antMatchers("/r4").hasAnyAuthority("r4")
  16. .antMatchers("/**").permitAll()
  17. ;
  18. }
  19. //资源服务令牌解析服务 配置远程ResourceServerTokenServices后,可不用设置yml远程security.oauth2配置
  20. @Bean
  21. public ResourceServerTokenServices tokenService() {
  22. //使用远程服务请求授权服务器校验token,必须指定校验token 的url、client_id,client_secret
  23. RemoteTokenServices service=new RemoteTokenServices();
  24. service.setCheckTokenEndpointUrl("http://localhost:10101/oauth/check_token");
  25. service.setClientId("client");
  26. service.setClientSecret("secret");
  27. return service;
  28. }
  29. }

3.3 application.yml配置认证服务器地址、id、密钥

  1. security:
  2. oauth2:
  3. client:
  4. client-id: client
  5. client-secret: secret
  6. access-token-uri: http://localhost:10101/oauth/token
  7. user-authorization-uri: http://localhost:10101/oauth/authorize
  8. resource:
  9. token-info-uri: http://localhost:10101/oauth/check_token

 

4 authorization_code授权码模式

4.1 启动测试

 

4.2 访问获取授权码

打开浏览器,输入地址:

http://localhost:10101/oauth/authorize?client_id=client&response_type=code

第一次访问会跳转到登录页面,输入用户名密码admin 123456,获取授权码

4.3 通过授权码向服务器申请令牌

http://client:secret@localhost:10101/oauth/token

也可以将client:secret@放置在请求参数里面

 

 

4.4 测试令牌

通过POSTMAN测试发现admin可以访问r3,r4。不能访问r1,r2

4.5 校验令牌

http://localhost:10101/oauth/check_token

5 password密码授权模式

对于我们内部网站或客户端,授权码模式过于复杂。可用密码模式做为自由传统网站。

在未对现有代码改动时,我们直接用PostMan调用会报错。

我们需要对现有代码进行改造。

5.1 WebSecurityConfiguration改造

  1. //将认证管理器实例 注入到Spring
  2. @Bean
  3. public AuthenticationManager authenticationManagerBean() throws Exception {
  4. return super.authenticationManagerBean();
  5. }

5.2 AuthorizationServerConfiguration改造

  1. //从spring获取认证管理器实例 支持密码授权模式
  2. @Autowired
  3. public AuthenticationManager authenticationManager;
  4. //配置服务端点信息 通过authenticationManager绑定指定认证管理器实例
  5. @Override
  6. public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
  7. endpoints
  8. .authenticationManager(authenticationManager)//认证管理器 支持密码授权模式
  9. .authorizationCodeServices(authorizationCodeServices())//授权码服务
  10. .tokenStore(tokenStore())//令牌管理服务
  11. .allowedTokenEndpointRequestMethods(HttpMethod.POST);
  12. }

5.3 测试密码授权模式

6 client_credentials客户端授权模式

不需要改动代码,直接上PostMan测试。合适微服务服务后台相互调用。

项目中单独使用安全度不高。需要配合网关gateway进行authorization_code、password授权模式对外部请求资源拦截。

 

7 implicit授权模式

已过时。只合适某些静态资源。无需额外配置。

http://localhost:10101/oauth/authorize?client_id=client&response_type=token

登陆后返回的地址直接加上了token

https://www.baidu.com/#access_token=29cb038d-2b05-4288-9d5d-ab4486a4ed2b&token_type=bearer&expires_in=3599&scope=all

 

 

8 刷新令牌

8.1 AuthorizationServerConfiguration修改支持令牌刷新

  1. //令牌管理服务
  2. public AuthorizationServerTokenServices tokenService() {
  3. //刷新refresh_token模式支持
  4. DefaultTokenServices tokenServices = new DefaultTokenServices();
  5. //配置令牌
  6. tokenServices.setTokenStore(tokenStore());
  7. // access token有效期2个小时
  8. tokenServices.setAccessTokenValiditySeconds(60*60*1);
  9. // refresh token有效期30天
  10. tokenServices.setRefreshTokenValiditySeconds(60*60*24*30);
  11. // 支持使用refresh token刷新access token
  12. tokenServices.setSupportRefreshToken(true);
  13. // 允许重复使用refresh token
  14. tokenServices.setReuseRefreshToken(false);
  15. return tokenServices;
  16. }
  17. //配置服务端点信息
  18. @Override
  19. public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
  20. endpoints
  21. .authorizationCodeServices(authorizationCodeServices())//授权码服务
  22. .authenticationManager(authenticationManager)//认证管理器 支持密码授权模式
  23. // .tokenStore(tokenStore())//令牌 配置令牌管理服务后可以注释
  24. .tokenServices(tokenService())//令牌管理服务
  25. .allowedTokenEndpointRequestMethods(HttpMethod.POST)
  26. ;
  27. }

8.2 测试刷新令牌

 

9 自定义获取数据库用户权限实现

9.1 UserDetailsService实现

根据用户名获取用户的权限

  1. @Service
  2. public class UserDetailsServiceImpl implements UserDetailsService {
  3. @Autowired
  4. private TbUserService tbUserService;
  5. @Autowired
  6. private TbPermissionService tbPermissionService;
  7. @Override
  8. public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
  9. TbUser tbUser = tbUserService.getByUserName(userName);
  10. //框架存放权限的地方
  11. List<GrantedAuthority> grantedAuthorities = Lists.newArrayList();
  12. if (tbUser != null){
  13. List<TbPermission> tbPermissions = tbPermissionService.selectByUserId(tbUser.getId());
  14. tbPermissions.forEach(tbPermission -> {
  15. GrantedAuthority grantedAuthority = new SimpleGrantedAuthority(tbPermission.getEnname());
  16. grantedAuthorities.add(grantedAuthority);
  17. });
  18. }
  19. //认证是交给框架完成的 这边直接返回框架User
  20. return new User(tbUser.getUsername(),tbUser.getPassword(),grantedAuthorities);
  21. }
  22. }

相关数据库表数据

9.2 WebSecurityConfiguration修改

WebSecurityConfiguration加载自定义UserDetailsService

  1. //返回一个自定义数据库获取用户权限的实现
  2. @Autowired
  3. public UserDetailsServiceImpl userDetailsService;
  4. //认证服务器 配置用户认证
  5. @Override
  6. protected void configure(AuthenticationManagerBuilder auth) throws Exception {
  7. auth.userDetailsService(userDetailsService);
  8. // auth.inMemoryAuthentication()
  9. // //注意roles authorities 在后面的才会生效。
  10. // //.roles("r1","r2").authorities("r3","r4") roles无效 authorities有效
  11. // //两种选一种
  12. // //一般我们简单系统只需根据authorities权限配置就行
  13. // .withUser("admin").password(passwordEncoder().encode("123456")).roles("r1","r2").authorities("r3","r4")
  14. // .and()
  15. // .withUser("user").password(passwordEncoder().encode("123456")).authorities("r3","r4").roles("r1","r2")
  16. // ;
  17. }

每次获取token时,都会进入自定义实现从数据库获取权限

http://client:secret@localhost:10101/oauth/token

10 @PreAuthorize开启注解

10.1 引入spring-boot-starter-aop或者aspectjweaver

项目中已经引入spring-boot-starter-web,不用再引入spring-boot-starter-aop或者aspectjweaver。只需修改yml。

10.2 修改yml

如果已经引入spring-boot-starter-web或spring-boot-starter-aop,需要配置aop.auto = true。aspectjweaver不需要修改。

  1. spring:
  2. aop:
  3. auto: true

10.3 ResourceServerConfiguration修改

添加@EnableGlobalMethodSecurity(prePostEnabled = true),注释http安全里面权限验证。

  1. @Configuration
  2. @EnableResourceServer
  3. @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, jsr250Enabled = true)
  4. public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
  5. @Override
  6. public void configure(HttpSecurity http) throws Exception {
  7. http
  8. .exceptionHandling()
  9. .and()
  10. .csrf().disable() //打开的csrf保护
  11. .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)//禁用session
  12. .and()
  13. .authorizeRequests()
  14. // 以下为配置所需保护的资源路径及权限,需要与认证服务器配置的授权部分对应
  15. // 此处r1 r2 使用角色 r3 r4 使用权限
  16. // 验证WebSecurityConfiguration roles authorities 在后面的才会生效。
  17. // roles("r1","r2").authorities("r3","r4") roles无效 authorities有效
  18. // .antMatchers("/r1").hasAnyRole("r1")
  19. // .antMatchers("/r2").hasAnyRole("r2")
  20. // .antMatchers("/r3").hasAnyAuthority("r3")
  21. // .antMatchers("/r4").hasAnyAuthority("r4")
  22. .antMatchers("/**").permitAll()
  23. ;
  24. }

10.4 TbContentController修改

在具体方法添加@PreAuthorize("hasAnyAuthority('r5')")注解

10.5 测试

r4可以访问,r5不能访问

 

11 JWT令牌配置

11.1 pom.xml修改

资源服务器必须引入

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-aop</artifactId>
  4. </dependency>

11.2 添加tokenConfig

认证服务器和资源服务器都需要

  1. @Configuration
  2. public class TokenConfig {
  3. //密钥
  4. private String SIGNING_KEY = "hlcloud";
  5. @Bean
  6. public TokenStore tokenStore() {
  7. //JWT令牌存储方案
  8. return new JwtTokenStore(accessTokenConverter());
  9. }
  10. @Bean
  11. public JwtAccessTokenConverter accessTokenConverter() {
  12. JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
  13. converter.setSigningKey(SIGNING_KEY); //对称秘钥,资源服务器使用该秘钥来验证
  14. return converter;
  15. }
  16. /* @Bean
  17. public TokenStore tokenStore() {
  18. //使用内存存储令牌(普通令牌)
  19. return new InMemoryTokenStore();
  20. }*/
  21. }

11.3 认证服务器修改

AuthorizationServerConfiguration
  1. // //使用内存存储令牌(普通令牌)
  2. // @Bean
  3. // public TokenStore tokenStore() {
  4. // return new InMemoryTokenStore();
  5. // }
  6. //使用JWT令牌存储方案
  7. @Autowired
  8. public TokenStore tokenStore;
  9. //使用jwt令牌转换加密
  10. @Autowired
  11. private JwtAccessTokenConverter accessTokenConverter;
  12. //令牌管理服务
  13. public AuthorizationServerTokenServices tokenService() {
  14. //刷新refresh_token模式支持
  15. DefaultTokenServices tokenServices = new DefaultTokenServices();
  16. //配置令牌
  17. tokenServices.setTokenStore(tokenStore);
  18. // access token有效期24个小时
  19. tokenServices.setAccessTokenValiditySeconds(60*60*24);
  20. // refresh token有效期3天
  21. tokenServices.setRefreshTokenValiditySeconds(60*60*24*3);
  22. // 支持使用refresh token刷新access token
  23. tokenServices.setSupportRefreshToken(true);
  24. // 允许重复使用refresh token
  25. tokenServices.setReuseRefreshToken(false);
  26. //令牌增强 jwt转换
  27. TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
  28. tokenEnhancerChain.setTokenEnhancers(Arrays.asList(accessTokenConverter));
  29. tokenServices.setTokenEnhancer(tokenEnhancerChain);
  30. return tokenServices;
  31. }

11.4 资源服务器修改

ResourceServerConfiguration注释远程调用验证token,jwt本地解密验证。
  1. // //资源服务令牌解析服务 配置远程ResourceServerTokenServices后,可不用设置yml远程auth配置
  2. // @Bean
  3. // public ResourceServerTokenServices tokenService() {
  4. // //使用远程服务请求授权服务器校验token,必须指定校验token 的url、client_id,client_secret
  5. // RemoteTokenServices service=new RemoteTokenServices();
  6. // service.setCheckTokenEndpointUrl("http://localhost:10101/oauth/check_token");
  7. // service.setClientId("client");
  8. // service.setClientSecret("secret");
  9. // return service;
  10. // }

11.5 测试

此时看到返回的令牌已经变长

测试资源服务器

12 认证服务JDBC改造

12.1 授权码JDBC改造

  1. // //设置授权码模式的授权码如何存取,暂时采用内存方式
  2. // @Bean
  3. // public AuthorizationCodeServices authorizationCodeServices() {
  4. // return new InMemoryAuthorizationCodeServices();
  5. // }
  6. //设置授权码模式的授权码如何存取,暂时采用内存方式
  7. @Bean
  8. public AuthorizationCodeServices authorizationCodeServices(DataSource dataSource) {
  9. return new JdbcAuthorizationCodeServices(dataSource);
  10. }
  11. @Autowired
  12. public AuthorizationCodeServices authorizationCodeServices;

12.2 客户端详情JDBC改造

  1. //将客户端信息存储到数据库
  2. @Bean
  3. public JdbcClientDetailsService jdbcClientDetailsService(DataSource dataSource) {
  4. return new JdbcClientDetailsService(dataSource);
  5. }
  6. @Autowired
  7. private JdbcClientDetailsService jdbcClientDetailsService;
  8. //客户端详情服务
  9. @Override
  10. public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
  11. clients.withClientDetails(jdbcClientDetailsService);
  12. // clients.inMemory()// 使用in-memory存储
  13. // .withClient("client")// client_id
  14. // .secret(new BCryptPasswordEncoder().encode("secret"))//客户端密钥
  15. // .authorizedGrantTypes("authorization_code", "password","client_credentials","implicit","refresh_token")// 该client允许的授权类型authorization_code,password,refresh_token,implicit,client_credentials
  16. // .scopes("all")// 允许的授权范围
  17. // .autoApprove(true)//false跳转到授权页面
  18. // //加上验证回调地址
  19. // .redirectUris("http://www.baidu.com")
  20. // ;
  21. }

12.3 资源服务器ResourceServerConfiguration修改

如果不想使用使用resource_ids,可不用做这一步。添加了resid则需要在数据库里面修改响应字段。

  1. @Override
  2. public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
  3. resources.resourceId("res_id")
  4. .stateless(true);
  5. ;
  6. super.configure(resources);
  7. }

12.4 相关表结构

oauth_client_details:存储客户端详情

oauth_code:存储授权码

  1. /*
  2. Navicat Premium Data Transfer
  3. Source Server : 127.0.0.1-test
  4. Source Server Type : MySQL
  5. Source Server Version : 50731
  6. Source Host : 127.0.0.1:3306
  7. Source Schema : oauth2
  8. Target Server Type : MySQL
  9. Target Server Version : 50731
  10. File Encoding : 65001
  11. Date: 30/09/2020 13:46:39
  12. */
  13. SET NAMES utf8mb4;
  14. SET FOREIGN_KEY_CHECKS = 0;
  15. -- ----------------------------
  16. -- Table structure for oauth_access_token
  17. -- ----------------------------
  18. DROP TABLE IF EXISTS `oauth_access_token`;
  19. CREATE TABLE `oauth_access_token` (
  20. `token_id` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  21. `token` blob NULL,
  22. `authentication_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  23. `user_name` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  24. `client_id` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  25. `authentication` blob NULL,
  26. `refresh_token` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  27. PRIMARY KEY (`authentication_id`) USING BTREE
  28. ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
  29. -- ----------------------------
  30. -- Records of oauth_access_token
  31. -- ----------------------------
  32. -- ----------------------------
  33. -- Table structure for oauth_approvals
  34. -- ----------------------------
  35. DROP TABLE IF EXISTS `oauth_approvals`;
  36. CREATE TABLE `oauth_approvals` (
  37. `userId` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  38. `clientId` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  39. `scope` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  40. `status` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  41. `expiresAt` timestamp(0) NULL DEFAULT NULL,
  42. `lastModifiedAt` timestamp(0) NULL DEFAULT NULL
  43. ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
  44. -- ----------------------------
  45. -- Records of oauth_approvals
  46. -- ----------------------------
  47. -- ----------------------------
  48. -- Table structure for oauth_client_details
  49. -- ----------------------------
  50. DROP TABLE IF EXISTS `oauth_client_details`;
  51. CREATE TABLE `oauth_client_details` (
  52. `client_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  53. `resource_ids` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  54. `client_secret` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  55. `scope` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  56. `authorized_grant_types` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  57. `web_server_redirect_uri` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  58. `authorities` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  59. `access_token_validity` int(11) NULL DEFAULT NULL,
  60. `refresh_token_validity` int(11) NULL DEFAULT NULL,
  61. `additional_information` varchar(4096) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  62. `autoapprove` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  63. PRIMARY KEY (`client_id`) USING BTREE
  64. ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
  65. -- ----------------------------
  66. -- Records of oauth_client_details
  67. -- ----------------------------
  68. INSERT INTO `oauth_client_details` VALUES ('client', 'res_id', '$2a$10$/Sm77HZ5AFy.ZhwnjoIxn.VC7TNrr9/RaXZeYVf7V8mqG9VLrF8jK', 'all', 'authorization_code,password,client_credentials,implicit,refresh_token', 'http://www.baidu.com', NULL, NULL, NULL, NULL, 'true');
  69. -- ----------------------------
  70. -- Table structure for oauth_client_token
  71. -- ----------------------------
  72. DROP TABLE IF EXISTS `oauth_client_token`;
  73. CREATE TABLE `oauth_client_token` (
  74. `token_id` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  75. `token` blob NULL,
  76. `authentication_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  77. `user_name` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  78. `client_id` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  79. PRIMARY KEY (`authentication_id`) USING BTREE
  80. ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
  81. -- ----------------------------
  82. -- Records of oauth_client_token
  83. -- ----------------------------
  84. -- ----------------------------
  85. -- Table structure for oauth_code
  86. -- ----------------------------
  87. DROP TABLE IF EXISTS `oauth_code`;
  88. CREATE TABLE `oauth_code` (
  89. `code` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  90. `authentication` blob NULL
  91. ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
  92. -- ----------------------------
  93. -- Table structure for oauth_refresh_token
  94. -- ----------------------------
  95. DROP TABLE IF EXISTS `oauth_refresh_token`;
  96. CREATE TABLE `oauth_refresh_token` (
  97. `token_id` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  98. `token` blob NULL,
  99. `authentication` blob NULL
  100. ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
  101. -- ----------------------------
  102. -- Records of oauth_refresh_token
  103. -- ----------------------------
  104. -- ----------------------------
  105. -- Table structure for tb_permission
  106. -- ----------------------------
  107. DROP TABLE IF EXISTS `tb_permission`;
  108. CREATE TABLE `tb_permission` (
  109. `id` bigint(20) NOT NULL AUTO_INCREMENT,
  110. `parent_id` bigint(20) NULL DEFAULT NULL COMMENT '父权限',
  111. `name` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '权限名称',
  112. `enname` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '权限英文名称',
  113. `url` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '授权路径',
  114. `description` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '备注',
  115. `created` datetime(0) NOT NULL,
  116. `updated` datetime(0) NOT NULL,
  117. PRIMARY KEY (`id`) USING BTREE
  118. ) ENGINE = InnoDB AUTO_INCREMENT = 49 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '权限表' ROW_FORMAT = Dynamic;
  119. -- ----------------------------
  120. -- Records of tb_permission
  121. -- ----------------------------
  122. INSERT INTO `tb_permission` VALUES (37, 0, '系统管理', 'System', '/', NULL, '2019-04-04 23:22:54', '2019-04-04 23:22:56');
  123. INSERT INTO `tb_permission` VALUES (38, 37, '用户管理', 'SystemUser', '/users/', NULL, '2019-04-04 23:25:31', '2019-04-04 23:25:33');
  124. INSERT INTO `tb_permission` VALUES (39, 38, '查看用户', 'SystemUserView', '/users/view/**', NULL, '2019-04-04 15:30:30', '2019-04-04 15:30:43');
  125. INSERT INTO `tb_permission` VALUES (40, 38, '新增用户', 'SystemUserInsert', '/users/insert/**', NULL, '2019-04-04 15:30:31', '2019-04-04 15:30:44');
  126. INSERT INTO `tb_permission` VALUES (41, 38, '编辑用户', 'SystemUserUpdate', '/users/update/**', NULL, '2019-04-04 15:30:32', '2019-04-04 15:30:45');
  127. INSERT INTO `tb_permission` VALUES (42, 38, '删除用户', 'SystemUserDelete', '/users/delete/**', NULL, '2019-04-04 15:30:48', '2019-04-04 15:30:45');
  128. INSERT INTO `tb_permission` VALUES (44, 37, '内容管理', 'resource', '/', NULL, '2019-04-06 18:23:58', '2019-04-06 18:24:00');
  129. INSERT INTO `tb_permission` VALUES (45, 44, '查看内容', 'r1', '/r1', NULL, '2019-04-06 23:49:39', '2019-04-06 23:49:41');
  130. INSERT INTO `tb_permission` VALUES (46, 44, '新增内容', 'r2', '/r2', NULL, '2019-04-06 23:51:00', '2019-04-06 23:51:02');
  131. INSERT INTO `tb_permission` VALUES (47, 44, '编辑内容', 'r3', '/r3', NULL, '2019-04-06 23:51:04', '2019-04-06 23:51:06');
  132. INSERT INTO `tb_permission` VALUES (48, 44, '删除内容', 'r4', '/r4', NULL, '2019-04-06 23:51:08', '2019-04-06 23:51:10');
  133. -- ----------------------------
  134. -- Table structure for tb_role
  135. -- ----------------------------
  136. DROP TABLE IF EXISTS `tb_role`;
  137. CREATE TABLE `tb_role` (
  138. `id` bigint(20) NOT NULL AUTO_INCREMENT,
  139. `parent_id` bigint(20) NULL DEFAULT NULL COMMENT '父角色',
  140. `name` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '角色名称',
  141. `enname` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '角色英文名称',
  142. `description` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '备注',
  143. `created` datetime(0) NOT NULL,
  144. `updated` datetime(0) NOT NULL,
  145. PRIMARY KEY (`id`) USING BTREE
  146. ) ENGINE = InnoDB AUTO_INCREMENT = 38 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '角色表' ROW_FORMAT = Dynamic;
  147. -- ----------------------------
  148. -- Records of tb_role
  149. -- ----------------------------
  150. INSERT INTO `tb_role` VALUES (37, 0, '超级管理员', 'admin', NULL, '2019-04-04 23:22:03', '2019-04-04 23:22:05');
  151. -- ----------------------------
  152. -- Table structure for tb_role_permission
  153. -- ----------------------------
  154. DROP TABLE IF EXISTS `tb_role_permission`;
  155. CREATE TABLE `tb_role_permission` (
  156. `id` bigint(20) NOT NULL AUTO_INCREMENT,
  157. `role_id` bigint(20) NOT NULL COMMENT '角色 ID',
  158. `permission_id` bigint(20) NOT NULL COMMENT '权限 ID',
  159. PRIMARY KEY (`id`) USING BTREE
  160. ) ENGINE = InnoDB AUTO_INCREMENT = 48 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '角色权限表' ROW_FORMAT = Dynamic;
  161. -- ----------------------------
  162. -- Records of tb_role_permission
  163. -- ----------------------------
  164. INSERT INTO `tb_role_permission` VALUES (37, 37, 37);
  165. INSERT INTO `tb_role_permission` VALUES (38, 37, 38);
  166. INSERT INTO `tb_role_permission` VALUES (39, 37, 39);
  167. INSERT INTO `tb_role_permission` VALUES (40, 37, 40);
  168. INSERT INTO `tb_role_permission` VALUES (41, 37, 41);
  169. INSERT INTO `tb_role_permission` VALUES (42, 37, 42);
  170. INSERT INTO `tb_role_permission` VALUES (43, 37, 44);
  171. INSERT INTO `tb_role_permission` VALUES (44, 37, 45);
  172. INSERT INTO `tb_role_permission` VALUES (45, 37, 46);
  173. INSERT INTO `tb_role_permission` VALUES (46, 37, 47);
  174. INSERT INTO `tb_role_permission` VALUES (47, 37, 48);
  175. -- ----------------------------
  176. -- Table structure for tb_user
  177. -- ----------------------------
  178. DROP TABLE IF EXISTS `tb_user`;
  179. CREATE TABLE `tb_user` (
  180. `id` bigint(20) NOT NULL AUTO_INCREMENT,
  181. `username` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户名',
  182. `password` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '密码,加密存储',
  183. `phone` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '注册手机号',
  184. `email` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '注册邮箱',
  185. `created` datetime(0) NOT NULL,
  186. `updated` datetime(0) NOT NULL,
  187. PRIMARY KEY (`id`) USING BTREE,
  188. UNIQUE INDEX `username`(`username`) USING BTREE,
  189. UNIQUE INDEX `phone`(`phone`) USING BTREE,
  190. UNIQUE INDEX `email`(`email`) USING BTREE
  191. ) ENGINE = InnoDB AUTO_INCREMENT = 38 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '用户表' ROW_FORMAT = Dynamic;
  192. -- ----------------------------
  193. -- Records of tb_user
  194. -- ----------------------------
  195. INSERT INTO `tb_user` VALUES (37, 'admin', '$2a$10$9ZhDOBp.sRKat4l14ygu/.LscxrMUcDAfeVOEPiYwbcRkoB09gCmi', '15888888888', 'lee.lusifer@gmail.com', '2019-04-04 23:21:27', '2019-04-04 23:21:29');
  196. -- ----------------------------
  197. -- Table structure for tb_user_role
  198. -- ----------------------------
  199. DROP TABLE IF EXISTS `tb_user_role`;
  200. CREATE TABLE `tb_user_role` (
  201. `id` bigint(20) NOT NULL AUTO_INCREMENT,
  202. `user_id` bigint(20) NOT NULL COMMENT '用户 ID',
  203. `role_id` bigint(20) NOT NULL COMMENT '角色 ID',
  204. PRIMARY KEY (`id`) USING BTREE
  205. ) ENGINE = InnoDB AUTO_INCREMENT = 38 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '用户角色表' ROW_FORMAT = Dynamic;
  206. -- ----------------------------
  207. -- Records of tb_user_role
  208. -- ----------------------------
  209. INSERT INTO `tb_user_role` VALUES (37, 37, 37);
  210. SET FOREIGN_KEY_CHECKS = 1;

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/84364
推荐阅读
相关标签
  

闽ICP备14008679号