V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
beginor
V2EX  ›  程序员

来个另类的, 让 Spring Web 应用使用 ASP.NET Core Identity 的数据库进行用户认证

  •  
  •   beginor ·
    beginor · 2021-03-26 12:47:48 +08:00 · 1640 次点击
    这是一个创建于 1098 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近开始接触 Java 的 Spring 全家桶, 感觉 Spring 在安全认证方面做的比较松散, 不如 ASP.NET Core Identity 来的严谨和完善。

    认真学习 Spring Security 和 Apache Shiro 这两个常用的认证类库之后, 发现它们居然可以无缝对接到 ASP.NET Core Identity 的数据库, 甚至使用同样的用户信息进行认证。

    aspnet_core_identity_db_schema

    有兴趣的可以看看 https://beginor.github.io/2021/03/26/using-aspnet-core-identity-database-with-spring.html

    也可以直接浏览源代码 https://github.com/beginor/spring-identity-demo

    第 1 条附言  ·  2021-03-26 16:56:08 +08:00
    在数据库层面基本上统一了 .NET 和 Spring 应用的认证, 使用相同的数据库, 保护企业现有的资产, 比如使用原来的 .NET 后台管理用户、 角色、 权限、 菜单以及相互绑定, 而在新开发的 Spring 应用中直接使用这些信息。
    6 条回复    2021-03-26 16:47:20 +08:00
    xuanbg
        1
    xuanbg  
       2021-03-26 13:06:07 +08:00
    Spring Security 和 Apache Shiro 这两个一点都不好用
    beginor
        2
    beginor  
    OP
       2021-03-26 13:39:01 +08:00
    @xuanbg 那么请问 Spring 应用的话用什么做认证更好用呢?
    zoharSoul
        3
    zoharSoul  
       2021-03-26 13:44:57 +08:00
    @beginor 写个拦截器验证下 token 完事
    hantsy
        4
    hantsy  
       2021-03-26 13:49:08 +08:00
    用同样的数据库?真奇葩啊。

    你完全可以用 .Net Identity Server 作为安全方案 。
    hantsy
        5
    hantsy  
       2021-03-26 13:52:03 +08:00
    Identity Server 符合 Oauth2,OIDC 标准,与 Spring Secuirty 集成,几行配置就完成了。
    https://docs.microsoft.com/en-us/dotnet/architecture/cloud-native/identity-server
    beginor
        6
    beginor  
    OP
       2021-03-26 16:47:20 +08:00
    @zoharSoul @hantsy 不是一个层面上的问题, 我要实现的是一套用户表, 同时给 .net 和 java 使用
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2715 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 00:21 · PVG 08:21 · LAX 17:21 · JFK 20:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.