博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring安全框架:spring-security
阅读量:2240 次
发布时间:2019-05-09

本文共 4076 字,大约阅读时间需要 13 分钟。

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

(1) 相关依赖

org.springframework.security
spring-security-web
org.springframework.security
spring-security-config

(2) spring-security.xml配置文件

(3) web.xml

xxx-sellergoods-web
shoplogin.html
CharacterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
utf-8
CharacterEncodingFilter
/*
xxx-sellergoods-web
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:spring/springmvc.xml
1
xxx-sellergoods-web
*.do
contextConfigLocation
classpath:spring/spring-*.xml
org.springframework.web.context.ContextLoaderListener
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
springSecurityFilterChain
/*

(4) 认证类

import java.util.ArrayList;import java.util.List;import org.springframework.security.core.GrantedAuthority;import org.springframework.security.core.authority.SimpleGrantedAuthority;import org.springframework.security.core.userdetails.User;import org.springframework.security.core.userdetails.UserDetails;import org.springframework.security.core.userdetails.UserDetailsService;import org.springframework.security.core.userdetails.UsernameNotFoundException;public class UserDetailsServiceImpl implements UserDetailsService {    private SellerService sellerService;        public void setSellerService(SellerService sellerService) {        this.sellerService = sellerService;    }    @Override    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {                List
grantAuths = new ArrayList<>(); grantAuths.add(new SimpleGrantedAuthority("ROLE_SELLER")); /** * User: * * 参数: * * 1.用户名 * * 2.密码 * * 3.认证信息(角色) */ // 去数据库进行查询: TbSeller seller = sellerService.findByUserName(username); if(seller != null){ if(seller.getStatus().equals("1")){ return new User(username,seller.getPassword(),grantAuths ); }else{ return null; } } return null; }}

 

转载于:https://www.cnblogs.com/lin-nest/p/10322565.html

你可能感兴趣的文章
泛型与通配符详解
查看>>
BaseServiceImpl中的实现关键点
查看>>
Struts2中的session、request、respsonse获取方法
查看>>
如何理解MVC模型
查看>>
SpringMVC中乱码解决方案
查看>>
SpringMVC中时间格式转换的解决方案
查看>>
post和get请求相关知识点
查看>>
关于try finally 中的return语句的问题
查看>>
RequestBody/ResponseBody处理Json数据
查看>>
springmvc请求参数获取的几种方法
查看>>
在eclipse中创建和myeclipse一样的包结构
查看>>
Java中的IO流
查看>>
java中的关键字
查看>>
如果某个方法是静态的,它的行为就不具有多态性
查看>>
优化Hibernate所鼓励的7大措施
查看>>
Java 8系列之重新认识HashMap
查看>>
HashMap 、 ArrayList、String 重写了equals方法 而Object类(比如User)没有重写
查看>>
Servlet的生命周期
查看>>
Object中的getClass()返回的是当前运行的类
查看>>
加载驱动程序的方法
查看>>