2016-12-24 3 views
1

ユーザーがアカウントにサインアップできるアプリケーションがあります。私たちの認証とユーザーサービスはUAAですので、実際にユーザーがいなくても安全なエンドポイントと通信できる必要があります。Spring Cloudセキュリティ - 認証なしのリクエストを許可する

1つのマイクロサービスから別のものへの通話を許可するためにSpring Cloud Securityを設定するには、UAAと通信してユーザーを作成しますか?

したがって、2つの主要なマイクロサービスが利用されています。最初のWebアプリケーションはWebアプリケーションをホストし、Zuulを使用して2番目のマイクロサービスに転送します。このマイクロサービスはUAAと通信し、他のアプリケーション固有のユーザー要求を処理します。

私が最初にmicroservice(ランディングページ)は、第2のmicroservice(ユーザ情報)で

@SpringBootApplication 
@EnableZuulProxy 
@EnableOAuth2Sso 
@EnableEurekaClient 
@EnableAutoConfiguration 
public class LandingPageUiApplication extends WebSecurityConfigurerAdapter { 

    public static void main(String[] args) { 
     SpringApplication.run(LandingPageUiApplication.class, args); 
    } 

    @Override 
    public void configure(HttpSecurity http) throws Exception { 
     http.csrf().disable().authorizeRequests().anyRequest().permitAll(); 
    } 
} 

と、この上でこのWebSecurityConfigurerAdapterを持っている:

@SpringBootApplication 
@EnableCircuitBreaker 
@EnableFeignClients 
public class UserInformationServiceApplication { 

    public static void main(String[] args) { 
     SpringApplication.run(UserInformationServiceApplication.class, args); 
    } 

    @Bean 
    public ModelMapper modelMapper() { 
     return new ModelMapper(); 
    } 
} 

は残念ながら、私はRESTのアクセスに苦労しています最初のMicroservice上のエンドポイントと、2番目のMicroserviceに何かを転送することはできません。私は一般的に401応答コードを受け取ります。それぞれのapplication.yamlファイルはクライアントとResouceサーバーとしてUAAと

ランディングページApplication.yaml

spring: 
    application: 
    name: Landing Page 
    aop: 
    proxy-target-class: true 

security: 
    oauth2: 
    client: 
     accessTokenUri: http://localhost:8080/uaa/oauth/token 
     userAuthorizationUri: http://localhost:8080/uaa/oauth/authorize 
     clientId: landing-page 
     clientSecret: landing-page-secret 
     scope: openid,uaa.admin,uaa.user 
    resource: 
     userInfoUri: http://localhost:8080/uaa/userinfo 

zuul: 
    routes: 
    users: 
     serviceId: USER-INFO-SERVICE 
     path: /users/** 

server: 
    port: 8081 

eureka: 
    instance: 
    hostname: 127.0.0.1 
    nonSecurePort: ${server.port} 
    leaseRenewalIntervalInSeconds: 10 
    metadataMap: 
     instanceId: ${spring.application.name}:${server.port} 
    client: 
    serviceUrl: 
     defaultZone: http://localhost:8761/eureka/ 
    region: default 
    registryFetchIntervalSeconds: 5 

とUserInfoSerevice Application.yaml

server: 
    port: 0 

security: 
    oauth2: 
    client: 
     clientId: user-info-service 
     clientSecret: app-secret 
    resource: 
     jwt: 
     keyUri: http://localhost:8080/uaa/token_key 


spring: 
    application: 
    name: user-info-service 
    profiles: development,default 
    datasource: 
    url: jdbc:h2:mem:AZ;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE 
    driverClassName: org.h2.Driver 
    username: sa 
    password: 
    database-platform: org.hibernate.dialect.H2Dialect 


eureka: 
    instance: 
    hostname: 127.0.0.1 
    nonSecurePort: ${server.port} 
    leaseRenewalIntervalInSeconds: 10 
    metadataMap: 
     instanceId: ${spring.application.name}:${server.port} 
    client: 
    serviceUrl: 
     defaultZone: http://localhost:8761/eureka/ 
    region: default 
    registryFetchIntervalSeconds: 5 

任意の助けを通信するように設定されています大変感謝しています。 MS

@Configuration 
    @EnableOAuth2Sso 
    @EnableAutoConfiguration 
    protected static class TestConfiguration extends WebSecurityConfigurerAdapter { 


     @Override 
     public void configure(HttpSecurity http) throws Exception { 
      http.csrf().disable().antMatcher("/**") 
       .authorizeRequests() 
       .anyRequest().permitAll(); 
     } 

    } 

と子で、次:

答えて

1

答えは親MSにおけるこのWebConfigAdapterの設定を入れていた

@Configuration 
    @Order(-10) 
    @EnableOAuth2Client 
    @EnableAutoConfiguration 
    protected static class TestConfiguration extends WebSecurityConfigurerAdapter { 


     @Override 
     public void configure(HttpSecurity http) throws Exception { 
      http.csrf().disable().anonymous().authenticationFilter(new AnonymousAuthenticationFilter("HALLO")) //allow anonymous access 
        .and() 
        .authorizeRequests() 
        .antMatchers("/**") 
        .permitAll(); 
     } 
    } 
関連する問題