Skip to content

Commit 32bca5d

Browse files
author
Andrea Giassi
committed
Exposed salt generator endpoint
1 parent 866cdf6 commit 32bca5d

File tree

5 files changed

+33
-1
lines changed

5 files changed

+33
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#### 14/04/2020
44

5+
- Exposed salt generator endpoint
56
- New email validation support
67
- Documentation improvements
78

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ Create and grant a new MySql user on the "users" database.
128128

129129
Open the application.properties file located in /src/main/resources.
130130

131+
Target your localhost MySql database:
132+
133+
spring.datasource.url=jdbc:mysql://localhost:3306/users?useSSL=false&allowPublicKeyRetrieval=true
134+
131135
Set the username and password of the MySql's user:
132136

133137
spring.datasource.username=yourMySqlUser

src/main/java/com/giassi/microservice/demo2/rest/RBACRestController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.giassi.microservice.demo2.rest.users.dtos.RoleDTO;
55
import com.giassi.microservice.demo2.rest.users.entities.Permission;
66
import com.giassi.microservice.demo2.rest.users.entities.Role;
7+
import com.giassi.microservice.demo2.rest.users.services.EncryptionService;
78
import com.giassi.microservice.demo2.rest.users.services.PermissionService;
89
import com.giassi.microservice.demo2.rest.users.services.RoleService;
910
import org.springframework.beans.factory.annotation.Autowired;
@@ -94,4 +95,10 @@ public ResponseEntity<RoleDTO> removePermissionOnRole(@PathVariable("roleId") Lo
9495
return new ResponseEntity(new RoleDTO(roleService.removePermissionOnRole(roleId, permissionKey)), null, HttpStatus.OK);
9596
}
9697

98+
// salt generation
99+
@GetMapping("/salt")
100+
public ResponseEntity<String> generateSalt() {
101+
return new ResponseEntity<String>(EncryptionService.generateSalt(32), HttpStatus.CREATED);
102+
}
103+
97104
}

src/main/java/com/giassi/microservice/demo2/rest/users/services/EncryptionService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
public class EncryptionService {
2222

2323
public static final String ALGORITHM = "PBKDF2WithHmacSHA1";
24+
public static final int KEY_LENGTH = 256;
2425

2526
// demo salt for testing or first setup purpose
2627
public static final String DEFAULT_SALT = "WZeBXmCI9cAz3LyY9Sdllj9l5iPsXC";
2728

2829
private static final Random RANDOM = new SecureRandom();
2930
private static final String ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
3031
private static final int ITERATIONS = 10000;
31-
private static final int KEY_LENGTH = 256;
3232

3333
public static String generateSalt(int length) {
3434
StringBuilder saltStr = new StringBuilder(length);

src/main/resources/microservice-rbac-user-management.postman_collection.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,26 @@
613613
}
614614
},
615615
"response": []
616+
},
617+
{
618+
"name": "rbac - generate salt",
619+
"request": {
620+
"method": "GET",
621+
"header": [],
622+
"url": {
623+
"raw": "localhost:8090/users/rbac/salt",
624+
"host": [
625+
"localhost"
626+
],
627+
"port": "8090",
628+
"path": [
629+
"users",
630+
"rbac",
631+
"salt"
632+
]
633+
}
634+
},
635+
"response": []
616636
}
617637
],
618638
"event": [

0 commit comments

Comments
 (0)