spring-boot - 面向所有 API 和用户的集中式 spring secuirty
问题描述
我计划将 spring security 用于我的平台作为集中式。
我有我的身份验证服务器,它为我想要实现安全性的授权进行识别,
我想为所有授权建立一个集中式服务器,集中式服务器将在数据库中拥有所有用户、角色、API、操作和上下文。
Apigetway->Authorisation Server 如果授权正确则 APi gateway->其他微服务
但是当我通过 spring security 时,它在每个微服务中只有 mvc 方法和 preAuthorize 方法,如下所示
mvc方法。
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity web) throws Exception {
// Spring Security ignores URLs of static resources
web.ignoring().requestMatchers(
PathRequest.toStaticResources().atCommonLocations());
}
@Override
protected void configure(HttpSecurity http) throws Exception {
// configure login
http.formLogin()
.loginPage("/login")
.usernameParameter("account")
.passwordParameter("password")
.defaultSuccessUrl("/", true)
.permitAll();
// configure logout
http.logout()
.logoutUrl("/logout")
.logoutSuccessUrl("/login")
.permitAll()
.invalidateHttpSession(true);
// configure URL authorization
http.authorizeRequests()
.mvcMatchers("/signup").permitAll()
.mvcMatchers(HttpMethod.GET, "/issues/").hasAuthority("readIssue")
.mvcMatchers(HttpMethod.GET, "/issue/new").hasAuthority("writeIssue")
.mvcMatchers(HttpMethod.POST, "/issues/").hasAuthority("writeIssue")
.mvcMatchers("/users").hasAuthority("manageUser")
.anyRequest().authenticated();
}
预授权方法
@GetMapping
@PreAuthorize("@securityService.hasPrivilege('READ_USERS') OR principal.username == #model.get('email')")
public String getAccountView(ModelMap model) {
return "user/account";
}
是否有集中的方式来处理弹簧安全?
解决方案
推荐阅读
- pandas - Pandas 折线图 - Y 轴将小数值转换为浮点数
- c# - HackerRank 攀登排行榜
- python - 文本输入的实时自动完成如何在 Python 中工作?
- java - MPAndroidChart 如何更改超过限制线的条形图颜色?
- powershell - 找不到与参数名称“文件”匹配的参数
- python - 将 json 文件与 oracle 表数据进行比较的实用程序
- airflow - 如何在 Airflow 发起追赶?
- beautifulsoup - 使用 BeautifulSoup 提取
- 元素并包含存储它的结构
- angular - 具有服务器端分页“滚动”的角度材料数据表
- python - 获取 TypeError:扩展两个切片列表时,“NoneType”对象不是可迭代错误