首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Spring Security 学习(三)

2013-02-18 
Spring Security 学习(3)?A) 上篇中用户名和密码直接写在配置文件中,而实际项目中我们是放在数据库中的。好

Spring Security 学习(3)

?

A) 上篇中用户名和密码直接写在配置文件中,而实际项目中我们是放在数据库中的。

好吧 . 开始把用户信息 和权限 放入 数据库 (oracle)

?

1.建表?

?

--用户表create table users(       username varchar2(50) not null primary key ,       password varchar2(50) not null,       enabled char(1) not null --是否禁用);-- 用户权限表create table authorities(       username varchar2(50) not null,       authority varchar2(50) not null);--外键 alter table authorities add constraint fk_username foreign key (username) references users(username);--唯一索引create unique index ix_auth_username on authorities (username,authority);--插入测试数据. INSERT INTO users(username,PASSWORD,enabled)VALUES('admin','21232f297a57a5a743894a0e4a801fc3',1);INSERT INTO users(username,PASSWORD,enabled)VALUES('user','ee11cbb19052e40b07aac0ca060c23ee',1); INSERT INTO authorities VALUES('admin','ROLE_ADMIN');INSERT INTO authorities VALUES('user','ROLE_USER');select * from usersselect * from authorities

?

2.添加Jar 包?

commons-dbcp-1.2.2.jar,commons-pool-1.3.jar,ojdbc6.jar,spring-jdbc-2.5.6.jar

?

3.配置.(applicationContext.xml)

?

<!-- 数据库连接池 (DBCP) --><bean id="dataSource" value="oracle.jdbc.driver.OracleDriver" /><property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:houserent" /><property name="username" value="spring" /><property name="password" value="bdqn" /></bean><!--配置认证管理器 --><security:authentication-manager><security:authentication-provider><security:password-encoder hash="md5" /><!--指定了数据源--><security:jdbc-user-servicedata-source-ref="dataSource" /><!-- <security:user-service> --><!-- <security:user name="user" password="ee11cbb19052e40b07aac0ca060c23ee" --><!-- authorities="ROLE_USER" /> --><!-- </security:user-service> --></security:authentication-provider></security:authentication-manager>

?

现在就可以 测试 登陆信息 是来自数据库了.

?

遗留下来的问题 :

?实际项目中需要将这些放到数据数据库中,那么这些信息在数据库中的表结构是什么,能不能自己定义呢?spring Security将表结构已经定义好了,我们可以参考 发行文档中的. ?继续学习中....

?

热点排行