标签:otf autowire dmi source coder build dex 设置 ref
/**
* 通过重载,配置user-detail服务
* @param auth
* @throws Exception
*/
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// super.configure(auth);
//inMemoryAuthentication()启用用户存储
//withUser方法为内存用户存储添加新用户
//.role("USER") == .authorities("ROLE_USER")
auth.inMemoryAuthentication()
.withUser("user").password("password").roles("USER").and()
.withUser("admin").password("password").roles("USER","ADMIN");
}
AuthenticationManagerBuilder auth
/**
* 通过重载,配置user-detail服务
* @param auth
* @throws Exception
*/
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// super.configure(auth);
//基于数据库
//dataSource是通过自动装配的得到的
//第一个查询中我们获取了用户的用户名、密码、是否启用的信息
//第二个查询查找了用户作为群组的成员说授予的权限
//如果你的数据库设计满足于默认查询的表,那么可以不用自己设置这两个查询
//自定义查询时,所有查询都将用户名作为唯一的参数
auth.jdbcAuthentication().dataSource(dataSource).usersByUsernameQuery("select username,password,true from Spitter" +
" where username = ? ").authoritiesByUsernameQuery("select username,‘ROLE_USER from Spitter where username = ?")
.passwordEncoder(new StandardPasswordEncoder("53cr3t"));
}
/**
* 通过重载,配置user-detail服务
* @param auth
* @throws Exception
*/
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// super.configure(auth);
//基于内存
//inMemoryAuthentication()启用用户存储
//withUser方法为内存用户存储添加新用户
//.role("USER") == .authorities("ROLE_USER")
// auth.inMemoryAuthentication()
// .withUser("user").password("password").roles("USER").and()
// .withUser("admin").password("password").roles("USER","ADMIN");
//基于数据库
//dataSource是通过自动装配的得到的
//第一个查询中我们获取了用户的用户名、密码、是否启用的信息
//第二个查询查找了用户作为群组的成员说授予的权限
//如果你的数据库设计满足于默认查询的表,那么可以不用自己设置这两个查询
//自定义查询时,所有查询都将用户名作为唯一的参数
// auth.jdbcAuthentication().dataSource(dataSource).usersByUsernameQuery("select username,password,true from Spitter" +
// " where username = ? ").authoritiesByUsernameQuery("select username,‘ROLE_USER from Spitter where username = ?")
// .passwordEncoder(new StandardPasswordEncoder("53cr3t"));
//配置自定义用户服务(假如我们需要认证的用户存储在非关系型数据库,如果mongo或者Neo4j,
// 我们需要实现了UserDetailsService的类,这种方式也可用于关系型数据库)
auth.userDetailsService(new SpittrUserService());
}
package spittr.service;
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 java.util.ArrayList;
import java.util.List;
/**
* @version 版权 Copyright(c)2019
* @ClassName:
* @Descripton:
* @author: Shing
* @date: 2020-07-03 06:58
*/
public class SpittrUserService implements UserDetailsService {
// @Autowired
// private UserService userService;
@Override
public UserDetails loadUserByUsername(String usernaem) throws UsernameNotFoundException {
//TODO 通过username查询用户
//创建权限列表
List<GrantedAuthority> authorities = new ArrayList<>();
authorities.add(new SimpleGrantedAuthority("ROLE_SPITTR"));
return new User(,,authorities);
}
}
标签:otf autowire dmi source coder build dex 设置 ref
原文地址:https://www.cnblogs.com/-shing/p/a57a2a10360f2adcce9872025609c1c4.html