💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# 第一步 ~~~ @Configuration public class SecurityConfiguration extends WebSecurityConfigurerAdapter { @Autowired private UserDetailsService userDetailsService; @Override public void configure(AuthenticationManagerBuilder auth) throws Exception { auth.userDetailsService(userDetailsService)//自定义设置类 .passwordEncoder(password()); } @Bean //加密方式 public PasswordEncoder password(){ return new BCryptPasswordEncoder(); } } ~~~ # 第二步 ***** ~~~ import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.AuthorityUtils; 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.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; import java.util.List; @Service("userDetailsService") public class MyUserDetailsService implements UserDetailsService { @Override public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException { BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); String password = passwordEncoder.encode("admin");//加密密码 List<GrantedAuthority> auths = AuthorityUtils.commaSeparatedStringToAuthorityList("auths");//权限集合 return new User("admin",password,auths);//用户名,密码,权限 } } ~~~ ![](https://img.kancloud.cn/ca/57/ca5715c6325f28b3a541a4d5899ba0bb_1507x718.png)