如何使用Hibernate 3带注释的类配置Spring Security 2数据库身份验证? [英] How do I configure Spring Security 2 database authentication with Hibernate 3 Annotated Classes?

查看:137
本文介绍了如何使用Hibernate 3带注释的类配置Spring Security 2数据库身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Hibernate 3(带有JPA批注),Spring 2.5和Spring Security 2.0.5构建应用程序.

I'm building an app using Hibernate 3 (with JPA Annotations), Spring 2.5 and Spring Security 2.0.5.

我想知道我需要在Spring安全性配置文件(applicationContext-security.xml)中的<authentication-provider>标记中放入什么,以便使Spring Security使用我现有的服务层类(AuthenticationService)进行交易.我的自定义用户和角色域对象.

I want to know what I need to put in my <authentication-provider> tag in my spring security config file (applicationContext-security.xml) so that I can get Spring Security to use my existing Service layer class (AuthenticationService) which deals with my custom User and Role domain objects.

我了解Spring Security要求使用以下模式显示两个表:

I understand that Spring Security requires two tables to be present with the following schema:

     create table users(
      username varchar_ignorecase(50) not null primary key,
      password varchar_ignorecase(50) not null,
      enabled boolean not null);

  create table authorities (
      username varchar_ignorecase(50) not null,
      authority varchar_ignorecase(50) not null,
      constraint fk_authorities_users foreign key(username) references users(username));

  create unique index ix_auth_username on authorities (username,authority);;

但是我想使用与上述表定义不同的自己的域对象.

but I want to use my own domain objects which are different to the above table definitions.

有人可以在这里向我指出正确的方向吗?我找不到任何有用的文档,也不确定我想做的事实际上是否可行.

Could someone please point me in the right direction here? I can't find any useful documentation and I'm not sure whether what I want to do is actually possible.

谢谢!

推荐答案

您可以实现自定义

You can implement a custom UserDetailsService as a bridge between your domain and Spring Security. Then you supply Spring Security with it as follows (for Spring Security 2.x):

<security:authentication-provider user-service-ref='myUserDetailsService'/>

<bean id="myUserDetailsService" class="... your implementation ...">
    ...
</bean>

这篇关于如何使用Hibernate 3带注释的类配置Spring Security 2数据库身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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