Spring Security Spring授权服务器0.3.1注册多个RegisteredClientRepository时出现问题

js81xvg6  于 2023-03-12  发布在  Spring
关注(0)|答案(1)|浏览(288)

Hi,
I need register several clients but when I try to do this it this exception is thrown, I have made sure that each client has a different identifier:

  • Caused by: java.lang.IllegalArgumentException: Registered client must be unique. Found duplicate client secret for identifier: appclientes at org.springframework.security.oauth2.server.authorization.client.InMemoryRegisteredClientRepository.lambda$assertUniqueIdentifiers$0(InMemoryRegisteredClientRepository.java:107) at java.base/java.util.concurrent.ConcurrentHashMap$ValuesView.forEach(ConcurrentHashMap.java:4772) at org.springframework.security.oauth2.server.authorization.client.InMemoryRegisteredClientRepository.assertUniqueIdentifiers(InMemoryRegisteredClientRepository.java:95) at org.springframework.security.oauth2.server.authorization.client.InMemoryRegisteredClientRepository.(InMemoryRegisteredClientRepository.java:64) at com.pryconsa.backend.config.AuthorizationServerConfig.registeredClientRepository(AuthorizationServerConfig.java:100) at com.pryconsa.backend.config.AuthorizationServerConfig$$EnhancerBySpringCGLIB$$46216dc1.CGLIB$registeredClientRepository$2() at com.pryconsa.backend.config.AuthorizationServerConfig$$EnhancerBySpringCGLIB$$46216dc1$$FastClassBySpringCGLIB$$b448ca22.invoke() at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) at com.pryconsa.backend.config.AuthorizationServerConfig$$EnhancerBySpringCGLIB$$46216dc1.registeredClientRepository() at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ... 58 common frames omitted *

My code is the following:

@Bean
public RegisteredClientRepository registeredClientRepository() {        
    TokenSettings tokenClient1Settings = TokenSettings.builder()
            .accessTokenTimeToLive(Duration.ofSeconds(client1AccessTokenValiditySeconds))
            .build();
    
    RegisteredClient registeredClient1 = RegisteredClient.withId(client1Id)
            .clientId(client1Id)
            .clientSecret("{noop}" + client1Secret)
            .authorizationGrantType(AuthorizationGrantType.PASSWORD)
            .clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC)
            .tokenSettings(tokenBackofficeSettings)
            .scope("read")
            .scope("write")
            .build();
    
    TokenSettings tokenClient2Settings = TokenSettings.builder()
            .accessTokenTimeToLive(Duration.ofSeconds(client2AccessTokenValiditySeconds))
            .build();
    
    RegisteredClient registeredClient2 = RegisteredClient.withId(client2Id)
            .clientId(client2Id)
            .clientSecret("{noop}" + client2Secret)
            .authorizationGrantType(AuthorizationGrantType.PASSWORD)
            .clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC)
            .tokenSettings(tokenClient2Settings)
            .scope("read")
            .scope("write")
            .build();
    
    return new InMemoryRegisteredClientRepository(List.of(registeredClient1, registeredClient2));
}
r3i60tvu

r3i60tvu1#

我相信异常在这种情况下真的很有帮助。它从字面上告诉你这里出了什么问题。

  • 您已经在数据库中注册了具有该client-id的客户端
  • 或者clientId 1和clientId 2具有相同的值

相关问题