-
创建数据库(推荐Mysql)
-
配置数据库连接并设置验证方式为DB
通过数据库配置正确配置数据库连接之后
修改 thain-web/src/main/resources/application.properties中
#通过数据库进行用户验证 thain.login.source=DBAuthentication
-
添加用户
当前版本暂未提供后台管理,添加用户可以通过此方法
com.xiaomi.thain.server.dao.UserDao.insertUser(ThainUser user)
-
配置Ldap并启动服务参考openLdap
LDIF定义如下(定义了基本的用户admin:admin)
dn: {your base DN} objectClass: dcObject objectClass: organization objectClass: top dc: {your DC} o: {your organization} dn: ou=people,{your base DN} objectClass: organizationalUnit objectClass: top ou: people dn: uid=admin,ou=people,{your base DN} objectClass: inetOrgPerson objectClass: organizationalPerson objectClass: person objectClass: top cn: admin sn: admin uid: admin userPassword:: e0NSWVBUfVo2VGdhNGVkQkFjekU=
-
配置Ldap连接并设置验证方式为Ldap
thain-server/src/main/resources/application.properties中添加
spring.ldap.urls=ldap:{ldap-url} spring.ldap.username={ldap-username} spring.ldap.password={ldap-password} spring.ldap.base={ldap-baseDn}
并修改
#通过Ldap进行用户验证 thain.login.source=LdapAuthentication
-
添加用户
添加用户可以通过此方法
com.xiaomi.thain.server.dao.LdapUserDao.save(LdapUser user)
-
申请需要登录的第三方应用的client-id和client-secret并添加两条基本配置:
spring.security.oauth2.client.registration.{clientName}.client-id=${clientId}
spring.security.oauth2.client.registration.{clientName}.client-secret=${clientSecret}更具体配置可以参考spring-security文档
-
如需手动注册ClientRegistration,可以按照如下配置
@Configuration public class OAuth2LoginConfig { //添加客户端并注册bean @Bean public ClientRegistrationRepository clientRegistrationRepository() { return new InMemoryClientRegistrationRepository(this.googleClientRegistration()); } //添加google客户端的配置 private ClientRegistration googleClientRegistration() { return ClientRegistration.withRegistrationId("google") .clientId("google-client-id") .clientSecret("google-client-secret") //... .clientName("Google") .build(); } }
并修改
@EnableWebSecurity @Slf4j public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private final ClientRegistrationRepository clientRegistrationRepository; //... /** * 第三方登录配置 * * @param http HttpSecurity */ private void thirdConfig(HttpSecurity http) throws Exception { http.oauth2Login() .clientRegistrationRepository(clientRegistrationRepository); //... } }
-
修改前端项目thain-fe的登录页面,添加相应第三方登录链接,系统默认提供了google的第三方登录
<a href="/api/oauth2/authorization/{clientName}"></a>
-
如果不需要第三方登录,则删除配置
项目用户权限验证采用spring security框架,更多内容参考spring-security