关于格式可以复制到markdown里看图片无关大局,我以后会注意整理下格式的
分割线____________________________________
# AuthorizationServer 配置 (认证服务器配置)目前只实现了用户Passwrod登录
![c2e4fbae5f0db68da8dfc3b0634beaec.png](en-resource://database/1268:0)
## 数据库
需要先配置创建数据库
![2c3bf68c357e0d0826fb2d673dfbd9f2.png](en-resource://database/1270:0)
oath_access_token 表 存储access_token
oauth_client_details 存储客户端的信息 例如clientId clientSecret scope(客户端拥有的权限 因为我是自己后台和第三方所以这个无所谓) authorized_grant_type(这个客户端可以使用的认证方式oauth的那四种以逗号分割)
web_server_redirect_uri 授权码模式认证的回调地址
oauth_refresh_token 存储用户用来刷新的token
这些表官网应该有实在不行https://www.funtl.com
还要一些自己的基础数据库根据需求自己建
redis也顺便配置一下就可以了
## 配置SecurityConfig
第一个就是注册一个自己的用户登录校验处理器 也是就是UserDetailsService和密码加密器
``` java
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(myUserDeatisService)
.passwordEncoder(passwordEncoder);
}
```
第二个就是配置一些 url的放行和session的配置如果是适配app小程序什么的就不用配置session了 还要表单登录和csrf 有一些配置是复制别人的我也没看懂
``` java
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()//这句话的意思是下面这些都是授权的配置
.antMatchers("/photo/**/**","register/**/**","/swagger-ui.html#/**","/v2/api-docs", "/configuration/ui", "/swagger-resources", "/configuration/security", "/swagger-ui.html", "/webjars/**","/swagger-resources/configuration/ui","/swagger-ui.html").permitAll() //这句话是这个url不需要用户验证即可访问
.and()
.authorizeRequests().anyRequest().authenticated()
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED)
.and()
.httpBasic()
.and()
.cors()
.and()
.csrf().disable();//关闭csrf的跨站防护功能
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin().and()
.csrf().disable()
.httpBasic();
}
```
第三个配置就属于复制的看不懂有知道评论说一下
``` java
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/favor.ioc");
}
```
第四个就是创建一个authenticationManager放到容器中这个是authorizationConfig要的不明白为什么要配置
``` java
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
```
# AuthorizationConfig
第一个就是决定你的用户的Token的存放地址的 mys