0

カスタム認証サーバーとクライアントを実装しようとしています。このコードを例として使用します。ユーザーを使用しないように Tonr2 アプリケーションを変更しました。この2つのアプリケーションを変換したい。Tonr2 は、Sparklr2 からのセッションに基づいてユーザーのセッションを作成する必要があります。今、私はこの部分を修正しました:

Sparklr2 (ResourceConfiguration クラス):

@Bean
    public OAuth2ProtectedResourceDetails sparklr() {
        ClientCredentialsResourceDetails details = new ClientCredentialsResourceDetails();
        details.setId("sparklr/tonr");
        details.setClientId("tonr");
        details.setClientSecret("secret");
        details.setAccessTokenUri(accessTokenUri);
        details.setAuthenticationScheme(AuthenticationScheme.query);
        details.setClientAuthenticationScheme(AuthenticationScheme.form);
        details.setScope(Arrays.asList("read", "write"));
        return details;
    }

Tonr2 では:

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
// I removed all users
//  @Override
//  protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//      auth.inMemoryAuthentication().withUser("marissa").password("wombat").roles("USER").and().withUser("sam")
//              .password("kangaroo").roles("USER");
//  }

@Override
public void configure(WebSecurity web) throws Exception {
    web.ignoring().antMatchers("/resources/**");
}

@Override
protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
            .antMatchers("/sparklr/**").permitAll();
}

}

と:

@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
     clients.inMemory().withClient("tonr")
                .resourceIds(SPARKLR_RESOURCE_ID)
                .authorizedGrantTypes("client_credentials")
                        //.authorities("ROLE_CLIENT")
                .scopes("read", "write")
                .secret("secret");

しかし、私は得ました:

RestTemplate - POST request for "http://localhost:8080/sparklr2/oauth/token" resulted in 401 (Unauthorized); invoking error handler
error="access_denied", error_description="Error requesting access token."
at org.springframework.security.oauth2.client.token.OAuth2AccessTokenSupport.retrieveToken(OAuth2AccessTokenSupport.java:145)

修正方法は?または、これを適切に行う方法の例がありますか?

4

0 に答える 0