SSM整合SpringSecurity
2021-04-11 02:28
阅读:585
YPE html>
标签:角色 mtd att 配置 lin log username 页码 row
1.pom.xml配置
4.0.0 com.qingfeng SpringSecurity0.0.1-SNAPSHOT war 5.1.3.RELEASE javax.servlet javax.servlet-api3.1.0 provided org.springframework.security spring-security-core${spring.security.version} org.springframework.security spring-security-web${spring.security.version} org.springframework.security spring-security-config${spring.security.version} org.apache.tomcat.maven tomcat7-maven-plugin9001 /
2.web.xml配置
contextConfigLocation classpath:spring-security.xml org.springframework.web.context.ContextLoaderListener springSecurityFilterChain org.springframework.web.filter.DelegatingFilterProxy springSecurityFilterChain /*
3.spring-security.xml配置
4.UserDetailsServiceImpl.java类
package com.qingfeng.service; 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 { @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { //构建角色集合 ,项目中此处应该是根据用户名查询用户的角色列表 ListgeAuthorities = new ArrayList (); //添加角色ROLE_ADMIN geAuthorities.add(new SimpleGrantedAuthority("ROLE_ADMIN")); /** * 第一参数:username * 第二参数:"$2a$10$rIxa8dDL8F8Bf.TeC5rOeev96e0wTo0FIuLmtdJ6T/a8CptHlAlga"是BCrypt加密的密码 * 第三参数:geAuthorities是它的角色 */ return new User(username,"$2a$10$rIxa8dDL8F8Bf.TeC5rOeev96e0wTo0FIuLmtdJ6T/a8CptHlAlga",geAuthorities); } }
5.编写登录login.html页面
登录
6.编写登录login_error.html页面
登录错误 用户名和密码错误!
7.编写登录index.html页面
欢迎来到 SpringSecurity 欢迎来到 SpringSecurity
8.运行项目,输入http://localhost:9001/地址,用户随便填写,密码:123456
SSM整合SpringSecurity
标签:角色 mtd att 配置 lin log username 页码 row
原文地址:https://www.cnblogs.com/Amywangqing/p/13362484.html
文章来自:搜素材网的编程语言模块,转载请注明文章出处。
文章标题:SSM整合SpringSecurity
文章链接:http://soscw.com/index.php/essay/74068.html
文章标题:SSM整合SpringSecurity
文章链接:http://soscw.com/index.php/essay/74068.html
评论
亲,登录后才可以留言!