SSM整合SpringSecurity

2021-04-11 02:28

阅读:596

YPE html>

标签:角色   mtd   att   配置   lin   log   username   页码   row   

1.pom.xml配置

4.0.0com.qingfeng
	SpringSecurity
	0.0.1-SNAPSHOTwar5.1.3.RELEASEjavax.servlet
			javax.servlet-api
			3.1.0providedorg.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-plugin
                9001/

  

2.web.xml配置

contextConfigLocationclasspath:spring-security.xml
            org.springframework.web.context.ContextLoaderListener
        springSecurityFilterChainorg.springframework.web.filter.DelegatingFilterProxyspringSecurityFilterChain/*

  

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 {
		//构建角色集合 ,项目中此处应该是根据用户名查询用户的角色列表
		List geAuthorities = 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


评论


亲,登录后才可以留言!