zoukankan      html  css  js  c++  java
  • Spring Security框架

    Spring Security框架入门

    1.1 Spring Security简介

    Spring Security是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安全框架。它提供了一组可以在Spring应用上下文中配置的Bean,充分利用了Spring IoC,DI(控制反转Inversion of Control ,DI:Dependency Injection 依赖注入)和AOP(面向切面编程)功能,为应用系统提供声明式的安全访问控制功能,减少了为企业系统安全控制编写大量重复代码的工作。

    2.配置文件

    pom.xml

            <!--spring security相关  -->
            <dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-web</artifactId>
                <version>4.1.0.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-config</artifactId>
                <version>4.1.0.RELEASE</version>
            </dependency>

    spring-security.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- 为什么要用2个beans, -->
    <beans:beans xmlns="http://www.springframework.org/schema/security"
        xmlns:beans="http://www.springframework.org/schema/beans" 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.xsd
                            http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
    
    
        
        <!-- 以下页面不被拦截 -->
        <http pattern="/login.html" security="none"></http>
        <http pattern="/login_error.html" security="none"></http>
        
        <!-- 页面拦截规则 -->
        <http use-expressions="false">
            <!-- /** 表示根目录及以下子目录都在匹配范围,access="ROLE_USER"   配置角色名称,必须以ROLE_开头 -->    
             <!-- 当前用户必须有ROLE_USER的角色才能访问根目录及子目录资源-->    
            <intercept-url pattern="/**" access="ROLE_USER" />
            <!--开启表单登录功能  -->
            <form-login login-page="/login.html" default-target-url="/index.html" authentication-failure-url="/login_error.html"/>    
            <csrf disabled="true"/>    <!-- 关闭csrf(跨站请求伪造) ,如果不加会出现错误 403-->
        </http>
        
        
        
        
    
        <!-- 认证管理器 -->
        <authentication-manager>
            <authentication-provider>
                <user-service>
                    <user name="admin" password="123456" authorities="ROLE_USER"/>
                </user-service>        
            </authentication-provider>    
        </authentication-manager>
        
    </beans:beans>
  • 相关阅读:
    mysql去重
    java 实现一套流程管理、流转的思路(伪工作流)
    js模块加载框架 sea.js学习笔记
    使用js命名空间进行模块式开发
    二叉树的基本操作实现(数据结构实验)
    学生信息管理系统-顺序表&&链表(数据结构第一次作业)
    计算表达式的值--顺序栈(数据结构第二次实验)
    使用seek()方法报错:“io.UnsupportedOperation: can't do nonzero cur-relative seeks”错误的原因
    seek()方法的使用
    python中如何打印某月日历
  • 原文地址:https://www.cnblogs.com/binghuaZhang/p/14194741.html
Copyright © 2011-2022 走看看