From edac05f9d8a0e3cda2cf21dffb6af60e4397beee Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 14 Mar 2019 10:08:47 +0100 Subject: [PATCH] [New] Allow to pass password encoding in REST API Request --- .../li/strolch/rest/endpoint/AuthenticationService.java | 8 +++++++- .../li/strolch/rest/endpoint/PrivilegeUsersService.java | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/AuthenticationService.java b/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/AuthenticationService.java index 27c9753bc..ece69828e 100644 --- a/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/AuthenticationService.java +++ b/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/AuthenticationService.java @@ -80,7 +80,13 @@ public class AuthenticationService { String passwordEncoded = login.get("password").getAsString(); byte[] decode = Base64.getDecoder().decode(passwordEncoded); - String passwordString = new String(decode); + String passwordString; + if (login.has("encoding") && !login.get("encoding").getAsString().isEmpty()) { + passwordString = new String(decode, login.get("encoding").getAsString()); + } else { + passwordString = new String(decode); + } + char[] password = passwordString.toCharArray(); if (password.length < 3) { logger.error("Authentication failed: Password was not given or is too short!"); diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/PrivilegeUsersService.java b/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/PrivilegeUsersService.java index 3d518a772..dfa10fc5d 100644 --- a/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/PrivilegeUsersService.java +++ b/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/PrivilegeUsersService.java @@ -280,7 +280,12 @@ public class PrivilegeUsersService { String passwordEncoded = jsonObject.get("password").getAsString(); byte[] decode = Base64.getDecoder().decode(passwordEncoded); - String passwordString = new String(decode); + String passwordString; + if (jsonObject.has("encoding") && !jsonObject.get("encoding").getAsString().isEmpty()) { + passwordString = new String(decode, jsonObject.get("encoding").getAsString()); + } else { + passwordString = new String(decode); + } ServiceHandler svcHandler = RestfulStrolchComponent.getInstance().getComponent(ServiceHandler.class); PrivilegeSetUserPasswordService svc = new PrivilegeSetUserPasswordService();