-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14785 from antoniodvr/quarkus-14284
jpa-security custom password type
- Loading branch information
Showing
11 changed files
with
170 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...curity-jpa/deployment/src/test/java/io/quarkus/security/jpa/CustomPasswordMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.quarkus.security.jpa; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class CustomPasswordMapperTest extends JpaSecurityRealmTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(testClasses) | ||
.addClasses(CustomPasswordUserEntity.class, CustomPasswordProvider.class) | ||
.addAsResource("custom-password-mapper/import.sql", "import.sql") | ||
.addAsResource("custom-password-mapper/application.properties", "application.properties")); | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...security-jpa/deployment/src/test/java/io/quarkus/security/jpa/CustomPasswordProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.quarkus.security.jpa; | ||
|
||
import javax.xml.bind.DatatypeConverter; | ||
|
||
import org.wildfly.security.password.Password; | ||
import org.wildfly.security.password.interfaces.SimpleDigestPassword; | ||
|
||
public class CustomPasswordProvider implements PasswordProvider { | ||
@Override | ||
public Password getPassword(String pass) { | ||
byte[] digest = DatatypeConverter.parseHexBinary(pass); | ||
return SimpleDigestPassword.createRaw(SimpleDigestPassword.ALGORITHM_SIMPLE_DIGEST_SHA_256, digest); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...curity-jpa/deployment/src/test/java/io/quarkus/security/jpa/CustomPasswordUserEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.quarkus.security.jpa; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
|
||
@UserDefinition | ||
@Table(name = "test_user") | ||
@Entity | ||
public class CustomPasswordUserEntity { | ||
@Id | ||
@GeneratedValue | ||
public Long id; | ||
|
||
@Column(name = "username") | ||
@Username | ||
public String name; | ||
|
||
@Column(name = "password") | ||
@Password(value = PasswordType.CUSTOM, provider = CustomPasswordProvider.class) | ||
public String pass; | ||
|
||
@Roles | ||
public String role; | ||
} |
8 changes: 8 additions & 0 deletions
8
.../security-jpa/deployment/src/test/resources/custom-password-mapper/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
quarkus.datasource.db-kind=h2 | ||
quarkus.datasource.username=sa | ||
quarkus.datasource.password=sa | ||
quarkus.datasource.jdbc.url=jdbc:h2:mem:custom-password-mapper' | ||
|
||
quarkus.hibernate-orm.sql-load-script=import.sql | ||
quarkus.hibernate-orm.database.generation=drop-and-create | ||
#quarkus.hibernate-orm.log.sql=true |
3 changes: 3 additions & 0 deletions
3
extensions/security-jpa/deployment/src/test/resources/custom-password-mapper/import.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
INSERT INTO test_user (id, username, password, role) VALUES (1, 'admin', '8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918', 'admin'); | ||
INSERT INTO test_user (id, username, password, role) VALUES (2, 'user','04f8996da763b7a969b1028ee3007569eaf3a635486ddab211d512c85b9df8fb', 'user'); | ||
INSERT INTO test_user (id, username, password, role) VALUES (3, 'noRoleUser','bc84dfdb831a33641357ef365ddafd8d2c2d190242893355dab9b33067e99083', ''); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
extensions/security-jpa/runtime/src/main/java/io/quarkus/security/jpa/PasswordProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.quarkus.security.jpa; | ||
|
||
import org.wildfly.security.password.Password; | ||
|
||
/** | ||
* Provides the {@link Password} according to how the password is hashed in the database. | ||
*/ | ||
public interface PasswordProvider { | ||
Password getPassword(String pass); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters