向Spring安全上下文中存储的主体对象添加其他详细信息 [英] Adding additional details to principal object stored in spring security context

查看:769
本文介绍了向Spring安全上下文中存储的主体对象添加其他详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring 3.0和Spring Security 3.我能够使用Spring Security对数据库进行身份验证。使用:

I am using Spring 3.0 and Spring Security 3. I am able to authenticate a user against a database using Spring Security. Using:

SecurityContextHolder.getContext().getAuthentication().getPrincipal()

我能够检索当前登录用户的用户名。我希望添加其他详细信息,例如用户标识和模块访问存储在Spring Security上下文中的主体对象,以便我以后可以检索它。如何向主体对象添加其他详细信息,然后如何在jsp或java类中检索它。如果可能,请提供相应的代码段。

I am able to retrieve username of the current logged in user. I wish to add additional details like user id and the module accesses to the principal object stored in Spring Security context so that I can retrieve it later. How can I add additional details to the principal object and then how can I retrieve it later on a jsp or java class. Please provide an appropriate code snippet if possible.

编辑:我使用JDBC访问我的数据库。

I am using JDBC to access my database.

在此先感谢。

推荐答案

为了向经过身份验证的用户添加更多详细信息。您需要首先创建自己的User对象实现,该实现应该扩展Spring安全性User对象。之后,您可以添加要添加到经过身份验证的用户的属性。完成此操作后,您需要在UserDetailService中返回用户对象的实现(如果您没有使用LDAP进行身份验证)。此链接提供了向经过身份验证的用户添加更多详细信息的详细信息 -

In order to add more details to the authenticated user. You need to first create your own implementation of the User object which should extend the spring security User object. After that you can add the properties you want to add to the authenticated user. Once this is done you need to return your implementation of the user object in UserDetailService (If you are not using LDAP for authentication). This link provides the details for adding more details to the authenticated user--

http://javahotpot.blogspot.in/2013/12/spring-security-adding-more-information.html

这篇关于向Spring安全上下文中存储的主体对象添加其他详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆