Spring Acegi Security实例解析二
来源:互联网 发布:laravel5.4数据库队列 编辑:程序博客网 时间:2024/05/16 06:38
1. 在MySql中执行如下脚本:
Drop TABLE IF EXISTS `test`.`student`;Create TABLE `test`.`student` (`name` varchar(40) NOT NULL,`psw` varchar(10) NOT NULL,`enabled` boolean);insert into student values("lanp","lanpiao",true);Drop TABLE IF EXISTS `test`.`user_privileges`;Create TABLE `test`.`user_privileges` (`name` varchar(40) NOT NULL,`privilege` varchar(40) NOT NULL);insert into user_privileges values("lanp","ROLE_PRESIDENT");
2. 将以下Jar包导入工程中:acegi-security-0.8.3.jar、commons-logging-1.0.4.jar、javax.servlet.jar、mysql-connector-java-5.0.3-bin.jar、oro-2.0.8.jar和spring-1.2-RC2.jar。并要加入工程的classpath中。
3. web.xml配置文件的配置如下:
<?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"><display-name>myacegi</display-name><context-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/applicationContext-acegi-security.xml</param-value></context-param><filter> <filter-name>MyAcegiFilter</filter-name> <filter-class>net.sf.acegisecurity.util.FilterToBeanProxy</filter-class><init-param> <param-name>targetBean</param-name> <param-value>filterChainProxy</param-value> </init-param></filter><filter-mapping> <filter-name>MyAcegiFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><welcome-file-list><welcome-file>index.html</welcome-file><welcome-file>index.htm</welcome-file><welcome-file>index.jsp</welcome-file><welcome-file>default.html</welcome-file><welcome-file>default.htm</welcome-file><welcome-file>default.jsp</welcome-file></welcome-file-list></web-app>
4. applicationContext-acegi-security.xml的配置如下:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"><beans><bean id="filterChainProxy" class="net.sf.acegisecurity.util.FilterChainProxy"> <property name="filterInvocationDefinitionSource"> <value> CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON PATTERN_TYPE_APACHE_ANT /**=httpSessionContextIntegrationFilter,authenticationProcessingFilter </value> </property> </bean> <bean id="httpSessionContextIntegrationFilter" class="net.sf.acegisecurity.context.HttpSessionContextIntegrationFilter"> <property name="context"><value>net.sf.acegisecurity.context.security.SecureContextImpl</value></property> </bean> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"> <value>com.mysql.jdbc.Driver</value> </property> <property name="url"> <value>jdbc:mysql://127.0.0.1:3306/test</value> </property> <property name="username"> <value>root</value> </property> <property name="password"> <value>157891</value> </property> </bean> <bean id="authenticationDao" class="net.sf.acegisecurity.providers.dao.jdbc.JdbcDaoImpl"> <property name="dataSource"><ref bean="dataSource"/></property> <property name="usersByUsernameQuery"> <value>SELECT name, psw, enabled FROM student WHERE name=?</value> </property> <property name="authoritiesByUsernameQuery"> <value>SELECT name, privilege FROM user_privileges where name=?</value> </property></bean><bean id="daoAuthenticationProvider" class="net.sf.acegisecurity.providers.dao.DaoAuthenticationProvider"> <property name="authenticationDao"> <ref bean="authenticationDao"/> </property></bean><bean id="authenticationManager" class="net.sf.acegisecurity.providers.ProviderManager"> <property name="providers"> <list> <ref bean="daoAuthenticationProvider"/> </list> </property></bean><bean id="authenticationEntryPoint" class="net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint"> <property name="loginFormUrl"> <value>/login.jsp</value> </property> <property name="forceHttps"><value>true</value></property></bean><bean id="authenticationProcessingFilter" class="net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilter"> <property name="filterProcessesUrl"> <value>/j_acegi_security_check</value> </property> <property name="authenticationFailureUrl"> <value>/login.jsp?failed=true</value> </property> <property name="defaultTargetUrl"> <value>/jsp/index.jsp</value> </property> <property name="authenticationManager"> <ref bean="authenticationManager"/> </property></bean></beans>
5. 登陆表单如下:
<body><form method="POST" action="j_acegi_security_check"> Name: <input width="100" type="text" name="j_username"><br> Password: <input width="100" type="password" name="j_password"><br> <input type="submit"></form></body>
- Spring Acegi Security实例解析二
- Spring Acegi Security实例解析一
- Spring Acegi Security实例解析三
- Acegi (Spring Security)入门
- spring-security acegi 学习计划
- Acegi (Spring Security)入门
- Acegi (Spring Security)入门
- Acegi (Spring Security)入门
- Acegi-security-samples-tutorial-1.0.7.zip 实例代码解析
- Spring Security(Acegi)实现原理与应用二
- Spring安全系统:Acegi Security Acegi简介
- Spring安全系统:Acegi Security Acegi简介
- Spring安全系统:Acegi Security
- Spring安全系统:Acegi Security
- Spring Security - Acegi 框架介绍
- spring security官网实例解析
- Acegi Security System for Spring 书摘(I)
- Acegi Security System for Spring 书摘(II)
- Action与Command区别
- ARM-Linux移植之(四)——根文件系统构建
- java书籍
- sctp仿真的相关解读
- 读书笔记_windows的APIHook技术_part 2
- Spring Acegi Security实例解析二
- PHP 中使用 Smarty 之五:Smarty 内置变量调解器
- jsp书籍
- 基于VS2010的MFC动态菜单
- 一:构造链式二叉树(二)
- (一)Linux网络编程--网络知识介绍
- matlab相关操作
- Android中的Fragment
- java图像界面开发简单实例