Keycloak oauth2login весенняя загрузка при входе в систему выдает ошибку, доступ запрещен - пользователь анонимный - PullRequest
0 голосов
/ 08 марта 2020

На основе приведенной ниже архитектуры ... Шлюз API - это место, где находится конфигурация oauth2login, и при попытке получить доступ к микросервису нисходящего потока с помощью конфигурации безопасности java ниже. Я продолжаю получать Доступ запрещен (пользователь анонимный) исключение. Как я понимаю, весенний конфиг способен аутентифицировать запрос с теми же учетными данными клиента, что и в конфигурации tje java, но не может каким-либо образом авторизоваться ..

enter image description here

API GATEWAY java config security

@Order(1)
@Configuration
@EnableWebSecurity
public class ApplicationSecurityConfig extends WebSecurityConfigurerAdapter {

  @Override
  protected void configure(HttpSecurity httpSecurity) throws Exception {
   httpSecurity
      .csrf().disable()
      .anonymous().and()
     .authorizeRequests().antMatchers("/downstream/api/**").permitAll()
     .antMatchers("/downstream/api/**").authenticated()
     .and()
     .oauth2Login();
  }

  @Bean
  public ClientRegistrationRepository clientRegistrationRepository() {
    List<ClientRegistration> registrations = new ArrayList<>();
    registrations.add(keycloakClientRegistration());
    return new InMemoryClientRegistrationRepository(registrations);
  }

  private ClientRegistration keycloakClientRegistration() {
    return ClientRegistration.withRegistrationId("jhipster")
      .clientId("DB")
      .clientName("DB")
      .clientSecret("DB-KEY")
      .clientAuthenticationMethod(ClientAuthenticationMethod.BASIC)
      .authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
      .redirectUriTemplate("$KEYCLOAK_PATH/login/oauth2/code/jhipster")
      .scope("openid", "profile", "email", "address", "phone")
      .authorizationUri("$KEYCLOAK_PATH/auth/realms/jhipster/protocol/openid-connect/auth")
      .tokenUri("$KEYCLOAK_PATH/auth/realms/jhipster/protocol/openid-connect/token")
      .userInfoUri("$KEYCLOAK_PATH/auth/realms/jhipster/protocol/openid-connect/userinfo")
      .userNameAttributeName("user_name")
      .jwkSetUri("$KEYCLOAK_PATH/auth/realms/jhipster/protocol/openid-connect/certs")
      .build();
  }

GET https: // $ MY_APP_DOMAIN / api / db / v1 / entity / 1224 с моим правильным oauth 2.0 учетные данные ... auth_grant = auth_code

Продолжает давать исключение:

принципал = anonymousUser, тип = AUTHORIZATION_FAILURE, data = {details = org.springframework.security. web.authentication. WebAuthenticationDetails@ffff8868: RemoteIpAddress: 10.254.22.127; SessionId: hc2gU4OkkhTrpCXJIb8aYGkl753p7H95NNMn6Ve6, type = org.springframework.security.access.AccessDeniedException, message = Доступ запрещен}]]

g ":« Отказано в доступе, пользователь запрещен ( перенаправление на точку входа аутентификации "," logger ":" org.springframework.security.web.access.ExceptionTranslationFilter "," thread ":" XNIO-2 task-16 "," level ":" DEBUG "," stack_trace ": "org.springframework.security.access.AccessDeniedException: доступ запрещен \ n \ tat org.springframework.security.access.vote.AffirmatoryBased.decide (AffirrativeBased. java: 84) \ n \ tat org.springframework.security. access.intercept. *

...