当使用xml配置spring security时,常常在spring-security.xml中使用到如下配置:
<beans:bean id="authenticationProvider"
class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
<beans:property name="userDetailsService" ref="myUserDetailService"/>
<beans:property name="hideUserNotFoundExceptions" value="false"/>
<beans:property name="passwordEncoder" ref="passwordEncoder"></beans:property>
<!-- 对密码加密算法中使用特定的加密盐及种子 -->
<beans:property name="saltSource" ref="saltSource"></beans:property>
</beans:bean>这里的myUserDetailService即为自定义的用户信息处理类,比如下面的代码:
package com.napchen.digital.service.impl;
import com.napchen.digital.bean.Authority;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;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;import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;import javax.annotation.Resource;import java.util.HashSet;
import java.util.List;import java.util.Set;
/**
* Created by NapChen on 2016/11/30 0030.
*/
public class MyUserDetailServiceImpl implements UserDetailsService {
private com.napchen.digital.bean.User user;
@Autowired
@Qualifier("userServiceImpl")
private UserServiceImpl userServiceImpl;
@Autowired private AuthorityServiceImp