opensingular / singular-keycloak-database-federation

Keycloak User Storage SPI for Relational Databases (Keycloak User Federation, supports postgresql, mysql, oracle and mysql)
Apache License 2.0
120 stars 57 forks source link

Modify the implementation to include Pbkdf2Sha256PasswordHashProviderFactory #20

Closed rohit-uf closed 2 years ago

rohit-uf commented 2 years ago

Hi. I am using keycloak server with django + postgresql DB. I am able to connect with the database but the password hashing algorithm used by Django is PBKDF2 with a SHA256 hash. I would like to add this feature. I am an amateur when it comes to spring boot and keycloak. Can you guys please elaborate upon the following issues:

  1. How can I start approaching this feature
  2. How can I build the JAR file, for only the modified part of code and not the entire src/ folder
dla-c-box commented 2 years ago

From what I see, you'd add the choice in DBUserStorageProviderFactory.java (search for "bcrypt", add yours at the end of this list.) Then in UserRepository.java -> validateCredentials, you'd see what you have to do to validate the credentials using that algorithm. To get the jar file, the build step is here (mvn is maven, a build tool for Java).

rohit-uf commented 2 years ago

@dla-c-box Thanks a lot for the explanation. Actually when I am running mvn clean package in the root of my springboot project, it says "Error - --classpath needs to be specified". I am trying to find resources online to read about maven. If you could provide with some context about the same, that would be great. Thanks

dla-c-box commented 2 years ago

Do you already have a jdk? Otherwise, on Linux, the initial setup could look like this: sudo apt-get update sudo apt-get install openjdk-11-jdk sudo apt install maven

If you are using the VScode editor, the Java extension pack is here.

rohit-uf commented 2 years ago

Hi @dla-c-box . I was able to successfully build and integrate the provider after changing some code. I only had to put target/ folder in the JAR file and it worked. Thanks for your help

rohit-uf commented 2 years ago

Hi @dla-c-box . I found a workaround for my problem. instead of implementing hashing mechanism in JAVA, I am calling an API now and sending username and password over it to validate it from my backend. Eventually I will send the password as an encrypted string.

I wrote the code in UserRepository class, in validateCredentials method and I manually put the jar files of relevant dependencies in the providers/ directory. But still I am seeing this java.lang.NoClassDefFoundError: org/springframework/util/MultiValueMap error.

Could you please help with this?

dla-c-box commented 2 years ago

Did you add a reference to MultiValueMap in your source code? If so, remove it and, if it was used, replace it with native Java classes instead.

rohit-uf commented 2 years ago

Hi @dla-c-box. Yes I have added the reference to that. But I also need WebClient from spring-starter-webflux package. Can I not use the springframework package?

I copied the jar for spring-starter-webflux package in the providers/ folder and then ran kc.sh start-dev command. Is there any way of using this package along with keycloak

Edit: I ran the mvn clean package command and it generated some more JAR files in the dist/ directory. I used that and it worked