royclarkson / spring-rest-service-oauth

A simple OAuth protected REST service built with Spring Boot and Spring Security OAuth

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adding new users

28formica77 opened this issue · comments

Hi - I have this working nicely but want to be able to add new users. I can't work out how to get the entries into the table that maps users to roles. If I try to save the object without the role mapping I get a constraint violation but the id is only set on save so how can I do this? Any advice greatly appreciated.

Thanks

Anthony

In this sample app the users are being loaded from /src/main/resources/import.sql. How are you trying to add users?

I wanted to add users from a client registration page so I created an appropriate method in the controller. I have this working with custom SQL inserts, first to the user_info table then to the user_role table. This works fine but I am bypassing most of the hibernate code with custom SQL. I never found a way of saving a user object [userRepository.save(newUser)] with a valid hashset to include the roles. My solution feels unsatisfactory in that I am not using the Spring features fully.

I think create a rest API named /register in a controller and add .antMatchers("/oauth/**", "/register").permitAll() to ResourceServerConfiguration.configure() will do the trick.