Spring MVC,从服务层的安全上下文中获取主体 [英] Spring MVC, getting principal from security context in service layer
本文介绍了Spring MVC,从服务层的安全上下文中获取主体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- 在spring控制器中将principal作为参数
Principal principal
有什么好处,然后将其传递给服务层而不是获取服务层立即通过SecurityContextHolder.getContext()。getAuthentication()。getPrincipal()
? - 获得委托人的最佳方法是什么服务层中的详细信息没有检查
getAuthentication()
和getPrincipal()
无处不在的对象(类似于自定义包装器) ?
- What are the advantages to get principal as a parameter
Principal principal
in spring controller and then pass it to service layer over getting principal in the service layer immediately thoughSecurityContextHolder.getContext().getAuthentication().getPrincipal()
? - What is the best approach to get principal details in service layer without checking
getAuthentication()
andgetPrincipal()
objects for null everywhere (something like a custom wrapper)?
推荐答案
-
- 您的服务API将更易于使用。您将直接看到对主体的依赖,因此您不会在主体不存在的环境中错误地调用某些服务方法。
- 一般情况下,对SpringSecurity代码的依赖性越小意味着迁移到新的Spring Security版本时问题就越少。
- 您将能够重用不存在Spring Security的环境中的服务层。
这篇关于Spring MVC,从服务层的安全上下文中获取主体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文