简单测试

一开始看项目的时候不太清楚,spring security的机制和默认配置。比如:默认的登录字段和请求路径还有默认的拦截等等。

下面开始粘代码!还是粘相关详细配置

说明:一开始我是想把spring security和spring统一版本,但是总是出问题。所以这里我用的spring 4.0但security 的3点几的。

1、pom.xml

<spring-security.version>3.2.4.RELEASE</spring-security.version>

<dependency>

<groupId>org.springframework.security</groupId>

<artifactId>spring-security-config</artifactId>

<version>${spring-security.version}</version>

</dependency>

<dependency>

<groupId>org.springframework.security</groupId>

<artifactId>spring-security-taglibs</artifactId>

<version>${spring-security.version}</version>

</dependency>

<dependency>

<groupId>org.springframework.security</groupId>

<artifactId>spring-security-core</artifactId>

<version>${spring-security.version}</version>

</dependency>

<dependency>

<groupId>org.springframework.security</groupId>

<artifactId>spring-security-web</artifactId>

<version>${spring-security.version}</version>

</dependency>

<dependency>

<groupId>org.springframework.security</groupId>

<artifactId>spring-security-ldap</artifactId>

<version>${spring-security.version}</version>

</dependency>

<dependency>

<groupId>org.springframework.security</groupId>

<artifactId>spring-security-taglibs</artifactId>

<version>${spring-security.version}</version>

</dependency>

2、web.xml 全部(因为这里经常报错却是因为security配置)

<?xml version="1.0" encoding="utf-8"?>

<web-app version="2.5"

xmlns="http://java.sun.com/xml/ns/javaee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<display-name>security</display-name>

<listener>

<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>

</listener>

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:applicationContext-*.xml,classpath:spring-security.xml</param-value>

</context-param>

<filter>

<filter-name>encodingFilter</filter-name>

<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

<init-param>

<param-name>encoding</param-name>

<param-value>UTF-8</param-value>

</init-param>

<init-param>

<param-name>forceEncoding</param-name>

<param-value>true</param-value>

</init-param>

</filter>

<filter-mapping>

<filter-name>encodingFilter</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

<!-- SpringSecurity 核心过滤器配置 -->

<filter>

<filter-name>springSecurityFilterChain</filter-name>

<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>

</filter>

<filter-mapping>

<filter-name>springSecurityFilterChain</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

<listener>

<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>

</listener>

<!-- Handles all requests into the application -->

<servlet>

<servlet-name>admin</servlet-name>

<!--<servlet-class>com.sohu.mobile.admin.commons.web.DispatcherController</servlet-class>

-->

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>admin</servlet-name>

<url-pattern>/admin/*</url-pattern>

</servlet-mapping>

<error-page>

<error-code>404</error-code>

<location>/err404.jsp</location>

</error-page>

</web-app>

3、spring-security.xml(spring版本和security版本最好对应,不然总是报错)

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:security="http://www.springframework.org/schema/security"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-4.0.xsd

http://www.springframework.org/schema/security

http://www.springframework.org/schema/security/spring-security-3.2.xsd">

<!-- 配置不过滤的资源(静态资源及登录相关) -->

<security:http pattern="/login.jsp" security="none"></security:http>

<security:http auto-config="true">

<security:intercept-url pattern="/app.jsp" access="ROLE_ADMIN"/>

<security:intercept-url pattern="/**" access="ROLE_ADMIN"/>

<security:form-login login-page="/login.jsp" authentication-failure-url="/login.jsp" default-target-url="/app.jsp"/>

</security:http>

<!--本地配置用户权限-->

<security:authentication-manager>

<security:authentication-provider>

<security:user-service >

<security:user name="admin" password="admin" authorities="ROLE_ADMIN"/>

</security:user-service>

</security:authentication-provider>

</security:authentication-manager>

</beans>

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-06 15:47:14

简单测试的相关文章

centos7搭建ELK Cluster集群日志分析平台(四):简单测试

续之前安装好的ELK集群 各主机:es-1 ~ es-3 :192.168.1.21/22/23 logstash: 192.168.1.24 kibana: 192.168.1.25 测试机:client: 192.168.1.26 在测试机上安装并启动filebeat 1. 下载filebeat  ~]# wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-5.4.0-linux-x86_64.tar.gz

Redis安装及简单测试

题目链接:11645 - Bits 题意:给定一个数字n,要求0-n的二进制形式下,连续11的个数. 思路:和 UVA 11038 这题类似,枚举中间,然后处理两边的情况. 不过本题最大的答案会超过longlong,要用高精度,不过借鉴http://www.cnblogs.com/TO-Asia/p/3214706.html这个人的方法,直接用两个数字来保存一个数字,这样能保存到2个longlong的长度,就足够存放这题的答案了. 代码: #include <stdio.h> #include

简单测试java - properties

import java.io.BufferedInputStream;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.InputStream;import java.util.Enumeration;import java.util.Properties;public class TestPorperty {    /**     * 写入-properties文件:     *     

基于MySQL元数据的Hive的安装和简单测试

引言: Hive是一种强大的数据仓库查询语言,类似SQL,本文将介绍如何搭建Hive的开发测试环境. 1. 什么是Hive? hive是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张数据库表,并提供简单的sql查询功能,可以将sql语句转换为MapReduce任务进行运行. 其优点是学习成本低,可以通过类SQL语句快速实现简单的MapReduce统计,不必开发专门的MapReduce应用,十分适合数据仓库的统计分析. 2.  按照Hive的准备条件 2.1  Hadoop集

Windows IO 性能简单测试

转自:http://bbs.csdn.net/topics/360111289, 有改动. #include <windows.h>#include <stdio.h>#include <process.h>#include<memory>#pragma comment(lib,"ws2_32.lib")ULONGLONG g_nReadCounts=0,g_nWriteCounts=0,g_nOtherCounts=0,g_nReads

构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(37)-文章发布系统④-百万级数据和千万级数据简单测试

我想测试EF在一百万条数据下的显示时间!这分数据应该有很多同学想要,看看EF的性能! 服务器 现在来向SQL2008R2插入1000000条数据吧 declare @i int; set @i=0; while @i<1000000 begin INSERT INTO [AppDB].[dbo].[MIS_Article] ([Id] ,[ChannelId] ,[CategoryId] ,[Title] ,[ImgUrl] ,[BodyContent] ,[Sort] ,[Click] ,[C

简单测试用控件.

props.push('{"prop":"x","min":-100,"max":100}'); props.push('{"prop":"y","min":-100,"max":100}'); props.push('{"prop":"scaleX","min":-1,"max

memcached window版 下载安装,简单测试

官网: http://www.memcached.org/ 只有tag格式的,搞了好久都没找到windows版的,还有很多uri找不开,google的都打不开,中国政府就是威武. 下载地址: http://jehiah.cz/projects/memcached-win32/files/memcached-1.2.1-win32.zip 这个用讯雷可以下载下来! 错误: 通过cmd命令行进入到D:\webEve\memcached(下载后的解压目录) 运行 memcached.exe -d in

Android Socket简单测试

这里是将pc作为server,设备作为客户端. Server端代码: public static final String SERVERIP = "192.168.0.2"; public static final int SERVERPORT = 51706; public void run() { try { System.out.println("S: Connecting..."); ServerSocket serverSocket = new Serve

struts2+hibernate+spring注解版框架搭建以及简单测试(方便脑补)

为了之后学习的日子里加深对框架的理解和使用,这里将搭建步奏简单写一下,目的主要是方便以后自己回来脑补: 1:File--->New--->Other--->Maven--->Maven Project--->Next(之后界面如下所示:) --->Next(点击next之后出现如下界面:选择最后一个 maven-archetype-webapp,然后点击next) --->Next(点击next之后出现如下界面,然后选择好组织号,工程号,版本号即可),最后点击Fi