1. 程式人生 > >spring security --- 與cas 結合

spring security --- 與cas 結合

1,新建springboot專案,引入spring security 包,springboot自動啟動springsecurity 配置

2,啟動專案並訪問會提示輸入使用者名稱和密碼

3,繼承UserDetailsService,重寫loaduserByUsername()方法,其中入參為登入傳入的使用者名稱,返回引數為

new User(ss,password,grantedAuthorityList) 返回使用者名稱,密碼,許可權資訊。

   @Component

public class SpringSecurityConfig implements UserDetailsService {

    private static final 
Logger LOGGER = LoggerFactory.getLogger(SpringSecurityConfig.class); @Autowired private PasswordEncoder passwordEncoderDemo; @Autowired private UserDetails userDetailsDemo; @Override public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException { LOGGER.info("
傳入的名稱是{}",s); String ss = passwordEncoderDemo.encode(s); String password = userDetailsDemo.getPassword(); List<GrantedAuthority> grantedAuthorityList = (List<GrantedAuthority>) userDetailsDemo.getAuthorities(); return new User(ss,password,grantedAuthorityList); } }

4,