springSecurity的使用整合ssm

2021-03-02 16:28

阅读:640

标签:group   12px   ref   跨域   any   logo   disable   schema   ota   

一.导入坐标


org.springframework.security
spring-security-web


org.springframework.security
spring-security-config


org.springframework.security
spring-security-core


org.springframework.security
spring-security-taglibs

二.web.xml中配置

springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy



springSecurityFilterChain
/*

contextConfigLocation

classpath*:spring-security.xml

三.编写springSecurity.xml


xmlns:security="http://www.springframework.org/schema/security"
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">












login-page="/login.jsp"
login-processing-url="/login.do"
default-target-url="/index.jsp"
authentication-failure-url="/failer.jsp"
authentication-success-forward-url="/pages/main.jsp"
/>





 











 

 四.由于controlle层的实现控制都教给了security框架,只要写一个service业务

1.public interface IUserService extends UserDetailsService  定义一个service接口继承UserDetailsService

2.service的实现,重写loadUserByUsername方法

@Service("userServices")//绑定 user-service-ref
@Transactional
public class IUserServiceImpl implements IUserService {
@Autowired
private IUserDao iUserDao;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
UsersInfo usersInfo = iUserDao.findName(username);//获取自己的user类对象属性
//处理自己的对象封装成UserDetails对象,使用UserDetails的实现类User类进行处理
User user =new User(usersInfo.getUsername(),usersInfo.getPassword(),"权限认证的方法");
return user;
}
}

springSecurity的使用整合ssm

标签:group   12px   ref   跨域   any   logo   disable   schema   ota   

原文地址:https://www.cnblogs.com/jerrybu/p/14404285.html


评论


亲,登录后才可以留言!