У меня есть сервер авторизации на ip 172.30.0.2 и сервер ресурсов на 172.30.0.3.
Внутри application.yml сервера ресурсов, у меня есть:
security:
oauth2:
resource:
userInfoUri: http://172.30.0.2:8080/v1/user
с этой конфигурацией все работает нормально.
Но если я использую:
http://domain-management-query.domain-management-ms:8080/v1/user
Я получаю 400 ошибок. Я получаю ту же ошибку, выполнив команду wget из командной строки из контейнера resouceserver.
Как я могу использовать докерские домены вместо префикса ip?
Я не использую docker-compose для domain-management-query.domain-management-ms, но эта команда запуска docker:
docker run -it --rm -p 8080:8080 --network=jacopetto -v $(pwd):/home/gradle/project --net-alias=domain-management-query.domain-management-ms uniroma1/j8-gradle-ms:1.0 /bin/sh
Из другого сервиса я могу пропинговать его и разрешить по имени хоста.
Моя конфигурация из этой книги: https://github.com/carnellj/spmia-chapter7/ (Аутентификация-сервис + организация-сервис).
служба ресурсов:
@Configuration
public class ResourceServerConfiguration extends
ResourceServerConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception{
http.cors().disable().authorizeRequests().anyRequest().authenticated();
}
@Bean
RequestDumperFilter requestDumperFilter() {
return new RequestDumperFilter();
}
}
Служба авторизации:
@Configuration
public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
@Autowired
private DataSource dataSource;
// The Authentication-
//ManagerBean is used
//by Spring Security to
//handle authentication.
@Override
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
/*
The UserDetailsService is used by Spring
Security to handle user information that
will be returned the Spring Security.
*/
@Override
@Bean
public UserDetailsService userDetailsServiceBean() throws Exception {
return super.userDetailsServiceBean();
}
/**
* The configure() method is
* where you’ll define users, their
* passwords, and their roles.
*/
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("john.carnell")
.password("{noop}password1")
.roles("USER")
.and()
.withUser("william.woodward")
.password("{noop}password2")
.roles("USER", "ADMIN")
;
}
}
AuthorizationServerConfigurerAdapter:
@Configuration
public class JWTOAuth2Config extends AuthorizationServerConfigurerAdapter {
@Autowired
private AuthenticationManager authenticationManager;
@Autowired
private UserDetailsService userDetailsService;
/**
* Which *clients* are going to register to the service.
*/
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("jacopetto")
.secret("{noop}thisissecret")
.authorizedGrantTypes("refresh_token",
"password",
"client_credentials")
.scopes("webclient", "mobileclient");
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints
.authenticationManager(authenticationManager)
.userDetailsService(userDetailsService);
}
@Override
public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
oauthServer.allowFormAuthenticationForClients();
}
}
Я также пытался сократить имя хоста до dom-manag-query.d-m
, но, похоже, не работает.