Java 多oauth客户端spring安全性
我有两个表,每个表中有不同的用户,有两个web应用程序连接到我的Spring后端,每个前端应用程序有一个用户表。我希望每个表的用户使用不同的clientId和clientSecret进行连接。我试图创建两个授权服务器,但似乎不起作用Java 多oauth客户端spring安全性,java,spring,spring-security,spring-security-oauth2,Java,Spring,Spring Security,Spring Security Oauth2,我有两个表,每个表中有不同的用户,有两个web应用程序连接到我的Spring后端,每个前端应用程序有一个用户表。我希望每个表的用户使用不同的clientId和clientSecret进行连接。我试图创建两个授权服务器,但似乎不起作用 public class ClientAuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter { @Autowired private ClientConfig
public class ClientAuthorizationServerConfiguration extends
AuthorizationServerConfigurerAdapter {
@Autowired
private ClientConfigurationProperties clientConfiguration;
private TokenStore tokenStore = new InMemoryTokenStore();
@Autowired
@Qualifier("authenticationManagerBean")
private AuthenticationManager authenticationManager;
@Autowired
private RepositoryClientDetailsService clientDetailsService;
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints)
throws Exception {
endpoints
.tokenStore(this.tokenStore)
.authenticationManager(this.authenticationManager)
.userDetailsService(clientDetailsService);
}
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws
Exception {
clients
.inMemory()
.withClient(clientConfiguration.getClientId())
.authorizedGrantTypes("password", "refresh_token")
.authorities("USER")
.scopes("read", "write")
.resourceIds(ClientApiResourceServerConfiguration.RESOURCE_ID)
.secret("{noop}"+clientConfiguration.getClientSecret());
}
@Bean
@Primary
public DefaultTokenServices tokenServices() {
DefaultTokenServices tokenServices = new DefaultTokenServices();
tokenServices.setSupportRefreshToken(true);
tokenServices.setTokenStore(this.tokenStore);
return tokenServices;
}
@Bean
public PasswordEncoder passwordEncoder() {
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
}
}
这是我的第二个授权服务器
您可以添加一个集中式数据库,仅用于身份验证目的。该数据库将包含所有客户信息(客户ID、客户机密等)和所有用户信息(主要是用户名和密码)。完整的用户信息将保留在各自的数据库中,但此身份验证数据库将只有用户凭据 您的所有应用程序都可以使用客户端凭据授予类型对自己进行身份验证。Spring提供了发出经过身份验证的REST请求的功能
您的所有用户(来自两个应用程序)也可以使用一个集中的身份验证服务器和身份验证数据库进行身份验证。我想如果我尝试这样做,所有用户都可以同时访问这两个应用程序,我在数据库中创建了两个表,第一个表用于app1,第二个表用于app2,但是,如果它们都有相同的oauth客户机id和密码,那么它们可以很容易地向这两个客户机发送请求。在oauth上下文中,app1是一个客户机,app2是另一个客户机。这两个应用程序将具有不同的客户端凭据。在用户表中,用户应该具有指向客户端的外键。这将有助于识别用户属于哪个客户端。现在,例如,app1的用户尝试登录,用户将输入其凭据,然后在幕后(如果启用了客户端凭据授予类型,则app1将需要对自己进行身份验证)app1将获取这些用户的凭据,添加其客户端凭据,如果用户属于该客户端,它将从身份验证服务器获取令牌。谢谢,我将尝试它。
@Configuration
@EnableAuthorizationServer
@Order(1)
public class AuthorizationServerConfiguration extends
AuthorizationServerConfigurerAdapter {
@Autowired
private ApplicationConfigurationProperties configuration;
@Autowired
private RepositoryClientDetailsService clientDetailsService;
private TokenStore tokenStore = new InMemoryTokenStore();
@Autowired
@Qualifier("authenticationManagerBean")
private AuthenticationManager authenticationManager;
@Autowired
private RepositoryUserDetailsService userDetailsService;
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints)
throws Exception {
endpoints
.tokenStore(this.tokenStore)
.authenticationManager(this.authenticationManager)
.userDetailsService(userDetailsService);
}
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws
Exception {
clients
.inMemory()
.withClient(configuration.getClientId())
.authorizedGrantTypes("password", "refresh_token")
.authorities("USER")
.scopes("read", "write")
.resourceIds(RestApiResourceServerConfiguration.RESOURCE_ID)
.secret("{noop}"+configuration.getClientSecret());
}
@Bean
@Primary
public DefaultTokenServices tokenServices() {
DefaultTokenServices tokenServices = new DefaultTokenServices();
tokenServices.setSupportRefreshToken(true);
tokenServices.setTokenStore(this.tokenStore);
return tokenServices;
}
@Bean
public PasswordEncoder passwordEncoder() {
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
}
}