Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change from single user (config) to database based multi user system. #1165

Open
wants to merge 31 commits into
base: master
Choose a base branch
from

Conversation

fnkbsi
Copy link
Contributor

@fnkbsi fnkbsi commented Jun 2, 2023

Implements multi user access. Uses the steve database to store the "webusers" and their roles. Privileges on websites are set in the source code in SecurityConfiguration.java. Sites for administration of the "webuser" included.
May fixes #991

@fnkbsi fnkbsi marked this pull request as ready for review June 2, 2023 18:37
Copy link
Contributor

@juherr juherr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The feature looks nice but I didn't test yet.

Only @goekay will be able to merge it.

Please consider my remarks because they will help him to review and give feedbacks.

pom.xml Outdated
@@ -772,5 +772,17 @@
<artifactId>encoder</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks the 2 new dependencies are not used. They should be removed IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both dependencies used in SecurityConfiguration.java
by "import org.springframework.boot.jdbc.DataSourceBuilder;" (line 55)

Copy link
Member

@goekay goekay Jun 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

steve is not using spring boot though. it is a spring app, not a spring boot app.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fnkbsi steve uses jooq for the data access. You should be able to replace spring-jdbc by that. Then no need to datasourcebuilder.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@goekay any feedback about the feature itself?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i find the feature very valuable, but need time to to review the code. at a glance, i find that the implementation needs some tidying up which is already happening. thanks @fnkbsi

import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.DelegatingPasswordEncoder;
//import org.springframework.security.core.userdetails.User;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented code doesn't the review. Could you remove the code instead?

fnkbsi and others added 9 commits June 3, 2023 18:45
…initDataSource() (changed to public) to use the dataSource in SecurityConfiguration; deleted initDataSource in dslContext()
@Autowired, also changed position; removed getDataSource Methode with the spring-boot import
…endency org.springframework artifactId spring-jdbc to the springframework section
…ectly;

At dslContext(), if dataSource isn't initialized then run initDataSource()
@@ -82,13 +84,14 @@
@ComponentScan("de.rwth.idsg.steve")
public class BeanConfiguration implements WebMvcConfigurer {

private HikariDataSource dataSource;
@Autowired private HikariDataSource dataSource;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should remove the attribut and replace it by the bean factory method everywhere it is used (spring proxies are not supposed to instanciate more than once)

@@ -127,7 +130,9 @@ private void initDataSource() {
*/
@Bean
public DSLContext dslContext() {
initDataSource();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HikariDataSource dataSource = initDataSource(); // better if named dataSource()

/**
* Password encoding changed with spring-security 5.0.0. We either have to use a prefix before the password to
* indicate which actual encoder {@link DelegatingPasswordEncoder} should use [1, 2] or specify the encoder as we do.
*
* [1] https://spring.io/blog/2017/11/01/spring-security-5-0-0-rc1-released#password-storage-format
* [2] {@link PasswordEncoderFactories#createDelegatingPasswordEncoder()}
*/

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless change

.authorizeHttpRequests(
req -> req.antMatchers(prefix + "/**").hasRole("ADMIN")
)
.authorizeRequests(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the expected rights?

On my side, I'd love that users can read but not create/update/delete.
Admin can do everything.

.antMatchers(prefix + "/ocppTags/" + "**").hasAnyRole("USER", "ADMIN")
.antMatchers(prefix + "/signout/" + "**").hasAnyRole("USER", "ADMIN")
.antMatchers(prefix + "/noAccess/" + "**").hasAnyRole("USER", "ADMIN")
.antMatchers(prefix + "/**").hasRole("ADMIN")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to manage the api route

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The api route is managed by the api key security filter chain.
A similar approach for the api key or a combination of api key and user/password is possible, but needs to be discussed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I forgot it 😅

*/
@Bean
public UserDetailsManager authenticateUsers() {
JdbcUserDetailsManager users = new JdbcUserDetailsManager(dataSource);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be discussed but I think a home-made JooqUserDetailsManager is not a difficult task and will avoid an extra dependency.

@juherr
Copy link
Contributor

juherr commented Jun 19, 2024

@goekay Please, review. The change will improve the product a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support multi users and rbac
3 participants