Search code examples
spring-bootspring-securityspring-data-mongodbspring-oauth2

No converter found capable of converting from type com.mongodb.BasicDBObject to type org.springframework.security.oauth2.provider.OAuth2Authenticatio


I am using the following and using following libraries:

spring-boot : 1.5.4

spring-security - 3.2.7

spring-oauth : 2.0.7

spring-boot-starter-data-mongodb : 1.5.4

spring-data-mongodb : 1.10.4

When I try get oauthtoken using this POST url: http://localhost:8080/oauth/token?grant_type=password&username=abc&password=xyz&client_id=testing&client_secret=testing using postman I get this error :

 {
"error": "server_error",
"error_description": "No converter found capable of converting from type [com.mongodb.BasicDBObject] to type [org.springframework.security.oauth2.provider.OAuth2Authentication]"
}

Please help

Regards

Kris


Solution

  • I need to provide a converter from DBObject to OAuth2Authentication, I referred to this link Set MongoDb converter programmatically for registering programatically the converters

    MappingMongoConverter converter = new MappingMongoConverter(mongoDbFactory, context);
    converter.setTypeMapper(mapper);
    converter.setCustomConversions(new CustomConversions(
        Arrays.asList(
                new TimeZoneReadConverter(),
                new TimeZoneWriteConverter()
        )
     ));
    converter.afterPropertiesSet();
    MongoTemplate template = new MongoTemplate(mongoDbFactory, converter);
    

    and this link Spring MongoDB mapping OAuth2Authentication which converts DBObject to OAuth2Authentication and I resolved this issue.

    Regards

    kris