博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring Security
阅读量:2390 次
发布时间:2019-05-10

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

文章目录

在这里插入图片描述

Spring Security快速入门

在这里插入图片描述

spring提供安全认证服务的框架

在这里插入图片描述

在这里插入图片描述

  • 导入Maven依赖
5.0.2.RELEASE
5.0.1.RELEASE
org.springframework
spring-core
${spring.version}
org.springframework
spring-web
${spring.version}
org.springframework
spring-webmvc
${spring.version}
org.springframework
spring-context-support
${spring.version}
org.springframework
spring-test
${spring.version}
org.springframework
spring-jdbc
${spring.version}
org.springframework.security
spring-security-web
${spring.security.version}
org.springframework.security
spring-security-config
${spring.security.version}
javax.servlet
javax.servlet-api
3.1.0
provided
org.apache.maven.plugins
maven-compiler-plugin
3.2
1.8
1.8
UTF-8
org.apache.tomcat.maven
tomcat9-maven-plugin
8090
/
  • web.xml配置
contextConfigLocation
classpath:spring-security.xml
org.springframework.web.context.ContextLoaderListener
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
springSecurityFilterChain
/*
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp

自定义页面

  • Spring-security.xml配置

在这里插入图片描述

spring security认证用户登录

在这里插入图片描述

import org.springframework.security.core.userdetails.UserDetailsService;public interface IUserService extends UserDetailsService {
}

在这里插入图片描述

在这里插入图片描述

@Service("userService")@Transactionalpublic class UserServiceImpl implements IUserService {
@Autowired private IUserDao userDao; @Autowired private BCryptPasswordEncoder bCryptPasswordEncoder; @Override public UserInfo findById(String id) throws Exception{
return userDao.findById(id); } @Override public void save(UserInfo userInfo) throws Exception {
//对密码进行加密处理 userInfo.setPassword(bCryptPasswordEncoder.encode(userInfo.getPassword())); userDao.save(userInfo); } @Override public List
findAll() throws Exception {
return userDao.findAll(); } @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
UserInfo userInfo = null; try {
userInfo = userDao.findByUsername(username); } catch (Exception e) {
e.printStackTrace(); } //处理自己的用户对象封装成UserDetails // User user=new User(userInfo.getUsername(),"{noop}"+userInfo.getPassword(),getAuthority(userInfo.getRoles())); User user = new User(userInfo.getUsername(), userInfo.getPassword(), userInfo.getStatus() == 0 ? false : true, true, true, true, getAuthority(userInfo.getRoles())); return user; } //作用就是返回一个List集合,集合中装入的是角色描述 public List
getAuthority(List
roles) {
List
list = new ArrayList<>(); for (Role role : roles) {
list.add(new SimpleGrantedAuthority("ROLE_" + role.getRoleName())); } return list; }}

完整Spring-security.xml配置文件

权限关联与控制

在这里插入图片描述

待续~

转载地址:http://zaxab.baihongyu.com/

你可能感兴趣的文章
rdp 安全策略
查看>>
Threat Intelligence Quotient Test
查看>>
Cisco路由器上防止DDOS的一些建议
查看>>
系统安全防护之UNIX下入侵检测方法
查看>>
域控渗透技巧
查看>>
Minion security project and 分布式nmap
查看>>
防火墙相关
查看>>
网络性能测试工具Iperf上手指南
查看>>
opensecuritytraining video
查看>>
collective intelligence framework
查看>>
2015年关注的技术书籍
查看>>
windows 2003 server 记录远程桌面的连接登录日志和修改3389连接端口方法
查看>>
samhain:比较变态的入侵检测系统
查看>>
Linux psacct文档
查看>>
使用setuptools自动安装python模块
查看>>
python IDE环境
查看>>
传说中的windows加固 -.... -
查看>>
windows目录监控软件
查看>>
Virus Bulletin malware分析杂志以及paper
查看>>
Security Considerations for AppLocker
查看>>