如何在grails中使用XML用户文件实现身份验证?
作为 grails 的新手,我想了解如何使用 XML 用户文件对用户进行身份验证?例如:只有当凭据(用户名和密码)与 XML 文件中的凭据匹配时,用户才能登录。谁能帮忙举个简单的例子。我基本上想知道要编写哪些附加类或需要修改。请指导!!!
Being a newbie to grails, I want to learn how to authenticate users using an XML users file? For ex: A user is able to login only when the credentials(username & password) match with the one in XML file. Can anyone please help giving a simple example. I basically want to know what additonal classes are to be written or require modifications. Please guide!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Spring Security Core 插件 对用户身份验证数据源提供可插入支持。插件和 Spring Security 都不关心你从哪里获取数据,只关心你实现所需的接口以便其他类可以使用它。
您需要做的就是创建一个
UserDetailsService
实现来解析 XML 并从那里创建一个GrailsUser
实例。请参阅文档中的“11 Custom UserDetailsService”部分,了解示例自定义类和如何连接的描述。The Spring Security Core plugin has pluggable support for the source of user authentication data. Neither the plugin nor Spring Security care where you get the data, just that you implement the required interface so the other classes can use it.
All you'd need to do is create a
UserDetailsService
implementation that parses the XML and creates aGrailsUser
instance from there. See section "11 Custom UserDetailsService" in the documentation for an example customized class and description of how to wire things up.为什么要针对包含用户信息的 xml 文件进行身份验证?最简单、最快的方法是使用 grails 插件 http://www 集成 spring security .grails.org/plugin/spring-security-core。用户存储在数据库中,您可以配置很多东西,例如加密,acls,...
why do you want to authenticate against a xml file containing user information? the easiest and quickest way would be to integration spring security by using the grails plugin http://www.grails.org/plugin/spring-security-core. the user is stored in the database and you can configure lots of things like crypto, acls, ...